Removing a node from a phylogenetic tree with its edges
Entering edit mode
3.4 years ago
Moses ▴ 130

Hi All,

I have phylogenetic trees with preset outgroups that I am using it to root my trees and convert it to binary trees. I would later want to remove this outgroup with its parent (which is the root for the tree) and continune the tree with the second child of this removed parent which in turn becomes the new root. I'm reading a newick format tree using pythons ete3 package, lets say my tree is stored in a file like this:


then I run the following code on this newick tree:

t = Tree('tree1.tree')
tree_root = t.get_tree_root() = 'root'
root_node = t.search_nodes(name='root')[0]
t.write(format=1, outfile='rooted_tree.tree')

The resulting rooted tree is being outputted as this:


If you notice it's not removing the root, and keeping an edge with its descendant, hence im having a tree that starts with a node that has a single edge. I would want my code to give me this result:


so to remove that last edge from the tree. I do not know how to delete the root of the tree so that it will delete its descending edge also. I tried deleting the outgroup first then the root node it still did not work. Any help.suggestions would really be appreciated. Thanks.

python3 ete3 phylogenetics • 1.8k views
Entering edit mode

For now I'm resorting to tree.prune function that the ete3 package provides. I was hesitant to use this at first because I thought there might (will) be more overhead by getting all the leaves first that I want to keep and then pruning that subtree instead of just removing two nodes from an existing tree. Offcourse I will repeat this process over many trees which are much larger from this one (100s to 1000s of leaves). Would it be faster to just delete the node instead?

Entering edit mode

Prune would have been my suggestion anyway, so I think you’re fine to proceed as you are.

You might also consider looking at the package dendropy for tree manipulations. It and ETE both have some subtly different strengths and weaknesses.

Entering edit mode

I see. Thanks for that I will check it out.


Login before adding your answer.

Traffic: 1140 users visited in the last hour
Help About
Access RSS

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

Powered by the version 2.3.6