annotate DrawSpec.R @ 3:966fcf7ae66e draft

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