R/methods.R

#' @rdname checkw4m
setMethod("checkw4m", "ExpressionSet",
         function(eset, ...) {

             datMN <- t(exprs(eset))
             samDF <- pData(eset)
             varDF <- fData(eset)

             chkL <- .checkW4mFormatF(datMN, samDF, varDF)

             if(!chkL) {
                 stop("Problem with the sample or variable names in the tables (see above)", call. = FALSE)
             } else
                 return(TRUE)
         })

#' @rdname writew4m
setMethod("writew4m", "ExpressionSet",
          function(eset, filePrefixC = getwd(), verboseL = TRUE, ...){

              datMN <- exprs(eset)
              datDF <- cbind.data.frame(dataMatrix = rownames(datMN),
                                        as.data.frame(datMN))

              filDatC <- paste0(filePrefixC, "dataMatrix.tsv")
              filSamC <- paste0(filePrefixC, "sampleMetadata.tsv")
              filVarC <- paste0(filePrefixC, "variableMetadata.tsv")

              write.table(datDF,
                          file = filDatC,
                          quote = FALSE,
                          row.names = FALSE,
                          sep = "\t")

              samDF <- pData(eset)
              samDF <- cbind.data.frame(sampleMetadata = rownames(samDF),
                                        samDF)
              write.table(samDF,
                          file = filSamC,
                          quote = FALSE,
                          row.names = FALSE,
                          sep = "\t")

              varDF <- fData(eset)
              varDF <- cbind.data.frame(variableMetadata = rownames(varDF),
                                        varDF)
              write.table(varDF,
                          file = filVarC,
                          quote = FALSE,
                          row.names = FALSE,
                          sep = "\t")

              if(verboseL) {
                  cat("The following 3 files:\n")
                  print(basename(filDatC))
                  print(basename(filSamC))
                  print(basename(filVarC))
                  cat("have been written in the following directory:\n")
                  print(dirname(filDatC))
                  }

          })
ethevenot/r-w4m2bioc documentation built on May 16, 2019, 9:06 a.m.