# How to isolate individual gene expression values within a cluster?

**URL:** https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722
**Category:** anndata
**Created:** [September 2, 2022, 2:38am UTC](https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722 "2022-09-02T02:38:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dub2s](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/dub2s/32/361_2.png) [@dub2s](https://discourse.scverse.org/u/dub2s)
#### Post date: [September 2, 2022, 2:38am UTC](https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722/1 "2022-09-02T02:38:41Z")

</div>

After clustering the data using scanpy, is it possible to extract list of genes alongwith their expression values from within a cluster ? Basically, I want to see the expression of a particular gene among the different clusters.

I am not sure how the expression of a gene would be defined within a cluster ?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![ivirshup](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ivirshup/32/160_2.png) [@ivirshup](https://discourse.scverse.org/u/ivirshup)
#### Post date: [September 3, 2022, 2:49pm UTC](https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722/2 "2022-09-03T14:49:04Z")

</div>

If you’re looking to get the expression values you could subset the `AnnData` to the clusters of interest like:

```python
adata[adata.obs["leiden"].isin(["clusters", "of", "interest"])]

```

But there are also plenty of ways to visualize this in scanpy. See [this plotting tutorial](https://scanpy-tutorials.readthedocs.io/en/latest/plotting/core.html#Identification-of-clusters-based-on-known-marker-genes) for examples.

---

<div class="post-metadata">

### Author: ![dub2s](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/dub2s/32/361_2.png) [@dub2s](https://discourse.scverse.org/u/dub2s)
#### Post date: [September 4, 2022, 12:00am UTC](https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722/3 "2022-09-04T00:00:41Z")

</div>

Thank you very much for your reply.

I was wondering if the following would be a good metric to define mean expression of a gene within that cluster ?

`

> cs13\_adata[:,i].X.mean(0).item() ## where cs13 is the adata sliced from the original one via one of the clusuter and i is a given gene

`

---

<div class="post-metadata">

### Author: ![ivirshup](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ivirshup/32/160_2.png) [@ivirshup](https://discourse.scverse.org/u/ivirshup)
#### Post date: [September 14, 2022, 1:48pm UTC](https://discourse.scverse.org/t/how-to-isolate-individual-gene-expression-values-within-a-cluster/722/4 "2022-09-14T13:48:22Z")

</div>

That would calculate the mean, yes.
