treewalk {phylobase}R Documentation

tree traversal and utility functions

Description

Functions for describing relationships among phylogenetic nodes (i.e. internal nodes or tips).

Usage

ancestors(phy, node, type=c("all","parent","ALL"))
ancestor(phy, node)
siblings(phy,node,include.self=FALSE)
children(phy, node)
descendants(phy, node, type=c("tips","children","all"))
MRCA(phy, ...)
shortestPath(phy, node1, node2)
## S4 method for signature 'phylo4':
sumEdgeLength(x, node)

Arguments

phy a phylo4 object (or one inheriting from phylo4, e.g. a phylo4d object)
x a phylo4 object (or one inheriting from phylo4, e.g. a phylo4d object)
node either an integer corresponding to a node ID number, or a character corresponding to a node label; for ancestors and descendants, this may be a vector of multiple node numbers or names
type (ancestors) specify whether to return just direct ancestor ("parent"), all ancestor nodes ("all"), or all ancestor nodes including self ("ALL"); (descendants) specify whether to return just direct descendants ("children"), all extant descendants ("tips"), or all descendant nodes ("all")
include.self whether to include self in list of siblings
... a list of node numbers or names, or a vector of node numbers or names
node1 a node number (or name)
node2 a node number (or name)

Details

ancestors and descendants can take node vectors of arbitrary length, returning a list of output vectors if the number of valid input nodes is greater than one. List element names are taken directly from the input node vector.

If any supplied nodes are not found in the tree, the behavior currently varies across functions. Invalid nodes are automatically omitted by ancestors and descendants, with a warning. ancestor will return NA for any invalid nodes, with a warning. Both children and siblings will return an empty vector, again with a warning. In contrast, MRCA and shortestPath will throw an immediate error if any input nodes are invalid.

Value

ancestors and descendants return a named vector (or a list of such vectors in the case of multiple input nodes) of the ancestors and descendants of a node
ancestor and children ancestor is analogous to ancestors(..., type="parent") (i.e. direct ancestor only), but returns a single concatenated vector in the case of multiple input nodes; children is analogous to descendants(..., type="children") (i.e. direct descendants only), but is not currently intended to be used with multiple input nodes
siblings returns sibling nodes (children of the same parent)
MRCA returns the most recent common ancestor of two or more nodes
shortestPath returns the nodes of the shortest path from one node to another (excluding node1 and node2)
sumEdgeLength returns the sum of branch length for branches starting at nodes provided

Note

MRCA is uppercase to avoid conflict with mrca in ape

See Also

mrca, in the ape package, gives a list of all subtrees

Examples

  data(geospiza)
  nodeLabels(geospiza) <- LETTERS[1:nNodes(geospiza)]
  plot(as(geospiza, "phylo4"), show.node.label=TRUE)
  ancestor(geospiza, "E")
  children(geospiza, "C")
  descendants(geospiza, "D", type="tips")
  descendants(geospiza, "D", type="all")
  ancestors(geospiza, "D")
  MRCA(geospiza, "conirostris", "difficilis", "fuliginosa")
  MRCA(geospiza, "olivacea", "conirostris")

  ## shortest path between 2 nodes
  shortestPath(geospiza, "fortis", "fuliginosa")
  shortestPath(geospiza, "F", "L")

  ## FIXME
  ## if(require(ape)){ edgelabels() }

  ## branch length from a tip to the root
  sumEdgeLength(geospiza, ancestors(geospiza, "fortis", type="ALL"))


[Package phylobase version 0.5 Index]