#' @title Preprocess an Affymetrix dataset with GC-RMA. #' #' @description This function preprocess an Affymetrix dataset using RMA and saves the #' results in a given TSV file. In addition, it returns the ESET object. #' #' The function assumes that a folder containing the raw data exists (as cel files). #' #' Note: the function does not check for the existence of folders or files. The batch effect #' correction is currently not yet supported. #' #' @param input_data_dir A string representing the folder that contains the input data. #' @param output_data_file A string representing the file that should contain the #' preprocessed data. #' @param compressed A boolean representing whether the cel files are compressed. This #' is FALSE by default. #' @param batch_correction A boolean indicating whether batch correction should #' be performed, default to FALSE. Note: not yet suported. #' @param batch_filename A string indicating where the batch information can be found, #' default to 'Batch.tsv'. Note: not yet suported. #' @param clean_samples A boolean indicating whether the dataset should be cleaned by removing #' the samples that do not have clinical data. Default to FALSE. #' @param verbose A boolean representing whether the function should display log information. This #' is TRUE by default. #' @return The expression data as an ESET object. preprocess_data_affymetrix_gcrma <- function(input_data_dir, output_data_file, compressed = FALSE, batch_correction = FALSE, batch_filename = "Batch.tsv", clean_samples = FALSE, verbose = TRUE) { # We define the I/Os. raw_data_input_dir <- paste0(input_data_dir, "RAW/") # We run the RMA pre-processing method on the data. input_data_files <- affy::list.celfiles(raw_data_input_dir, full.names = TRUE) remove(raw_data_input_dir) batch <- affy::ReadAffy(filenames = input_data_files, compress = compressed, verbose = verbose) eset <- gcrma::gcrma(batch) # If necessary, we remove the samples that do not have clinical data. if (clean_samples) { # We load the clinical data as to get the samples to keep. samples <- rownames(Biobase::pData(ArrayUtils::load_clinical_data(input_data_dir, verbose = FALSE))) # We only keep the samples with clinical data. eset <- eset[, samples] } # We save the eset data as TSV file. utils::write.table(Biobase::exprs(eset), file = output_data_file, sep = "\t", quote = FALSE) # We clean up and log information. remove(input_data_files, batch) if (verbose == TRUE) { message(paste0("[", Sys.time(), "] Expression data pre-processed with RMA.")) } # We return the created ESET. return(eset) }