Prune Trees To Overlapping Taxa
2
1
Entering edit mode
8.8 years ago
rezam ▴ 20

I have some phylogenetic trees with partial overlapping taxa. I would like to prune these trees, say 2 of them, to their overlapping taxa in order to be able to compare them. Is there any built in function for this in R, Python, etc (or I need to invent the wheel)?

Thanks!

pruning phylogenetic-tree • 2.9k views
ADD COMMENT
2
Entering edit mode
8.8 years ago
jhc ★ 3.0k

A Python approach using ETE:

from ete3 import Tree
newick1 = "((A, B, (C, D)), (E, F));"
newick2 = "((A, B, (C, G)), (E, T));"
t1 = Tree(newick1)
t2 = Tree(newick2)
common_leaves = set(t1.get_leaf_names()) &  set(t2.get_leaf_names())
t1.prune(common_leaves)
t2.prune(common_leaves)
t1.write()
Out[16]: '((A:1,B:1,C:1)1:1,E:1);'
t2.write()
Out[17]: '((A:1,B:1,C:1)1:1,E:1);'
ADD COMMENT
1
Entering edit mode
8.8 years ago
Brice Sarver ★ 3.8k

In R: match vectors of names between the two trees, then use drop.tip() inape.

ADD COMMENT

Login before adding your answer.

Traffic: 1913 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6