allensdk.core.simple_tree module

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

Bases: object

ancestor_ids(self, 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(self, 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(self, 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(self, 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(self, 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(self, 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(self, 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(self, node_ids=None)[source]
node_ids(self)[source]

Obtain the node ids of each node in the tree

Returns:
list :

elements are node ids

nodes(self, 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(self, 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(self, node_ids)[source]
parent_id(self, node_ids)[source]
parent_ids(self, 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(self, 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(self, 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.