R/Abis.R

Defines functions Abis total.norm

Documented in Abis

total.norm <- function(x) {
  y <- sum(x)
  z <- x / y
  z
}


#' Deconvolution Methods of ABIS
#' The ABIS helps users to Estimate of cellular fractions.
#' @param bulkdata  A matrix with genes in rows and samples in columns.
#' @param signature A data-frame containing signatures of different cell types.
#' @importFrom MASS rlm
#' @importFrom stats coef
#' @return  A data frame of Mixed cellular fractions.
#' @export
#' @examples
#'
#' Bulk <- Bulk_GSE60424
#' res <- Abis(bulkdata = Bulk,
#'             signature = LM22)




Abis <- function(bulkdata, signature) {

  bulkgenes <- rownames(bulkdata)

  siggenes <- rownames(signature)

  genes <- intersect(bulkgenes, siggenes)

  Dec <- apply(bulkdata[genes, , drop = FALSE],
               2,
               function(x) {
                 stats::coef(MASS::rlm(as.matrix(signature[genes, ]), x, maxit = 100))
               })

  Dec <- Dec * 100

  ABIS_res <- signif(Dec, 3)

  ABIS_res[ABIS_res < 0] <- 0

  res_Abis <- t(apply(t(ABIS_res), 1, total.norm))



  return(res_Abis)
}
libcell/deconvBench documentation built on Sept. 24, 2022, 12:36 p.m.