Teichlab / bbknn

Batch balanced KNN
MIT License
149 stars 25 forks source link

should change location of 'distances' and 'connectivities' for new versions of anndata #25

Closed alasla closed 4 years ago

alasla commented 4 years ago
/usr/local/lib/python3.6/dist-packages/bbknn/__init__.py:294: FutureWarning: This location for 'distances' is deprecated. It has been moved to .obsp[distances], and will not be accesible here in a future version of anndata.
  adata.uns['neighbors']['distances'] = bbknn_out[0]
/usr/local/lib/python3.6/dist-packages/bbknn/__init__.py:295: FutureWarning: This location for 'connectivities' is deprecated. It has been moved to .obsp[connectivities], and will not be accesible here in a future version of anndata.
  adata.uns['neighbors']['connectivities'] = bbknn_out[1]

New versions of anndata/scanpy look for the distances and connectivities to be in adata.obsp instead of uns['neighbors']. Probably should update the outputs of bbknn to the adata.obsp as well.

ktpolanski commented 4 years ago

Thanks for the heads up, will update soon. How new a version we talking here? As this way I can add appropriate version information to the dependencies.

chlee-tabin commented 4 years ago

Just to whom it may concern, I also learned the hard way, I was puzzled why bbknn was not working and found that for

scanpy==1.5.1 anndata==0.7.1 umap==0.3.10 numpy==1.18.1 scipy==1.4.1 pandas==1.0.1 scikit-learn==0.22.2 statsmodels==0.11.1 python-igraph==0.8.2 leidenalg==0.8.0

the interim solution could be:

distances, connectivities = bbknn.bbknn_pca_matrix(adata.obsm["X_pca"], adata.obs['sample'])
adata_bbknn.obsp['distances'] = distances
adata_bbknn.obsp['connectivities'] = connectivities
ktpolanski commented 4 years ago

Thanks for the reminder. I checked the release history for anndata, found out they restructured in 0.7, thought up a way to check the package version and store in .obsp or .uns accordingly, and then got a case of lockdown brain and never followed through. I'll try to push this out soon. My apologies.

ktpolanski commented 4 years ago

Released as 1.3.10. Sorry about the delay again.

chlee-tabin commented 4 years ago

@ktpolanski

I am getting this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-1a416d7acffc> in <module>
----> 1 adata_bbknn = bbknn.bbknn(adata, batch_key='batch2', n_pcs=16, trim=0, copy=True)
      2 # Fix of bbknn
      3 #adata_bbknn.obsp['distances'] = adata_bbknn.uns['neighbors']['distances']
      4 #adata_bbknn.obsp['connectivities'] = adata_bbknn.uns['neighbors']['connectivities']
      5 sc.tl.umap(adata_bbknn, min_dist=0.3)

~/anaconda3/envs/jlab/lib/python3.8/site-packages/bbknn/__init__.py in bbknn(adata, batch_key, use_rep, approx, metric, copy, **kwargs)
    296         adata.uns['neighbors']['params']['bbknn']['batch_key'] = batch_key
    297         #store the graphs in .uns['neighbors'] or .obsp, conditional on anndata version
--> 298         if version.parse(anndata.__version__) < version.parse('0.7.0'):
    299                 adata.uns['neighbors']['distances'] = bbknn_out[0]
    300                 adata.uns['neighbors']['connectivities'] = bbknn_out[1]

~/anaconda3/envs/jlab/lib/python3.8/site-packages/packaging/version.py in parse(version)
     54     """
     55     try:
---> 56         return Version(version)
     57     except InvalidVersion:
     58         return LegacyVersion(version)

~/anaconda3/envs/jlab/lib/python3.8/site-packages/packaging/version.py in __init__(self, version)
    273 
    274         # Validate the version and parse it into pieces
--> 275         match = self._regex.search(version)
    276         if not match:
    277             raise InvalidVersion("Invalid version: '{0}'".format(version))

TypeError: expected string or bytes-like object
ktpolanski commented 4 years ago

Weird. Can you tell me what you get when you run anndata.__version__? It worked fine over here.

chlee-tabin commented 4 years ago
import anndata as ad
ad.__version__
<Version('0.7.1')>

I am jusing jupter lab and casually copied the import as above (I don't know whether this will make a difference, not very versed in python).

ktpolanski commented 4 years ago

Yep, I've been able to replicate and fix the issue. Hopefully. Grab 1.3.11 and confirm it's good now?

chlee-tabin commented 4 years ago

@ktpolanski It works well Thanks!

ktpolanski commented 4 years ago

Ok, cool. Closing again :)