1

I am downloading all the images from the Neurotransmitter study of the Allen Brain Atlas using this script:


from allensdk.api.queries.image_download_api import ImageDownloadApi
from allensdk.config.manifest import Manifest
import pandas as pd
import os


#getting transmitter study
#product id from http://api.brain-map.org/api/v2/data/query.json?criteria=model::Product

nt_datasets = image_api.get_section_data_sets_by_product([27])

#an instance of Image Api for downloading
image_api = ImageDownloadApi()


for index, row in df_nt.iterrows(): 
    #get section dataset id
    section_dataset_id= row['id']

    #each section dataset id has multiple image sections    
    section_images = pd.DataFrame( 
        image_api.section_image_query(
        section_data_set_id=section_dataset_id)
    )

    for section_image_id in section_images['id'].tolist():
        file_path = os.path.join('/path/to/save/dir/', 
                                 str(section_image_id) + '.jpg' )
        Manifest.safe_make_parent_dirs(file_path)
        image_api.download_section_image(section_image_id, 
                                         file_path=file_path,
                                         downsample=downsample)

This script downloads presumably all the available ISH experiments. However, I am wondering what would be the best way to get more of the metadata as follows:

1) type of ISH experiment, known as "gene" (for example whether an image is MBP-stained, Nissl-stained or etc). Shown in red circle below.

image1

2) Structure and correspondence to the atlas image (annotations, for example to see to which part of brain a section belongs to). I think this could be acquired with tree_search but not sure how. Shown in red circles below from two different webpages on Allen website.

image2

3) The scale of the image, for example how big one pixel is in the downloaded image (e.g., 0.001x0.001 mm). I would require this for image analysis with respect to MRI, for example. Shown below in the red circle.

image3

All the above information are somehow available on the website, my question is whether you could help me to do this programmatically via the SDK.

EDIT:

Also would be great to download "Nissl" stains programmatically, as they do not show using the above loop iteration. The picture is shown below.

enter image description here

4

1 回答 1

2

To access this information, you'll need to formulate a somewhat complex API query.

from allensdk.api.queries.rma_api import RmaApi

api = RmaApi()

data_set_id = 146586401

data = api.model_query('SectionDataSet', 
                       criteria='[id$eq%d]' % data_set_id, 
                       include='section_images,treatments,probes(gene),specimen(structure)')

print("gene symbol: %s" % data[0]['probes'][0]['gene']['acronym'])
print("treatment name: %s" % data[0]['treatments'][0]['name'])
print("specimen location: %s" % data[0]['specimen']['structure']['name'])
print("section xy resolution: %f um" % data[0]['section_images'][0]['resolution'])
gene symbol: MBP
treatment name: ISH
specimen location: Cingulate Cortex
section xy resolution: 1.008000 um

Without doing a deep dive on the API data model, SectionDataSets have constituent SectionImages, Treatments, Probes, and source Specimens. Probes target Genes, and Specimens can be associated with a Structure. The query is downloading all of that information for a single SectionDataSet into a nested dictionary.

I don't remember how to find the specimen block extent. I'll update the answer if I find it.

于 2019-02-24T19:51:44.023 回答