R/load_data.R

#' Load the quality control files (.qc) generated by OncoSNP.
#' 
#' @param qcFile File generated that can be generated in the oncosnp module or
#'        a single qc file generated by oncosnp directly.
#' @return A data.frame of the quality control file that has its columns 
#'         renamed to be programmer-friendly to use.
#' @export
load_oncosnp_qc_file <- function(qcFile) {
  inDt <- data.table::fread(qcFile)
  data.table::setnames(inDt, 
                       colnames(inDt), 
                       c("LRRShift", "normalContent", "copyNum", 
                         "logLikelihood", "outlierRate", 
                         "LRRStd", "BAFStd", "ploidyNo"))
  return(dplyr::tbl_df(inDt))
}

#' Load the OncoSNP CNV file (.cnv).
#' 
#' @param cnvFile OncoSNP CNV file 
#' @return A data.table of the standard output file (.cnvs) that has its columns 
#'         renamed to be programmer-friendly to use
#' @export
load_oncosnp_cnv_file <- function(cnvFile, version = c("1.3.0")) {
  cnvDt <- data.table::fread(cnvFile)

#   if (version == "1.2"){
#     colnames(inDf)[1:3] <- c('chr', 'start', 'end')
#     colnames(inDf)[7] <- 'num.markers'
#     colnames(inDf)[10] <- 'state'
  if (numeric_version(version) == numeric_version("1.3.0")){
    data.table::setnames(cnvDt, 
                         colnames(cnvDt),
                         c("chr", "start", "end", "copyNum", "loh", "rank", 
                           "logLik", "numMarkers", "normFrac", "state", 
                           "ploidyNum", "majorCopyNumber", "minorCopyNumber")
                         )
  }
  return(dplyr::tbl_df(cnvDt))
}

#' Load the PennCNV probe data.
#' 
#' @param probeFile The PennCNV probe file
#' @return A data.table of the probe file
#' @export
load_penncnv_probe_data <- function(probeFile){
  probeDt <- data.table::fread(probeFile, colClasses = c("Chr" = "character"))
  data.table::setnames(probeDt,
                       colnames(probeDt),
                       c("probeID", "chr", "pos", "LRR", "BAF"))
  return(dplyr::tbl_df(probeDt))
}
tinyheero/oncosnputils documentation built on May 31, 2019, 3:36 p.m.