Prune Trees To Overlapping Taxa
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!
• 3,452 views
•
link
2 answers
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);'
• 0 views
•
link
In R: match vectors of names between the two trees, then use drop.tip() inape.
• 0 views
•
link
Log in to answer this question.