sp.tips: Find the shortest path between tips of a tree

View source: R/utils.R

sp.tipsR Documentation

Find the shortest path between tips of a tree

Description

The function sp.tips finds the shortest path between tips of a tree, identified as tip1 and tip2. This function applies to trees with the class phylo, phylo4 or phylo4d. Several tips can be provided at a time.

Usage

sp.tips(x, tip1, tip2, useTipNames = FALSE, quiet = FALSE, include.mrca = TRUE)

Arguments

x

A tree of class phylo, phylo4 or phylo4d.

tip1

A vector of integers identifying tips by their numbers, or a vector of characters identifying tips by their names. Recycled if needed.

tip2

A vector of integers identifying tips by their numbers, or a vector of characters identifying tips by their names. Recycled if needed.

useTipNames

a logical stating whether the output must be named using tip names in all cases (TRUE), or not (FALSE). If not, names of tip1 and tip2 will be used.

quiet

a logical stating whether a warning must be issued when tip1==tip2, or not (see details).

include.mrca

a logical stating whether the most recent common ancestor shall be included in the returned path (TRUE, default) or not (FALSE).

Details

The function checks if there are cases where tip1 and tip2 are the same. These cases are deleted when detected, issuing a warning (unless quiet is set to TRUE).

Value

A list whose components are vectors of named nodes forming the shortest path between a couple of tips.

Author(s)

Thibaut Jombart tjombart@imperial.ac.uk

See Also

shortestPath which does the same thing as sp.tips, for any node (internal or tip), but much more slowly.

Examples



if(require(ape) & require(phylobase)){
## make a tree
x <- as(rtree(20),"phylo4")
plot(x,show.node=TRUE)
## get shortest path between tip 1 and all other tips.
sp.tips(x, "t1", "t2")
sp.tips(x, 1, 2:20, TRUE)

}


adephylo documentation built on Oct. 6, 2023, 5:07 p.m.