Teichlab / cellphonedb

MIT License
339 stars 105 forks source link

TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [nan] of <class 'float'> #253

Closed mcap91 closed 3 years ago

mcap91 commented 3 years ago

Hello,

I have successfully run cellphoneDB with the test_counts.txt and test_meta.txt. I am trying to run data from a Seurat object but keep receiving this Unexpected/index error. Here is the output from cellphoneDB:

[ ][APP][16/01/21-13:10:36][WARNING] Latest local available version is v2.0.0, using it [ ][APP][16/01/21-13:10:36][WARNING] User selected downloaded database v2.0.0 is available, using it [ ][CORE][16/01/21-13:10:36][INFO] Initializing SqlAlchemy CellPhoneDB Core [ ][CORE][16/01/21-13:10:36][INFO] Using custom database at /wynton/home/akassoglou/mcaponegro/.cpdb/releases/v2.0.0/cellphone.db [ ][APP][16/01/21-13:10:36][INFO] Launching Method cpdb_statistical_analysis_local_method_launcher [ ][APP][16/01/21-13:10:36][INFO] Launching Method _set_paths [ ][APP][16/01/21-13:10:36][INFO] Launching Method _load_meta_counts [ ][CORE][16/01/21-13:10:59][INFO] Launching Method cpdb_statistical_analysis_launcher [ ][CORE][16/01/21-13:10:59][INFO] Launching Method _counts_validations [ ][CORE][16/01/21-13:11:02][INFO] [Cluster Statistical Analysis Simple] Threshold:0.1 Iterations:1000 Debug-seed:-1 Threads:4 Precision:3 [ ][CORE][16/01/21-13:11:02][INFO] Running Simple Prefilters [ ][CORE][16/01/21-13:11:04][INFO] Running Real Simple Analysis [ ][APP][16/01/21-13:11:05][ERROR] Unexpected error /wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib64/python3.6/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) Traceback (most recent call last): File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/api_endpoints/terminal_api/method_terminal_api_endpoints/method_terminal_commands.py", line 144, in statistical_analysis subsampler, File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/local_launchers/local_method_launcher.py", line 64, in cpdb_statistical_analysis_local_method_launcher subsampler File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/core/methods/method_launcher.py", line 75, in cpdb_statistical_analysis_launcher self.separator) File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_method.py", line 35, in call result_precision, File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_simple_method.py", line 50, in call counts_data=counts_data) File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py", line 186, in mean_analysis counts_data=counts_data) File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py", line 463, in cluster_interaction_mean mean_ligand = means_cluster_ligands[interaction['{}{}'.format(counts_data, suffixes[1])]] File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib64/python3.6/site-packages/pandas/core/series.py", line 767, in getitem result = self.index.get_value(self, key) File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib64/python3.6/site-packages/pandas/core/indexes/base.py", line 3115, in get_value k = self._convert_scalar_indexer(k, kind='getitem') File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib64/python3.6/site-packages/pandas/core/indexes/base.py", line 1663, in _convert_scalar_indexer return self._invalid_indexer('label', key) File "/wynton/group/gladstone/users/mcaponegro/cpdb_for_R/cpdb-venv/lib64/python3.6/site-packages/pandas/core/indexes/base.py", line 1863, in _invalid_indexer kind=type(key))) TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [nan] of <class 'float'>

TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [nan] of <class 'float'>

I think my issue is arising from converting mouse to human genes (I am using --counts-data=gene_name). If I pull the data directly from the Seurat object following https://www.cellphonedb.org/faq-and-troubleshooting and submit to cellphoneDB I get:

[ ][CORE][16/01/21-12:13:19][INFO] [Cluster Statistical Analysis Complex] Threshold:0.1 Iterations:1000 Debug-seed:-1 Threads:4 Precision:3 [ ][CORE][16/01/21-12:13:19][INFO] Running Complex Prefilters [ ][APP][16/01/21-12:13:19][WARNING] Result is empty

presumably because these are mouse gene IDs?

However, when I run my mouse to human gene conversion (using biomaRt) and write the table using the same code from https://www.cellphonedb.org/faq-and-troubleshooting I get this indexing error in question.

There are no NAs in my counts. All row names match col names. I am using R to generate counts/meta input files. I have seen several posts about this issue. Has it been resolved? What index is it referring to?

Thank you, Mike

mcap91 commented 3 years ago

Hello, I figured out the issue for anyone who runs into this problem. There were in fact mislabeled gene names in the rows of my counts matrix. They were not NA but they were "" blank. I removed them and cellphoneDB worked fine. Thank you