This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Unrooting Trees Help

Hi,

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.

tree phylogeny

2 answers

In R, using the library ape

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

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), "trees_unrooted.tr")

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

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

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.

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

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.

Log in to answer this question.