Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kBET metrics does not work with scipy==1.14.0 #412

Open
kollo97 opened this issue Jul 18, 2024 · 1 comment
Open

kBET metrics does not work with scipy==1.14.0 #412

kollo97 opened this issue Jul 18, 2024 · 1 comment

Comments

@kollo97
Copy link

kollo97 commented Jul 18, 2024

Hi,

first of all I want to say that this is a great tool!

I ran into an error related to the recently released scipy version 1.14.0.
When trying to calculate the kBET score of an integration, I currently get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[49], line 17
      1 selected_metrics = {
      2     'ari_' : True,
      3     'nmi_' : True,
   (...)
     15     'n_cores' : 20
     16 }
---> 17 metrics_seurat_all = scib.metrics.metrics(adata, adata_seurat, batch_key, label_key, embed = 'X_pca', **selected_metrics)
     18 metrics_harmony_all = scib.metrics.metrics(adata, adata_harmony, batch_key, label_key, embed = 'X_harmony', **selected_metrics)
     19 metrics_hvg_all = scib.metrics.metrics(adata, adata_hvg, batch_key, label_key, embed = 'X_pca', **selected_metrics)

File ~/miniforge3/envs/angl_BM/lib/python3.12/site-packages/scib/metrics/metrics.py:407, in metrics(adata, adata_int, batch_key, label_key, embed, cluster_key, cluster_nmi, ari_, nmi_, nmi_method, nmi_dir, silhouette_, si_metric, pcr_, cell_cycle_, organism, hvg_score_, isolated_labels_, isolated_labels_f1_, isolated_labels_asw_, n_isolated, graph_conn_, trajectory_, kBET_, lisi_graph_, ilisi_, clisi_, subsample, n_cores, type_, verbose)
    405 if kBET_:
    406     print("kBET...")
--> 407     kbet_score = kBET(
    408         adata_int,
    409         batch_key=batch_key,
    410         label_key=label_key,
    411         type_=type_,
    412         embed=embed,
    413         scaled=True,
    414         verbose=verbose,
    415     )
    416 else:
    417     kbet_score = np.nan

File ~/miniforge3/envs/angl_BM/lib/python3.12/site-packages/scib/metrics/kbet.py:173, in kBET(adata, batch_key, label_key, type_, embed, scaled, return_df, verbose)
    170 nn_index_tmp[:] = np.nan
    172 try:
--> 173     nn_index_tmp[idx_nonan] = diffusion_nn(
    174         adata_sub_sub, k=k0
    175     ).astype("float")
    176     # call kBET
    177     score = kBET_single(
    178         matrix=matrix,
    179         batch=adata_sub.obs[batch_key],
   (...)
    183         k0=k0,
    184     )

File ~/miniforge3/envs/angl_BM/lib/python3.12/site-packages/scib/metrics/utils.py:141, in diffusion_nn(adata, k, max_iterations)
    134     raise NeighborsError(
    135         f"could not find {k} nearest neighbors in {max_iterations}"
    136         "diffusion steps.\n Please increase max_iterations or reduce"
    137         " k.\n"
    138     )
    140 M.setdiag(0)
--> 141 k_indices = np.argpartition(M.A, -k, axis=1)[:, -k:]
    143 return k_indices

AttributeError: 'csr_matrix' object has no attribute 'A'

After a quick search, I found that this was most likely related to my currently installed scipy version 1.14.0. As described in the following issue and release notes of scipy v1.14.0, the .A attribute of a csr_matrix has been deprecated in this release.
scipy/scipy#21049
https://github.com/scipy/scipy/releases/tag/v1.14.0

Downgrading the scipy version to v1.13.0 solved the issue for me.

Best regards!

@rcannood
Copy link

rcannood commented Sep 4, 2024

Just encountered this issue in OpenProblems as well!

Thanks for posting a workaround, @kollo97 !

rcannood added a commit to openproblems-bio/openproblems-v2 that referenced this issue Sep 4, 2024
rcannood added a commit to openproblems-bio/openproblems-v2 that referenced this issue Sep 4, 2024
* update images

* fix numpy issues

* fix scib kbet by pinning scipy to <= 1.13 (see theislab/scib#412)

* remove unnecessary workaround

* add workaround to other mse component

* update viash test to only run on the main branch or in PRs
rcannood added a commit to openproblems-bio/openproblems that referenced this issue Sep 4, 2024
* update images

* fix numpy issues

* fix scib kbet by pinning scipy to <= 1.13 (see theislab/scib#412)

* remove unnecessary workaround

* add workaround to other mse component

* update viash test to only run on the main branch or in PRs

Former-commit-id: 9493835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants