R/Bayice.R

Defines functions Bayice

Documented in Bayice

#' BayICE
#'
#' @param scdata single data with genes in rows and cells in columns.
#' @param bulkdata A matrix with genes in rows and samples in columns.
#' @param label The cell type label of single data.
#' @importFrom BayICE BayICE
#'
#' @return   A data frame of Mixed cellular fractions.
#'
#'
#' @export
#' @examples
#'
#' Bulk <- Bulk_GSE60424
#' SC <- SC_GSE60424
#' Label <- Label_GSE60424$Label
#' res <- Bayice(bulkdata = Bulk,
#'               scdata = SC,
#'               label = Label)
#'



Bayice <- function(scdata, bulkdata,label) {

  scdata <- scdata[apply(scdata, 1, var)!=0,]

  bulkdata <- bulkdata[apply(bulkdata, 1, var)!=0,]

  gene <- intersect(rownames(scdata),rownames(bulkdata))

  scdata <- scdata[gene,]

  bulkdata <- bulkdata[gene,]

  ref <- as.matrix(scdata)

  mix <- as.matrix(bulkdata)

  type <- label

  BayICE_res <- BayICE::BayICE(ref.set=log(ref+1),
                               mix.set=log(mix+1),
                               ref.id=type,
                               iter=100,
                               burnin = 0.6,
                               thinning = 3,
                               parC = 10^-5)

  Bayice_res <- t(BayICE_res$w)

  colnames(Bayice_res) <- c(unique(type),"orther cell")

  res_Bayice <- as.data.frame(Bayice_res)



  return(res_Bayice)

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