R/checkBadFeatures-deprecated.R

Defines functions checkBadFeatures

#' Check BiocParallel Logs for Bad Features
#' 
#' Parse logs generated by BiocParallel to identify features with errors
#' when running \code{spatialDGMM()} function from \code{Cardinal}.
#' 
#' @param logdir Directory containing BiocParallel log files (default = current working directory)
#' @return \code{vector} of features that resulted in an error when running \code{spatialDGMM()}
#' @examples 
#' badFeatures <- checkBadFeatures()
#' 
#' @export
checkBadFeatures <- function(logdir=getwd()) {
  badFeaturesVector <- c()
  for (i in 1:(detectCores()-2)) {
    filename <- paste0(logdir, "/BPJOB.task", as.character(i), ".log")
    logfile <- readChar(filename, file.info(filename)$size)
    logstring <- str_split(logfile,
                           '############### LOG OUTPUT ###############')[[1]]
    logstring <- logstring[length(logstring)]
    logstring <- str_split(logstring, 'feature = ')[[1]]
    logstring <- logstring[grepl('ERROR', logstring)]
    for (errorline in logstring) {
      badFeaturesVector <- c(badFeaturesVector,
                               as.numeric(str_split(errorline, ' ')[[1]][1]))
    }
  }
  return(badFeaturesVector)
}
gtluu/cardinalscripts documentation built on Nov. 28, 2023, 3:35 a.m.