view transformation_script.R @ 0:eacea1349a7c draft

planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 83f2d1045c0bf086bbe2de5204cd5c1d8354116f
author ethevenot
date Fri, 29 Jul 2016 12:11:01 -0400
parents
children d9e05021553c
line wrap: on
line source

## Etienne Thevenot
## W4M Core Development Team
## etienne.thevenot@cea.fr
## 2015-04-25

transformF <- function(datMN,
                       metC) {

    ## options

    optStrAsFacL <- options()[["stringsAsFactors"]]
    options(stringsAsFactors = FALSE)

    ## transformation

    switch(metC,
           log2 = {

               cat("\n'log2' transformation\n", sep="")

               if(length(which(datMN < 0)))
                   stop("The 'dataMatrix' contains negative values")

               zerMN <- datMN == 0

               ## Number of missing values
               nasN <- length(which(is.na(datMN)))
               cat("\nMissing values in the 'dataMatrix': ",
                   nasN,
                   " (",
                   round(nasN / cumprod(dim(datMN))[2] * 100),
                   "%)\n",
                   sep="")

               ## Number of zero values
               zerN <- length(which(zerMN))
               cat("\nZero values in the 'dataMatrix': ",
                   zerN,
                   " (",
                   round(zerN / cumprod(dim(datMN))[2] * 100),
                   "%)\n",
                   sep="")

               trfMN <- log2(1 + datMN)

           },
           log10 = {

               cat("\n'log10' transformation\n", sep="")

               if(length(which(datMN < 0)))
                   stop("The 'dataMatrix' contains negative values")

               zerMN <- datMN == 0

               ## Number of missing values
               nasN <- length(which(is.na(datMN)))
               cat("\nMissing values in the 'dataMatrix': ",
                   nasN,
                   " (",
                   round(nasN / cumprod(dim(datMN))[2] * 100),
                   "%)\n",
                   sep="")

               ## Number of zero values
               zerN <- length(which(zerMN))
               cat("\nZero values in the 'dataMatrix': ",
                   zerN,
                   " (",
                   round(zerN / cumprod(dim(datMN))[2] * 100),
                   "%)\n",
                   sep="")

               trfMN <- log10(1 + datMN)

           }) ## end of 'log10' method


    ## returning

    options(stringsAsFactors=optStrAsFacL)

    return(trfMN)

} ## end of transformF