# Cell type annotation with new data

**URL:** <https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877>\
**Category:** Help\
**Created:** [October 30, 2022, 11:12pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877 "2022-10-30T23:12:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [October 30, 2022, 11:12pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/1 "2022-10-30T23:12:25Z")

</div>

Hello all,

Would you please tell me how to annotate cell type with new data when using scanpy in previous steps? Thank you so much!

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [October 31, 2022, 9:28am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/2 "2022-10-31T09:28:42Z")

</div>

Hi @Chris

Cell type annotation always requires knowing your biological system, meaning you should know more or less which cell types you should expect in your data. The easiest thing you can do is to identify marker genes with `sc.tl.rank_genes_groups`, check them per cluster with `sc.pl.rank_genes_groups_dotplot` and manually annotate them.

In case you are not sure and want a first “draft” annotation, you can always use methods that leverage marker gene databases and automatically annotate your clusters. For example, here is a vignette using `decoupler`: [Cell type annotation from marker genes — decoupler 1.2.1 documentation](https://decoupler-py.readthedocs.io/en/latest/notebooks/cell_annotation.html)

In any case, the annotation of your clusters will always depend on the biological question you are trying to answer with your data, so if you use an automated method always check with someone that knows the system and can validate that the annotations are correct.

Hope this is helpful!

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 2, 2022, 12:56am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/3 "2022-11-02T00:56:57Z")

</div>

Thanks @PauBadiaM!

I know the tissue of the cells come from and ran sc.tl.rank\_genes\_groups. How scanpy know which cell type to include in the dot plot when using sc.pl.rank\_genes\_groups\_dotpot()?

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 2, 2022, 8:39am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/4 "2022-11-02T08:39:07Z")

</div>

Previous to running `sc.tl.rank_genes_groups` you must have clustered your cells to identify characteristic cell populations, using `sc.tl.leiden` for example. Then, `sc.tl.rank_genes_groups` identifies which genes are specific (“markers”) for each of these clusters. Then `sc.pl.rank_genes_groups_dotpot` just plots the top N marker genes for each of them. So, to answer your question, it depends on the clusters that you defined previously. Note that it can be the case that more than one cluster belongs to the same cell type (they will show very similar marker genes), this usually happens for the most abundant cell types in your system.

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 2, 2022, 1:20pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/5 "2022-11-02T13:20:04Z")

</div>

Sorry but I still have things not clear. So for example I got 10 clusters and identified 2 markers genes for each cluster. How can I know which cell type to put in the dotplot()?

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 2, 2022, 1:47pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/6 "2022-11-02T13:47:33Z")

</div>

You should be able to do it based on the genes that you observe. For example, if you see that a cluster has _CD19_ and _PXK_ as marker genes, you could annotate it as B cells since these are known markers for B cells. If you are not sure about them, you can try to google them out one by one and come up with an annotation, or use automated approaches like `decoupler`, mentioned before.

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 2, 2022, 4:23pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/7 "2022-11-02T16:23:52Z")

</div>

Could I use this data to do cell-type annotation?

> **[choose gene expression markers | PanglaoDB](https://panglaodb.se/markers.html?cell_type=%27choose%27)**
>
> Gene expression markers for choose

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 2, 2022, 4:28pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/8 "2022-11-02T16:28:00Z")

</div>

Indeed! This is the database that `decoupler` uses to enrich cell types.

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 3, 2022, 3:31am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/9 "2022-11-03T03:31:36Z")

</div>

In the effort of doing cell type annotation, I run:

sc.pl.umap(adata, color =[‘CD3E’], frameon = False, layer = ‘scvi\_normalized’)

* * *

TypeError Traceback (most recent call last)  
 in   
----\> 1 sc.pl.umap(adata, color =[‘CD3E’], frameon = False, layer = ‘scvi\_normalized’)

5 frames  
/usr/local/lib/python3.7/dist-packages/matplotlib/colorbar.py in **init** (self, ax, mappable, \*\*kw)  
1228 they will need to be customized again. However, if the norm only  
1229 changes values of _vmin_, _vmax_ or _cmap_ then the old formatter  
 → 1230 and locator will be preserved.  
1231 “”"  
1232

TypeError: **init** () got an unexpected keyword argument ‘location’

Would you suggest a way to fix this? I appreciate it!

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 3, 2022, 1:51pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/10 "2022-11-03T13:51:08Z")

</div>

Hi moderators,

I follow along the tutorial here:

[https://decoupler-py.readthedocs.io/en/latest/notebooks/cell\_annotation.html](https://decoupler-py.readthedocs.io/en/latest/notebooks/cell_annotation.html)

markers = dc.get\_resource(‘PanglaoDB’)

markers

* * *

TypeError Traceback (most recent call last)  
 in   
----\> 1 markers = dc.get\_resource(‘PanglaoDB’)  
2 markers

4 frames  
/usr/local/lib/python3.7/dist-packages/omnipath/\_core/downloader/\_downloader.py in **init** (self, opts)  
52 allowed\_methods=[“HEAD”, “GET”, “OPTIONS”],  
53 status\_forcelist=[413, 429, 500, 502, 503, 504],  
—\> 54 backoff\_factor=1,  
55 )  
56 )

TypeError: **init** () got an unexpected keyword argument ‘allowed\_methods’

I try to suggestion on the decoupler page:

rm /content/.cache/omnipathdb/\*

rm: cannot remove ‘/content/.cache/omnipathdb/\*’: No such file or directory

Would you please help? I appreciate it!

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 3, 2022, 3:45pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/11 "2022-11-03T15:45:04Z")

</div>

Hi @Chris

Could you install the latest versions of `decoupler` and `omnipath` and try again? Run this:

```auto
pip install git+https://github.com/saezlab/decoupler-py
pip install git+https://github.com/saezlab/omnipath

```

Let me know if it works! 😉

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 3, 2022, 5:02pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/12 "2022-11-03T17:02:19Z")

</div>

Two lines of your code cleared the bug above 😃 Thank you!

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 3, 2022, 7:31pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/13 "2022-11-03T19:31:34Z")

</div>

Other bug came 😂

sc.pl.umap(acts, color=‘NK cells’)

TypeError Traceback (most recent call last)  
 in   
----\> 1 sc.pl.umap(acts, color=‘NK cells’)

5 frames  
/usr/local/lib/python3.7/dist-packages/matplotlib/colorbar.py in **init** (self, ax, mappable, \*\*kw)  
1228 they will need to be customized again. However, if the norm only  
1229 changes values of _vmin_, _vmax_ or _cmap_ then the old formatter  
 → 1230 and locator will be preserved.  
1231 “”"  
1232

TypeError: **init** () got an unexpected keyword argument ‘location’

I got this error before with different data and still don’t know why 🥲  
Would you please have a look?

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 4, 2022, 8:18am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/14 "2022-11-04T08:18:43Z")

</div>

It might be an incompatibility with a recent update of `matplotlib`, as described in this GitHub issue:

> <https://github.com/scverse/scanpy/issues/2318#issuecomment-1273295202>
>
> I was running this code \`sc.pl.umap(adata, color = \['KIR3DL1'\], frameon = False,… layer = 'scvi\_normalized')\` to create umap but it gave me an error message with empty heatmap color bar legend.
> 
> !\[스크린샷 2022-09-02 오전 9 34 00\](https://user-images.githubusercontent.com/64761042/188034720-20eacca2-efa0-4d6c-9e7f-0543f85d1cd7.png)
> 
> 
> !\[스크린샷 2022-09-01 오후 6 58 54\](https://user-images.githubusercontent.com/64761042/188034773-c32610cc-60a3-4c17-a000-8296f013b3e7.png)

Try downgrading matplotlib to 3.5.2:

```auto
pip install matplotlib==3.5.2

```

---

<div class="post-metadata">

**Author:** ![Chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Chris](https://discourse.scverse.org/u/Chris)\
**Post date:** [November 5, 2022, 10:25pm UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/16 "2022-11-05T22:25:37Z")

</div>

sc.pl.umap(acts, color=‘NK cells’)

Is that color = ‘NK cells’ because you know your sample has NK cells? If new tissue, not blood cells, how can I know the value to put in color? Thank you so much!

---

<div class="post-metadata">

**Author:** ![PauBadiaM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/paubadiam/32/410_2.png) [@PauBadiaM](https://discourse.scverse.org/u/PauBadiaM)\
**Post date:** [November 7, 2022, 8:39am UTC](https://discourse.scverse.org/t/cell-type-annotation-with-new-data/877/17 "2022-11-07T08:39:16Z")

</div>

Hi @Chris

This is just an example on how to visualize a specific cell type of interest, in this case NK cells. What you can do is to identify which are the most represented cell types in your data with `dc.summarize_acts` (as shown in the notebook) and then plot them in case you want to manually check them.
