Make a UPGMA clusterΒΆ

Section author: Catherine Lozupone

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

NOTE: UPGMA should not be used for phylogenetic reconstruction.

>>> from cogent3 import LoadSeqs
>>> from cogent3.phylo import distance
>>> from cogent3.cluster.UPGMA import upgma

Import a substitution model (or create your own)

>>> from cogent3.evolve.models import HKY85

Load the alignment.

>>> al = LoadSeqs("data/test.paml")

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 UPGMA cluster.

>>> mycluster = upgma(d.get_pairwise_distances())
>>> print(mycluster.ascii_art())
                   |         |          /-HowlerMon
          /edge.0--|          \edge.2--|
         |         |                    \-Human
-root----|         |
         |          \-DogFaced

We demonstrate saving this UPGMA cluster to a file.

>>> mycluster.write('test_upgma.tree')