# Import modules | |
from Bio import Phylo | |
from Bio.Phylo.TreeConstruction import DistanceCalculator | |
from Bio.Phylo.TreeConstruction import DistanceTreeConstructor | |
from Bio import AlignIO | |
# Read the sequences and align | |
aln = AlignIO.read('msa.phy', 'phylip') | |
# Print the alignment | |
print aln | |
# Calculate the distance matrix | |
calculator = DistanceCalculator('identity') | |
dm = calculator.get_distance(aln) | |
# Print the distance Matrix | |
print('\nDistance Matrix\n===================') | |
print(dm) | |
# Construct the phylogenetic tree using UPGMA algorithm | |
constructor = DistanceTreeConstructor() | |
tree = constructor.upgma(dm) | |
# Draw the phylogenetic tree | |
Phylo.draw(tree) | |
# Print the phylogenetic tree in the terminal | |
print('\nPhylogenetic Tree\n===================') | |
Phylo.draw_ascii(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment