Closed carmensandoval closed 1 year ago
Thanks for the report. That does seem strange.
I think the issue that we're assuming the dict-like values are actually dict
s.
Did you literally run:
import scanpy as sc
adata = sc.read_h5ad('/path/to/my.h5ad')
sc.pp.filter_cells(adata, min_genes=200)
Because I don't think that should be able to give you anything in uns
that isn't a dict
.
Could you please also report some info on your environment? E.g. the output of import session_info; session_info.show(dependencies=True, html=False)
from the python session where you get the error.
My apologies -- this happens when converting a pegasus object to anndata.
adata = pg.read_input('../cellbender/SAM24425932/SAM24425932_cellbender_out_filtered.h5')
adata = adata.to_anndata()
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
AttributeError: 'DataDict' object has no attribute 'copy'
Saving it first, then reading it with scanpy.read_h5ad works fine.
adata = pg.read_input('../cellbender/SAM24425932/SAM24425932_cellbender_out_filtered.h5')
pg.write_output(adata, 'test.h5ad')
adata = sc.read_h5ad('test.h5ad')
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
I guess this is more a question for the developers of pegasus, but it does seem like something is missing when converting,
Context: I found myself in this hole because of the inability to read cellbender output with scanpy 1.9.1. Pegasus can load them and save these h5 files without issue, so I was thinking of using it as an importer to be able to use scanpy on those objects.
(I can now load these h5 files from cellbender using the function provided here, but still have issues saving - hence why I'm trying to find a way to convert between the two 'formats'.)
Yes, I think this would be an issue for pegasus. It shouldn't be putting DataDict
s into AnnData.
You could maybe do something like:
from collections.abc import Mapping
def sanitize_uns(d):
return {k: sanitize_uns(v) if isinstance(v, Mapping) else v for k, v in d.items()}
adata.uns = sanitize_uns(adata.uns)
Potentially we should be more aggressive with converting on the anndata side. However, Mapping
subtypes are quite common it would be easy to convert something that shouldn't be converted.
This issue has been automatically marked as stale because it has not had recent activity. Please add a comment if you want to keep the issue open. Thank you for your contributions!
I’m closing this because there was no follow-up. Please feel free to respond and we’ll re-open it.
Trying to work with an anndata object that I can use with
pegasus
just fine returns the following error:Any ideas what could be going on and how to fix this?