# Extracting data for all genes from an ROI

**URL:** <https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507>\
**Category:** Technical\
**Tags:** atlas-mouse-brain-adult, api, anatomy, transcriptomics, how-to\
**Created:** [April 10, 2020, 3:01pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507 "2020-04-10T15:01:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vbhave](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vbhave](https://community.brain-map.org/u/vbhave)\
**Post date:** [April 10, 2020, 3:01pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/1 "2020-04-10T15:01:57Z")

</div>

I was writing to ask about how we might obtain a full gene expression dataset for a handful of brain regions from the adult mouse (e.g. the DR and PAG).

We’re interested in getting data by anatomical region as opposed to voxel. Because the ABA interface already permits looking at differentially expressed genes between regions, it would be great if we could obtain the data used as the basis for that tool. My understanding is that the API does have quantified data by structure that we can access.

This information would be incredibly valuable to us. For instance, we’d want to leverage the expression data to refine the way we classify cell types in single-cell RNA sequencing.

---

<div class="post-metadata">

**Author:** ![jeremyinseattle](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/jeremyinseattle/32/50_2.png) [@jeremyinseattle](https://community.brain-map.org/u/jeremyinseattle)\
**Post date:** [April 10, 2020, 4:14pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/2 "2020-04-10T16:14:31Z")

</div>

A good starting point would be [Structure Unionization](http://help.brain-map.org/display/devmouse/API#API-ExpressionStructuresStructureUnionization) (see [this post](https://community.brain-map.org/t/quantification-of-gene-expression-by-in-situ-hybridization-finding-and-using-the-raw-values/153)). This gets the converse of what you want: all regions for one gene, but does wrap up by region as requested. I’m not sure about getting all gene data for a few regions, but maybe someone else on here knows.

---

<div class="post-metadata">

**Author:** ![wayne](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/wayne/32/16_2.png) [@wayne](https://community.brain-map.org/u/wayne)\
**Post date:** [June 2, 2020, 4:15pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/3 "2020-06-02T16:15:13Z")

</div>

Here is the API call that would get you structure unionization data by region.

```
http://api.brain-map.org/api/v2/data/query.json?criteria=model::StructureUnionize,rma::criteria,structure[acronym$eq'DR']

```

This returns an entry for each of the tens of thousands of section data sets (experiments) in the atlas, so it is likely that you will want to refine it further to get just what you need. There is lots of documentation available such as the links in Jeremy’s post above and these:  
[http://help.brain-map.org/display/api/Allen%2BBrain%2BAtlas%2BAPI](http://help.brain-map.org/display/api/Allen%2BBrain%2BAtlas%2BAPI)  
[http://help.brain-map.org/display/api/RESTful+Model+Access+(RMA)](http://help.brain-map.org/display/api/RESTful+Model+Access+(RMA))

---

<div class="post-metadata">

**Author:** ![vbhave](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vbhave](https://community.brain-map.org/u/vbhave)\
**Post date:** [June 2, 2020, 6:13pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/4 "2020-06-02T18:13:55Z")

</div>

Thank you! In this JSON, is there information about the gene being looked at in each section dataset? Or am I misunderstanding what you’re doing here? Really appreciate the help.

---

<div class="post-metadata">

**Author:** ![wayne](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/wayne/32/16_2.png) [@wayne](https://community.brain-map.org/u/wayne)\
**Post date:** [June 2, 2020, 6:16pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/5 "2020-06-02T18:16:41Z")

</div>

No, as it is written that information is not there, but it could be. Perhaps you can more explicitly describe what it is you need. So far we have identified expression per structure with gene information added. Anything else?

---

<div class="post-metadata">

**Author:** ![vbhave](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vbhave](https://community.brain-map.org/u/vbhave)\
**Post date:** [June 2, 2020, 6:41pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/6 "2020-06-02T18:41:54Z")

</div>

> [@wayne](#):
>
> ```auto
> http://api.brain-map.org/api/v2/data/query.json?criteria=model::StructureUnionize,rma::criteria,structure[acronym$eq'DR']
> 
> ```

This is very close! The last step would be find out what gene is being assayed in each of the thousands of “section\_data\_set\_ids” (and perhaps other information about each experiment) so that we can look at gene expression in the region, and potentially restrict our analyses to certain experiments.

---

<div class="post-metadata">

**Author:** ![wayne](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/wayne/32/16_2.png) [@wayne](https://community.brain-map.org/u/wayne)\
**Post date:** [June 2, 2020, 7:09pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/7 "2020-06-02T19:09:25Z")

</div>

How about this one?  
[http://api.brain-map.org/api/v2/data/query.json?criteria=model::SectionDataSet,rma::criteria,structure\_unionizes(structure[acronym$eq'DR']),genes,rma::include,genes,structure\_unionizes](http://api.brain-map.org/api/v2/data/query.json?criteria=model::SectionDataSet,rma::criteria,structure_unionizes(structure%5Bacronym%24eq%27DR%27%5D),genes,rma::include,genes,structure_unionizes)

---

<div class="post-metadata">

**Author:** ![vbhave](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vbhave](https://community.brain-map.org/u/vbhave)\
**Post date:** [June 2, 2020, 8:16pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/8 "2020-06-02T20:16:41Z")

</div>

So this seems great! I’m assuming these are the Structure Unionize attributes for all the experiments specifically in DR?

Just a couple of quick q’s: I appended “rma::options[num\_rows$eqall]” to the end of that last query, but both the max number of displayed rows (25971) and total rows (26038) are fewer than the total (26069) in the first query that you sent me:  
[http://api.brain-map.org/api/v2/data/query.json?criteria=model::StructureUnionize,rma::criteria,structure[acronym$eq’DR’]](http://api.brain-map.org/api/v2/data/query.json?criteria=model::StructureUnionize,rma::criteria,structure%5Bacronym%24eq%27DR%27%5D)

Any idea what might be going on here, with both the row display and overall number of rows?

---

<div class="post-metadata">

**Author:** ![wayne](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/wayne/32/16_2.png) [@wayne](https://community.brain-map.org/u/wayne)\
**Post date:** [June 2, 2020, 8:30pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/9 "2020-06-02T20:30:21Z")

</div>

Adding these additional fields is the equivalent of doing a database “INNER JOIN”. It is likely that not every record will have a corresponding record in another table.

If you are really interested in tracking it down further, I am going to refer you to the API documentation to write queries that return more information that you can use to help your investigation.

---

<div class="post-metadata">

**Author:** ![ddofer](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/ddofer/32/2306_2.png) [@ddofer](https://community.brain-map.org/u/ddofer)\
**Post date:** [July 31, 2025, 1:47pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/10 "2025-07-31T13:47:03Z")

</div>

Is there a working solution for this, for the developing mouse brain? (I want to do something similar: All genes, organized by region, and all time points)

---

<div class="post-metadata">

**Author:** ![danielsf](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/danielsf/32/209_2.png) [@danielsf](https://community.brain-map.org/u/danielsf)\
**Post date:** [August 4, 2025, 6:52pm UTC](https://community.brain-map.org/t/extracting-data-for-all-genes-from-an-roi/507/11 "2025-08-04T18:52:09Z")

</div>

I have tried to provide an example in the response [on this thread.](https://community.brain-map.org/t/batch-download-developing-mouse-brain/4602)
