annotate transformation_script.R @ 1:d971449245b1 draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 60ebb3e8919c09c18f89a5362750ae45ca84d0c2
author ethevenot
date Wed, 28 Feb 2018 09:20:37 -0500
parents c7b8e82af08e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
1 ## Etienne Thevenot
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
2 ## W4M Core Development Team
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
3 ## etienne.thevenot@cea.fr
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
4 ## 2015-04-25
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
5
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
6 transformF <- function(datMN,
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
7 metC) {
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
8
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
9 ## options
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
10
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
11 optStrAsFacL <- options()[["stringsAsFactors"]]
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
12 options(stringsAsFactors = FALSE)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
13
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
14 ## checking
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
15
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
16 if(length(which(datMN < 0))) {
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
17 cat("\nThe 'dataMatrix' contains negative values\n")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
18 sink()
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
19 stop("The 'dataMatrix' contains negative values", call. = FALSE)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
20 }
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
21
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
22 ## Number of missing values
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
23 nasN <- length(which(is.na(datMN)))
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
24 cat("\nMissing values in the 'dataMatrix': ",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
25 nasN,
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
26 " (",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
27 round(nasN / cumprod(dim(datMN))[2] * 100),
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
28 "%)\n",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
29 sep="")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
30
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
31 ## Number of zero values
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
32 zerN <- length(which(datMN == 0))
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
33 cat("\nZero values in the 'dataMatrix': ",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
34 zerN,
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
35 " (",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
36 round(zerN / cumprod(dim(datMN))[2] * 100),
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
37 "%)\n",
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
38 sep="")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
39
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
40 ## transformation
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
41
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
42 switch(metC,
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
43 log2 = {
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
44
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
45 cat("\n'log2' transformation\n", sep="")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
46
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
47 trfMN <- log2(1 + datMN)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
48
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
49 },
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
50 log10 = {
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
51
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
52 cat("\n'log10' transformation\n", sep="")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
53
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
54 trfMN <- log10(1 + datMN)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
55
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
56 },
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
57 sqrt = {
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
58
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
59 cat("\n'Square root' transformation\n", sep="")
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
60
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
61 trfMN <- sqrt(datMN)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
62
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
63
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
64 }) ## end of method
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
65
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
66
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
67 ## returning
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
68
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
69 options(stringsAsFactors=optStrAsFacL)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
70
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
71 return(trfMN)
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
72
c7b8e82af08e planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 308ae36af707ede5697d1b8a0c93f8b5b68872cf
ethevenot
parents:
diff changeset
73 } ## end of transformF