View source: R/make_nested_set.r
make_nested_set | R Documentation |
Makes a nested set table for a phylo object. Phylo objects made by the ape package store phylogenies as an "adjacency list", which in R is a table within which any given edge is represented by the two node numbers it connects. With this data structure, it is very computationally expensive to figure out which tips are the descendents of a given node. Instead, using a "nested set" data structure, this operation is trivial. A nested set stores the minimum and maximum tip index for each node, such that the descendents of that node are given by the inclusive range between those values.
make_nested_set(phy, n_cores = 2)
phy |
phylo object. Must be rooted, and sorted such that tip indices are ordered. This is the default for rooted trees read in using ape's read.tree function. |
n_cores |
integer. Number of CPU cores to use for parallel operations. If set to 1, lapply will be used instead of mclapply. A warning will be shown if n_cores > 1 on Windows, which does not support forked parallelism (default: 2). |
Matrix object representing a nested set of nodes. Each row matches rows of the "edges" object within phy. Object has the following columns:
Node value in the original phylo object.
minimum tip index subtended by node.
maximum tip index subtended by node.
Is min:max congiguous? 1 (true) or 0 (false).
John L. Darcy
https://en.wikipedia.org/wiki/Nested_set_model https://en.wikipedia.org/wiki/Adjacency_list
ape::phylo
# library(specificity)
# library(ape)
# phy <- get(data(endophyte))$supertree
# # check if tree is rooted:
# ape::is.rooted(phy)
# # make nested set table:
# phy_ns <- make_nested_set(phy)
# # show that nested set table matches up with edges table in phy:
# all(phy$edge[,2] == phy_ns[,1])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.