Welcome to PhyloNetwork’s documentation!

Contents:

The phylonetwork is the main module of the project PhyloNetworks.

It includes classes to represent phylogenetic networks and trees with or without nested taxa, as well as functions for both the successive and random generation of all phylogenetic trees over a set of taxa.

class phylonetwork.classes.PhyloNetwork(data=None, name='', eNewick=None, ignore_prefix=None, id_offset=0)[source]

Main class for phylogenetic networks and trees (with or without nested taxa).

You can create a PhyloNetwork with its eNewick representation:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)5);")
>>> network.taxa()
... ['1','2','3','4','5']
>>> network.leaves()
... ['_3', '_4', '_6', '_7']
>>> network.label('_6')
... '3'

If your eNewick string is malformed, you’ll receive a MalformedNewickException:

>>> network = PhyloNetwork(eNewick="(1)")
... Traceback (most recent call last):
... (...)
... PhyloNetwork.classes.MalformedNewickException: Malformed eNewick string

You can also start with an existing networkx graph:

>>> graph = networkx.DiGraph()
>>> graph.add_nodes_from(range(5))
>>> graph.add_edges_from([(0,1), (0,2), (1,3), (1,4)])
>>> network = PhyloNetwork(data = graph)
>>> network.leaves()
... [2, 3, 4]
>>> network.taxa()
... []
CSA(tax1, tax2)[source]

Returns a set with the common strict ancestors of taxa1 and taxa2.

EXAMPLE:

>>> network = PhyloNetwork(eNewick=((,(3,4)#1)2,#1)1;)
>>> network.CSA('3', '4')
... ['#1', '_1']
>>> network.LCSA('3', '4')
... '#1'

EXAMPLE:

>>> network = PhyloNetwork(eNewick="(((1)), 2);")
>>> network.CSA('1', '2')
... ['_2', '_1']
>>> network.LCSA('1', '2')
... '_2'
LCSA(tax1, tax2)[source]

Returns a minimum of CSA(taxa1, taxa2) respect the height of nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick=((,(3,4)#1)2,#1)1;)
>>> network.CSA('3', '4')
... ['#1', '_1']
>>> network.LCSA('3', '4')
... '#1'

EXAMPLE:

>>> network = PhyloNetwork(eNewick="(((1)), 2);")
>>> network.CSA('1', '2')
... ['_2', '_1']
>>> network.LCSA('1', '2')
... '_2'
ancestors(taxon)[source]

Returns a set with all nodes that have a fixed descendant taxa.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3,4)1,(5,6,7)2);")
>>> network.ancestors('3')
... ['_3', '_2', '_1']
>>> '3' in network.descendant_taxa('_2')
... True
cluster(u)[source]

Returns the cluster of u in the network, None if the node is not in the network.

cluster_representation()[source]

Returns the cluster of all nodes in the network.

common_taxa(net2)[source]

Returns common taxa between self and net2.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2), 3)4;")
>>> network2 = PhyloNewtwork(eNewick="(1,(4,5)2);")
>>> network.common_taxa(network2)
... ['1', '2', '4']
>>> network.common_taxa_leaves(network2)
... ['1']
common_taxa_leaves(net2)[source]

Returns common taxa between self and net2 that are leaves on both networks.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2), 3)4;")
>>> network2 = PhyloNewtwork(eNewick="(1,(4,5)2);")
>>> network.common_taxa(network2)
... ['1', '2', '4']
>>> network.common_taxa_leaves(network2)
... ['1']
cophenetic_matrix()[source]

Returns a matrix with the cophenetic coeficient of labelled nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="(((1,2), 3), 4);")
>>> network.cophenetic_matrix()
... array([[3, 2, 1, 0],
...       [0, 3, 1, 0],
...       [0, 0, 2, 0], 
...       [0, 0, 0, 1])
depth(u)[source]

Returns the depth of u. If the node u is not from the phylogenetic network, then returns None.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((((LEAF#1))),#1);")
>>> network.nodes()
... ['#1', '_4', '_3', '_2', '_1']
>>> map(network.depth, network.nodes())
... [1, 3, 2, 1, 0]
>>> network.depth('non-existing node')
... None
descendant_nodes(u)[source]

Returns a set with all the descendents of u.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((,(3,4)#1)2,#1)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> network.node_by_taxa('2')
... '_2'
>>> network.descendant_nodes('_2')
... ['_5', '_4', '#1' '_3', '_2']
>>> network.strict_descendant_nodes('_2')
... ['_3', '_2']
>>> network.descendant_taxa('_2')
... ['4', '3', '2']
descendant_taxa(u)[source]

Returns a set with all the labelled descendents of u.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((,(3,4)#1)2,#1)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> network.node_by_taxa('2')
... '_2'
>>> network.descendant_taxa('_2')
... ['4', '3', '2']
>>> network.strict_descendant_taxa('_2')
... ['2']
>>> network.descendant_nodes('_2')
... ['_5', '_4', '#1', '_3', '_2']
eNewick()[source]

Returns the eNewick representation of the network.

elementary_nodes()[source]

Return the set of elementary nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1)E,2);")
>>> network.nodes()
... ['_4', '_3', '_2', '_1']
>>> map(network.is_elementary_node, network.nodes())
... [False, False, True, False]
>>> network.label('_2')
... 'E'
>>> network.elementary_nodes()
... '_2'
has_nested_taxa()[source]

Returns True is an internal node is labelled. False otherwise.

height(u)[source]

Returns the height of u. If the node u is not from the phylogenetic network, then returns None.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((((LEAF#1))),#1);")
>>> network.nodes()
... ['#1', '_4', '_3', '_2', '_1']
>>> map(network.height, network.nodes())
... [0, 1, 2, 3, 4]
>>> network.height('non-existing node')
... None
interior_nodes()[source]

Returns the set of non-leaf nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4));")
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.interior_nodes()
... ['_5', '_2', '_1']
>>> map(network.is_leaf, network.interior_nodes())
... [False, False, False]
is_elementary_node(u)[source]

Returns True if u is an elementary node, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1)E,2);")
>>> network.nodes()
... ['_4', '_3', '_2', '_1']
>>> map(network.is_elementary_node, network.nodes())
... [False, False, True, False]
>>> network.label('_2')
... 'E'
>>> network.elementary_nodes()
... '_2'
is_hybrid_node(u)[source]

Returns True if u is not a tree node, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,2));")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> map(network.is_hybrid_node, network.nodes())
... [False, False, False, False, False, False]
>>> network.is_hybrid_node('non-existing node')
... False
>>> network = PhyloNetwork(eNewick="((4,5#1)2,(#1,6)3)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> map(network.is_hybrid_node, network.nodes())
... [False, False, False, False, False, True]
is_labelled(u)[source]

Returns True if u is a labelled node, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,2))4;")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> map(network.is_labelled, network.nodes())
... [True, True, False, True, False, True]
>>> network.label('_1')
... '4'
is_leaf(u)[source]

Returns True if u is a leaf, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,2));")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> network.leaves()
... ['_3', '_5', '_6']
>>> network.is_leaf('_1')
... False
>>> network.is_leaf('_6')
... True
>>> network.is_leaf('non-existing node')
... False
is_phylogenetic_network()[source]

Returns True if the network is a Phylogenetic Network. False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)5);")
>>> network.is_phylogenetic_network()
... True
>>> graph = networkx.DiGraph()
>>> graph.add_nodes_from(range(4))
>>> graph.add_edges_from([(0,1), (0,2), (1,2), (2,3), (3,1)])
>>> PhyloNetwork(data=graph).is_phylogenetic_network()
... False
is_root(u)[source]

Returns True if u is a root, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,2));")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> network.leaves()
... ['_3', '_5', '_6']
>>> network.is_root('_3')
... False
>>> network.is_root('_1')
... True
is_tree_node(u)[source]

Returns True if u is a tree node, False otherwise.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,2));")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> map(network.is_tree_node, network.nodes())
... [True, True, True, True, True, True]
>>> network.is_tree_node('non-existing node')
... False
>>> network = PhyloNetwork(eNewick="((4,5#1)2,(#1,6)3)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> map(network.is_tree_node, network.nodes())
... [True, True, True, True, True, False]
label(node)[source]

Returns the label of node, or None if not labelled.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)5);")
>>> network.taxa()
... ['1', '2', '3', '4', '5']
>>> network.leaves()
... ['_3', '_4', '_6', '_7']
>>> network.label('_6')
... '3'
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.label('_1')
... None
labelled_nodes()[source]

Returns the set of labelled nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((A,B,C),1);")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> network.labelled_nodes()
... ['_6', '_5', '_4', '_3']
>>> map(network.label, network.labelled_nodes())
... ['1', 'C', 'B', 'A']
>>> network.unlabelled_nodes()
... ['_2', '_1']
>>> map(network.label, network.unlabelled_nodes())
... [None, None]
leaves()[source]

Returns the set of leaves of self.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((3),(1,(5,6)2))4;")
>>> network.nodes()
... ['_8', '_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.leaves()
... ['_3', '_5', '_7', '_8']
>>> map(network.is_leaf, network.leaves())
... [True, True, True, True]
mu(u)[source]

Returns a tuple containing the number of paths from u to all labelled nodes of the phylogenetic network. Returns None if the node u is not in the phylogenetic network.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((((LEAF1, LEAF2#1)), #1)INT,#1);")
>>> network.taxa()
... ['INT', 'LEAF1', LEAF2]
>>> network.roots()
... '_1'
>>> network.mu('_1')
... array([1, 1, 3])
>>> network.successors('_1')
... ['#1', '_2']
>>> network.mu('#1') # This is LEAF2
... array([0, 0, 1])
>>> network.mu('_2') # We lost the path root -> LEAF2
... array([1, 1, 2])
mu_string()[source]

Returns a string representing the mu value of all nodes, with the same order as sorted_nodes()

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((((LEAF1, LEAF2#1)), #1)INT,#1);")
>>> network.taxa()
... ['INT', 'LEAF1', LEAF2]
>>> network.sorted_nodes()
... ['#1', '_5', '_4', '_3', '_2', '_1']
>>> network.mu_string()
... '[0 0 1]-[0 1 0]-[0 1 1]-[0 1 1]-[1 1 2]-[1 1 3]'
>>> network.mu('#1')
... array([0, 0, 1])
>>> network.mu('_1')
... array([1, 1, 3])
nested_label(node)[source]

Returns a string representation of descendants of u. Very useful to identify where is a node located in the network.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((2,3), (4,(5,6)))1;")
>>> network.nodes()
... ['_9', '_8', '_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.nested_label('_7') # Where is node '_7' in the network?
... '{5,6}' # '_7' is the parent of leaves '5' and '6'.
>>> network.nested_label('_6')
... '4' # '_6' is the leaf '4'
>>> network.nested_label('_5')
... '{4,{5,6}}' # '_5' is the parent of leaf '4' and node '_7'
nested_label_representation()[source]

Returns the nested label of all nodes in the network.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2), (3,4));")
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.nested_label_representation()
... set(['{3,4}', '1', '3', '2', '4', '{1,2}', '{{1,2},{3,4}}'])
nodal_area()[source]

Returns the sum of all elements of the nodal matrix.

EXAMPLES:

>>> network = PhyloNetwork(eNewick="(((1,2), 3), 4);")
>>> network.nodal_matrix()
... array([[0, 1, 2, 3],
...       [1, 0, 2, 3],
...       [1, 1, 0, 2], 
...       [1, 1, 1, 0])
>>> network.nodal_area()
... 19
nodal_matrix()[source]

Returns a matrix containing the nodal ‘distance’ between all labelled nodes.

EXAMPLES:

>>> network = PhyloNetwork(eNewick="(((1,2), 3), 4);")
>>> network.nodal_matrix()
... array([[0, 1, 2, 3],
...       [1, 0, 2, 3],
...       [1, 1, 0, 2], 
...       [1, 1, 1, 0])
node_by_taxa(taxa)[source]

Returns the node labelled by taxa or None if no node is labelled by taxa. Important: If more than one node is labelled with taxa, only the first one will be displayed. In order to get all nodes with a fixed label, use nodes_by_taxa.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)1);")
>>> network.taxa()
... ['1', '2', '3', '4']
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.node_by_taxa('3')
... '_6'
>>> network.node_by_taxa('non-existing taxa')
... None
>>> network.node_by_taxa('1')
... '_5'
nodes_by_taxa(taxa)[source]

Returns all nodes labelled with taxa.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)1);")
>>> network.taxa()
... ['1', '2', '3', '4']
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
>>> network.node_by_taxa('3')
... '_6'
>>> network.nodes_by_taxa('3')
... ['_6']
>>> network.node_by_taxa('1')
... '_5'
>>> network.nodes_by_taxa('1')
... ['_5', '_3']
>>> network.nodes_by_taxa('non-existing taxa')
... set([])
roots()[source]

Returns the set of roots of self.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="(1,2,3)ROOT;")
>>> network.nodes()
... ['_4', '_3', '_2', '_1']
>>> network.roots()
... ['_1']
>>> network.label('_1')
... 'ROOT'

EXAMPLE:

>>> graph = networkx.DiGraph()
>>> graph.add_nodes_from(range(5))
>>> graph.add_edges_from([(0,1), (2,3), (1,4), (3,4)])
>>> network = PhyloNetwork(graph)
>>> network.nodes()
... [0, 1, 2, 3, 4]
>>> network.roots()
... [0, 2]
>>> network.is_phylogenetic_network()
... True
set_label(node, label)[source]

Set a new label to a node.

EXAMPLE:

>>> graph = networkx.DiGraph()
>>> graph.add_nodes_from(range(5))
>>> graph.add_edges_from([(0,1), (0,2), (1,3), (1,4)])
>>> network = PhyloNetwork(data = graph)
>>> network.leaves()
... [2, 3, 4]
>>> network.taxa()
... []
>>> network.set_label(2, 'Label 1')
>>> network.set_label(3, 'Label 2')
>>> network.set_label(4, 'Label 3')
>>> network.taxa()
... ['Label 1', 'Label 2', 'Label 3']
>>> network.set_label(2, 'New label')
>>> network.taxa()
... ['Label 2', 'Label 3', 'New label']
sorted_nodes()[source]

Returns the set of nodes sorted with the total order over their mu value.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((((LEAF1, LEAF2#1)), #1)INT,#1);")
>>> network.taxa()
... ['INT', 'LEAF1', LEAF2]
>>> network.sorted_nodes()
... ['#1', '_5', '_4', '_3', '_2', '_1']
>>> network.mu_string()
... '[0 0 1]-[0 1 0]-[0 1 1]-[0 1 1]-[1 1 2]-[1 1 3]'
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
strict_ancestors(taxon)[source]

Returns a set with all nodes that have a fixed strict descendant taxa.

EXAMPLE:

>>> network = PhyloNetwork(eNewick=((,(3,4)#1)2,#1)1;)
>>> network.node_by_taxa('2')
... '_2'
>>> '_2' in network.ancestors('3')
... True
>>> '_2' in network.strict_ancestors('3')
... False
strict_descendant_nodes(u)[source]

Returns a set with all the strict descendents of u.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((,(3,4)#1)2,#1)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> network.node_by_taxa('2')
... '_2'
>>> network.descendant_nodes('_2')
... ['_5', '_4', '#1', '_3', '_2']
>>> network.strict_descendant_nodes('_2')
... ['_3', '_2']
strict_descendant_taxa(u)[source]

Returns a set with all the strict labelled descendents of u.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((,(3,4)#1)2,#1)1;")
>>> network.nodes()
... ['_5', '_4', '_3', '_2', '_1', '#1']
>>> network.node_by_taxa('2')
... '_2'
>>> network.descendant_taxa('_2')
... ['4', '3', '2']
>>> network.strict_descendant_taxa('_2')
... ['2']
taxa()[source]

Returns the taxa (set of labels) of self.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2),(3,4)5);")
>>> network.taxa()
... ['1', '2', '3', '4', '5']
>>> network.leaves()
... ['_3', '_4', '_6', '_7']
>>> network.label('_6')
... '3'
>>> network.nodes()
... ['_7', '_6', '_5', '_4', '_3', '_2', '_1']
topological_restriction(subtaxa)[source]

Returns a minimal subnetwork of self such that it containts a fixed subtaxa.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((1,2), (3,4));")
>>> network.taxa()
... ['1', '2', '3', '4']
>>> network.roots()
... ['_1']
>>> subnetwork = network.topological_restriction(['1', '2'])
>>> subnetwork.taxa()
... ['1', '2']
>>> subnetwork.nodes() # '_1' should not be
... ['_4', '_3', '_2']
>>> subnetwork.roots()
... ['_2']
>>> subnetwork = network.topological_restriction(['1', '3'])
>>> '_1' in subnetwork.roots()
... True
unlabelled_nodes()[source]

Returns the set of unlabelled nodes.

EXAMPLE:

>>> network = PhyloNetwork(eNewick="((A,B,C),1);")
>>> network.nodes()
... ['_6', '_5', '_4', '_3', '_2', '_1']
>>> network.labelled_nodes()
... ['_6', '_5', '_4', '_3']
>>> map(network.label, network.labelled_nodes())
... ['1', 'C', 'B', 'A']
>>> network.unlabelled_nodes()
... ['_2', '_1']
>>> map(network.label, network.unlabelled_nodes())
... [None, None]
phylonetwork.generators.all_trees(taxa, binary=False, nested_taxa=True)[source]

Returns a generator for trees with given taxa. If nested_taxa is True, then trees with internal nodes labeled will also be produced. If binary is True, then only binary trees will be generated; otherwise trees will have internal nodes with arbitrary out-degree.

EXAMPLE:

>>> generator = all_trees(['A', 'B', 'C'], binary=True)
>>> generator.next().eNewick()
... '((C,B),A);'
>>> generator.next().eNewick()
... '(C,(B,A));'
>>> tmp = 2
>>> for tree in generator: tmp = tmp+1
>>> tmp
... 21

EXAMPLE:

>>> for tree in all_trees(['A', 'B', 'C', binary=True, nested_taxa=False):
>>>     print tree.eNewick()
... ((C,B),A);
... (C,(B,A));
... ((C,A),B);

EXAMPLE:

>>> for tree in all_trees(['A', 'B', 'C', binary=False, nested_taxa=False):
>>>     print tree.eNewick()
... ((C,B),A);
... (C,(B,A));
... ((C,A),B);
... (A,B,C);
phylonetwork.generators.number_of_trees_bin_nont_global(n)[source]

Gives the number of phylogenetic trees on n taxa. Assume binary trees and without nested taxa.

phylonetwork.generators.number_of_trees_bin_nont_partial(n, l, N)[source]

Gives the number of phylogenetic trees on n taxa with l leaves and N nodes. Assume binary trees without nested taxa.

phylonetwork.generators.number_of_trees_bin_nt_partial(n, l, N, e)[source]

Gives the number of phylogenetic trees on n taxa with l leaves, N nodes, e of them being elementary. Assume binary trees with nested taxa.

phylonetwork.generators.number_of_trees_nobin_nont_global(n)[source]

Gives the number of phylogenetic trees on n taxa. Assume not necessarily binary trees and without nested taxa.

phylonetwork.generators.number_of_trees_nobin_nont_partial(n, l, N)[source]

Gives the number of phylogenetic trees on n taxa with l leaves and N nodes. Assume not necessarily binary trees and without nested taxa.

phylonetwork.generators.number_of_trees_nobin_nt_partial(n, l, N)[source]

Gives the number of phylogenetic trees on n taxa with l leaves, N nodes, e of them being elementary. Assume binary trees with nested taxa.

phylonetwork.generators.random_tree_bin_nont_global(taxa, id_offset=0)[source]

Returns a random binary tree without nested taxa.

EXAMPLE:

>>> network = random_tree_bin_nont_global(['A', 'B', 'C', 'D'])
>>> network.nested_label(network.roots()[0])
... '{D,{C,{A,B}}}' # random 
>>> network = random_tree_bin_nont_global(['A', 'B', 'C', 'D'])
>>> network.nested_label(network.roots()[0])
... '{A,{C,{B,D}}}' # random 
phylonetwork.generators.random_tree_bin_nt_global(taxa, id_offset=0)[source]

Returns a random binary tree with nested taxa.

EXAMPLE:

>>> network = random_tree_bin_nt_global(['A', 'B', 'C', 'D'])
>>> network.eNewick()
... '((D,A),B)C;' # random
>>> network = random_tree_bin_nt_global(['A', 'B', 'C', 'D'])
>>> network.eNewick()
... '((D,A),(B)C);' # random
phylonetwork.generators.random_tree_generator(taxa, binary=False, nested_taxa=True, id_offset=0)[source]

Returns generator of random trees. If nested_taxa = True, then trees with internal labels will also be produced. If binary = True, then only binary trees will be produced.

EXAMPLE:

>>> generator = random_tree_generator(['a', 'b', 'c', 'd', 'e', 'f'], binary=True)
>>> for i in range(3):
>>>     print generator.next().eNewick()
... '((d,b),(c,((e)f)a));'
... '(c,(((a,e),d),f)b);'
... '(((c,f),((b)e)d))a;'
phylonetwork.generators.random_tree_nobin_nont_global(taxa, id_offset=0)[source]

Returns a random tree without nested taxa.

EXAMPLE:

>>> network = random_tree_nobin_nont_global(['A', 'B', 'C', 'D'])
>>> network.nested_label(network.roots()[0])
... '{A,B,{C,D}}' # random, not binary
>>> network = random_tree_nobin_nont_global(['A', 'B', 'C', 'D'])
>>> network.nested_label(network.roots()[0])
... '{D,{A,{B,C}}}' # random
phylonetwork.generators.random_tree_nobin_nt_global(taxa, id_offset)[source]

Returns a random tree with nested taxa.

EXAMPLE:

>>> network = random_tree_nobin_nt_global(['A', 'B', 'C', 'D'])
>>> network.eNewick()
... '((D,A),C,B);' # random, non-binary
>>> network = random_tree_nobin_nt_global(['A', 'B', 'C', 'D'])
>>> network.eNewick()
... '(((D,C),B),A);' # random
phylonetwork.distances.RF_distance(net1, net2)[source]

Computes the RF distance between two phylogenetic networks.

phylonetwork.distances.cophenetic_distance(net1, net2, p=1, take_root=False, check=False)[source]

Computes the nodal distance unsplitted between two phylogenetic networks. If check = True, then it checks if the two networks have the same taxa. Otherwise it will only check if the number of labels is equal.

phylonetwork.distances.mu_distance(net1, net2)[source]

Compute the mu distance between two phylogenetic networks.

phylonetwork.distances.nested_label_distance(net1, net2)[source]

Computes the nested label distance between two phylogenetic networks.

phylonetwork.distances.nodal_distance_splitted(net1, net2, p=1, take_root=False, check=False)[source]

Computes the nodal distance splitted between two phylogenetic networks. If check = True, then it checks if the two networks have the same taxa. Otherwise it will only check if the number of labels is equal.

phylonetwork.distances.nodal_distance_unsplitted(net1, net2, p=1, take_root=False, check=False)[source]

Computes the nodal distance unsplitted between two phylogenetic networks. If check = True, then it checks if the two networks have the same taxa. Otherwise it will only check if the number of labels is equal.

phylonetwork.distances.transposition_distance(net1, net2)[source]

Computes the transposition distance between two phylogenetic networks.

Indices and tables

Table Of Contents

This Page