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