View source: R/get_subtree_at_node.R
get_subtree_at_node | R Documentation |
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.
get_subtree_at_node(tree, node)
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 |
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).
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, |
Stilianos Louca
get_subtree_with_tips
# 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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.