R/monoClade.R

#' identify nodes of a monophyletic clade
#'
#' identify nodes of a monophyletic clade
#' @param phylo dated tree in ape format
#' @param node
#' @keywords 
#' @return storeNodes
#' @export
#' @examples
#' monoClade()

monoClade <- function(phylo, node) {
  tips <- Ntip(phylo)
  nextNodes <- node
  storeNodes <- nextNodes
  stopPoint <- FALSE
  
  while(stopPoint == FALSE) {
    startPoints <- unlist(sapply(nextNodes, function(x) which(phylo$edge[,1] == x)))
    nextNodes <- phylo$edge[startPoints, 2]
    storeNodes <- c(storeNodes, nextNodes)
    stopPoint <- all(nextNodes <= tips)
  }
  return(storeNodes)
}
PuttickMacroevolution/cladeMode documentation built on May 8, 2019, 3:47 a.m.