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.
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.
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.
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.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
typo?
write.tree(unrooted_tr, "tree_unrooted.txt")