historydag.HistoryDagNode
- class historydag.HistoryDagNode(label, clades, attr)[source]
A recursive representation of a history DAG object.
a dictionary keyed by clades (frozensets) containing EdgeSet objects
a label, which is a namedtuple.
Methods
__init__
(label, clades, attr)add_edge
(target[, weight, prob, prob_norm])Adds edge, if allowed and not already present.
Returns the node's child clades, or a frozenset containing a frozenset if this node is a UANode.
children
([clade])Returns generator object containing child nodes.
Returns the union of this node's child clades (or a set containing only the node label, for leaf nodes.)
Returns a HistoryDagNode object with the same clades, label, and attr dictionary, but no descendant edges.
Return whether node is a root of any histories in the DAG.
is_leaf
()Returns whether this is a leaf node.
is_root
()Deprecated name for
is_ua_node()
Returns whether this is the source node in the DAG, from which all others are reachable.
Deprecated name for
empty_copy()
Deprecated name for
child_clades()
remove_edge_by_clade_and_id
(target, clade)remove_node
([nodedict])Recursively removes node self and any orphaned children from dag.
Returns the node's child clades as a sorted tuple containing leaf labels in sorted tuples.
Deprecated name for
sorted_child_clades()
to_ascii
(name_func[, show_internal, ...])A convenience function that uses the
to_ete()
method and ete3's ASCII drawing tools to render a sub-history below self.to_ete
([name_func, feature_funcs, sort_func])Convert a history DAG node which is part of a history to an ete tree.
Deprecated name for
clade_union()
- empty_copy()[source]
Returns a HistoryDagNode object with the same clades, label, and attr dictionary, but no descendant edges.
- Return type:
- node_self()[source]
Deprecated name for
empty_copy()
- Return type:
- clade_union()[source]
Returns the union of this node’s child clades (or a set containing only the node label, for leaf nodes.)
- Return type:
- under_clade()[source]
Deprecated name for
clade_union()
- Return type:
- is_ua_node()[source]
Returns whether this is the source node in the DAG, from which all others are reachable.
- Return type:
- is_root()[source]
Deprecated name for
is_ua_node()
- Return type:
- child_clades()[source]
Returns the node’s child clades, or a frozenset containing a frozenset if this node is a UANode.
- Return type:
- partitions()[source]
Deprecated name for
child_clades()
- Return type:
- sorted_child_clades()[source]
Returns the node’s child clades as a sorted tuple containing leaf labels in sorted tuples.
- Return type:
- sorted_partitions()[source]
Deprecated name for
sorted_child_clades()
- Return type:
- children(clade=None)[source]
Returns generator object containing child nodes.
- Parameters:
clade (
Optional
[Set
[Union
[NamedTuple
,UALabel
]]]) – If clade is provided, returns generator object of edge targets from that- Return type:
clade. If no clade is provided, generator includes all children of self.
- add_edge(target, weight=0, prob=None, prob_norm=True)[source]
Adds edge, if allowed and not already present.
Returns whether edge was added.
- Return type:
- remove_node(nodedict={})[source]
Recursively removes node self and any orphaned children from dag.
May not work on root. Does not check to make sure that parent clade still has descendant edges.
- to_ascii(name_func, show_internal=False, compact=False, sort_method=None)[source]
A convenience function that uses the
to_ete()
method and ete3’s ASCII drawing tools to render a sub-history below self.Expects that this node is part of a tree-shaped history DAG. If this is not true, this method may fail silently.
- Parameters:
name_func – A function taking a HistoryDagNode and returning a string to identify that node in the ascii tree.
show_internal – Whether to show internal node names.
compact – Whether to show the tree in a more compact format
sort_method – Either None, ladderize, leaf-name, or child-name. leaf-name sorts children by the alphabetically first leaf name below each child node. child-name sorts directly by child name.
- Returns:
A string including whitespace and newlines (no tabs) which when printed shows the structure of the history.
- to_ete(name_func=lambda n: ..., feature_funcs={}, sort_func=lambda seq: ...)[source]
Convert a history DAG node which is part of a history to an ete tree.
- Parameters:
name_func (
Callable
[[HistoryDagNode
],str
]) – A map from nodes to newick node namesfeature_funcs (
Mapping
[str
,Callable
[[HistoryDagNode
],str
]]) – A dictionary keyed by extended newick field names, containing functions specifying how to populate that field for each node.
- Return type:
TreeNode
- Returns:
An ete3 Tree with the same topology as the subhistory below self, and node names and attributes as specified.