Teichlab / cellphonedb

MIT License
339 stars 105 forks source link

"statistical_analysis" won't run on the example data, but "analysis" will. Error = AttributeError: type object 'object' has no attribute 'dtype' #266

Closed maktaylo closed 3 years ago

maktaylo commented 3 years ago

Has anyone run into this issue?

cellphonedb method statistical_analysis test_meta.txt test_counts.txt /Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.cluster.kmeans module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.cluster. Anything that cannot be imported from sklearn.cluster is now part of the private API. warnings.warn(message, FutureWarning) [ ][APP][10/02/21-15:46:08][WARNING] Latest local available version is v2.0.0, using it [ ][APP][10/02/21-15:46:08][WARNING] User selected downloaded database v2.0.0 is available, using it [ ][CORE][10/02/21-15:46:08][INFO] Initializing SqlAlchemy CellPhoneDB Core [ ][CORE][10/02/21-15:46:08][INFO] Using custom database at /Users/marktaylor/.cpdb/releases/v2.0.0/cellphone.db [ ][APP][10/02/21-15:46:08][INFO] Launching Method cpdb_statistical_analysis_local_method_launcher [ ][APP][10/02/21-15:46:08][INFO] Launching Method _set_paths [ ][APP][10/02/21-15:46:08][WARNING] Output directory (/Users/marktaylor/Desktop/Projects/Balmain lab/mouse_scRNAseq/results/CellPhoneDB/example_dat/out) exist and is not empty. Result can overwrite old results [ ][APP][10/02/21-15:46:08][INFO] Launching Method _load_meta_counts [ ][CORE][10/02/21-15:46:08][INFO] Launching Method cpdb_statistical_analysis_launcher [ ][CORE][10/02/21-15:46:08][INFO] Launching Method _counts_validations [ ][CORE][10/02/21-15:46:08][INFO] [Cluster Statistical Analysis] Threshold:0.1 Iterations:1000 Debug-seed:-1 Threads:4 Precision:3 /Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py:87: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy complex_components['mean'] = complex_components['protein_multidata_id'].apply( [ ][CORE][10/02/21-15:46:09][INFO] Running Real Analysis [ ][APP][10/02/21-15:46:09][ERROR] Unexpected error Traceback (most recent call last): File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/api_endpoints/terminal_api/method_terminal_api_endpoints/method_terminal_commands.py", line 127, in statistical_analysis LocalMethodLauncher(cpdb_app.create_app(verbose, database)). \ File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/local_launchers/local_method_launcher.py", line 54, in cpdb_statistical_analysis_local_method_launcher self.cellphonedb_app.method.cpdb_statistical_analysis_launcher( File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/core/methods/method_launcher.py", line 62, in cpdb_statistical_analysis_launcher cpdb_statistical_analysis_method.call(meta, File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_method.py", line 23, in call cpdb_statistical_analysis_complex_method.call(meta.copy(), File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_complex_method.py", line 80, in call real_percents_analysis = cpdb_statistical_analysis_helper.percent_analysis(clusters, File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py", line 260, in percent_analysis percents = pd.DataFrame(columns=clusters['names'], index=clusters['means'].index) File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/pandas/core/frame.py", line 411, in init mgr = init_dict(data, index, columns, dtype=dtype) File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 242, in init_dict val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype) File "/Users/marktaylor/cpdb-venv/lib/python3.8/site-packages/pandas/core/dtypes/cast.py", line 1221, in construct_1d_arraylike_from_scalar dtype = dtype.dtype AttributeError: type object 'object' has no attribute 'dtype'

martin-jeremy commented 3 years ago

I had the same error. It seems like a dependency didn't install correctly. I work in a conda env, so I solved my problem like that :

conda create -n cpdb-env python=3.8 r-ggplot r-pheatmap -y
conda activate cpdb-env
pip install cellphonedb
# when i run, i have the same error
conda install tensorflow
pip install cellphonedb

Then I didn't have more issue. Perhaps a bad version of pandas in the requirements of cellphonedb ? I don't know...

tjbencomo commented 3 years ago

I also encountered @maktaylo's issue where the statistical analysis function had dtype error. Following @martin-jeremy's solution worked after I told conda to create a new environment with python=3.7 instead of 3.8. When I tried with python=3.8 it error and said tensorflow wasn't available. This was on OSX

maktaylo commented 3 years ago

Thanks so much for your responses--this is a huge help, and will try these solutions asap!

On Thu, Feb 11, 2021 at 11:17 PM Tomas Bencomo notifications@github.com wrote:

I also encountered @maktaylo https://github.com/maktaylo's issue where the statistical analysis function had dtype error. Following @martin-jeremy https://github.com/martin-jeremy's solution worked after I told conda to create a new environment with python=3.7 instead of 3.8. When I tried with python=3.8 it error and said tensorflow wasn't available. This was on OSX

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Teichlab/cellphonedb/issues/266#issuecomment-778024319, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZIEWBWEMCCCKXKKE2TYH3S6TIZDANCNFSM4XN4NYNA .

jonathanysp commented 3 years ago

The pandas version which cellphonedb depends on (0.25.x) does not work with the latest numpy version.

Force downgrading your numpy to version 1.19.5 will fix it.

pip install --force-reinstall numpy==1.19.5

The requirements.txt needs to be updated to lock the numpy version.

prete commented 3 years ago

pandas/numpy requriments were fixed in #264 and should not be an issue in CellphoneDB>=2.1.6

prete commented 3 years ago

For future references requirments are pandas>=1.0.0,<=1.1.4 and numpy>=1.16.5,<=1.20.9 (at least up to CellPhoneDB v2.1.8)