read_eset.R 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' @title Read an expression set from a TSV file.
#'
#' @description This function loads an expression matrix and returns an eset. The
#' function assumes a folder with the data exists and does not
#' check for its existence.
#'
#' @param data_file A string representing the file that contains the expression data.
#' @param header A boolean indicating whether the file contains a header (default to TRUE).
#' @param sep A string that is used as a field separator to read the data (default to
#'  tab for TSV files).
#' @param row_names The index of the row names (default to 1).
#' @param as_is A boolean indicating whether R should keep the data as they are in the
#'  file (default to TRUE).
#' @param verbose A boolean representing whether the function should display log information. This
#'  is TRUE by default.
#' @return An ExpressionSet containing the preprocessed expression data.
read_eset <- function(data_file,
                      header    = TRUE,
                      sep       = "\t",
                      row_names = 1,
                      as_is     = TRUE,
                      verbose   = TRUE) {

  # We load the matrix and creates the associated eset object.
  exprs_mat <- as.matrix(utils::read.table(data_file,
                                           header    = header,
                                           sep       = sep,
                                           row.names = row_names,
                                           as.is     = as_is))
  exprs_eset <- Biobase::ExpressionSet(assayData = exprs_mat)

  # We clean up and log information.
  rm(exprs_mat)
  if (verbose == TRUE) {
    message(paste0("[", Sys.time(), "] Expression data read."))
  }

  # We return the eset.
  return(exprs_eset)
}