make_nested_set: make_nested_set

View source: R/make_nested_set.r

make_nested_setR Documentation

make_nested_set

Description

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.

Usage

make_nested_set(phy, n_cores = 2)

Arguments

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).

Value

Matrix object representing a nested set of nodes. Each row matches rows of the "edges" object within phy. Object has the following columns:

1 (node)

Node value in the original phylo object.

2 (min)

minimum tip index subtended by node.

3 (max)

maximum tip index subtended by node.

4 (contig)

Is min:max congiguous? 1 (true) or 0 (false).

Author(s)

John L. Darcy

References

https://en.wikipedia.org/wiki/Nested_set_model https://en.wikipedia.org/wiki/Adjacency_list

See Also

ape::phylo

Examples

  # 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])


darcyj/specificity documentation built on Aug. 1, 2023, 8 a.m.