Skip to content

Instantly share code, notes, and snippets.

@dyf
Created April 14, 2017 01:14
Show Gist options
  • Save dyf/2dff94d2328caacfa2ec9cbc687384ea to your computer and use it in GitHub Desktop.
Save dyf/2dff94d2328caacfa2ec9cbc687384ea to your computer and use it in GitHub Desktop.
parsing ontologies
import json
from allensdk.core.structure_tree import StructureTree
file_name = "C:/Users/davidf/Downloads/mouse-brain-ontology.json"
structures = json.load(open(file_name,'r'))
# workaround for a bug in StructureTree.clean_structures that I just found
for s in structures:
s['id'] = int(s['id'])
s['structure_sets'] = []
# clean up the input to what StructureTree wants
clean_structures = StructureTree.clean_structures(structures)
# Make a StructureTree
st = StructureTree(clean_structures)
visp = st.get_structures_by_acronym(['VISp'])[0]
print visp['name']
print visp['id']
print "children of visp"
visp_children = st.children([visp['id']])[0]
print visp_children
print "parent of visp"
visp_parent = st.parent([visp['id']])[0]
print visp_parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment