phylogeny.core package

Submodules

phylogeny.core.distance module

class phylogeny.core.distance.DistanceMatrix[source]

Bases: numpy.ndarray

Wrapper for the Numpy array class with methods proper of a distance matrix.

For documentation for the Numpy array, read the Numpy documentation.

distances_to(name)[source]

Get all the distances to the named sequence.

classmethod from_sequences(sequences, distance_fn=<function simple_distance>)[source]

From the given sequences, compute pairwise edit distances.

get(item)[source]

Get item by name.

is_additive(tolerance=0.01)[source]

Is the distances matrix additive?

Check the four point condition on each quartet of indices of the matrix.

name_all()[source]
remove(name)[source]

Return a new matrix with the column and row with that name deleted.

set(item, value)[source]

Set item by name.

classmethod zeros(n, names=None)[source]

Return a zeroed n by n matrix

phylogeny.core.distance.simple_distance(seq_1, seq_2)[source]

From two binary sequences, compute their distance.

phylogeny.core.fpc module

The four point condition.

The Four Point Condition holds for any additive matrix.

Let’s say we have the following unrooted tree:

1 -\    /- 3
    >--<
2 -/    \- 4

Let the distance between leaves ‘a’ and ‘b’ be D(a,b). Consider the three following pairwise sums:

  • D(1,2) + D(3,4)
  • D(1,3) + D(2,4)
  • D(1,4) + D(2,3)

The smallest of these sums has to be D(1,2)+D(3,4), since it covers all the edges of the tree connecting the four leaves, EXCEPT for the ones on the path separating 1 and 2 from 3 and 4. Furthermore, the two larger of the three pairwise sums have to be identical, since they cover the same set of edges.

The Four Point Condition is the statement that the two largest values of the three pairwise distance sums are the same.

– Based on an explanation from the book:
“Computational Phylogenetics. An introduction to designing methods for phylogeny estimation” by Tandy Warnow
phylogeny.core.fpc.four_point_condition(dist_matrix, idx_quartet=None, tolerance=0.01)[source]

The Four Point Condition is the statement that the two largest values of the three pairwise distance sums are the same.

phylogeny.core.fpc.fpc_sums(distances, idx_quartet=None)[source]

From a matrix of distances and a quartet of indices, return the sums needed to check the four point condition.

phylogeny.core.tree module

class phylogeny.core.tree.Tree(*args, leaves=None, **kwargs)[source]

Bases: ete3.coretype.tree.TreeNode

Wrapper for the ETE Tree class adapted for the purposes of phylogeny reconstruction.

For documentation for the ETE Tree, read the ETE3 documentation.

add_as_sibling(a, b)[source]

Add leaf a as sibling of b in the tree.

distance_matrix()[source]

Get the matrix of distances between each pair of leaves.

classmethod from_newick(newick, *args, **kwargs)[source]

Read from the newick representation.

classmethod from_quartet(quartet)[source]

Transform the quartet structure to a tree.

classmethod from_tree(tree, *args, **kwargs)[source]

Create a new instance based on an existing tree.

classmethod join_trees(a, b)[source]

Make a ‘cherry’ of the two trees a and b.

classmethod make_cherry_of(a, b)[source]

Get a cherry tree out of both items.

prune_leaves(to_stay)[source]

Prune tree branches to leave only the leaves in to_stay.

static replace_node(old, new)[source]
show(mode=None, inline=False, styling=None, **kwargs)[source]

Display the tree.

total_nodes()[source]

Module contents