Question: Removing a node from a phylogenetic tree with its edges
gravatar for Moses
2.1 years ago by
united states/ Bloomingtion/ Indiana University Bloomington
Moses120 wrote:

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.

ete3 phylogenetics python3 • 967 views
ADD COMMENTlink modified 2.1 years ago • written 2.1 years ago by Moses120

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?

ADD REPLYlink written 2.1 years ago by Moses120

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.

ADD REPLYlink written 2.1 years ago by Joe19k

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

ADD REPLYlink written 2.1 years ago by Moses120
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2225 users visited in the last hour