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