Sunday, 22 July 2007

evolution - How to get smallest subtree containing a set of nodes from BioPhylo?

I'm testing out various phylogenetic libraries in Python. I want to read in a Newick tree, then, given a list of taxa, generate the smallest tree that contains them all. This task is quite simple and efficient in dendropy and ete2:



newick = '((raccoon, bear),((sea_lion,seal),((monkey,cat), weasel)),dog);'
taxa = ['raccoon', 'sea_lion']

import ete2
tree = ete2.Tree(newick)
pruned = tree.prune(taxa)

import dendropy
tree = dendropy.Tree.get_from_string(newick, 'newick')
pruned = tree.prune_taxa_with_labels(taxa)


I'm trying but failing to find equivalent functionality in the Bio.Phylo package. Trees do have a "prune" method, but it prunes a single node from the tree.

No comments:

Post a Comment