Mercurial > repos > marie-tremblay-metatoul > nmr_preprocessing
annotate DrawFunctions.R @ 2:5e64657b4fe5 draft
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
author | lecorguille |
---|---|
date | Wed, 28 Mar 2018 08:05:12 -0400 |
parents | |
children | 122df1bf0a8c |
rev | line source |
---|---|
2
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
1 require(ggplot2) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
2 require(gridExtra) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
3 require(reshape2) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
4 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
5 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
6 Draw <- function(Signal_data, type.draw = c("signal", "pca"), output = c("default", |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
7 "window", "png", "pdf"), dirpath = ".", filename = "%003d", height = 480, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
8 width = 640, pdf.onefile = TRUE, ...) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
9 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
10 # Data initialisation and checks ---------------------------------------------- |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
11 type.draw <- match.arg(type.draw) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
12 output <- match.arg(output) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
13 fullpath <- paste(file.path(dirpath, filename), output, sep = ".") |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
14 createFile <- TRUE |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
15 createWindow <- FALSE |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
16 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
17 # Drawing -------------------------------------------------------------------- |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
18 # output |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
19 switch(output, default = { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
20 createFile <- FALSE |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
21 }, window = { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
22 createWindow <- TRUE |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
23 createFile <- FALSE |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
24 }, png = { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
25 grDevices::png(fullpath, width, height) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
26 }, pdf = { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
27 grDevices::pdf(fullpath, width = width/72, height = height/72, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
28 onefile = pdf.onefile) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
29 }, { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
30 stop("Unknown output type.") |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
31 }) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
32 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
33 # Drawing type (signal/spectrum or PCA) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
34 funs <- list(signal = DrawSignal, pca = DrawPCA) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
35 if (type.draw %in% names(funs)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
36 fun <- funs[[type.draw]] |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
37 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
38 stop(paste("Unknown type:", type.draw)) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
39 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
40 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
41 # Plot finalisation ---------------------------------------------- |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
42 if (is.vector(Signal_data)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
43 Signal_data <- vec2mat(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
44 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
45 fun(Signal_data, createWindow = createWindow, ...) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
46 if (createFile) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
47 grDevices::dev.off() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
48 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
49 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
50 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
51 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
52 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
53 ##### DrawSignal |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
54 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
55 DrawSignal <- function(Signal_data, subtype = c("stacked", "together", |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
56 "separate", "diffmean", "diffmedian", "diffwith"), |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
57 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
58 xlab = "rowname", RowNames = NULL, row = 1, num.stacked = 4, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
59 main = NULL, createWindow) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
60 # nticks |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
61 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
62 # Data initialisation and checks ---------------------------------------------- |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
63 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
64 subtype <- match.arg(subtype) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
65 vec <- is.vector(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
66 if (vec) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
67 Signal_data <- vec2mat(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
68 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
69 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
70 n <- nrow(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
71 m <- ncol(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
72 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
73 if (n < num.stacked){ |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
74 num.stacked <- n |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
75 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
76 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
77 scale <- colnames(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
78 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
79 num.plot <- sum(ReImModArg) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
80 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
81 Var <- rowname <- value <- NULL # only for R CMD check |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
82 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
83 # Drawing array |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
84 if (num.plot <= 0) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
85 stop("Nothing selected in ReImModArg.") |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
86 } else if (num.plot <= 2) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
87 if (vertical) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
88 nrow <- num.plot |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
89 ncol <- 1 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
90 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
91 nrow <- 1 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
92 ncol <- num.plot |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
93 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
94 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
95 nrow <- 2 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
96 ncol <- 2 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
97 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
98 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
99 # RowNames |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
100 if (is.null(RowNames)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
101 RowNames <- rownames(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
102 if (is.null(RowNames)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
103 RowNames <- 1:n |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
104 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
105 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
106 if (!is.vector(RowNames)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
107 stop("RowNames is not a vector") |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
108 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
109 if (length(RowNames) != n) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
110 stop(paste("RowNames has length", length(RowNames), "and there are", n, "FIDs.")) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
111 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
112 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
113 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
114 if (n == 1) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
115 RowNames <- deparse(substitute(Signal_data)) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
116 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
117 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
118 elements <- list() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
119 if (ReImModArg[1]) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
120 elements[["Re"]] <- Re(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
121 rownames(elements[["Re"]]) <- RowNames |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
122 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
123 if (ReImModArg[2]) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
124 elements[["Im"]] <- Im(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
125 rownames(elements[["Im"]]) <- RowNames |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
126 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
127 if (ReImModArg[3]) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
128 elements[["Mod"]] <- Mod(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
129 rownames(elements[["Mod"]]) <- RowNames |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
130 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
131 if (ReImModArg[4]) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
132 elements[["Arg"]] <- Arg(Signal_data) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
133 rownames(elements[["Arg"]]) <- RowNames |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
134 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
135 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
136 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
137 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
138 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
139 # Drawing -------------------------------------------------------------------- |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
140 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
141 y = x = NULL # only for R CMD check |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
142 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
143 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
144 # SEPARATE or STACKED =============== |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
145 if (subtype == "separate" | subtype == "stacked") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
146 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
147 i <- 1 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
148 while (i <= n) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
149 if (createWindow) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
150 grDevices::dev.new(noRStudioGD = TRUE) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
151 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
152 if (subtype == "separate") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
153 # The other uses gridExtra to do that |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
154 graphics::par(mfrow = c(nrow, ncol)) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
155 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
156 plots <- list() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
157 if (subtype == "separate") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
158 last <- i |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
159 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
160 last <- min(i + num.stacked - 1, n) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
161 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
162 for (name in names(elements)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
163 if (subtype == "separate") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
164 if (n == 1) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
165 df <- data.frame(x = as.numeric(scale), y = elements[[name]]) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
166 } else {df <- data.frame(x = as.numeric(scale), y = elements[[name]][i, ]) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
167 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
168 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
169 plots[[name]] <- ggplot2::ggplot(data = df, ggplot2::aes(x = x, y = y)) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
170 ggplot2::geom_line(size = 1) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
171 ggplot2::theme(legend.position = "none") + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
172 ggplot2::labs(x = xlab, y = name) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
173 ggplot2::ggtitle(RowNames[i]) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
174 ggplot2::theme_bw() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
175 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
176 if ((df[1, "x"] - df[(dim(df)[1]), "x"]) > 0) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
177 plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
178 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
179 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
180 } else { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
181 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
182 if (n == 1 ) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
183 melted <- data.frame(rowname = rep(name, m), |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
184 Var = as.numeric(scale), value = elements[[name]][i,]) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
185 } else if (last==i){ |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
186 melted <- data.frame(rowname = rep(rownames(elements[[name]])[i], m), |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
187 Var = as.numeric(scale), value = elements[[name]][i,]) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
188 } else {melted <- reshape2::melt(elements[[name]][i:last, ], |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
189 varnames = c("rowname", "Var")) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
190 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
191 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
192 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
193 plots[[name]] <- ggplot2::ggplot(data = melted, ggplot2::aes(x = Var, y = value)) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
194 ggplot2::geom_line(size = 0.3) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
195 ggplot2::facet_grid(rowname ~ ., scales = "free_y") + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
196 ggplot2::theme(legend.position = "none") + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
197 ggplot2::labs(x = xlab, y = name) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
198 ggplot2::ggtitle(label = main) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
199 ggplot2::theme_bw() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
200 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
201 if ((melted[1, "Var"] - melted[(dim(melted)[1]), "Var"]) > 0) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
202 plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
203 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
204 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
205 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
206 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
207 if (subtype == "stacked") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
208 do.call(gridExtra::grid.arrange, c(plots, list(nrow = nrow, ncol = ncol))) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
209 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
210 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
211 i <- last + 1 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
212 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
213 } else if (subtype %in% c("together", "diffmean", "diffmedian", "diffwith")) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
214 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
215 # TOGHETER or DIFFMEAN or DIFFMEDIAN or DIFFWITH =============== |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
216 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
217 rainbow_colors <- grDevices::rainbow(n) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
218 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
219 if (createWindow) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
220 grDevices::dev.new(noRStudioGD = TRUE) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
221 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
222 graphics::par(mfrow = c(nrow, ncol)) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
223 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
224 plots <- list() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
225 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
226 # Loop for Re, Im, Mod and Arg |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
227 for (name in names(elements)) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
228 # Get this part of the signal |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
229 element <- elements[[name]] |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
230 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
231 # Express the signal according to a reference if asked by `subtype' |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
232 if (subtype == "diffmean") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
233 element <- sweep(element, MARGIN = 2, colMeans(element), `-`) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
234 } else if (subtype == "diffmedian") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
235 element <- sweep(element, MARGIN = 2, matrixStats::colMedians(element), `-`) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
236 } else if (subtype == "diffwith") { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
237 element <- sweep(element, MARGIN = 2, element[row, ], `-`) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
238 if (row == 1 & n > 1) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
239 # Since we use plot on the first row and lines on the following, the y |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
240 # scale is calculated at the first row so if the first row is all 0, it |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
241 # causes problems |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
242 tmp <- element[1, ] |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
243 element[1, ] <- element[2, ] |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
244 element[2, ] <- tmp |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
245 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
246 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
247 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
248 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
249 melted <- reshape2::melt(elements[[name]], varnames = c("rowname", "Var")) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
250 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
251 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
252 plots[[name]] <- ggplot2::ggplot(melted, ggplot2::aes(x = Var, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
253 y = value, group = rowname, colour = rowname)) + ggplot2::geom_line() + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
254 ggplot2::labs(x = xlab, y = name) + ggplot2::scale_colour_discrete(name = NULL) + |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
255 ggplot2::ggtitle(main) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
256 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
257 if ((melted[1, "Var"] - melted[(dim(melted)[1]), "Var"]) > |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
258 0) { |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
259 plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse() |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
260 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
261 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
262 do.call(gridExtra::grid.arrange, c(plots, list(nrow = nrow, |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
263 ncol = ncol))) |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
264 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
265 } |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
266 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
267 |
5e64657b4fe5
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
lecorguille
parents:
diff
changeset
|
268 } |