BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
324 stars 58 forks source link

Cell2location object has no attribute samples #217

Closed julie-jch closed 1 year ago

julie-jch commented 1 year ago

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)

I am following the tutorial and am the step: Estimate cell-type specific expression of every gene in the spatial data (needed for NCEM). Running the below code fails

#Compute expected expression per cell type
expected_dict = mod.module.model.compute_expected_per_cell_type(mod.samples["post_sample_q05"], mod.adata_manager)

# Add to anndata layers
for i, n in enumerate(mod.factor_names_):
    adata_vis.layers[n] = expected_dict['mu'][i]

# Save anndata object with results
adata_file = f"{run_name}/sp.h5ad"
adata_vis.write(adata_file)
adata_file

Here is the error obtained after running the above code. This is occurring with all my samples.

AttributeError                            Traceback (most recent call last)
Input In [28], in <cell line: 2>()
      1 #Compute expected expression per cell type
----> 2 expected_dict = mod.module.model.compute_expected_per_cell_type(mod.samples["post_sample_q05"], mod.adata_manager)
      4 # Add to anndata layers
      5 for i, n in enumerate(mod.factor_names_):

AttributeError: 'Cell2location' object has no attribute 'samples'

Version cell2location 0.8a0

vitkl commented 1 year ago

Hi @julie-jch

you need to run export_posterior which creates model.samples. Please see https://github.com/BayraktarLab/cell2location/issues/195#issuecomment-1217339978