question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subsetting not working after saving anndata

See original GitHub issue

I’ve been having some issues recently when trying to subset an anndata object after I save it to disk. Everything works perfectly, but after I save it to disk using adata.write(filename, compression='gzip') , and then read it back again from disk, the subsetting doesn’t work. It only happens after saving to disk, and it seems to only happen after I’ve run additional analysis (UMAP, rank_genes_groups, etc… I don’t know exactly which entry is the one breaking the writing/reading). This is the error I get:

Traceback (most recent call last): File “”, line 48, in <module> File “/Users/andres/miniconda3/envs/finalenv/lib/python3.7/site-packages/anndata/core/anndata.py”, line 1230, in getitem return self._getitem_view(index) File “/Users/andres/miniconda3/envs/finalenv/lib/python3.7/site-packages/anndata/core/anndata.py”, line 1234, in _getitem_view return AnnData(self, oidx=oidx, vidx=vidx, asview=True) File “/Users/andres/miniconda3/envs/finalenv/lib/python3.7/site-packages/anndata/core/anndata.py”, line 561, in init self._init_as_view(X, oidx, vidx) File “/Users/andres/miniconda3/envs/finalenv/lib/python3.7/site-packages/anndata/core/anndata.py”, line 633, in _init_as_view self._raw = adata_ref.raw[oidx] File “/Users/andres/miniconda3/envs/finalenv/lib/python3.7/site-packages/anndata/core/anndata.py”, line 344, in getitem new._varm = self._varm._view(self, vidx) AttributeError: ‘dict’ object has no attribute ‘_view’

Any subsetting (of observations or variables) gives me this error. I tried removing keys from .uns, etc. , but nothing seems to work.

These are the versions I’m running, all installed with conda:

scanpy==1.4.4.post1 anndata==0.6.22.post1 umap==0.3.10 numpy==1.17.2 scipy==1.3.1 pandas==0.25.2 scikit-learn==0.21.3 statsmodels==0.10.1 python-igraph==0.7.1 louvain==0.6.1

I also tried using different (or no) compression to save and read, but that didn’t help either. I don’t know if it’s related to the recent problems with h5py, but either way I am using h5py=2.9.0 and hdf5=1.10.5. Hopefully someone can help! Let me know if I should post this in the anndata repository instead.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ivirshupcommented, Nov 14, 2019

I think the easiest would be to pass the parts you want to the AnnData constructor, like:

new_adata = AnnData(
    X=adata.raw.X,
    var=adata.raw.var,
    varm=adata.raw.varm,
    obs=pd.DataFrame(index=adata.obs_names)
)
0reactions
a-munoz-rojascommented, Nov 14, 2019

That makes sense - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subsetting not working after saving anndata #884 - GitHub
I've been having some issues recently when trying to subset an anndata object after I save it to disk. Everything works perfectly, but...
Read more >
is there a way to subset an AnnData object after reading it in?
There are 3 columns in this data set that I need to work with as .obs but it looks like everything is in...
Read more >
Guide to filtering and subsetting single-cell anndata and ...
Manipulating the anndata object is fundamental to single-cell analysis using scanpy in python. I show several basic and advanced methods to ...
Read more >
5, maybe 10 minutes to AnnData - Adam Gayoso
Subsetting AnnData ​​ These index values can be used to subset the AnnData, which provides a view of the AnnData object. We can...
Read more >
anndata.pdf
Subsetting an AnnData object by indexing into it will also subset its elements according to the dimensions they were aligned to. This means...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found