R/bind_island_trees.R

Defines functions bind_island_trees

#' bind_island_trees
#'
#' @param sim a simulation output from DAISIE_sim
#' @param island_age the time length of the simulation
#'
#' @return a phylo object
#' @export

bind_island_trees <- function(sim, island_age) {
  branching_times <- list()
  for (i in 1:length(sim[[1]])) {
    branching_times[[i]] <- sim[[1]][[i]]$branching_times
  }
  branching_times[[1]] <- NULL
  trees <- list()
  for (i in 1:length(branching_times)) {
    trees[[i]] <- DDD::brts2phylo(branching_times[[i]], root = TRUE)
  }
  backbone_tree <- create_singleton_phylo(island_age) #add tip label stem
  island_tree <- ape::bind.tree(backbone_tree, trees[[1]], where = "root")
  for (i in 2:length(branching_times)) {
    island_tree <- ape::bind.tree(island_tree, trees[[i]], where = "root")
  }
  island_tree <- ape::drop.tip(phy = island_tree, tip = "stem")
  return(island_tree)
}
Neves-P/utilSIE documentation built on Nov. 20, 2019, 7 a.m.