Skip to contents

Sort tip labels in a tree or a collection of trees.

Usage

sort_tips(x)

# S3 method for phylo
sort_tips(x)

# S3 method for multiPhylo
sort_tips(x)

Arguments

x

a tree of class "phylo" or a collection of trees of class "multiPhylo"

Value

an input tree with sorted tips

Details

The rnni function assumes tip labels in an unambiguous order. This is due to the internal implementation not having tip labels, tip/leave are instead identified by the index in the node matrix. The sort_tips orders the tip labels and change the node indices in the node matrix so that the tips for two different trees of the same taxa have the same node id.

Examples

# generate random trees
# use rcoal(5) instead of rankedPhylo(5)
# as ranked phylo always generate tip.labels
# in the same order.
t1 = ape::rcoal(5) |> rankedPhylo()
t2 = ape::rcoal(5) |> rankedPhylo()
t1s = sort_tips(t1)
t2s = sort_tips(t2)
all(tips(t1s) == tips(t2s))
#> [1] TRUE

# for collection of trees:
trees = c(t1, t2)
sort_tips(trees)
#> 2 phylogenetic trees