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

Module 'scvi.data' has no attribute 'setup_anndata' #145

Closed Rajarshi1001 closed 2 years ago

Rajarshi1001 commented 2 years 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)

In the new version of cell2location, I got this issue while running the cell2location tutorial for the Mouse Brain data. The tutorial shows that AnnData was setup using 'scvi-tools' version 0.13.0 but the existing scvi version found was 0.16.0 so there is some issue with the attribute __setup_anndata and view_anndata_setup__.

# prepare anndata for the regression model
scvi.data.setup_anndata(adata=adata_ref,
                        # 10X reaction / sample / batch
                        batch_key='Sample',
                        # cell type, covariate used for constructing signatures
                        labels_key='Subset',
                        # multiplicative technical effects (platform, 3' vs 5', donor effect)
                        categorical_covariate_keys=['Method']
                       )
scvi.data.view_anndata_setup(adata=adata_ref)
module 'scvi.data' has no attribute 'setup_anndata'

image

yxnankai commented 2 years ago

I found this problem both, after trying to change the version of scvi-tools, you may try ` RegressionModel.setup_anndata(adata_ref, batch_key='Sample',

cell type, covariate used for constructing signatures

                    labels_key='Subset',
                    # multiplicative technical effects (platform, 3' vs 5', donor effect)
                    categorical_covariate_keys=['Method']     
                         )

` instead of scvi.data.setup_anndata, it do also work anyway ,but I'm not sure whether they lead to the same result.

Waiting for your comment, thank you!

It turns out to the same result.

vitkl commented 2 years ago

Yes, please use cell2location.models.RegressionModel.setup_anndata(adata_ref, ...) for reference signature estimation and cell2location.models.Cell2location.setup_anndata(adata_vis, ...) for cell2location application to spatial adata_vis.

These changes follow recent improvements to scvi-tools.

We will update the tutorials soon.

liukc19 commented 2 years ago

i have tried this method but can't solve this problem new error:

AttributeError                            Traceback (most recent call last)
Input In [10], in <cell line: 10>()
      1 # prepare anndata for the regression model
      2 cell2location.models.RegressionModel.setup_anndata(adata=adata_ref,
      3                         # 10X reaction / sample / batch
      4                         batch_key='Sample',
   (...)
      8                         categorical_covariate_keys=['Method']
      9                        )
---> 10 scvi.data.view_anndata_setup(adata_ref)

AttributeError: module 'scvi.data' has no attribute 'view_anndata_setup'

Help would be appreciated

vitkl commented 2 years ago

In scvi-tools versions after 0.16.0, the anndata setup settings can be viewed after the model is created: cell2location.models.RegressionModel.view_anndata_setup(model).