Question: Unrooting Trees Help
gravatar for dani.boobyer
6.5 years ago by
St Andrews
dani.boobyer40 wrote:


I need to unroot trees which are in Newick format (saved as .txt files). What's the easiest way to do this please? Ideally a method which makes it easy to unroot a large number of tree files.

Thanks for your help, Dani.

phylogeny tree • 6.7k views
ADD COMMENTlink modified 6.5 years ago by aidan-budd1.9k • written 6.5 years ago by dani.boobyer40
gravatar for David W
6.5 years ago by
David W4.7k
New Zealand
David W4.7k wrote:

In R, using the library ape

tr <- read.tree("tree.txt")
unrooted_tr <- unroot(tr)

If you have a lot of trees in a list, your can use lapply to unroot them all at once:

write.tree(lapply(trees, unroot), "")

There is also a function, is.rooted to check everything has worked as expected.

ADD COMMENTlink written 6.5 years ago by David W4.7k

typo? write.tree(unrooted_tr, "tree_unrooted.txt")

ADD REPLYlink written 17 months ago by al-ash110
gravatar for aidan-budd
6.5 years ago by
aidan-budd1.9k wrote:

Note that NEWICK format intrinsically describes trees as rooted, see the links to a description of the NEWICK format described in an answer to this post Are there multiple ways to write the same unrooted tree using Newick format?

Thus (a,b,c) could be considered as describing a rooted tree which has a trifurcation at its root.

However, many software packages use a convention which says something like "if the root of the tree, as specified in the NEWICK format, is trifurcating, and all the other nodes in the tree are bifurcating, the tree string is assumed to described an unrooted bifurcating tree"

RETREE from the PHYLIP package can be used (I'm fairly sure... haven't done this in a while) to script the conversion to unrooted trees.

ADD COMMENTlink modified 6.5 years ago • written 6.5 years ago by aidan-budd1.9k

Good point - apeuses the tri-furcating convention when it writes unrooted trees, but it's worth remembering it's only a convention and might lead to unexpected behavior in some software

ADD REPLYlink modified 6.5 years ago • written 6.5 years ago by David W4.7k

I always use retree in my scripts to re-root/unroot trees for analysis. It's quick and easy to do programatically. And yes, NEWICK does intrinsically write unrooted trees as rooted with a random/quasi-random trifurcation at the root which is important to keep in mind.

ADD REPLYlink written 6.5 years ago by Dan Gaston7.1k
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: 814 users visited in the last hour