Biology Stack Exchange is a question and answer site for biology researchers, academics, and students. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

The common_ancestor function should give you the result you want: it gives you the tree (I think) that is the most recent common ancestor of all the given targets.

share|improve this answer
Perfect! Thank you. – Ben Morris Nov 20 '12 at 16:35

Sorry for digging out this old question. But I think that given you have an unrooted tree, the common ancestor maybe not the correct answer.

What you need to do is this: Suppose you have an unrooted tree with n tips (species), and thus 2n-3 branches. You should cut the tree in half in all these possible branches. By doing this, you will have 4n-6 subtrees. The smallest subtree containing all your selected species will be your answer.

This is different from common ancestor because for an unrooted tree, it could be put in a way that those species not picked by you are clustered first, all your selected species becomes the outgroup. But if you "re-root" the tree properly, you could still make your selected species cluster together as a small, exclusive clade.

share|improve this answer
You are right that this wouldn't be correct for unrooted trees, so thanks for responding. I failed to mention in the question that the trees I was working with were in fact rooted (so the example tree was perhaps a bit misleading.) – Ben Morris Oct 9 '13 at 15:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.