scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.92k stars 599 forks source link

Neighbors.compute_transitions() with error 'AnnData' object has no attribute '_connectivities' #2109

Open pchiang5 opened 2 years ago

pchiang5 commented 2 years ago

Hello,

I would like to derive the transition matrix with the following input:

sc.Neighbors.compute_transitions(adata)

The error below was produced. The anndata object was fine with sc.pp.neighbors(adata) and sc.tl.umap(adata) for UMAP plotting. Thanks

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/miniconda3/envs/scVI/lib/python3.8/site-packages/scanpy/neighbors/__init__.py", line 911, in compute_transitions
    W = self._connectivities
AttributeError: 'AnnData' object has no attribute '_connectivities'

Versions

[Paste the output of scanpy.logging.print_versions() leaving a blank line after the details tag] WARNING: If you miss a compact list, please try `print_header`! ----- anndata 0.7.5 scanpy 1.8.2 sinfo 0.3.1 ----- PIL 8.0.1 absl NA anndata 0.7.5 attr 20.3.0 cffi 1.14.4 colorama 0.4.4 cycler 0.10.0 cython_runtime NA dateutil 2.8.1 deprecate 0.3.0 docrep 0.3.2 fsspec 2022.01.0 google NA h5py 3.1.0 igraph 0.9.1 joblib 0.17.0 kiwisolver 1.3.1 leidenalg 0.8.3 llvmlite 0.37.0 matplotlib 3.3.3 mkl 2.3.0 mpl_toolkits NA natsort 7.1.0 numba 0.54.1 numexpr 2.7.1 numpy 1.19.2 opt_einsum v3.3.0 packaging 20.7 pandas 1.1.5 pkg_resources NA pycparser 2.20 pygments 2.7.3 pynndescent 0.5.5 pyparsing 2.4.7 pyro 1.8.0+0ec1e87 pytorch_lightning 1.3.8 pytz 2020.4 rich NA scanpy 1.8.2 scipy 1.5.2 scvi 0.14.5 setuptools 49.6.0.post20201009 setuptools_scm NA sinfo 0.3.1 six 1.15.0 sklearn 1.0.1 sphinxcontrib NA tables 3.6.1 tensorboard 2.7.0 texttable 1.6.3 threadpoolctl 2.1.0 torch 1.9.0 torchmetrics 0.6.2 tqdm 4.62.3 typing_extensions NA umap 0.5.2 wcwidth 0.2.5 yaml 5.4.1 ----- Python 3.8.6 | packaged by conda-forge | (default, Nov 27 2020, 19:31:52) [GCC 9.3.0] Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.10 24 logical CPU cores, x86_64 ----- Session information updated at 2022-01-14 13:58
ivirshup commented 2 years ago

That method isn't a static method, so the calling convention would be more like:

neighbors = sc.Neighbors(adata)
neighbors.compute_transitions()
transitions = neighbors.transitions

But what are you trying to do exactly?

pchiang5 commented 2 years ago

Thank you.

Somehow I could not find the transition probability from the output of scanpy.tl.diffmap. Thus, I would like to extract it from the neighborhoodness. Together with the eigenvector and eigenvalue from the scanpy.tl.diffmap, they will be tried as the input for pseudotime analysis with URD. Are these 3 datasets equivalent to the output of diffusion map in the destiny package?

The inherent knn in URD was not used because I found the latent space from scVI output might represent the neighborhoodness better.

ivirshup commented 2 years ago

Are these 3 datasets equivalent to the output of diffusion map in the destiny package?

Given the same initial knn graph, that is my impression. @flying-sheep would be able to tell you for sure.