historydag.from_tree

historydag.from_tree(treeroot, label_features, label_functions={}, attr_func=lambda n: ..., child_node_func=lambda n: ..., leaf_node_func=ete3.TreeNode.get_leaves, edge_weight_func=lambda n: ...)[source]

Build a tree-shaped historydag.HistoryDag() (a ‘history’) object from the provided tree data.

Default arguments are suitable for loading a ete3.Tree, but by providing appropriate child_node_func and leaf_node_func, any data structure implementing a tree can be used.

Parameters:
  • treeroot (TreeNode) – The root node of a tree to be converted to HistoryDag history

  • label_features (List[str]) – tree node attribute names to be used as HistoryDagNode label fields. Each attribute name must be accessible by getattr(treenode, name). Field names provided in label_functions will take precedence.

  • label_functions (Mapping[str, Callable[[TreeNode], Any]]) – dictionary keyed by additional label field names, containing functions mapping tree nodes to intended label field values.

  • attr_func (Callable[[TreeNode], Any]) – function to populate HistoryDag node attr attribute, which is not used to distinguish nodes, and may be overwritten by attr of another node with the same label and child clades.

  • child_node_func (Callable[[TreeNode], Sequence[TreeNode]]) – function taking a tree node and returning an iterable containing the node’s children. By default, accesses node’s children attribute.

  • leaf_node_func (Callable[[TreeNode], Sequence[TreeNode]]) – function accepting a tree node and returning an iterable containing the leaf nodes accessible from that node.

  • edge_weight_func (Callable[[TreeNode], Any]) – function accepting a tree node and returning the weight of that node’s parent edge.

Return type:

HistoryDag

Returns:

HistoryDag object, which has the same topology as the input tree, with the required UA node added as a new root.