comparison 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
comparison
equal deleted inserted replaced
0:eacea1349a7c 1:d9e05021553c
3 ## etienne.thevenot@cea.fr 3 ## etienne.thevenot@cea.fr
4 ## 2015-04-25 4 ## 2015-04-25
5 5
6 transformF <- function(datMN, 6 transformF <- function(datMN,
7 metC) { 7 metC) {
8 8
9 ## options 9 ## options
10 10
11 optStrAsFacL <- options()[["stringsAsFactors"]] 11 optStrAsFacL <- options()[["stringsAsFactors"]]
12 options(stringsAsFactors = FALSE) 12 options(stringsAsFactors = FALSE)
13 13
14 ## checking
15
16 if(length(which(datMN < 0))) {
17 cat("\nThe 'dataMatrix' contains negative values\n")
18 sink()
19 stop("The 'dataMatrix' contains negative values", call. = FALSE)
20 }
21
22 ## Number of missing values
23 nasN <- length(which(is.na(datMN)))
24 cat("\nMissing values in the 'dataMatrix': ",
25 nasN,
26 " (",
27 round(nasN / cumprod(dim(datMN))[2] * 100),
28 "%)\n",
29 sep="")
30
31 ## Number of zero values
32 zerN <- length(which(datMN == 0))
33 cat("\nZero values in the 'dataMatrix': ",
34 zerN,
35 " (",
36 round(zerN / cumprod(dim(datMN))[2] * 100),
37 "%)\n",
38 sep="")
39
14 ## transformation 40 ## transformation
15 41
16 switch(metC, 42 switch(metC,
17 log2 = { 43 log2 = {
18 44
19 cat("\n'log2' transformation\n", sep="") 45 cat("\n'log2' transformation\n", sep="")
20
21 if(length(which(datMN < 0)))
22 stop("The 'dataMatrix' contains negative values")
23
24 zerMN <- datMN == 0
25
26 ## Number of missing values
27 nasN <- length(which(is.na(datMN)))
28 cat("\nMissing values in the 'dataMatrix': ",
29 nasN,
30 " (",
31 round(nasN / cumprod(dim(datMN))[2] * 100),
32 "%)\n",
33 sep="")
34
35 ## Number of zero values
36 zerN <- length(which(zerMN))
37 cat("\nZero values in the 'dataMatrix': ",
38 zerN,
39 " (",
40 round(zerN / cumprod(dim(datMN))[2] * 100),
41 "%)\n",
42 sep="")
43 46
44 trfMN <- log2(1 + datMN) 47 trfMN <- log2(1 + datMN)
45 48
46 }, 49 },
47 log10 = { 50 log10 = {
48 51
49 cat("\n'log10' transformation\n", sep="") 52 cat("\n'log10' transformation\n", sep="")
50 53
51 if(length(which(datMN < 0)))
52 stop("The 'dataMatrix' contains negative values")
53
54 zerMN <- datMN == 0
55
56 ## Number of missing values
57 nasN <- length(which(is.na(datMN)))
58 cat("\nMissing values in the 'dataMatrix': ",
59 nasN,
60 " (",
61 round(nasN / cumprod(dim(datMN))[2] * 100),
62 "%)\n",
63 sep="")
64
65 ## Number of zero values
66 zerN <- length(which(zerMN))
67 cat("\nZero values in the 'dataMatrix': ",
68 zerN,
69 " (",
70 round(zerN / cumprod(dim(datMN))[2] * 100),
71 "%)\n",
72 sep="")
73
74 trfMN <- log10(1 + datMN) 54 trfMN <- log10(1 + datMN)
75 55
76 }) ## end of 'log10' method 56 },
57 sqrt = {
58
59 cat("\n'Square root' transformation\n", sep="")
60
61 trfMN <- sqrt(datMN)
62
63
64 }) ## end of method
77 65
78 66
79 ## returning 67 ## returning
80 68
81 options(stringsAsFactors=optStrAsFacL) 69 options(stringsAsFactors=optStrAsFacL)