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

ov.pl.cpdb_group_heatmap error #109

Closed
qbly27 opened this issue Jul 17, 2024 · 1 comment
Closed

ov.pl.cpdb_group_heatmap error #109

qbly27 opened this issue Jul 17, 2024 · 1 comment

Comments

@qbly27
Copy link

qbly27 commented Jul 17, 2024

here, you might forget to change 'cell_labels' to the celltype_key?

--> 543 source_gene_pd[source_cell]=adata[adata.obs['cell_labels']==source_cell,

Details are above


KeyError Traceback (most recent call last)
File ~/miniconda3/envs/ov/lib/python3.11/site-packages/pandas/core/indexes/base.py:3805, 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: 'cell_labels'

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

KeyError Traceback (most recent call last)
Cell In[135], line 1
----> 1 ov.pl.cpdb_group_heatmap(adata=adata,
2 celltype_key='celltype',
3 means=cpdb_results['means'],
4 cmap={'Target':'Blues','Source':'Reds'},
5 source_cells=[Mast cell'],
6 target_cells=['T cell'],
7 plot_secret=True,
8 min_means=3,
9 nodecolor_dict=None,
10 ax=None,
11 figsize=(2,6),
12 fontsize=10
13 )

File ~/miniconda3/envs/ov/lib/python3.11/site-packages/omicverse/pl/_cpdb.py:543, in cpdb_group_heatmap(adata, celltype_key, means, source_cells, target_cells, min_means, nodecolor_dict, ax, figsize, fontsize, plot_secret, cmap, return_table)
541 source_gene_pd=pd.DataFrame(index=cor.index)
542 for source_cell in source_cells:
--> 543 source_gene_pd[source_cell]=adata[adata.obs['cell_labels']==source_cell,
544 [i.split('_')[0] for i in cor.index]].to_df().mean().values
546 target_gene_pd=pd.DataFrame(index=cor.index)
547 for target_cell in target_cells:

File ~/miniconda3/envs/ov/lib/python3.11/site-packages/pandas/core/frame.py:4102, in DataFrame.getitem(self, key)
4100 if self.columns.nlevels > 1:
4101 return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
4104 indexer = [indexer]

File ~/miniconda3/envs/ov/lib/python3.11/site-packages/pandas/core/indexes/base.py:3812, 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: 'cell_labels'

@Starlitnightly
Copy link
Owner

I'm sorry for the trouble, I'll fix it in the next version, until then you can manually define adata.obs['cell_labels'] = adata.obs[celltype_key] to avoid this error!

Zehua

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