biotite.sequence.phylo#

This subpackage provides functions for creating and handling (phylogenetic) trees.

A tree is represented as a rooted networkx.DiGraph, whose edges point from a parent node to its child node. Each edge has a "distance" attribute, that gives the distance between the two nodes. The leaf nodes are the integers 0 to n-1. They are reference indices into a separate list or array, containing the actual objects the tree represents, e.g. species names or sequences. The intermediate nodes may be any other hashable objects. By convention, the trees created by this subpackage use the integers n upwards for the intermediate nodes, so that the root is the node with the highest number. This subpackage adds a few convenience functions on top of NetworkX for common tree queries, namely get_root(), get_leaves(), get_distance() and get_leaf_distances(). Other queries are directly available from NetworkX, for example networkx.lowest_common_ancestor() or networkx.DiGraph.successors() and networkx.DiGraph.predecessors() for the children and the parent of a node, respectively.

A tree can be created from or exported to a Newick notation, using the from_newick() or to_newick() function, respectively.

A tree can be built from a pairwise distance matrix using the popular UPGMA (upgma()) and Neighbor-Joining (neighbor_joining()) algorithms.

Tree handling#

get_root

Get the root node of a tree.

get_leaves

Get the leaf nodes that are direct or indirect children of the given node.

get_distance

Get the distance between two nodes in a tree.

get_leaf_distances

Get the pairwise distances between all leaf nodes of a tree.

as_binary

Convert a tree into a binary tree.

Newick notation#

to_newick

Obtain the Newick notation of a tree.

from_newick

Create a tree from a Newick notation.

Clustering algorithms#

upgma

Perform hierarchical clustering using the unweighted pair group method with arithmetic mean (UPGMA).

neighbor_joining

Perform hierarchical clustering using the neighbor joining algorithm.