R/Estimate.R

Defines functions Estimate

Documented in Estimate

#' Estimate
#'
#' @param pro bulk
#' @param platform one of "affymetrix", "agilent", "illumina".
#' @param bulkdata A matrix with genes in rows and samples in columns.
#' @importFrom edgeR cpm
#' @importFrom estimate filterCommonGenes estimateScore
#' @return A data frame of Mixed cellular fractions.
#' @export
#'
#' @examples
#'
#'  Bulk <- Bulk_GSE60424
#'  res <- Estimate(bulkdata = Bulk)
#'
#'




 Estimate <- function(bulkdata,
                      pro = "bulk",
                      platform = c("affymetrix", "agilent", "illumina")[1]){

   dat <- log2(edgeR::cpm(bulkdata)+1)

   require(estimate)###need data "common_genes"

   tmp_path <- tempdir()

   dir.create(paste0(tmp_path,"/Estimate_res"))

   input.f=paste0(tmp_path,"/Estimate_res/",pro,'_estimate_input.txt')

   output.f=paste0(tmp_path,"/Estimate_res/",pro,'_estimate_gene.gct')

   output.ds=paste0(tmp_path,"/Estimate_res/",pro,'_estimate_score.gct')

   write.table(dat,file = input.f,sep = '\t',quote = F)


   estimate::filterCommonGenes(input.f=input.f,
                               output.f=output.f ,
                               id="GeneSymbol")

   estimate::estimateScore(input.ds = output.f,
                           output.ds=output.ds,
                           platform= platform)

   scores <- read.table(output.ds,skip = 2,header = T)

   rownames(scores)=scores[,1]

   scores <- t(scores[,3:ncol(scores)])

   res_Estimate <- scores

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