Defines functions get_paths

Documented in get_paths

#' All paths from root to tips
#' @param phy object of class phylo
#' @details Function makes use of network analysis tools avaiable in the R package igraph
#' it takes a phylo object and returns a data.frame object with all paths from
#' the root to the tips
#' take care: Node1 = root node
get_paths <- function(phy){
  require("igraph"); require("plyr")
  # convert phylo object to igraph
  g <- as.igraph(phy)
  # List all simple paths
  paths <- all_simple_paths(g, V(g))
  # Convert a vertex to an ordinary vector
  paths <- lapply(paths, as_ids)
  # remove internal paths (that do not span until tips)
  paths <- paths[grep("t|sp|tip", paths)]
  # convert list to data.frame
  paths_df <- rbind.fill(lapply(paths,
    function(y) { as.data.frame(t(y), stringsAsFactors=FALSE) }))
FranzKrah/seta documentation built on Sept. 15, 2017, 4:50 p.m.