allensdk.core.structure_tree module¶
- class allensdk.core.structure_tree.StructureTree(nodes)[source]¶
Bases:
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:
- structureslist of dict
Each element describes a structure. Should have a structure id path field (str values) and a structure_sets field (list of dict).
- whitelistlist of str, optional
Only these fields will be included in the final structure record. Default is the output of StructureTree.whitelist.
- data_transformsdict, 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.
- renamesdict, 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.
- export_label_description(alphas=None, exclude_label_vis=None, exclude_mesh_vis=None, label_key='acronym')[source]¶
Produces an itksnap label_description table from this structure tree
- Parameters:
- alphasdict, optional
Maps structure ids to alpha levels. Optional - will only use provided ids.
- exclude_label_vislist, optional
The structures denoted by these ids will not be visible in ITKSnap.
- exclude_mesh_vislist, optional
The structures denoted by these ids will not have visible meshes in ITKSnap.
- label_key: str, optional
Use this column for display labels.
- Returns:
- pd.DataFrame
Contains data needed for loading as an ITKSnap label description file.
- 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:
- nameslist 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_idslist 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:
- nameslist 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_idslist 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_idslist 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_colorstring
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.
- structure_descends_from(child_id, parent_id)[source]¶
Tests whether one structure descends from another.
- Parameters:
- child_idint
Id of the putative child structure.
- parent_idint
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.