get_subtrees_at_nodes {castor} | R Documentation |
Extract subtrees descending from specific nodes.
Description
Given a tree and a list of focal nodes, extract the subtrees descending from those focal nodes, with the focal nodes becoming the roots of the extracted subtrees.
Usage
get_subtrees_at_nodes(tree, nodes)
Arguments
tree |
A tree of class "phylo". |
nodes |
Character vector or integer vector specifying the names or indices, respectively, of the focal nodes at which to extract the subtrees. If an integer vector, entries must be between 1 and |
Details
The input tree need not be rooted, however "descendance" from a focal node is inferred based on the direction of edges in tree$edge
. The input 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
A list with the following elements:
subtrees |
List of the same length as |
new2old_tip |
List of the same length as |
new2old_node |
List of the same length as For example, |
new2old_edge |
List of the same length as |
Author(s)
Stilianos Louca
See Also
Examples
# generate a random tree
Ntips = 1000
tree = generate_random_tree(list(birth_rate_intercept=1),Ntips)$tree
# extract subtrees descending from random nodes
nodes = sample.int(tree$Nnode,size=10)
subtrees = get_subtrees_at_nodes(tree, nodes)$subtrees
# print summaries of extracted subtrees
for(n in length(nodes)){
cat(sprintf("Subtree at %d-th node has %d tips\n",nodes[n],length(subtrees[[n]]$tip.label)))
}