view transformation_script.R @ 3:cc0e9eff0de2 draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 60ebb3e8919c09c18f89a5362750ae45ca84d0c2
author ethevenot
date Wed, 28 Feb 2018 09:15:47 -0500
parents d9e05021553c
children
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)
    
    ## checking		     
    
    if(length(which(datMN < 0))) {
        cat("\nThe 'dataMatrix' contains negative values\n")
        sink()
        stop("The 'dataMatrix' contains negative values", call. = FALSE)
    }
    
    ## 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(datMN == 0))
    cat("\nZero values in the 'dataMatrix': ",
        zerN,
        " (",
        round(zerN / cumprod(dim(datMN))[2] * 100),
        "%)\n",
        sep="")
    
    ## transformation
    
    switch(metC,
           log2 = {

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

               trfMN <- log2(1 + datMN)

           },
           log10 = {

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

               trfMN <- log10(1 + datMN)

           },
           sqrt = {

               cat("\n'Square root' transformation\n", sep="")
               
               trfMN <- sqrt(datMN)


           }) ## end of method


    ## returning

    options(stringsAsFactors=optStrAsFacL)

    return(trfMN)

} ## end of transformF