historydag.dag_node
Functions
|
Return a HistoryDagNode with the given label and clades, with no children. |
Classes
|
A container class for edge target nodes, and associated probabilities and weights. |
|
A recursive representation of a history DAG object. |
|
A universal ancestor node, the root node of a HistoryDag. |
- class historydag.dag_node.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.
- 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.
- class historydag.dag_node.UANode(targetnodes)[source]
A universal ancestor node, the root node of a HistoryDag.
- class historydag.dag_node.EdgeSet(*args, weights=None, probs=None)[source]
A container class for edge target nodes, and associated probabilities and weights.
Goal: associate targets (edges) with arbitrary parameters, but support set-like operations like lookup and enforce that elements are unique.
Takes no arguments, or an ordered iterable containing target nodes.
- __init__(*args, weights=None, probs=None)[source]
Takes no arguments, or an ordered iterable containing target nodes.
- set_targets(targets, weights=None, probs=None)[source]
Set the target nodes of this node.
If no weights or probabilities are provided, then these will be set to 0 and 1/n, respectively.
- set_edge_stats(weights=None, probs=None)[source]
Set the edge weights and/or probabilities of this EdgeSet.
- shallowcopy()[source]
Return an identical EdgeSet object, which points to the same target nodes.
- Return type:
- sample(mask=None, log_probabilities=False)[source]
Returns a randomly sampled child edge, and its corresponding weight.
When possible, only edges with nonzero mask value will be sampled.
- Return type:
- add_to_edgeset(target, weight=0, prob=None, prob_norm=True)[source]
Add a target node to the EdgeSet.
currently does nothing if edge is already present. Also does nothing if the target node has one child clade, and parent node is not the DAG root.
- Parameters:
target – target node
weight – edge weight
prob – edge probability. If not provided, edge probability will be 1 / n where n is the number of edges in the edgeset.
prob_norm – if True, probability vector will be normalized.
- Return type:
- Returns:
Whether an edge was added