Last chance! 50% off unlimited learning
Sale ends in
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)
A list with the following elements:
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.
Integer vector of length Nnodes_new, mapping node indices in the new tree to node indices in the old tree.
Integer. Number of nodes (monofurcations) removed from the tree.
A rooted tree of class "phylo".
Logical, indicating whether the root node should always be kept (i.e., even if it only has a single child).
Logical, indicating whether all edges should be assumed to have length 1. If TRUE
, the outcome is the same as if the tree had no edges.
Stilianos Louca
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.
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))
Run the code above in your browser using DataLab