R/updateBinList.R

Defines functions updateBinList

Documented in updateBinList

#' Updates Bin list given a split group
#'
#' @export
#' @param binList List of bins
#' @param grp Group indicating the split of an bin
#' @examples
#' library(ape)
#' set.seed(6)
#' tree <- rtree(10)
#' Groups <- getPhyloGroups(tree)
#' treeList <- list(tree)
#' binList <- list(1:10)
#' factor <- 16
#' grp <- getLabelledGrp(factor,tree,Groups)
#' grp
#'
#' treeList <- updateTreeList(treeList,binList,grp,tree)
#' binList <- updateBinList(binList,grp)
#'
#'
#' Groups <- getNewGroups(tree,treeList,binList)
#'
#' factor=2
#' grp <- getLabelledGrp(factor,tree,Groups)
#' grp
#' unlist(grp)
#' tree$tip.label[unlist(grp)]
#'
#' treeList <- updateTreeList(treeList,binList,grp,tree)
#' binList <- updateBinList(binList,grp)
#'
#'
#'
#' Groups <- getNewGroups(tree,treeList,binList)
#' factor = 11
#' grp <- getLabelledGrp(factor,tree,Groups)
#' grp
#' unlist(grp)
#' tree$tip.label[unlist(grp)]
#'
#' treeList <- updateTreeList(treeList,binList,grp,tree)
#' binList <- updateBinList(binList,grp)
updateBinList <- function(binList,grp){
  ix <- phylofactor:::whichBinSplit(grp,binList)
  tips=sum(sapply(grp,FUN=function(g) length(g)==1)) ## How many tips are there? They will be removed from BinList and recalculated later.

  if (tips==0){
    binList[[ix]] <- grp[[1]]
    binList[[length(binList)+1]] <- grp[[2]]
  } else if (tips==1){
    cld <- which(!sapply(grp,FUN=function(g) length(g)==1))
    c#replace the split bin with the clade
    binList[[ix]] <- grp[[cld]]
  } else {
    binList[[ix]] <- NULL
  }
  return(binList)
}
reptalex/phylofactor documentation built on Feb. 28, 2024, 3:19 p.m.