Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error encountered when running ov.utils_plot_embedding_celltype #241

Open
Zstark11 opened this issue Dec 23, 2024 · 3 comments
Open

Error encountered when running ov.utils_plot_embedding_celltype #241

Zstark11 opened this issue Dec 23, 2024 · 3 comments

Comments

@Zstark11
Copy link

ov.utils.plot_embedding_celltype(adata,figsize=None,basis='X_mde_harmony',
                            celltype_key='scsa_celltype_cellmarker-1',
                            title='Cell type',
                            celltype_range=(2,6),
                            embedding_range=(4,10))

report errors:
The number of cell types is too large, please set the figsize parameter

Afterwards, I adjusted the figsize parameter

ov.utils.plot_embedding_celltype(adata,figsize=(12, 8),basis='X_mde_harmony',
                            celltype_key='scsa_celltype_cellmarker-1',
                            title='Cell type',
                            celltype_range=(2,5),
                            embedding_range=(4,10))

report errors:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexes/base.py:3805](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexes/base.py#line=3804), in Index.get_loc(self, key)
   3804 try:
-> 3805     return self._engine.get_loc(casted_key)
   3806 except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'scsa_celltype_cellmarker-1'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[54], line 1
----> 1 ov.utils.plot_embedding_celltype(adata,figsize=(12, 8),basis='X_mde_harmony',
      2                             celltype_key='scsa_celltype_cellmarker-1',
      3                             title='Cell type',
      4                             celltype_range=(2,5),
      5                             embedding_range=(4,10))

File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/omicverse/utils/_plot.py:554](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/omicverse/utils/_plot.py#line=553), in plot_embedding_celltype(adata, figsize, basis, celltype_key, title, celltype_range, embedding_range, xlim)
    550 for idx,cell in zip(range(cell_num_pd.shape[0]),
    551                     adata.obs[celltype_key].cat.categories):
    552     ax2.scatter(100,
    553             cell,c=cell_color_dict[cell],s=50)
--> 554     ax2.plot((100,cell_num_pd.loc[cell,celltype_key]),(idx,idx),
    555             c=cell_color_dict[cell],lw=4)
    556     ax2.text(100,idx+0.2,
    557             cell+'('+str("{:,}".format(cell_num_pd.loc[cell,celltype_key]))+')',fontsize=11)
    558 ax2.set_xlim(xlim,cell_num_pd.iloc[1].values[0]) 

File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexing.py:1183](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexing.py#line=1182), in _LocationIndexer.__getitem__(self, key)
   1181     key = tuple(com.apply_if_callable(x, self.obj) for x in key)
   1182     if self._is_scalar_access(key):
-> 1183         return self.obj._get_value(*key, takeable=self._takeable)
   1184     return self._getitem_tuple(key)
   1185 else:
   1186     # we by definition only have the 0th axis

File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/frame.py:4214](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/frame.py#line=4213), in DataFrame._get_value(self, index, col, takeable)
   4211     series = self._ixs(col, axis=1)
   4212     return series._values[index]
-> 4214 series = self._get_item_cache(col)
   4215 engine = self.index._engine
   4217 if not isinstance(self.index, MultiIndex):
   4218     # CategoricalIndex: Trying to use the engine fastpath may give incorrect
   4219     #  results if our categories are integers that dont match our codes
   4220     # IntervalIndex: IntervalTree has no get_loc

File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/frame.py:4638](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/frame.py#line=4637), in DataFrame._get_item_cache(self, item)
   4633 res = cache.get(item)
   4634 if res is None:
   4635     # All places that call _get_item_cache have unique columns,
   4636     #  pending resolution of GH#33047
-> 4638     loc = self.columns.get_loc(item)
   4639     res = self._ixs(loc, axis=1)
   4641     cache[item] = res

File [~/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812](http://biotrainee.vip:8102/home/data/miniconda3/envs/ZGY-1/lib/python3.10/site-packages/pandas/core/indexes/base.py#line=3811), in Index.get_loc(self, key)
   3807     if isinstance(casted_key, slice) or (
   3808         isinstance(casted_key, abc.Iterable)
   3809         and any(isinstance(x, slice) for x in casted_key)
   3810     ):
   3811         raise InvalidIndexError(key)
-> 3812     raise KeyError(key) from err
   3813 except TypeError:
   3814     # If we have a listlike key, _check_indexing_error will raise
   3815     #  InvalidIndexError. Otherwise we fall through and re-raise
   3816     #  the TypeError.
   3817     self._check_indexing_error(key)

KeyError: 'scsa_celltype_cellmarker-1'

Checked the contents of scsa_celltype_cellmarker-1 and did not find any abnormalities
adata.obs["scsa_celltype_cellmarker-1"]

AAACCTGAGGAT    Natural killer T (NKT) cell
AAACCTGCAGCG    Natural killer T (NKT) cell
AAACCTGGTACG    Natural killer T (NKT) cell
AAACCTGTCTTT                         T cell
AAACGGGAGCTG                      Stem cell
                           ...             
TTTGTCACAGAT                      Astrocyte
TTTGTCAGTGAT         Neural progenitor cell
TTTGTCAGTTCA                Epithelial cell
TTTGTCATCAAC                        Unknown
TTTGTCATCATA                   TCA                Epithelial cell
TTTGTCATCAAC                        Unknown
TTTGTCATCATA                      Stem cell
Name: scsa_celltype_cellmarker-1, Length: 10317, dtype: category
Categories (11, object): ['Astrocyte', 'B cell', 'Endothelial cell', 'Epithelial cell', ..., 'Neural progenitor cell', 'Stem cell', 'T cell', 'Unknown']   Stem cell
Name: scsa_celltype_cellmarker-1, Length: 10317, dtype: category
Categories (11, object): ['Astrocyte', 'B cell', 'Endothelial cell', 'Epithelial cell', ..., 'Neural progenitor cell', 'Stem cell', 'T cell', 'Unknown']
@Zstark11
Copy link
Author

I also reported the same error using SCSA's example data

@GhostInTheShellwjc
Copy link

I encounter the same problem with you.It only influences the left part of the picture,and
the umap picture is right.You can draw a pie chart instead of the left part (the sum of cells),using plotly.

@Zstark11
Copy link
Author

ov.utils.plot_embedding_celltype

What is the specific code to draw this pie chart? Is it a function in the ov.utils.plot_embedding_celltype?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants