Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

root

Roots Phylogenetic Trees


Description

root reroots a phylogenetic tree with respect to the specified outgroup or at the node specified in node.

unroot unroots a phylogenetic tree, or returns it unchanged if it is already unrooted.

is.rooted tests whether a tree is rooted.

Usage

root(phy, ...)
## S3 method for class 'phylo'
root(phy, outgroup, node = NULL, resolve.root = FALSE,
     interactive = FALSE, edgelabel = FALSE, ...)
## S3 method for class 'multiPhylo'
root(phy, outgroup, ...)

unroot(phy)
## S3 method for class 'phylo'
unroot(phy)
## S3 method for class 'multiPhylo'
unroot(phy)

is.rooted(phy)
## S3 method for class 'phylo'
is.rooted(phy)
## S3 method for class 'multiPhylo'
is.rooted(phy)

Arguments

phy

an object of class "phylo" or "multiPhylo".

outgroup

a vector of mode numeric or character specifying the new outgroup.

node

alternatively, a node number where to root the tree.

resolve.root

a logical specifying whether to resolve the new root as a bifurcating node.

interactive

if TRUE the user is asked to select the node by clicking on the tree which must be plotted.

edgelabel

a logical value specifying whether to treat node labels as edge labels and thus eventually switching them so that they are associated with the correct edges when using drawSupportOnEdges (see Czech et al. 2016).

...

arguments passed among methods (e.g., when rooting lists of trees).

Details

The argument outgroup can be either character or numeric. In the first case, it gives the labels of the tips of the new outgroup; in the second case the numbers of these labels in the vector phy$tip.label are given.

If outgroup is of length one (i.e., a single value), then the tree is rerooted using the node below this tip as the new root.

If outgroup is of length two or more, the most recent common ancestor (MRCA) of the ingroup is used as the new root. Note that the tree is unrooted before being rerooted, so that if outgroup is already the outgroup, then the returned tree is not the same than the original one (see examples). If outgroup is not monophyletic, the operation fails and an error message is issued.

If resolve.root = TRUE, root adds a zero-length branch below the MRCA of the ingroup.

A tree is considered rooted if either only two branches connect to the root, or if there is a root.edge element. In all other cases, is.rooted returns FALSE.

Value

an object of class "phylo" or "multiPhylo" for root and unroot; a logical vector for is.rooted.

Note

The use of resolve.root = TRUE together with node = gives an error if the specified node is the current root of the tree. This is because there is an ambiguity when resolving a node in an unrooted tree with no explicit outgroup. If the node is not the current root, the ambiguity is solved arbitrarily by considering the clade on the right of node (when the tree is plotted by default) as the ingroup. See a detailed explanation there:

Author(s)

Emmanuel Paradis

References

Czech, L., Huerta-Cepas, J. and Stamatakis, A. (2017) A critical review on the use of support values in tree viewers and bioinformatics toolkits. Molecular Biology and Evolution, 34, 1535–1542. doi: 10.1093/molbev/msx055

See Also

Examples

data(bird.orders)
plot(root(bird.orders, 1))
plot(root(bird.orders, 1:5))

tr <- root(bird.orders, 1)
is.rooted(bird.orders) # yes
is.rooted(tr)          # no
### This is because the tree has been unrooted first before rerooting.
### You can delete the outgroup...
is.rooted(drop.tip(tr, "Struthioniformes"))
### ... or resolve the basal trichotomy in two ways:
is.rooted(multi2di(tr))
is.rooted(root(bird.orders, 1, r = TRUE))
### To keep the basal trichotomy but forcing the tree as rooted:
tr$root.edge <- 0
is.rooted(tr)

x <- setNames(rmtree(10, 10), LETTERS[1:10])
is.rooted(x)

ape

Analyses of Phylogenetics and Evolution

v5.5
GPL-2 | GPL-3
Authors
Emmanuel Paradis [aut, cre, cph] (<https://orcid.org/0000-0003-3092-2199>), Simon Blomberg [aut, cph] (<https://orcid.org/0000-0003-1062-0839>), Ben Bolker [aut, cph] (<https://orcid.org/0000-0002-2127-0443>), Joseph Brown [aut, cph] (<https://orcid.org/0000-0002-3835-8062>), Santiago Claramunt [aut, cph] (<https://orcid.org/0000-0002-8926-5974>), Julien Claude [aut, cph] (<https://orcid.org/0000-0002-9267-1228>), Hoa Sien Cuong [aut, cph], Richard Desper [aut, cph], Gilles Didier [aut, cph] (<https://orcid.org/0000-0003-0596-9112>), Benoit Durand [aut, cph], Julien Dutheil [aut, cph] (<https://orcid.org/0000-0001-7753-4121>), RJ Ewing [aut, cph], Olivier Gascuel [aut, cph], Thomas Guillerme [aut, cph] (<https://orcid.org/0000-0003-4325-1275>), Christoph Heibl [aut, cph] (<https://orcid.org/0000-0002-7655-3299>), Anthony Ives [aut, cph] (<https://orcid.org/0000-0001-9375-9523>), Bradley Jones [aut, cph] (<https://orcid.org/0000-0003-4498-1069>), Franz Krah [aut, cph] (<https://orcid.org/0000-0001-7866-7508>), Daniel Lawson [aut, cph] (<https://orcid.org/0000-0002-5311-6213>), Vincent Lefort [aut, cph], Pierre Legendre [aut, cph] (<https://orcid.org/0000-0002-3838-3305>), Jim Lemon [aut, cph], Guillaume Louvel [aut, cph] (<https://orcid.org/0000-0002-7745-0785>), Eric Marcon [aut, cph] (<https://orcid.org/0000-0002-5249-321X>), Rosemary McCloskey [aut, cph] (<https://orcid.org/0000-0002-9772-8553>), Johan Nylander [aut, cph], Rainer Opgen-Rhein [aut, cph], Andrei-Alin Popescu [aut, cph], Manuela Royer-Carenzi [aut, cph], Klaus Schliep [aut, cph] (<https://orcid.org/0000-0003-2941-0161>), Korbinian Strimmer [aut, cph] (<https://orcid.org/0000-0001-7917-2056>), Damien de Vienne [aut, cph] (<https://orcid.org/0000-0001-9532-5251>)
Initial release
2021-04-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.