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

Ancestors

tree utility function


Description

Functions for describing relationships among phylogenetic nodes.

Usage

Ancestors(x, node, type = c("all", "parent"))

allDescendants(x)

Children(x, node)

Descendants(x, node, type = c("tips", "children", "all"))

Siblings(x, node, include.self = FALSE)

mrca.phylo(x, node = NULL, full = FALSE)

Arguments

x

a tree (a phylo object).

node

an integer or a vector of integers corresponding to a node ID

type

specify whether to return just direct children / parents or all

include.self

whether to include self in list of siblings

full

a logical indicating whether to return the MRCAs among all tips and nodes (if TRUE); the default is to return only the MRCAs among tips.

Details

These functions are inspired by treewalk in phylobase package, but work on the S3 phylo objects. The nodes are the indices as given in edge matrix of an phylo object. From taxon labels these indices can be easily derived matching against the tip.label argument of an phylo object, see example below. All the functions allow node to be either a scalar or vector. mrca is a faster version of the mrca in ape, in phangorn only because of dependencies. If the argument node is missing the function is evaluated for all nodes.

Value

a vector or a list containing the indices of the nodes.

Functions

  • allDescendants: list all the descendant nodes of each node

See Also

treewalk, as.phylo, nodelabels

Examples

tree <- rtree(10)
plot(tree, show.tip.label = FALSE)
nodelabels()
tiplabels()
Ancestors(tree, 1:3, "all")
Children(tree, 11)
Descendants(tree, 11, "tips")
Siblings(tree, 3)
# Siblings of all nodes
Siblings(tree)
mrca.phylo(tree, 1:3)
mrca.phylo(tree, match(c("t1", "t2", "t3"), tree$tip))
mrca.phylo(tree)
# same as mrca(tree), but faster for large trees

phangorn

Phylogenetic Reconstruction and Analysis

v2.7.0
GPL (>= 2)
Authors
Klaus Schliep [aut, cre] (<https://orcid.org/0000-0003-2941-0161>), Emmanuel Paradis [aut] (<https://orcid.org/0000-0003-3092-2199>), Leonardo de Oliveira Martins [aut] (<https://orcid.org/0000-0001-5247-1320>), Alastair Potts [aut], Tim W. White [aut], Cyrill Stachniss [ctb], Michelle Kendall [ctb], Keren Halabi [ctb], Richel Bilderbeek [ctb], Kristin Winchell [ctb], Liam Revell [ctb], Mike Gilchrist [ctb], Jeremy Beaulieu [ctb], Brian O'Meara [ctb], Long Qu [ctb]
Initial release

We don't support your browser anymore

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