Make a neighbor joining treeΒΆ

Section author: Gavin Huttley

An example of how to calculate the pairwise distances for a set of sequences.

>>> from cogent3 import LoadSeqs
>>> from cogent3.phylo import distance, nj

Import a substitution model (or create your own)

>>> from cogent3.evolve.models import HKY85

Load the alignment.

>>> al = LoadSeqs("data/long_testseqs.fasta")

Create a pairwise distances object calculator for the alignment, providing a substitution model instance.

>>> d = distance.EstimateDistances(al, submodel=HKY85())

Now use this matrix to build a neighbour joining tree.

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

We can visualise this tree by print mytree.ascii_art(), which generates the equivalent of:

         |          \-HowlerMon
-root----|          /-NineBande
         |          \-DogFaced

We can save this tree to file.

>>> mytree.write('test_nj.tree')