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.

__init__(label, clades, attr)[source]

Methods

__init__(label, clades, attr)

add_edge(target[, weight, prob, prob_norm])

Adds edge, if allowed and not already present.

child_clades()

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.

clade_union()

Returns the union of this node's child clades (or a set containing only the node label, for leaf nodes.)

empty_copy()

Returns a HistoryDagNode object with the same clades, label, and attr dictionary, but no descendant edges.

is_history_root()

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()

is_ua_node()

Returns whether this is the source node in the DAG, from which all others are reachable.

node_self()

Deprecated name for empty_copy()

partitions()

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.

sorted_child_clades()

Returns the node's child clades as a sorted tuple containing leaf labels in sorted tuples.

sorted_partitions()

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.

under_clade()

Deprecated name for clade_union()

__init__(label, clades, attr)[source]
empty_copy()[source]

Returns a HistoryDagNode object with the same clades, label, and attr dictionary, but no descendant edges.

Return type:

HistoryDagNode

node_self()[source]

Deprecated name for empty_copy()

Return type:

HistoryDagNode

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:

FrozenSet[Union[NamedTuple, UALabel]]

under_clade()[source]

Deprecated name for clade_union()

Return type:

FrozenSet[Union[NamedTuple, UALabel]]

is_leaf()[source]

Returns whether this is a leaf node.

Return type:

bool

is_ua_node()[source]

Returns whether this is the source node in the DAG, from which all others are reachable.

Return type:

bool

is_root()[source]

Deprecated name for is_ua_node()

Return type:

bool

is_history_root()[source]

Return whether node is a root of any histories in the DAG.

Return type:

bool

child_clades()[source]

Returns the node’s child clades, or a frozenset containing a frozenset if this node is a UANode.

Return type:

frozenset

partitions()[source]

Deprecated name for child_clades()

Return type:

frozenset

sorted_child_clades()[source]

Returns the node’s child clades as a sorted tuple containing leaf labels in sorted tuples.

Return type:

tuple

sorted_partitions()[source]

Deprecated name for sorted_child_clades()

Return type:

tuple

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:

Generator[HistoryDagNode, None, None]

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:

bool

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:
Return type:

TreeNode

Returns:

An ete3 Tree with the same topology as the subhistory below self, and node names and attributes as specified.