phylox.dinetwork.DiNetwork

class phylox.dinetwork.DiNetwork(*args: Any, **kwargs: Any)

Bases: DiGraph, CherryPickingMixin

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

child

from_cherry_picking_sequence(sequence[, ...])

Creates a PhyloX DiNetwork network from a cherry picking sequence, and possibly a matching sequence of heights of the cherries.

from_newick(newick[, add_root_edge])

Creates a PhyloX DiNetwork 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([simple])

Returns a newick string representing the network.

parent

Attributes

label_to_node_dict

Returns the dictionary mapping labels to nodes.

labels

Returns the dictionary mapping labels to lists of nodes.

leaves

Returns the set of leaves of the network.

reticulation_number

Returns the number of reticulations of the network.

reticulations

Returns the set of reticulations of the network.

roots

Returns the set of roots of the network.

classmethod from_newick(newick, add_root_edge=False)

Creates a PhyloX DiNetwork network from a newick string.

Parameters:
  • newick – a newick string.

  • add_root_edge – whether to add a root edge of length 0 if not explicitly defined by the 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(simple=False)

Returns a newick string representing the network.

Parameters:

simple – Boolean, indicating whether to create a simple newick string without parameters

Returns:

a newick string.

classmethod from_cherry_picking_sequence(sequence, heights=None, label_leaves=True)

Creates a PhyloX DiNetwork network from a cherry picking sequence, and possibly a matching sequence of heights of the cherries.

Parameters:
  • sequence – a cherry picking sequence (i.e., a list of 2-tuples)

  • heights – a list of positive floats with the same length as sequence. If None, the heights will be set to consecutive integers

  • label_leaves – Bool, whether to label the leaves with the nodes/labels used in the sequence

Returns:

a network.