View source: R/get_clade_list.R
get_clade_list | R Documentation |
Given a tree in standard "phylo" format, calculate an alternative representation of the tree structure as a list of tips/nodes with basic information on parents, children and incoming edge lengths. This function is analogous to the function read.tree.nodes
in the R package phybase
.
get_clade_list(tree, postorder=FALSE, missing_value=NA)
tree |
A tree of class "phylo". If |
postorder |
Logical, specifying whether nodes should be ordered and indexed in postorder traversal, i.e. with the root node listed last. Note that regardless of the value of |
missing_value |
Value to be used to denote missing information in the returned arrays, for example to denote the (non-existing) parent of the root node. |
This function is analogous to the function read.tree.nodes
in the R package phybase
v1.4, but becomes multiple orders of magnitude faster than the latter for large trees (i.e. with 1000-1000,000 tips). Specifically, calling get_clade_list
with postorder=TRUE
and missing_value=-9
on a bifurcating tree yields a similar behavior as calling read.tree.nodes
with the argument “name
” set to the tree's tip labels.
The input tree can include monofurcations, bifurcations and multifurcations. The asymptotic average time complexity of this function is O(Nedges), where Nedges is the number of edges in the tree.
A named list with the following elements:
success |
Logical, indicating whether model fitting succeeded. If |
Nsplits |
The maximum number of children of any node in the tree. For strictly bifurcating trees this will be 2. |
clades |
2D integer matrix of size Nclades x (Nsplits+1), with every row representing a specific tip/node in the tree. If |
lengths |
Numeric vector of size Nclades, listing the lengths of the incoming edges at each tip/node in |
old2new_clade |
Integer vector of size Nclades, mapping old tip/node indices to tip/node indices in the returned |
Stilianos Louca
# generate a random bifurcating tree
tree = generate_random_tree(list(birth_rate_intercept=1),
max_tips=100)$tree
# get tree structure as clade list
# then convert into a similar format as would be
# returned by phybase::read.tree.nodes v1.4
results = get_clade_list(tree,postorder=TRUE,missing_value=-9)
nodematrix = cbind( results$clades,
results$lengths,
matrix(-9,nrow=nrow(results$clades),ncol=3))
phybaseformat = list( nodes = nodematrix,
names = tree$tip.label,
root = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.