Skip to content

Instantly share code, notes, and snippets.

@airalcorn2
Created April 13, 2018 18:54
Show Gist options
  • Save airalcorn2/1507a29383ffae45abf51512545d6ff8 to your computer and use it in GitHub Desktop.
Save airalcorn2/1507a29383ffae45abf51512545d6ff8 to your computer and use it in GitHub Desktop.
A script for counting the total species in each clade in a Newick formatted file.
# Michael A. Alcorn
from Bio import Phylo
tree = Phylo.read("species_newick.txt", "newick")
clade_counts = {}
for clade in tree.find_clades():
if not clade.is_terminal():
clade_counts[str(clade)] = clade.count_terminals()
clade_counts = list(clade_counts.items())
clade_counts.sort(key = lambda x: -x[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment