allensdk.core.structure_tree module

class allensdk.core.structure_tree.StructureTree(nodes)[source]

Bases: allensdk.core.simple_tree.SimpleTree

static clean_structures(structures, whitelist=None, data_transforms=None, renames=None)[source]

Convert structures_with_sets query results into a form that can be used to construct a StructureTree

Parameters:
structures : list of dict

Each element describes a structure. Should have a structure id path field (str values) and a structure_sets field (list of dict).

whitelist : list of str, optional

Only these fields will be included in the final structure record. Default is the output of StructureTree.whitelist.

data_transforms : dict, optional

Keys are str field names. Values are functions which will be applied to the data associated with those fields. Default is to map colors from hex to rgb and convert the structure id path to a list of int.

renames : dict, optional

Controls the field names that appear in the output structure records. Default is to map ‘color_hex_triplet’ to ‘rgb_triplet’.

Returns:
list of dict :

structures, after conversion of structure_id_path and structure_sets

static collect_sets(structure)[source]

Structure sets may be specified by full records or id. This method collects all of the structure set records/ids in a structure record and replaces them with a single list of id records.

static data_transforms()[source]
get_ancestor_id_map()[source]

Get a dictionary mapping structure ids to ancestor ids across all nodes.

Returns:
dict :

Keys are structure ids. Values are lists of ancestor ids.

get_colormap()[source]

Get a dictionary mapping structure ids to colors across all nodes.

Returns:
dict :

Keys are structure ids. Values are RGB lists of integers.

get_id_acronym_map()[source]

Get a dictionary mapping structure acronyms to ids across all nodes.

Returns:
dict :

Keys are structure acronyms. Values are structure ids.

get_name_map()[source]

Get a dictionary mapping structure ids to names across all nodes.

Returns:
dict :

Keys are structure ids. Values are structure name strings.

get_structure_sets()[source]

Lists all unique structure sets that are assigned to at least one structure in the tree.

Returns:
list of int :

Elements are ids of structure sets.

get_structures_by_acronym(acronyms)[source]

Obtain a list of brain structures from their acronyms

Parameters:
names : list of str

Get structures corresponding to these acronyms.

Returns:
list of dict :

Each item describes a structure.

get_structures_by_id(structure_ids)[source]

Obtain a list of brain structures from their structure ids

Parameters:
structure_ids : list of int

Get structures corresponding to these ids.

Returns:
list of dict :

Each item describes a structure.

get_structures_by_name(names)[source]

Obtain a list of brain structures from their names,

Parameters:
names : list of str

Get structures corresponding to these names.

Returns:
list of dict :

Each item describes a structure.

get_structures_by_set_id(structure_set_ids)[source]

Obtain a list of brain structures from by the sets that contain them.

Parameters:
structure_set_ids : list of int

Get structures belonging to these structure sets.

Returns:
list of dict :

Each item describes a structure.

has_overlaps(structure_ids)[source]

Determine if a list of structures contains structures along with their ancestors

Parameters:
structure_ids : list of int

Check this set of structures for overlaps

Returns:
set :

Ids of structures that are the ancestors of other structures in the supplied set.

static hex_to_rgb(hex_color)[source]

Convert a hexadecimal color string to a uint8 triplet

Parameters:
hex_color : string

Must be 6 characters long, unless it is 7 long and the first character is #. If hex_color is a triplet of int, it will be returned unchanged.

Returns:
list of int :

3 characters long - 1 per two characters in the input string.

static path_to_list(path)[source]

Structure id paths are sometimes formatted as “/”-seperated strings. This method converts them to a list of integers, if needed.

static renames()[source]
structure_descends_from(child_id, parent_id)[source]

Tests whether one structure descends from another.

Parameters:
child_id : int

Id of the putative child structure.

parent_id : int

Id of the putative parent structure.

Returns:
bool :

True if the structure specified by child_id is a descendant of the one specified by parent_id. Otherwise False.

static whitelist()[source]