R/ReadBeta.R

Defines functions ReadBeta

Documented in ReadBeta

#' Read gene beta scores from MAGeCK-MLE results
#'
#' @docType methods
#' @name ReadBeta
#' @rdname ReadBeta
#' @aliases readbeta
#'
#' @param gene_summary A data frame or a file path to gene summary file generated by MAGeCK-MLE.
#'
#' @return A data frame, whose first column is Gene and other columns are comparisons.
#'
#' @author Wubing Zhang
#'
#' @examples
#' file3 = file.path(system.file("extdata", package = "MAGeCKFlute"),
#' "testdata/mle.gene_summary.txt")
#' dd = ReadBeta(file3)
#' head(dd)
#'
#' @export
ReadBeta <- function(gene_summary){
  if(is.null(dim(gene_summary))){
    gene_summary = read.table(file = gene_summary, sep = "\t", header = TRUE, quote = "",
                              comment.char = "", check.names = FALSE, stringsAsFactors = FALSE)
  }
  dd = gene_summary
  if(sum(grepl("beta$", colnames(dd)))>0){
    dd = dd[, c(1, which(grepl("beta$", colnames(dd))))]
    names(dd) = gsub(".beta", "", names(dd))
  }
  return(dd)
}
WubingZhang/MAGeCKFlute documentation built on Jan. 27, 2024, 2:43 p.m.