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

AttributeError: module 'cell2location' has no attribute 'run_cell2location' #199

Closed YaoZY157 closed 2 years ago

YaoZY157 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)

Hi,guys! When I run the official process ( https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_short_demo.html), I meet the trouble: AttributeError: module 'cell2location' has no attribute 'run_cell2location'. I install it according to the official website(https://github.com/BayraktarLab/cell2location).

import sys
import scanpy as sc
import anndata
import pandas as pd
import numpy as np
import os
import gc
import cell2location
import matplotlib as mpl
from matplotlib import rcParams
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')

#The official website process has been omitted( https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_short_demo.html)

sc.settings.set_figure_params(dpi = 100, color_map = 'viridis', dpi_save = 100,
                              vector_friendly = True, format = 'pdf',
                              facecolor='white')

r = cell2location.run_cell2location(

      # Single cell reference signatures as pd.DataFrame
      # (could also be data as anndata object for estimating signatures
      #  as cluster average expression - `sc_data=adata_snrna_raw`)
      sc_data=inf_aver,
      # Spatial data as anndata object
      sp_data=adata_vis,

      # the column in sc_data.obs that gives cluster idenitity of each cell
      summ_sc_data_args={'cluster_col': "annotation_1",
                        },

      train_args={'use_raw': True, # By default uses raw slots in both of the input datasets.
                  'n_iter': 40000, # Increase the number of iterations if needed (see QC below)

                  # Whe analysing the data that contains multiple experiments,
                  # cell2location automatically enters the mode which pools information across experiments
                  'sample_name_col': 'sample'}, # Column in sp_data.obs with experiment ID (see above)

      export_args={'path': results_folder, # path where to save results
                   'run_name_suffix': '' # optinal suffix to modify the name the run
                  },

      model_kwargs={ # Prior on the number of cells, cell types and co-located groups

                    'cell_number_prior': {
                        # - N - the expected number of cells per location:
                        'cells_per_spot': 8, # < - change this
                        # - A - the expected number of cell types per location (use default):
                        'factors_per_spot': 7,
                        # - Y - the expected number of co-located cell type groups per location (use default):
                        'combs_per_spot': 7
                    },

                     # Prior beliefs on the sensitivity of spatial technology:
                    'gene_level_prior':{
                        # Prior on the mean
                        'mean': 1/2,
                        # Prior on standard deviation,
                        # a good choice of this value should be at least 2 times lower that the mean
                        'sd': 1/4
                    }
      }
)

sc.logging.print_versions()

anndata 0.8.0 scanpy 1.9.1

PIL 9.2.0 absl NA asttokens NA attr 22.1.0 backcall 0.2.0 beta_ufunc NA binom_ufunc NA cell2location NA cffi 1.15.1 chex 0.1.4 colorama 0.4.5 cycler 0.10.0 cython_runtime NA dateutil 2.8.2 decorator 5.1.1 defusedxml 0.7.1 deprecate 0.3.2 docrep 0.3.2 entrypoints 0.4 etils 0.7.1 executing 0.10.0 flax 0.6.0 fsspec 2022.7.1 google NA h5py 3.7.0 hypergeom_ufunc NA igraph 0.9.11 ipykernel 6.15.1 ipython_genutils 0.2.0 ipywidgets 7.7.1 jax 0.3.16 jaxlib 0.3.15 jedi 0.18.1 joblib 1.1.0 kiwisolver 1.4.4 leidenalg 0.8.10 llvmlite 0.39.0 matplotlib 3.5.3 matplotlib_inline 0.1.5 mpl_toolkits NA msgpack 1.0.4 mudata 0.2.0 multipledispatch 0.6.0 natsort 8.1.0 nbinom_ufunc NA ncf_ufunc NA numba 0.56.0 numpy 1.22.4 numpyro 0.10.0 opt_einsum v3.3.0 optax 0.1.3 packaging 21.3 pandas 1.4.3 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA prompt_toolkit 3.0.30 psutil 5.9.1 ptyprocess 0.7.0 pure_eval 0.2.2 pycparser 2.21 pygments 2.13.0 pynndescent 0.5.7 pyparsing 3.0.9 pyro 1.8.1 pytorch_lightning 1.6.5 pytz 2022.2.1 rich NA scipy 1.9.0 scvi 0.17.1 seaborn 0.11.2 session_info 1.0.0 setuptools 65.0.1 six 1.16.0 sklearn 1.1.2 stack_data 0.4.0 statsmodels 0.13.2 tensorboard 2.9.0 texttable 1.6.4 threadpoolctl 3.1.0 toolz 0.12.0 torch 1.12.1+cu102 torchmetrics 0.9.3 tornado 6.2 tqdm 4.64.0 traitlets 5.3.0 tree 0.1.7 typing_extensions NA umap 0.5.3 wcwidth 0.2.5 yaml 6.0 zipp NA zmq 23.2.1

IPython 8.4.0 jupyter_client 7.3.4 jupyter_core 4.11.1 notebook 6.4.12

Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50) [GCC 10.3.0] Linux-3.10.0-957.el7.x86_64-x86_64-with-glibc2.17

Session information updated at 2022-09-12 17:53


##
AttributeError                            Traceback (most recent call last)
Input In [19], in <cell line: 1>()
----> 1 r = cell2location.run_cell2location(
      2
      3       # Single cell reference signatures as pd.DataFrame
      4       # (could also be data as anndata object for estimating signatures
      5       #  as cluster average expression - `sc_data=adata_snrna_raw`)
      6       sc_data=inf_aver,
      7       # Spatial data as anndata object
      8       sp_data=adata_vis,
      9
     10       # the column in sc_data.obs that gives cluster idenitity of each cell
     11       summ_sc_data_args={'cluster_col': "annotation_1",
     12                         },
     13
     14       train_args={'use_raw': True, # By default uses raw slots in both of the input datasets.
     15                   'n_iter': 40000, # Increase the number of iterations if needed (see QC below)
     16
     17                   # Whe analysing the data that contains multiple experiments,
     18                   # cell2location automatically enters the mode which pools information across experiments
     19                   'sample_name_col': 'sample'}, # Column in sp_data.obs with experiment ID (see above)
     20
     21
     22       export_args={'path': results_folder, # path where to save results
     23                    'run_name_suffix': '' # optinal suffix to modify the name the run
     24                   },
     25
     26       model_kwargs={ # Prior on the number of cells, cell types and co-located groups
     27
     28                     'cell_number_prior': {
     29                         # - N - the expected number of cells per location:
     30                         'cells_per_spot': 8, # < - change this
     31                         # - A - the expected number of cell types per location (use default):
     32                         'factors_per_spot': 7,
     33                         # - Y - the expected number of co-located cell type groups per location (use default):
     34                         'combs_per_spot': 7
     35                     },
     36
     37                      # Prior beliefs on the sensitivity of spatial technology:
     38                     'gene_level_prior':{
     39                         # Prior on the mean
     40                         'mean': 1/2,
     41                         # Prior on standard deviation,
     42                         # a good choice of this value should be at least 2 times lower that the mean
     43                         'sd': 1/4
     44                     }
     45       }
     46 )

AttributeError: module 'cell2location' has no attribute 'run_cell2location'
masoodlab commented 2 years ago

I am getting the same error message. Were you able to find a solution?

YaoZY157 commented 2 years ago

I am getting the same error message. Were you able to find a solution?

Sorry, I still have no idea (@_@).

vitkl commented 2 years ago

Hi @YaoZY157 @masoodlab