R/debCAM.R

Defines functions Debcam

Documented in Debcam

#' debCAM
#'
#' @param bulkdata A matrix with genes in rows and samples in columns.
#' @param celltypenum  Specify the range of underlying subpopulation number, default is 5.
#' @importFrom debCAM CAM Amat MGsforA
#' @return  A data frame of Mixed cellular fractions.
#'
#' @export
#'
#' @examples
#'
#' Bulk <- Bulk_GSE60424
#' res <- Debcam(bulkdata = Bulk,
#'               celltypenum = 5 )
#'
#'
#'


Debcam <- function(bulkdata,celltypenum=5) {


  rCAM <- debCAM::CAM(as.matrix(bulkdata),
                      K = 2:celltypenum,
                      thres.low = 0.30,
                      thres.high = 0.95)


  Aest <- debCAM::Amat(rCAM,celltypenum)##Absolute gene proportion

  MGlist <- debCAM::MGsforA(rCAM, K = celltypenum) #for three sub markerlist

  anncell <- NULL


  probpath <- system.file("extdata", "PanglaoDB_markers_27_Mar_2020.tsv", package = "deconvBench")

  pl <- read.table(probpath,sep = "\t",header = T)

  Plhuman <- pl[pl$species!="Mm",]


  for (i in 1:celltypenum) {

    marker <-  MGlist[[i]]

    celltype <-NULL

    for (m in 1:length(marker) ) {

      ct <- Plhuman[which(Plhuman$official.gene.symbol==marker[m]),3]

      celltype <-c(celltype,ct)
    }

    uniquecell <- unique(celltype)

    times_cell <- tabulate(match(celltype, uniquecell))

    names(times_cell) <- uniquecell

    cell <- names(sort(times_cell,decreasing = T))[1]

    anncell <- c(anncell,cell)

  }


  colnames(Aest) <- paste(anncell,1:celltypenum,sep = "_")

  rownames(Aest) <- colnames(bulkdata)

  res_dDebcam <- Aest


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