Brain Atlas Toolkit
This package is intended as a toolkit for manipulating hierarchical brain atlases. For example, the Allen Mouse Brain Atlas has a parent-child ontology of this structure:
{
"id": 997,
"acronym": "root",
"name": "root",
"graph_order": 0,
"parent_structure_id": null,
"children": [
{
"id": 8,
"acronym": "grey",
"name": "Basic cell groups and regions",
"graph_order": 1,
"parent_structure_id": 997,
"children": [
{
"id": 567,
"acronym": "CH",
"name": "Cerebrum",
"graph_order": 2,
"parent_structure_id": 8,
"children": [
...
Requirements
- python>=3.7
- A system-wide installation of graphviz: https://www.graphviz.org/ if you are going to use any of the visualization tools in this package.
Examples
Load a custom brain atlas from JSON file
from brain_atlas_toolkit import graph_tools
import json
json_file = "allen_ontology.json"
with open(json_file,'r') as infile:
ontology_dict = json.load(infile)
Note that this JSON file must have the structure of the example ontology shown above. The minimal set of keys in each element are:
- id
- name
- parent_structure_id
Initialize ontology graph
ontology_graph = graph_tools.Graph(ontology_dict)
Get all progeny (a.k.a. descendents or subregions) of a region of interest returned in a flattened list
ontology_graph.get_progeny('Somatomotor areas')
which returns:
['Somatomotor areas, Layer 1', 'Somatomotor areas, Layer 2/3', 'Somatomotor areas, Layer 5', 'Somatomotor areas, Layer 6a', 'Somatomotor areas, Layer 6b', 'Primary motor area', 'Primary motor area, Layer 1', 'Primary motor area, Layer 2/3', 'Primary motor area, Layer 5', 'Primary motor area, Layer 6a', 'Primary motor area, Layer 6b', 'Secondary motor area', 'Secondary motor area, layer 1', 'Secondary motor area, layer 2/3', 'Secondary motor area, layer 5', 'Secondary motor area, layer 6a', 'Secondary motor area, layer 6b']
Get the parent name of a region of interest
ontology_graph.get_parent('Somatomotor areas')
which returns:
Isocortex
Get the integer id of a region of interest
ontology_graph.get_id('Somatomotor areas')
which returns:
500
Get the acronym name of a region of interest
ontology_graph.get_parent('Somatomotor areas')
which returns:
MO
Print a branch of the ontology
ontology_graph.print_branch('Somatomotor areas')
which returns
0 Somatomotor areas
1 Somatomotor areas, Layer 1
1 Somatomotor areas, Layer 2/3
1 Somatomotor areas, Layer 5
1 Somatomotor areas, Layer 6a
1 Somatomotor areas, Layer 6b
1 Primary motor area
2 Primary motor area, Layer 1
2 Primary motor area, Layer 2/3
2 Primary motor area, Layer 5
2 Primary motor area, Layer 6a
2 Primary motor area, Layer 6b
1 Secondary motor area
2 Secondary motor area, layer 1
2 Secondary motor area, layer 2/3
2 Secondary motor area, layer 5
2 Secondary motor area, layer 6a
2 Secondary motor area, layer 6b
Print a branch of the ontology and control the depth of the tree
ontology_graph.print_branch('Somatomotor areas',stoplevel=1)
which returns
0 Somatomotor areas
1 Somatomotor areas, Layer 1
1 Somatomotor areas, Layer 2/3
1 Somatomotor areas, Layer 5
1 Somatomotor areas, Layer 6a
1 Somatomotor areas, Layer 6b
1 Primary motor area
1 Secondary motor area
The default stoplevel value is -1, which means print the entire tree to max depth.
Visualize a branch of the ontology
digraph = ontology_graph.visualize_graph('Somatomotor areas',level=2)
digraph.format='png' # control the image type; supports png, pdf and other formats
digraph.view()
The last line will save and then open up an image in your default image viewer application. The image should look like this (click image to view zoomed in version):
For full documentation of the digraph object, see the graphviz Python API documentation: https://graphviz.readthedocs.io/en/stable/
Metadata
Release files for brain-atlas-toolkit 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brain_atlas_toolkit-0.4.3.tar.gz | 114.0 kB | Without provenance | Details for brain_atlas_toolkit-0.4.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brain_atlas_toolkit-0.4.3-py3-none-any.whl | Python 3 | none | any | Details for brain_atlas_toolkit-0.4.3-py3-none-any.whl |
Total release size: 131.3 kB
Release files / brain_atlas_toolkit-0.4.3.tar.gz
| Download URL | brain_atlas_toolkit-0.4.3.tar.gz |
|---|---|
| Size | 114.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34ce38e1e94986752210cf8a757eeb97186b72c140ae285fa21ee685716db7d4
|
|
BLAKE2b-256 checksum How to use checksums |
a4aec934d795dca12df41de814e5b10589c5e5b2a2d56ebddd45eed579dca5a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / brain_atlas_toolkit-0.4.3-py3-none-any.whl
| Download URL | brain_atlas_toolkit-0.4.3-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
112f958a98495e38c0a2e1a97076f5b4faabf58c081567ce9fec55bc03303e2d
|
|
BLAKE2b-256 checksum How to use checksums |
2b0f10dc6befabcc3df9659c4cf734fed65e964fd75028b8593f449863496372
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for brain-atlas-toolkit 0.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.