diff transformation_script.R @ 1:d9e05021553c draft

planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit c4b65942d74d5bdfd46e748c0040a8b5ebe4fd1d
author ethevenot
date Sat, 06 Aug 2016 12:02:52 -0400
parents eacea1349a7c
children
line wrap: on
line diff
--- a/transformation_script.R	Fri Jul 29 12:11:01 2016 -0400
+++ b/transformation_script.R	Sat Aug 06 12:02:52 2016 -0400
@@ -5,42 +5,45 @@
 
 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="")
 
-               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)
 
            },
@@ -48,32 +51,17 @@
 
                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
+           },
+           sqrt = {
+
+               cat("\n'Square root' transformation\n", sep="")
+               
+               trfMN <- sqrt(datMN)
+
+
+           }) ## end of method
 
 
     ## returning