View source: R/collapse_monofurcations.R
collapse_monofurcations | R Documentation |
Eliminate monofurcations (nodes with only a single child) from a phylogenetic tree, by connecting their incoming and outgoing edge.
collapse_monofurcations(tree, force_keep_root=TRUE, as_edge_counts=FALSE)
tree |
A rooted tree of class "phylo". |
force_keep_root |
Logical, indicating whether the root node should always be kept (i.e., even if it only has a single child). |
as_edge_counts |
Logical, indicating whether all edges should be assumed to have length 1. If |
All tips in the input tree retain their original indices, however the returned tree may include fewer nodes and edges. Edge and node indices may change.
If tree$edge.length
is missing, then all edges in the input tree are assumed to have length 1.
A list with the following elements:
tree |
A new tree of class "phylo", containing only bifurcations (and multifurcations, if these existed in the input tree). The number of nodes in this tree, Nnodes_new, may be lower than of the input tree. |
new2old_node |
Integer vector of length Nnodes_new, mapping node indices in the new tree to node indices in the old tree. |
Nnodes_removed |
Integer. Number of nodes (monofurcations) removed from the tree. |
Stilianos Louca
multifurcations_to_bifurcations
# generate a random tree
Ntips = 1000
tree = generate_random_tree(list(birth_rate_intercept=1), max_tips=Ntips)$tree
# prune the tree to generate random monofurcations
random_tips = sample.int(n=Ntips, size=0.5 * Ntips, replace=FALSE)
tree = get_subtree_with_tips(tree, only_tips=random_tips, collapse_monofurcations=FALSE)$subtree
# collapse monofurcations
new_tree = collapse_monofurcations(tree)$tree
# print summary of old and new tree
cat(sprintf("Old tree has %d nodes\n",tree$Nnode))
cat(sprintf("New tree has %d nodes\n",new_tree$Nnode))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.