Mercurial > repos > ethevenot > transformation
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:eacea1349a7c |
---|---|
1 ## Etienne Thevenot | |
2 ## W4M Core Development Team | |
3 ## etienne.thevenot@cea.fr | |
4 ## 2015-04-25 | |
5 | |
6 transformF <- function(datMN, | |
7 metC) { | |
8 | |
9 ## options | |
10 | |
11 optStrAsFacL <- options()[["stringsAsFactors"]] | |
12 options(stringsAsFactors = FALSE) | |
13 | |
14 ## transformation | |
15 | |
16 switch(metC, | |
17 log2 = { | |
18 | |
19 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 | |
44 trfMN <- log2(1 + datMN) | |
45 | |
46 }, | |
47 log10 = { | |
48 | |
49 cat("\n'log10' transformation\n", sep="") | |
50 | |
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) | |
75 | |
76 }) ## end of 'log10' method | |
77 | |
78 | |
79 ## returning | |
80 | |
81 options(stringsAsFactors=optStrAsFacL) | |
82 | |
83 return(trfMN) | |
84 | |
85 } ## end of transformF |