Make a neighbor joining tree#
Section author: Gavin Huttley
Note
These docs now use the new_type
core objects via the following setting.
import os
# using new types without requiring an explicit argument
os.environ["COGENT3_NEW_TYPE"] = "1"
An example of how to calculate the pairwise distances for a set of sequences.
from cogent3 import load_aligned_seqs
from cogent3.evolve import distance
from cogent3.phylo import nj
Import a substitution model (or create your own)
from cogent3.evolve.models import get_model
Load the alignment.
al = load_aligned_seqs("data/long_testseqs.fasta", moltype="dna")
Create a pairwise distances object calculator for the alignment, providing a substitution model instance.
d = distance.EstimateDistances(al, submodel=get_model("HKY85"))
d.run(show_progress=False)
Now use this matrix to build a neighbour joining tree.
mytree = nj.nj(d.get_pairwise_distances(), show_progress=False)
print(mytree.ascii_art())
/-Mouse
/edge.1--|
| | /-Human
| \edge.0--|
-root----| \-HowlerMon
|
|--DogFaced
|
\-NineBande
We can save this tree to file.
mytree.write("test_nj.tree")