Making a phylogenetic tree from a protein sequence alignmentΒΆ

Section author: Gavin Huttley

In this example we pull together the distance calculation and tree building with the additional twist of using an empirical protein substitution matrix. We will therefore be computing the tree from a protein sequence alignment. We will first do the standard cogent import for LoadSeqs.

>>> from cogent import LoadSeqs, PROTEIN

We will use an empirical protein substitution matrix.

>>> from cogent.evolve.models import JTT92

The next components we need are for computing the matrix of pairwise sequence distances and then for estimating a neighbour joining tree from those distances.

>>> from cogent.phylo import nj, distance

Now load our sequence alignment, explicitly setting the alphabet to be protein.

>>> aln = LoadSeqs('data/abglobin_aa.phylip', interleaved=True,
...                 moltype=PROTEIN)

Create an Empirical Protein Matrix Substitution model object. This will take the unscaled empirical matrix and use it and the motif frequencies to create a scaled Q matrix.

>>> sm = JTT92()

We now use this and the alignment to construct a distance calculator.

>>> d = distance.EstimateDistances(aln, submodel = sm)
>>> d.run()

The resulting distances are passed to the nj function.

>>> mytree = nj.nj(d.getPairwiseDistances())

The shape of the resulting tree can be readily view by printing mytree.asciiArt(). The result will be equivalent to.

          /-human
         |
         |          /-rabbit
-root----|-edge.1--|
         |          \-rat
         |
         |          /-goat-cow
          \edge.0--|
                    \-marsupial

This tree can be saved to file, the with_distances argument specifies that branch lengths are to be included in the newick formatted output.

>>> mytree.writeToFile('test_nj.tree', with_distances=True)