phylox.dinetwork.DiNetwork
- class phylox.dinetwork.DiNetwork(*args: Any, **kwargs: Any)
Bases:
DiGraph,CherryPickingMixinA class for representing a directed phylogenetic network. Inherits from networkx.DiGraph.
- Parameters:
edges – a list of edges of the network.
nodes – a list of nodes of the network.
labels – a list of tuples of the form (node, label) where node is a node of the network and label is a label of the node.
kwargs – additional keyword arguments.
- __init__(*args, **kwargs)
Methods
__init__(*args, **kwargs)from_cherry_picking_sequence(sequence[, ...])from_newick(newick)Creates a network from a newick string.
is_leaf(node)Checks whether a node is a leaf.
is_reticulation(node)Checks whether a node is a reticulation.
is_root(node)Checks whether a node is a root.
is_tree_node(node)Checks whether a node is a tree node.
newick()Returns a newick string representing the network.
Attributes
Returns the dictionary mapping labels to nodes.
Returns the dictionary mapping labels to lists of nodes.
Returns the set of leaves of the network.
Returns the number of reticulations of the network.
Returns the set of reticulations of the network.
Returns the set of roots of the network.
- classmethod from_newick(newick)
Creates a network from a newick string. Not implemented.
- Parameters:
newick – a newick string.
- Returns:
a network.
- property label_to_node_dict
Returns the dictionary mapping labels to nodes. Uses a cached property if available.
- Returns:
the dictionary mapping labels to nodes.
- property leaves
Returns the set of leaves of the network. Uses a cached property if available.
- Returns:
the set of leaves of the network.
- property reticulations
Returns the set of reticulations of the network. Uses a cached property if available.
- Returns:
the set of reticulations of the network.
- property roots
Returns the set of roots of the network. Uses a cached property if available.
- Returns:
the set of roots of the network.
- property reticulation_number
Returns the number of reticulations of the network. Uses a cached property if available.
- Returns:
the number of reticulations of the network.
- property labels
Returns the dictionary mapping labels to lists of nodes. Use this instead of label_to_node_dict if there are multiple nodes with the same label. Uses a cached property if available.
- Returns:
the dictionary mapping labels to lists of nodes.
- child(node, exclude=[], randomNodes=False, seed=None)
Finds a child node of a node.
- Parameters:
node – a node of self.
exclude – a set of nodes of self.
randomNodes – a boolean value.
seed – a seed for the random number generator.
- Returns:
a child of node that is not in the set of nodes exclude. If randomNodes, then this child node is selected uniformly at random from all candidates.
- parent(node, exclude=[], randomNodes=False, seed=None)
Finds a parent of a node in a network.
- Parameters:
node – a node in the network.
exclude – a set of nodes of the network.
randomNodes – a boolean value.
seed – a seed for the random number generator.
- Returns:
a parent of node that is not in the set of nodes exclude. If randomNodes, then this parent is selected uniformly at random from all candidates.
- is_reticulation(node)
Checks whether a node is a reticulation. I.e., whether it has in-degree > 1 and out-degree <= 1.
- Parameters:
node – a node in the network.
- Returns:
a boolean value.
- is_leaf(node)
Checks whether a node is a leaf. I.e., whether it has out-degree = 0 and in-degree > 0.
- Parameters:
node – a node in the network.
- Returns:
a boolean value.
- is_root(node)
Checks whether a node is a root. I.e., whether it has in-degree = 0 and out-degree > 0.
- Parameters:
node – a node in the network.
- Returns:
a boolean value.
- is_tree_node(node)
Checks whether a node is a tree node. I.e., whether it has in-degree <= 1 and out-degree > 1.
- Parameters:
node – a node in the network.
- Returns:
a boolean value.
- newick()
Returns a newick string representing the network.
- Returns:
a newick string.