# How do I find the injection hemisphere for a mouse connectivity dataset?

**URL:** <https://community.brain-map.org/t/how-do-i-find-the-injection-hemisphere-for-a-mouse-connectivity-dataset/304>\
**Category:** Technical\
**Tags:** atlas-mouse-brain-connectivity, how-to, allensdk\
**Created:** [October 10, 2019, 7:25pm UTC](https://community.brain-map.org/t/how-do-i-find-the-injection-hemisphere-for-a-mouse-connectivity-dataset/304 "2019-10-10T19:25:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nileg](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.brain-map.org/nileg/32/39_2.png) [@nileg](https://community.brain-map.org/u/nileg)\
**Post date:** [October 10, 2019, 7:25pm UTC](https://community.brain-map.org/t/how-do-i-find-the-injection-hemisphere-for-a-mouse-connectivity-dataset/304/1 "2019-10-10T19:25:30Z")

</div>

Mouse connectivity tracing experiments may have been injected on either the right or the left hemispheres. How can one find the injection hemisphere programmatically?

### Using AllenSDK

AllenSDK is a Python package for accessing and analyzing our data. You can read the documentation here and install it via:

```auto
pip install allensdk

```

To find injection hemispheres, you can use the following code:

```auto
import pandas as pd
from allensdk.core.mouse_connectivity_cache import MouseConnectivityCache

cache = MouseConnectivityCache()
experiments = cache.get_experiments()

# restricting to just VISp experiments
visp_experiment_ids = [experiment["id"] for experiment in experiments if experiment["structure_abbrev"] == "VISp"]

unionizes = pd.DataFrame(cache.get_structure_unionizes(
    visp_experiment_ids, 
    is_injection=True, # we want data about the injections
    structure_ids=[997], # this is the root structure. The resulting records will summarize injection data for the whole brain
    hemisphere_ids=[1, 2] # 1 is left, 2 is right
))

# remove unneeded columns
injection_hemispheres = unionizes.loc[:, ["experiment_id", "hemisphere_id", "projection_volume"]]

# report hemispheres as "left" and "right" rather than 1 and 2
injection_hemispheres["hemisphere"] = injection_hemispheres.apply(lambda row: "left" if row["hemisphere_id"] == 1 else "right", axis=1)
injection_hemispheres.drop(columns="hemisphere_id", inplace=True)

```

this produces:

```auto
     experiment_id projection_volume hemisphere
0 500836840 0.375218 left
1 307297141 0.663636 right
2 272821309 0.125424 right
3 512315551 1.614223 left
4 510581751 0.031653 left
.. ... ... ...
277 596571282 0.001158 right
278 638978767 0.006102 right
279 503069254 0.071099 left
280 263780729 0.223684 right
281 156545918 0.031552 right

```

The first time you run this, it will take a little while to download data for all of these experiments.

### Direct API access

If you absolutely don’t want to use Python, you can query our API for a table of injection hemispheres:

```auto
http://api.brain-map.org/api/v2/data/query.json?criteria=model::ProjectionStructureUnionize,rma::criteria,[is_injection$eqtrue][structure_id$eq997],hemisphere[id$ne3],rma::include,hemisphere,rma::options[num_rows$eq%27all%27],[tabular$eq%27hemispheres.name%20as%20hemisphere,section_data_set_id,projection_volume%27]

```

This query grabs records for all experiments. If you only want a subset of experiments, you can add a criteria clause like `section_data_set[id$in477927130,304337288]` to restrict the results.

---

<div class="post-metadata">

**Author:** ![andrewms](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andrewms](https://community.brain-map.org/u/andrewms)\
**Post date:** [November 3, 2022, 8:33pm UTC](https://community.brain-map.org/t/how-do-i-find-the-injection-hemisphere-for-a-mouse-connectivity-dataset/304/2 "2022-11-03T20:33:22Z")

</div>

Hi @nileg ,

When I do this, some samples show up twice in this record, once with a left hemisphere volume injection and another time with a right hemisphere injection. Does this mean they were injected in both hemispheres? I see the same thing when I look on the api directly. Seems that this occurs with many samples. How do I interpret this?

Here’s an image of  
 ![listed-twice](https://canada1.discourse-cdn.com/flex027/uploads/brainobservatory/original/1X/c76498df7b58c195373d69ceb98bfc11af3fcb97.png)

Best,  
Andrew
