Mercurial > repos > marie-tremblay-metatoul > normalization
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:3cd762aac7a4 | 3:966fcf7ae66e |
---|---|
1 drawSpec <- function (X, startP = -1, endP = -1, groupLabel = NULL, useLog = -1, highBound = -1, lowBound = -1, | |
2 xlab = NULL, ylab = NULL, main = NULL, nAxisPos = 4, offside = 0) | |
3 { | |
4 groupLabel_name = groupLabel | |
5 X = as.data.frame(X) | |
6 # colnames(X) = c(1:ncol(X)) | |
7 X = as.matrix(X) | |
8 if (highBound != -1) { | |
9 for (i in 1:nrow(X)) { | |
10 myIndex = which(X[i, ] > highBound) | |
11 X[i, myIndex] = highBound | |
12 } | |
13 } | |
14 if (lowBound != -1) { | |
15 for (i in 1:nrow(X)) { | |
16 myIndex = which(X[i, ] < lowBound) | |
17 X[i, myIndex] = lowBound | |
18 } | |
19 } | |
20 if (is.null(groupLabel)) { | |
21 groupLabel = c(1:nrow(X)) | |
22 groupLabel = as.factor(groupLabel) | |
23 } | |
24 else { | |
25 levels(groupLabel) = c(1:length(levels(groupLabel))) | |
26 } | |
27 if (startP == -1) | |
28 startP = 1 | |
29 if (endP == -1) | |
30 endP = ncol(X) | |
31 if (is.null(xlab)) { | |
32 xlab = "index" | |
33 } | |
34 if (is.null(ylab)) { | |
35 ylab = "intensity" | |
36 } | |
37 if (is.null(main)) { | |
38 main = paste(" ", startP + offside, "-", endP + offside) | |
39 } | |
40 GraphRange <- c(startP:endP) | |
41 yn <- X[, GraphRange] | |
42 if (useLog != -1) | |
43 yn = log(yn) | |
44 if (length(yn) > ncol(X)) | |
45 { | |
46 plot(yn[1, ], ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n") | |
47 tempVal = trunc(length(GraphRange)/nAxisPos) | |
48 xPos = c(0:nAxisPos) * tempVal | |
49 axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside]) | |
50 for (i in 1:length(levels(groupLabel))) | |
51 { | |
52 groupLabelIdx = which(groupLabel == levels(groupLabel)[i]) | |
53 color <- palette(rainbow(length(levels(groupLabel)))) | |
54 for (j in 1:length(groupLabelIdx)) | |
55 { | |
56 lines(yn[groupLabelIdx[j], ], col = color[i]) | |
57 } | |
58 } | |
59 if (!is.null(groupLabel_name)) | |
60 { | |
61 legendPos = "topleft" | |
62 legend(legendPos, levels(groupLabel_name), col = as.integer(levels(groupLabel)), text.col = "black", pch = c(19, 19), bg = "gray90") | |
63 } | |
64 } | |
65 if (length(yn) == ncol(X)) | |
66 { | |
67 plot(yn, ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n") | |
68 tempVal = trunc(length(GraphRange)/nAxisPos) | |
69 xPos = c(0:nAxisPos) * tempVal | |
70 # axis(1, at = xPos, labels = xPos + startP + offside) | |
71 axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside]) | |
72 lines(yn) | |
73 } | |
74 } |