Skip to content

Instantly share code, notes, and snippets.

@Vini2
Created March 23, 2018 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vini2/0723caa046c6b8e1d745a623f2695abb to your computer and use it in GitHub Desktop.
Save Vini2/0723caa046c6b8e1d745a623f2695abb to your computer and use it in GitHub Desktop.
# 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