Spencerfar / LatentVelo

MIT License
22 stars 4 forks source link

TypeError: 'coo_matrix' object is not subscriptable #7

Closed AP-596 closed 5 months ago

AP-596 commented 5 months ago

Hello, I wanted to test LatentVelo on my dataset. However, I am getting the following error with anvi_clean_recipe function:

adata = ltv.utils.anvi_clean_recipe(adata, celltype_key='clusters') gc.collect()


TypeError Traceback (most recent call last) Cell In[56], line 2 1 #https://github.com/Spencerfar/LatentVelo/blob/main/paper_notebooks/Reprogramming.ipynb ----> 2 adata = ltv.utils.anvi_clean_recipe(adata, celltype_key='clusters') 3 gc.collect()

File /mnt/RAID/anaconda3/envs/scvelo_env/lib/python3.9/site-packages/latentvelo-0.1-py3.9.egg/latentvelo/utils.py:303, in anvi_clean_recipe(adata, spliced_key, unspliced_key, batch_key, root_cells, terminal_cells, normalize_library, n_top_genes, n_neighbors, smooth, umap, log, celltype_key, r2_adjust, share_normalization, center, bknn, retain_genes) 300 else: 301 print('using all genes') --> 303 if scp.sparse.issparse(adata.layers[spliced_key]): 304 adata.layers[spliced_key] = adata.layers[spliced_key].todense() 305 adata.layers[unspliced_key] = adata.layers[unspliced_key].todense()

File /mnt/RAID/anaconda3/envs/scvelo_env/lib/python3.9/site-packages/anndata/_core/aligned_mapping.py:150, in AlignedViewMixin.getitem(self, key) 148 def getitem(self, key: str) -> V: 149 return as_view( --> 150 _subset(self.parent_mapping[key], self.subset_idx), 151 ElementRef(self.parent, self.attrname, (key,)), 152 )

File /mnt/RAID/anaconda3/envs/scvelo_env/lib/python3.9/functools.py:877, in singledispatch..wrapper(*args, *kw) 873 if not args: 874 raise TypeError(f'{funcname} requires at least ' 875 '1 positional argument') --> 877 return dispatch(args[0].class)(args, **kw)

File /mnt/RAID/anaconda3/envs/scvelo_env/lib/python3.9/site-packages/anndata/_core/index.py:168, in _subset_spmatrix(a, subset_idx) 166 if len(subset_idx) > 1 and all(isinstance(x, cabc.Iterable) for x in subset_idx): 167 subset_idx = (subset_idx[0].reshape(-1, 1), *subset_idx[1:]) --> 168 return a[subset_idx]

TypeError: 'coo_matrix' object is not subscriptable

My package versions: Package Version


absl-py 2.1.0 aiohttp 3.9.3 aiosignal 1.3.1 anndata 0.10.5.post1 ansicolors 1.1.8 ansiwrap 0.8.4 anyio 4.2.0 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 array_api_compat 1.5 arrow 1.3.0 asttokens 2.0.5 async-lru 2.0.4 async-timeout 4.0.3 attrs 23.1.0 Babel 2.11.0 backcall 0.2.0 beautifulsoup4 4.12.2 bleach 4.1.0 cellrank 2.0.3 certifi 2024.2.2 cffi 1.15.1 chainmap 1.0.3 chardet 5.2.0 charset-normalizer 2.0.4 chex 0.1.85 click 8.1.7 coloredlogs 15.0.1 colormath 3.0.0 combomethod 1.0.12 comm 0.2.1 contextlib2 21.6.0 contourpy 1.2.0 cycler 0.11.0 Cython 3.0.8 debugpy 1.6.7 decorator 5.1.1 defusedxml 0.7.1 dnspython 2.6.1 docrep 0.3.2 etils 1.5.2 exceptiongroup 1.2.0 executing 0.8.3 fastjsonschema 2.16.2 filelock 3.13.1 flax 0.8.2 fonttools 4.25.0 fqdn 1.5.1 frozenlist 1.4.1 fsspec 2024.2.0 future 1.0.0 get-annotations 0.1.2 h11 0.14.0 h5py 3.9.0 httpcore 1.0.4 httpx 0.27.0 humanfriendly 10.0 humanize 4.9.0 hyperopt 0.1.2 idna 3.4 igraph 0.11.4 importlib-metadata 7.0.1 importlib-resources 6.1.1 intspan 1.6.1 ipykernel 6.28.0 ipython 8.15.0 ipywidgets 8.1.2 isoduration 20.11.0 jax 0.4.25 jaxlib 0.4.25 jedi 0.18.1 Jinja2 3.0.3 joblib 1.2.0 json5 0.9.22 jsonpointer 2.4 jsonschema 4.19.2 jsonschema-specifications 2023.12.1 jupyter 1.0.0 jupyter_client 8.6.0 jupyter-console 6.6.3 jupyter_core 5.5.0 jupyter-events 0.8.0 jupyter-lsp 2.2.0 jupyter_server 2.10.0 jupyter_server_terminals 0.4.4 jupyterlab 4.0.11 jupyterlab-pygments 0.1.2 jupyterlab_server 2.25.1 jupyterlab-widgets 3.0.10 kaleido 0.2.1 kiwisolver 1.4.4 latentvelo 0.1 leidenalg 0.10.2 lightning 2.1.4 lightning-utilities 0.10.1 llvmlite 0.42.0 loompy 3.0.7 Markdown 3.6 markdown-it-py 3.0.0 MarkupSafe 2.1.3 matplotlib 3.8.0 matplotlib-inline 0.1.6 mdurl 0.1.2 mementos 1.3.1 mistune 2.0.4 ml-collections 0.1.1 ml-dtypes 0.3.2 mpmath 1.3.0 msgpack 1.0.8 mudata 0.2.3 multidict 6.0.5 multipledispatch 1.0.0 multiqc 1.21 munkres 1.1.4 natsort 8.4.0 nbclient 0.8.0 nbconvert 7.10.0 nbformat 5.9.2 nest-asyncio 1.6.0 networkx 3.2.1 notebook 7.0.8 notebook_shim 0.2.3 nulltype 2.3.1 numba 0.59.0 numpy 1.24.4 numpy-groupies 0.10.2 numpyro 0.14.0 nvidia-cublas-cu12 12.1.3.1 nvidia-cuda-cupti-cu12 12.1.105 nvidia-cuda-nvrtc-cu12 12.1.105 nvidia-cuda-runtime-cu12 12.1.105 nvidia-cudnn-cu12 8.9.2.26 nvidia-cufft-cu12 11.0.2.54 nvidia-curand-cu12 10.3.2.106 nvidia-cusolver-cu12 11.4.5.107 nvidia-cusparse-cu12 12.1.0.106 nvidia-nccl-cu12 2.19.3 nvidia-nvjitlink-cu12 12.4.99 nvidia-nvtx-cu12 12.1.105 opt-einsum 3.3.0 optax 0.2.1 options 1.4.10 orbax-checkpoint 0.5.5 overrides 7.4.0 packaging 23.1 pandas 2.2.1 pandocfilters 1.5.0 parso 0.8.3 patsy 0.5.6 pexpect 4.8.0 pickleshare 0.7.5 pillow 10.2.0 pip 23.3.1 platformdirs 3.10.0 plotly 5.20.0 ply 3.11 progressbar2 4.4.2 prometheus-client 0.14.1 prompt-toolkit 3.0.43 protobuf 5.26.0 psutil 5.9.0 ptyprocess 0.7.0 pure-eval 0.2.2 pyaml-env 1.2.1 pycparser 2.21 pygam 0.9.1 Pygments 2.15.1 pygpcca 1.0.4 pymongo 4.6.2 pynndescent 0.5.11 pyparsing 3.0.9 PyQt5 5.15.10 PyQt5-sip 12.13.0 pyro-api 0.1.2 pyro-ppl 1.9.0 python-dateutil 2.8.2 python-json-logger 2.0.7 python-utils 3.8.2 pytorch-lightning 2.2.1 pytz 2023.3.post1 PyYAML 6.0.1 pyzmq 25.1.2 qtconsole 5.5.1 QtPy 2.4.1 readline 6.2.4.1 referencing 0.30.2 requests 2.31.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.7.1 rich-click 1.7.4 rpds-py 0.10.6 say 1.6.6 scanpy 1.9.8 scikit-learn 1.3.0 scikit-misc 0.3.1 scipy 1.8.1 scvelo 0.3.1 scvi 0.6.8 scvi-tools 1.1.2 seaborn 0.13.2 Send2Trash 1.8.2 session-info 1.0.0 setuptools 68.2.2 show 1.6.0 simplere 1.2.13 sip 6.7.12 six 1.12.0 sniffio 1.3.0 soupsieve 2.5 spectra 0.0.11 stack-data 0.2.0 statsmodels 0.14.1 stdlib-list 0.10.0 sympy 1.12 tenacity 8.2.3 tensorstore 0.1.55 terminado 0.17.1 textdata 2.4.1 texttable 1.7.0 textwrap3 0.9.2 threadpoolctl 2.2.0 tinycss2 1.2.1 tomli 2.0.1 toolz 0.12.1 torch 2.2.1 torchdiffeq 0.2.3 torchmetrics 1.3.1 torchvision 0.17.1 tornado 6.3.3 tqdm 4.66.2 traitlets 5.14.1 triton 2.2.0 types-python-dateutil 2.8.19.20240106 typing_extensions 4.10.0 tzdata 2024.1 umap-learn 0.5.5 uri-template 1.3.0 urllib3 2.1.0 wcwidth 0.2.13 webcolors 1.13 webencodings 0.5.1 websocket-client 0.58.0 wheel 0.41.2 widgetsnbextension 4.0.10 wrapt 1.16.0 xlrd 2.0.1 yarl 1.9.4 zipp 3.17.0

Could you please help me with it ?

arvinhm commented 5 months ago

Converting sparse matrices in adata.layers['spliced'] and adata.layers['unspliced'] to dense arrays with .toarray() will resolve your specific issue. This package has lots of other issues, but the below code will temporarily solve your problem. adata.layers['spliced'] = adata.layers['spliced'].toarray() adata.layers['unspliced'] = adata.layers['unspliced'].toarray()