Hello list,

I'm not aware that a function such as which.node exists in any phylo
package available. Or at least one that can retrieve the node number from a
tree (phy) given a list of tips (tips). For this reason I went ahead and
wrote a simple function (see below). The function allows tips to be given
in "character" or "numeric" classes.

If someone finds it useful or so if any of the developers would like to
make it part of their packages, go ahead.

which.node <- function(phy, tips)
{
if (is.character(tips) == TRUE){
tips_n = vector("numeric",length(tips))
for (i in 1:length(tips))
tips_n[i] = which(phy$tip.label == tips[i])
rows = vector("numeric",length(tips_n))
for (i in 1:length(tips_n))
rows[i] = which(phy$edge[,2] == tips_n[i])
nodes = sort(phy$edge[rows,1])
return(nodes[1])
} else if (is.numeric(tips) == TRUE){
rows = vector("numeric",length(tips))
for (i in 1:length(tips))
rows[i] = which(phy$edge[,2] == tips[i])
nodes = sort(phy$edge[rows,1])
return(nodes[1])
} else if (is.null(tips) == TRUE){
stop('tips vector is empty')
}
}


All the best,

Santiago

-- 
Santiago Sánchez-Ramírez
Department of Ecology and Evolutionary Biology, University of Toronto
Department of Natural History (Mycology), Royal Ontario Museum
100 Queen's Park
Toronto, ON
M5S 2C6
Canada
Other email: santiago.sanc...@mail.utoronto.ca
Tel. 416-586-8025

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to