Learn R Programming

adephylo (version 1.1-16)

sp.tips: 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)

Value

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

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).

Author

Thibaut Jombart tjombart@imperial.ac.uk

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).

See Also

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

Examples

Run this code


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)

}

Run the code above in your browser using DataLab