R/mts_formatMatrix.R

Defines functions mts_formatMatrix

Documented in mts_formatMatrix

mts_formatMatrix <- function(matrix, cores) {
  
  # Error catching - from input
  if (missing(cores)) {
    cores <- 1
    message("1 core selected")
  } else if (!is.numeric(cores) || cores < 1) {
    stop("cores should be >= 1")
  } else {
    message(cores, " cores selected")
  }
  
  if (missing(matrix)) {
    stop("No Matrix Provided")
  } else {
    if (!is.data.frame(matrix)) {
      stop("matrix must be a data frame")
    }
  }
  
  result_list <- pbmclapply(split(matrix, rownames(matrix), drop = TRUE), function(x) {
    tab <- data.frame("Samples" = colnames(x),
                      "ImpactGroup" = as.numeric(x),
                      stringsAsFactors = FALSE)
    
    # impact column has same length as column number 
    tab$Impact <- character(length(tab$Samples))
    
    # high impact = 1, low impact = 2
    tab$Impact[tab$ImpactGroup %in% c(1)] <- "HIGH" 
    tab$Impact[tab$ImpactGroup %in% c(2)] <- "LOW"
    
    # change positions of columns
    tab <- tab[, c(1, 3, 2)]
    
    return(tab)
  }, mc.cores = cores)
  
  return(result_list)
}

Try the MultiSEp package in your browser

Any scripts or data that you put into this service are public.

MultiSEp documentation built on Aug. 27, 2026, 5:07 p.m.