Skip to content

Instantly share code, notes, and snippets.

@lydiang
lydiang / download_adult_human_atlases.py
Created September 24, 2022 23:40
Example code to download the adult human atlas images and svg from the Allen API
import urllib.request
import json
import os
def fetch_atlas_metadata( atlas_id ) :
# RMA query to find images for atlas
query_url = "http://api.brain-map.org/api/v2/data/query.json?criteria=model::Atlas"
query_url += ",rma::criteria,[id$eq%d]" % (atlas_id)
query_url += ",rma::include,structure_graph(ontology),graphic_group_labels"
count value
44658375 0
6931 1
7339 2
134366 6
70327 7
14877 9
130357 10
5559 12
14706 15
import SimpleITK as sitk
import numpy as np
import pandas as pd
# downloaded from http://download.alleninstitute.org/informatics-archive/current-release/mouse_ccf/annotation/ccf_2017/
filename = 'annotation_25.nrrd'
itkimage = sitk.ReadImage(filename)
print(itkimage)
numpyImage = sitk.GetArrayFromImage(itkimage)
@lydiang
lydiang / bucket_structure_and_metadata.py
Created March 31, 2020 16:31
Allen Mouse Brain Atlas Open Dataset bucket structure
#
# Bucket Organization
#
'''
allen_mouse_brain_atlas
+-- manifest.json # for later integration with AllenSDK
+-- section_data_sets.json # high level metadata for each section data set
+-- section_data_set_<section_data_set_id>
¦ +-- section_data_set.json # detailed metadata for each section data set
¦ +-- downsample_<downsample_factor>
http://api.brain-map.org/api/v2/data/query.xml?criteria=
model::AtlasImage
,
rma::criteria,
[annotated$eqtrue],atlas_data_set(atlases[id$in181276165,181276164,181276162,181276160,181276151,181276130,181275741])
,
rma::include,
atlas_data_set(atlases)
,rma::options
[only$eq'atlases.name,atlases.id,data_sets.section_thickness,sub_images.section_number,sub_images.id']
@lydiang
lydiang / hba_position_example.py
Last active July 9, 2018 07:09
Example python script to plot microarray sampling position on the donor MRI
import os
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#
# Example python code to plot microarray sample on MRI image
# and replicate an instance of the planar view
#
@lydiang
lydiang / ccf_unique_ids.py
Last active November 10, 2016 21:58
Example Python script to find and count unique structure id in the CCF annotation volume
import urllib
import os
import pandas as pd
import numpy as np
import nrrd
#
# Example code to get all unique ID in CCF annotation volume
# and match them up to structure acronyms
#
@lydiang
lydiang / structure_api_query.txt
Created November 9, 2016 18:27
API query to get all structure from an ontology in CSV format
http://api.brain-map.org/api/v2/data/query.csv?criteria=model::Structure,
rma::criteria,[ontology_id$eq1],
rma::options[order$eq%27structures.graph_order$asc%27][num_rows$eqall]
@lydiang
lydiang / break_up_atlas_svg.py
Last active October 31, 2016 16:05
Example Python script to break up an atlas svg into per-structure svg #AllenBrainAtlasAPI #AtlasDownload
import urllib, json
import os
import xml.etree.ElementTree as ET
#
# Example python code to break up an atlas svg by structure
#
# Read the Allen Brain Atlas API documentation:
# http://help.brain-map.org/display/api/Atlas+Drawings+and+Ontologies
#
@lydiang
lydiang / download_image_series_8bit.py
Last active October 31, 2016 16:05
Example Python script to download images from a image series from the #AllenBrainAtlasAPI #ImageDownload
import urllib, json
import os
#
# Example python code to download images from an image series
#
# Find the image series you want from the Allen Brain Atlas portal
# Take a note of the dataset id
#