Unrooting Trees Help
2
3
Entering edit mode
11.2 years ago
dani.boobyer ▴ 50

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 • 11k views
ADD COMMENT
9
Entering edit mode
11.2 years ago
David W 4.9k

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.

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
9
Entering edit mode
11.2 years ago

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 COMMENT
2
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2254 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

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

Powered by the version 2.3.6