Mercurial > repos > marie-tremblay-metatoul > nmr_bucketing
annotate DrawSpec.R @ 9:62c62e31fc80 draft
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
author | lecorguille |
---|---|
date | Fri, 21 Apr 2017 08:53:40 -0400 |
parents | |
children |
rev | line source |
---|---|
9
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
1 drawSpec <- function (X, startP = -1, endP = -1, groupLabel = NULL, useLog = -1, highBound = -1, lowBound = -1, |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
2 xlab = NULL, ylab = NULL, main = NULL, nAxisPos = 4, offside = 0) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
3 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
4 groupLabel_name = groupLabel |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
5 X = as.data.frame(X) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
6 # colnames(X) = c(1:ncol(X)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
7 X = as.matrix(X) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
8 if (highBound != -1) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
9 for (i in 1:nrow(X)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
10 myIndex = which(X[i, ] > highBound) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
11 X[i, myIndex] = highBound |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
12 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
13 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
14 if (lowBound != -1) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
15 for (i in 1:nrow(X)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
16 myIndex = which(X[i, ] < lowBound) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
17 X[i, myIndex] = lowBound |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
18 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
19 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
20 if (is.null(groupLabel)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
21 groupLabel = c(1:nrow(X)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
22 groupLabel = as.factor(groupLabel) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
23 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
24 else { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
25 levels(groupLabel) = c(1:length(levels(groupLabel))) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
26 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
27 if (startP == -1) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
28 startP = 1 |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
29 if (endP == -1) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
30 endP = ncol(X) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
31 if (is.null(xlab)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
32 xlab = "index" |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
33 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
34 if (is.null(ylab)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
35 ylab = "intensity" |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
36 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
37 if (is.null(main)) { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
38 main = paste(" ", startP + offside, "-", endP + offside) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
39 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
40 GraphRange <- c(startP:endP) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
41 yn <- X[, GraphRange] |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
42 if (useLog != -1) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
43 yn = log(yn) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
44 if (length(yn) > ncol(X)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
45 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
46 plot(yn[1, ], ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n") |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
47 tempVal = trunc(length(GraphRange)/nAxisPos) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
48 xPos = c(0:nAxisPos) * tempVal |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
49 axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside]) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
50 for (i in 1:length(levels(groupLabel))) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
51 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
52 groupLabelIdx = which(groupLabel == levels(groupLabel)[i]) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
53 color <- palette(rainbow(length(levels(groupLabel)))) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
54 for (j in 1:length(groupLabelIdx)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
55 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
56 lines(yn[groupLabelIdx[j], ], col = color[i]) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
57 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
58 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
59 if (!is.null(groupLabel_name)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
60 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
61 legendPos = "topleft" |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
62 legend(legendPos, levels(groupLabel_name), col = as.integer(levels(groupLabel)), text.col = "black", pch = c(19, 19), bg = "gray90") |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
63 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
64 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
65 if (length(yn) == ncol(X)) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
66 { |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
67 plot(yn, ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n") |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
68 tempVal = trunc(length(GraphRange)/nAxisPos) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
69 xPos = c(0:nAxisPos) * tempVal |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
70 # axis(1, at = xPos, labels = xPos + startP + offside) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
71 axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside]) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
72 lines(yn) |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
73 } |
62c62e31fc80
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit fc2be0f9fa66f830d592d74d14b47a63e761647b
lecorguille
parents:
diff
changeset
|
74 } |