get_subtree_at_node {castor} | R Documentation |
Extract a subtree descending from a specific node.
Description
Given a tree and a focal node, extract the subtree descending from the focal node and place the focal node as the root of the extracted subtree.
Usage
get_subtree_at_node(tree, node)
Arguments
tree |
A tree of class "phylo". |
node |
Character or integer specifying the name or index, respectively, of the focal node at which to extract the subtree. If an integer, it must be between 1 and |
Details
The input tree need not be rooted, however "descendance" from the 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 named list with the following elements:
subtree |
A new tree of class "phylo", containing the subtree descending from the focal node. This tree will be rooted, with the new root being the focal node. |
new2old_tip |
Integer vector of length Ntips_kept (=number of tips in the extracted subtree) with values in 1,..,Ntips, mapping tip indices of the subtree to tip indices in the original tree. In particular, |
new2old_node |
Integer vector of length Nnodes_kept (=number of nodes in the extracted subtree) with values in 1,..,Nnodes, mapping node indices of the subtree to node indices in the original tree. For example, |
new2old_edge |
Integer vector of length Nedges_kept (=number of edges in the extracted subtree), with values in 1,..,Nedges, mapping edge indices of the subtree to edge indices in the original tree. In particular, |
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 subtree descending from a random node
node = sample.int(tree$Nnode,size=1)
subtree = get_subtree_at_node(tree, node)$subtree
# print summary of subtree
cat(sprintf("Subtree at %d-th node has %d tips\n",node,length(subtree$tip.label)))