-
Notifications
You must be signed in to change notification settings - Fork 69
Description
- I have confirmed this bug exists on the latest version of cell2location. See https://github.com/BayraktarLab/cell2location#installation
- I follow the instructions from the scvi-tools tutorial.
I have followed the tutorial for using cell2location, and in the last part, when estimating the cell-type specific expression of every gene in ST data, when appending the results to the anndata objects, either when appended to 'layers' (as the tutorial explains) or to obsm (shown here), an error arises.
The error only arises when reading the saved adatas later, using scanpy read_h5ad, apparently because the file is corrupted. I don't really know which is the appropriate way to save this results back into an anndata object so that I can use this gene-expression matrices for downstream analysis, without explicitly saving them into different files (per cell-type gene expression matrix file).
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Minimal code sample (that we can run without your data, using public data)
# Compute expected expression per cell type and add to adata
expected_dict = mod.module.model.compute_expected_per_cell_type(
mod.samples["post_sample_q05"], mod.adata_manager
)
for i, n in enumerate(mod.factor_names_):
#adata_vis.layers[n] = expected_dict['mu'][i] #this corrupts adata
adata_vis.obsm[n] = expected_dict['mu'][i]
adata_vis.write(f"{run_name}/sp{sample}.h5ad") #this will later be read for doing DEA per area File "/home/quiquevb/.conda/envs/cell2loc_env/lib/python3.9/site-packages/anndata/utils.py", line 109, in dim_len
return x.shape[axis]
AttributeError: 'dict' object has no attribute 'shape'
Error raised while reading key '' of <class 'h5py._hl.files.File'> from /