allensdk.core.simple_tree module

class allensdk.core.simple_tree.SimpleTree(nodes, node_id_cb, parent_id_cb)[source]

Bases: object

ancestor_ids(node_ids)[source]

Obtain the ids of one or more nodes’ ancestors

Parameters:
node_ids : list of hashable

Items are ids of nodes whose ancestors you wish to find.

Returns:
list of list of hashable :

Items are lists of input nodes’ ancestors’ ids.

Notes

Given the tree: A -> B -> C

`-> D

The ancestors of C are [C, B, A]. The ancestors of A are [A]. The ancestors of D are [D, A]

ancestors(node_ids)[source]

Get one or mode nodes’ ancestor nodes

Parameters:
node_ids : list of hashable

Items are ids of nodes whose ancestors will be found.

Returns:
list of list of dict :

Items are lists of ancestor nodes corresponding to argued ids.

child_ids(node_ids)[source]

Obtain the ids of one or more nodes’ children

Parameters:
node_ids : list of hashable

Items are ids of nodes whose children you wish to find.

Returns:
list of list of hashable :

Items are lists of input nodes’ children’s ids.

children(node_ids)[source]

Get one or mode nodes’ child nodes

Parameters:
node_ids : list of hashable

Items are ids of nodes whose children will be found.

Returns:
list of list of dict :

Items are lists of child nodes corresponding to argued ids.

descendant_ids(node_ids)[source]

Obtain the ids of one or more nodes’ descendants

Parameters:
node_ids : list of hashable

Items are ids of nodes whose descendants you wish to find.

Returns:
list of list of hashable :

Items are lists of input nodes’ descendants’ ids.

Notes

Given the tree: A -> B -> C

`-> D

The descendants of A are [B, C, D]. The descendants of C are [].

descendants(node_ids)[source]

Get one or mode nodes’ descendant nodes

Parameters:
node_ids : list of hashable

Items are ids of nodes whose descendants will be found.

Returns:
list of list of dict :

Items are lists of descendant nodes corresponding to argued ids.

filter_nodes(criterion)[source]

Obtain a list of nodes filtered by some criterion

Parameters:
criterion : function | node dict => bool

Only nodes for which criterion returns true will be returned.

Returns:
list of dict :

Items are node dictionaries that passed the filter.

node(**kwargs)[source]
node_ids()[source]

Obtain the node ids of each node in the tree

Returns:
list :

elements are node ids

nodes(node_ids=None)[source]

Get one or more nodes’ full dictionaries from their ids.

Parameters:
node_ids : list of hashable

Items are ids of nodes to be returned. Default is all.

Returns:
list of dict :

Items are nodes corresponding to argued ids.

nodes_by_property(key, values, to_fn=None)[source]

Get nodes by a specified property

Parameters:
key : hashable or function

The property used for lookup. Should be unique. If a function, will be invoked on each node.

values : list

Select matching elements from the lookup.

to_fn : function, optional

Defines the outputs, on a per-node basis. Defaults to returning the whole node.

Returns:
list :

outputs, 1 for each input value.

parent(**kwargs)[source]
parent_id(**kwargs)[source]
parent_ids(node_ids)[source]

Obtain the ids of one or more nodes’ parents

Parameters:
node_ids : list of hashable

Items are ids of nodes whose parents you wish to find.

Returns:
list of hashable :

Items are ids of input nodes’ parents in order.

parents(node_ids)[source]

Get one or mode nodes’ parent nodes

Parameters:
node_ids : list of hashable

Items are ids of nodes whose parents will be found.

Returns:
list of dict :

Items are parents of nodes corresponding to argued ids.

value_map(from_fn, to_fn)[source]

Obtain a look-up table relating a pair of node properties across nodes

Parameters:
from_fn : function | node dict => hashable value

The keys of the output dictionary will be obtained by calling from_fn on each node. Should be unique.

to_fn : function | node_dict => value

The values of the output function will be obtained by calling to_fn on each node.

Returns:
dict :

Maps the node property defined by from_fn to the node property defined by to_fn across nodes.