I’m trying to download all the images on IvyGAP (ISH, H&E, TumorFeature). I was able to locate the APIs page (http://help.brain-map.org/display/glioblastoma/API), but it seems that this either has to be done through website GUI or there are some id’s that I could not associate to the proper images. Is there any direct way (such as FTP) to download all of these images?
There is no built-in functionality to download all the images for the Ivy Glioblastoma Atlas project. However, with a bit of programming effort, the generic image download functionality of the Allen Brain Atlas API can be leveraged to do so.
The Glioblastoma API page ( http://help.brain-map.org/display/glioblastoma/API ) lists general API calls in the “Experimental Overview and Metadata” section to get information about specimens (Note that you can change the ‘xml’ to ‘json’ if that is easier for you to work with).
Using the example for “All ISH SectionDataSets in sub-block Specimen “W32-1-1-K.01””, you can collect the ids of “sub image” records that are of interest to you.
http://api.brain-map.org/api/v2/data/query.xml?criteria=
model::SectionDataSet
,rma::criteria,specimen[external_specimen_name$eq’W32-1-1-K.01’],treatments[name$eq’ISH’]
,rma::include,genes,sub_images
sub_image_id = msg.2.sub_images.0.id = 278272303
This value can be used in an additional call to download the image:
http://api.brain-map.org/api/v2/image_download/278272303
This variation will get the annotated version of the same image:
http://api.brain-map.org/api/v2/image_download/278272303?view=tumor_feature_annotation
This variation will get the boundary version of the same image:
http://api.brain-map.org/api/v2/image_download/278272303?view=tumor_feature_boundary
This help page describes the general API functions available to download Allen Brain Atlas images: http://help.brain-map.org/display/api/Downloading+an+Image
Here is a small Python snippet to get a table that contains all URLs for one sub-block.
import pandas as pd
import requests
def get_urls_sub_block(sub_block_name):
url = f"https://api.brain-map.org/api/v2/data/query.json?criteria=model::SectionDataSet,rma::criteria,specimen[external_specimen_name$eq'{sub_block_name}'],treatments[name$eq'ISH'],rma::include,genes,sub_images"
response = requests.get(url)
data = response.json()["msg"]
image_ids = []
gene_symbols = []
for image in data:
try:
image_id = image["sub_images"][0]["id"]
image_ids.append(image_id)
except:
print(f"Error in {sub_block_name}")
image_ids.append("error")
try:
gene_symbol = image["genes"][0]["acronym"]
gene_symbols.append(gene_symbol)
except:
print(f"Error in {sub_block_name}")
gene_symbols.append("error")
images_df = pd.DataFrame({"image_id": image_ids, "gene_symbol": gene_symbols})
images_df["sub_block_name"] = sub_block_name
images_df["url"] = images_df.image_id.apply(lambda x: f"https://api.brain-map.org/api/v2/image_download/{x}")
return images_df
sub_block_name = "W32-1-1-K.01"
get_urls_sub_block(sub_block_name)
Result:
image_id gene_symbol sub_block_name url
278269506 MECOM W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278269506
278272201 PDGFRA W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272201
278272354 ITGA6 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272354
278272252 ID1 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272252
278269352 TNFAIP3 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278269352
278272303 OLIG2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272303
278269301 HIF1A W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278269301
278271742 MYC W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271742
278271691 ID2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271691
278269455 TGFBR2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278269455
278271793 MET W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271793
278272099 PROM1 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272099
278272048 EZH2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272048
278271844 IGFBP2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271844
278271895 CD44 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271895
278271997 DANCR W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271997
278272150 POSTN W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278272150
278271946 NOS2 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271946
278271640 PDPN W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271640
278271589 PI3 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278271589
278269404 BIRC5 W32-1-1-K.01 https://api.brain-map.org/api/v2/image_download/278269404