JCVenterInstitute / NSForest

A machine learning method for the discovery of the minimum marker gene combinations for cell type identification from single-cell RNA sequencing
MIT License
53 stars 20 forks source link

KeyError: '0' on the ranking step #5

Closed YuliaInn closed 1 month ago

YuliaInn commented 2 years ago

I transferred a Seurat object, so my anndata looks like this:

MU150CDXT_scaled

AnnData object with n_obs × n_vars = 3841 × 2000 obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA', 'percent.mt', 'percent.rb', 'RNA_snn_res.0.5', 'louvain' var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable'

I assume NSForest needs just highly variable genes and scaled expression values. I also transferred cells' and features' metadata from Seurat object. I renamed seurat clusters to "louvain" manually.

When I run MU150CDXT_markers = NS_Forest(MU150CDXT_scaled)

I get this output with an error:

8 0 Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 2895, in get_loc return self._engine.get_loc(casted_key) File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 98, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index_class_helper.pxi", line 93, in pandas._libs.index.Int64Engine._check_type KeyError: '0' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in File "/Users/yuliai/PycharmProjects/NSforest/NSForest_v3.py", line 202, in NS_Forest Positive_RankedList_Complete = negativeOut(RankedList, column, medianValues, Median_Expression_Level) File "/Users/yuliai/PycharmProjects/NSforest/NSForest_v3.py", line 48, in negativeOut if medianValues.loc[column, i] > Median_Expression_Level: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexing.py", line 873, in getitem return self._getitem_tuple(key) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexing.py", line 1044, in _getitem_tuple return self._getitem_lowerdim(tup) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexing.py", line 786, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexing.py", line 1110, in _getitem_axis return self._get_label(key, axis=axis) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexing.py", line 1059, in _get_label return self.obj.xs(label, axis=axis) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 3491, in xs loc = self.index.get_loc(key) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 2897, in get_loc raise KeyError(key) from err KeyError: '0'

I guess something is wrong with my 'column' variable. I do not really understand where it comes from.

malosreet commented 2 years ago

I was able to move past the error on this step when I renamed all my clusters to the format "cluster0", "cluster1", etc, similar to this response: https://github.com/JCVenterInstitute/NSForest/issues/4#issuecomment-882963655

yunzhang813 commented 1 month ago

Thanks of the ticket. Code refactored in v4.0.