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

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:

pip install allensdk

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

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:

     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:

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.

3 Likes