| get_ancestral_nodes {castor} | R Documentation |
Compute ancestral nodes.
Description
Given a rooted phylogenetic tree and a set of tips and/or nodes ("descendants"), determine their ancestral node indices, traveling a specific number of splits back in time (i.e., towards the root).
Usage
get_ancestral_nodes(tree, descendants, Nsplits)
Arguments
tree |
A rooted tree of class "phylo". |
descendants |
An integer vector or character vector, specifying the tips/nodes for each of which to determine the ancestral node. If an integer vector, it must list indices of tips (from 1 to Ntips) and/or nodes (from Ntips+1 to Ntips+Nnodes), where Ntips and Nnodes is the number of tips and nodes in the tree, respectively. If a character vector, it must list tip and/or node names. In this case |
Nsplits |
Either a single integer or an integer vector of the same length as |
Details
The tree may include multi-furcations (i.e. nodes with more than 2 children) as well as mono-furcations (i.e. nodes with only one child).
Value
An integer vector of the same length as descendants, with values in 1,..,Nnodes, listing the node indices representing the ancestors of descendants traveling backward Nsplits.
Author(s)
Stilianos Louca
See Also
get_pairwise_mrcas, get_mrca_of_set
Examples
# generate a random tree
tree = generate_random_tree(list(birth_rate_intercept=1),
max_tips = 50,
tip_basename = "tip.",
node_basename = "node.")$tree
# pick 3 tips
descendants=c("tip.5", "tip.7","tip.10")
# determine the immediate parent node of each tip
ancestors = castor::get_ancestral_nodes(tree, descendants, Nsplits=1)
print(tree$node.label[ancestors])