git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/maigesPack@94775 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -457,7 +457,7 @@ plot.maigesActMod <- function(x, type=c("S", "C")[2], keepEmpty=FALSE, ...) { |
457 | 457 |
idx1 <- order(rownames(table)) |
458 | 458 |
idx2 <- order.dendrogram(as.dendrogram(hclust(dist(t(table))))) |
459 | 459 |
|
460 |
- heatmap(table[idx1, idx2], scale="none", col=maigesPack:::greenRed(), |
|
460 |
+ heatmap(table[idx1, idx2], scale="none", col=greenRed(), |
|
461 | 461 |
zlim=limite, Rowv=NA, Colv=NA, ...) |
462 | 462 |
|
463 | 463 |
} |
... | ... |
@@ -475,7 +475,7 @@ plot.maigesActMod <- function(x, type=c("S", "C")[2], keepEmpty=FALSE, ...) { |
475 | 475 |
idx1 <- order(rownames(table)) |
476 | 476 |
idx2 <- order.dendrogram(as.dendrogram(hclust(dist(t(table))))) |
477 | 477 |
|
478 |
- heatmap(table[idx1, idx2], scale="none", col=maigesPack:::greenRed(), |
|
478 |
+ heatmap(table[idx1, idx2], scale="none", col=greenRed(), |
|
479 | 479 |
zlim=limite, Rowv=NA, Colv=NA, ...) |
480 | 480 |
|
481 | 481 |
} |
... | ... |
@@ -496,7 +496,7 @@ plot.maigesActNet <- function(x, type=c("score","p-value")[1], ...) { |
496 | 496 |
limite <- c(0, limite) |
497 | 497 |
idx <- order.dendrogram(as.dendrogram(hclust(dist(t(x@scores))))) |
498 | 498 |
|
499 |
- heatmap(x@scores[, idx], scale="none", col=maigesPack:::blackBlue(), |
|
499 |
+ heatmap(x@scores[, idx], scale="none", col=blackBlue(), |
|
500 | 500 |
zlim=limite, Rowv=NA, Colv=NA, ...) |
501 | 501 |
|
502 | 502 |
} |
... | ... |
@@ -508,7 +508,7 @@ plot.maigesActNet <- function(x, type=c("score","p-value")[1], ...) { |
508 | 508 |
idx <- order.dendrogram(as.dendrogram(hclust(dist(t(x@Pvalues))))) |
509 | 509 |
|
510 | 510 |
heatmap(-log10(x@Pvalues)[, idx], scale="none", |
511 |
- col=maigesPack:::blackBlue(), zlim=limite, Rowv=NA, Colv=NA, ...) |
|
511 |
+ col=blackBlue(), zlim=limite, Rowv=NA, Colv=NA, ...) |
|
512 | 512 |
|
513 | 513 |
} |
514 | 514 |
} |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/maigesPack@27800 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/maigesPack@27611 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,515 @@ |
1 |
+## Define methods for plot generic function |
|
2 |
+## |
|
3 |
+## Gustavo H. Esteves |
|
4 |
+## 27/05/07 |
|
5 |
+## |
|
6 |
+## Version: 1.1 |
|
7 |
+## |
|
8 |
+ |
|
9 |
+ |
|
10 |
+## For maigesRaw class |
|
11 |
+plot.maigesRaw <- function(x, bkgSub="subtract", z=NULL, legend.func=NULL, |
|
12 |
+ylab="W", ...) { |
|
13 |
+ |
|
14 |
+ ## Correcting background |
|
15 |
+ tmp <- backgroundCorrect(as(x, "RGList"), bkgSub) |
|
16 |
+ tmp <- as(tmp, "marrayRaw") |
|
17 |
+ tmp <- as(tmp, "marrayNorm") |
|
18 |
+ |
|
19 |
+ ## indexing ref labelled with green |
|
20 |
+ idx <- tolower(getLabels(x, "Ref")) == "red" |
|
21 |
+ if(sum(idx) > 0) |
|
22 |
+ maM(tmp)[, idx] <- -maM(tmp)[, idx] |
|
23 |
+ |
|
24 |
+ maLabels(maTargets(tmp)) <- as.character(maInfo(maTargets(tmp))[[1]]) |
|
25 |
+ maPlot(tmp, z=z, legend.func=legend.func, ylab=ylab, ...) |
|
26 |
+} |
|
27 |
+ |
|
28 |
+ |
|
29 |
+## For maiges class |
|
30 |
+plot.maiges <- function(x, z=NULL, legend.func=NULL, ylab="W", ...) { |
|
31 |
+ |
|
32 |
+ ## Converting to marrayNorm class (from marray package) |
|
33 |
+ tmp <- as(x, "marrayNorm") |
|
34 |
+ |
|
35 |
+ ## indexing ref labelled with green |
|
36 |
+ idx <- tolower(getLabels(x, "Ref")) == "red" |
|
37 |
+ if(sum(idx) > 0) |
|
38 |
+ maM(tmp)[, idx] <- -maM(tmp)[, idx] |
|
39 |
+ |
|
40 |
+ maPlot(tmp, z=z, legend.func=legend.func, ylab=ylab, ...) |
|
41 |
+ |
|
42 |
+} |
|
43 |
+ |
|
44 |
+ |
|
45 |
+## For maigesANOVA class |
|
46 |
+plot.maigesANOVA <- plot.maiges |
|
47 |
+ |
|
48 |
+ |
|
49 |
+## For maigesDE class (shows volcano plot) |
|
50 |
+plot.maigesDE <- function(x, adjP="none", idx=1, ...) { |
|
51 |
+ |
|
52 |
+ ## Adjusting p-values if specified by the user. |
|
53 |
+ if(adjP != "none") { |
|
54 |
+ tmp1 <- multtest::mt.rawp2adjp(x@p.value[, idx], proc=adjP) |
|
55 |
+ x@p.value[, idx] <- tmp1$adjp[order(tmp1$index), 2] |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ if(sum(dim(x@fold)) == 0) |
|
59 |
+ stop("I can't plot volcano with fold slot empty.") |
|
60 |
+ else |
|
61 |
+ tmp1 <- x@fold[, idx] |
|
62 |
+ |
|
63 |
+ tmp2 <- -log10(x@p.value[, idx]) |
|
64 |
+ if(!is.null(colnames(x@stat)[idx])) |
|
65 |
+ plotName <- colnames(x@stat)[idx] |
|
66 |
+ else |
|
67 |
+ plotName <- x@test |
|
68 |
+ |
|
69 |
+ plot(tmp1, tmp2, main=paste("Volcano plot -", plotName), xlab="log2(fold)", |
|
70 |
+ ylab=paste("-log10(P.value)"), ...) |
|
71 |
+ |
|
72 |
+} |
|
73 |
+ |
|
74 |
+ |
|
75 |
+## For maigesDEcluster class |
|
76 |
+plot.maigesDEcluster <- function(x, adjP="none", idx=1, ...) { |
|
77 |
+ |
|
78 |
+ ## Adjusting p-values if specified by the user. |
|
79 |
+ if(adjP != "none") { |
|
80 |
+ tmp1 <- multtest::mt.rawp2adjp(x@p.value[, idx], proc=adjP) |
|
81 |
+ x@p.value[, idx] <- tmp1$adjp[order(tmp1$index), 2] |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ if(sum(dim(x@fold)) == 0) |
|
85 |
+ tmp1 <- apply(x@W, 1, mean, na.rm=TRUE) |
|
86 |
+ else |
|
87 |
+ tmp1 <- x@fold[, idx] |
|
88 |
+ |
|
89 |
+ tmp2 <- -log10(x@p.value[, idx]) |
|
90 |
+ if(!is.null(colnames(x@stat)[idx])) |
|
91 |
+ plotName <- colnames(x@stat)[idx] |
|
92 |
+ else |
|
93 |
+ plotName <- x@test |
|
94 |
+ |
|
95 |
+ plot(tmp1, tmp2, main=paste("Volcano plot -", plotName), xlab="log2(fold)", |
|
96 |
+ ylab=paste("-log10(P.value)"), ...) |
|
97 |
+ |
|
98 |
+} |
|
99 |
+ |
|
100 |
+ |
|
101 |
+## For maigesClass class (bi or tri-dimensional graphs of classifiers) |
|
102 |
+plot.maigesClass <- function(x, idx=1, ...) { |
|
103 |
+ |
|
104 |
+ ## Getting sample types |
|
105 |
+ types <- colnames(x@W) |
|
106 |
+ uTypes <- unique(types) |
|
107 |
+ |
|
108 |
+ if(dim(x@cliques)[2] == 2) { |
|
109 |
+ tmp1 <- x@W[x@cliques.idx[idx, 1], ] |
|
110 |
+ tmp2 <- x@W[x@cliques.idx[idx, 2], ] |
|
111 |
+ xlimite <- c(2*min(tmp1)-quantile(tmp1, 0.35), max(tmp1)) |
|
112 |
+ ylimite <- c(min(tmp2), 2*max(tmp2)-quantile(tmp2, 0.65)) |
|
113 |
+ |
|
114 |
+ toLegend <- c(2*min(tmp1)-quantile(tmp1, 0.3), |
|
115 |
+ 2*max(tmp2)-quantile(tmp2, 0.7)) |
|
116 |
+ |
|
117 |
+ plot(tmp1[types == uTypes[1]], tmp2[types == uTypes[1]], ylim=ylimite, |
|
118 |
+ xlim=xlimite, main="Classification graphic", xlab=x@cliques[idx,1], |
|
119 |
+ ylab=x@cliques[idx,2], pch=22, bg="red", col="red", ...) |
|
120 |
+ |
|
121 |
+ points(tmp1[types == uTypes[2]], tmp2[types == uTypes[2]], pch=19, |
|
122 |
+ col="green") |
|
123 |
+ |
|
124 |
+ legend(toLegend[1], toLegend[2], uTypes, pch=c(22,19), |
|
125 |
+ pt.bg=c("red","green"), col=c("red", "green")) |
|
126 |
+ |
|
127 |
+ } |
|
128 |
+ else if(dim(x@cliques)[2] == 3) { |
|
129 |
+ |
|
130 |
+ ## Loading required library |
|
131 |
+ require("rgl") |
|
132 |
+ |
|
133 |
+ tmp1 <- x@W[x@cliques.idx[idx, 1], ] |
|
134 |
+ tmp2 <- x@W[x@cliques.idx[idx, 2], ] |
|
135 |
+ tmp3 <- x@W[x@cliques.idx[idx, 3], ] |
|
136 |
+ |
|
137 |
+ labels <- c(x@cliques[idx, 1], x@cliques[idx, 2], x@cliques[idx, 3]) |
|
138 |
+ |
|
139 |
+ rgl::open3d() |
|
140 |
+ |
|
141 |
+ rgl::text3d(tmp1[types == uTypes[1]], tmp2[types == uTypes[1]], |
|
142 |
+ tmp3[types == uTypes[1]], text=types[types == uTypes[1]], col="red") |
|
143 |
+ |
|
144 |
+ rgl::text3d(tmp1[types != uTypes[1]], tmp2[types != uTypes[1]], |
|
145 |
+ tmp3[types != uTypes[1]], text=types[types != uTypes[1]], col="green") |
|
146 |
+ |
|
147 |
+ rgl::decorate3d(xlab=labels[1], ylab=labels[2], zlab=labels[3], |
|
148 |
+ box=FALSE) |
|
149 |
+ |
|
150 |
+ rgl::bbox3d(color=c("#767676","black"), emission="#767676", |
|
151 |
+ specular="#767676", shininess=10, alpha=0.9, marklen=50) |
|
152 |
+ } |
|
153 |
+ else |
|
154 |
+ stop("I can't plot graphics with more than 3 genes in the classifiers!") |
|
155 |
+ |
|
156 |
+} |
|
157 |
+ |
|
158 |
+ |
|
159 |
+## For maigesRelNetM class (circular graph with significative iterations) |
|
160 |
+plot.maigesRelNetM <- function(x=NULL, cutPval=0.05, names=NULL, ...) { |
|
161 |
+ |
|
162 |
+ ## Giving default names if it is NULL |
|
163 |
+ if(is.null(names)) |
|
164 |
+ names <- c(x@types, "Significance of differences") |
|
165 |
+ |
|
166 |
+ |
|
167 |
+ ## Defining additional functions |
|
168 |
+ graphPath <- function(data=NULL, cuttoffPvalue) { |
|
169 |
+ N <- length(rownames(data@Corr1)) |
|
170 |
+ corObj1 <- data@Corr1 |
|
171 |
+ corObj2 <- data@Corr2 |
|
172 |
+ Diff <- data@DifP |
|
173 |
+ ## Construct graphs centered on the 1st table |
|
174 |
+ vertices <- rownames(corObj1) |
|
175 |
+ arestas1 <- vector("list", length=length(vertices)) |
|
176 |
+ names(arestas1) <- vertices |
|
177 |
+ arestas3 <- arestas2 <- arestas1 |
|
178 |
+ for (i in 1:length(vertices)) { |
|
179 |
+ idx <- Diff[i, ] <= cuttoffPvalue |
|
180 |
+ arestas1[[i]] <- list(edges=vertices[idx], |
|
181 |
+ weights=unname(corObj1[i, idx])) |
|
182 |
+ |
|
183 |
+ arestas2[[i]] <- list(edges=vertices[idx], |
|
184 |
+ weights=unname(corObj2[i, idx])) |
|
185 |
+ |
|
186 |
+ arestas3[[i]] <- list(edges=vertices[idx], |
|
187 |
+ weights=unname(Diff[i, idx])) |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ ## Defining the object with the graphs |
|
191 |
+ Path <- list(Type1=new("graphNEL", vertices, edgeL=arestas1), |
|
192 |
+ Type2=new("graphNEL", vertices, edgeL=arestas2), |
|
193 |
+ Dif=new("graphNEL", vertices, edgeL=arestas3)) |
|
194 |
+ |
|
195 |
+ return(Path) |
|
196 |
+ } |
|
197 |
+ |
|
198 |
+ plot.dots <- function(xy, v, n) { |
|
199 |
+ text(xy[, 1], xy[, 2], v, cex=1.2, col="blue") |
|
200 |
+ } |
|
201 |
+ |
|
202 |
+ draw.edges <- function(coor, vertices, edges, alpha, sorting) { |
|
203 |
+ |
|
204 |
+ main <- edges[[1]] |
|
205 |
+ a <- coor[which(vertices == main), ] |
|
206 |
+ if(sorting == "A") |
|
207 |
+ strength <- order(abs(edges[[3]])) |
|
208 |
+ else |
|
209 |
+ strength <- order(abs(edges[[3]]), decreasing=TRUE) |
|
210 |
+ |
|
211 |
+ for (k in 1:length(edges[[2]])) { |
|
212 |
+ b <- coor[edges[[2]][k], ] |
|
213 |
+ ba <- b-a |
|
214 |
+ ba <- ba/sqrt(sum(ba*ba)) |
|
215 |
+ x <- a+ba*alpha |
|
216 |
+ y <- b-ba*alpha |
|
217 |
+ if (edges[[3]][k] > 0 ) |
|
218 |
+ color <- "red" |
|
219 |
+ else |
|
220 |
+ color <- "green" |
|
221 |
+ a1 <- c(x[1], y[1]) |
|
222 |
+ a2 <- c(x[2], y[2]) |
|
223 |
+ |
|
224 |
+ lines(a1, a2, lwd=strength[k], lty=1, col=color) |
|
225 |
+ } |
|
226 |
+ } |
|
227 |
+ |
|
228 |
+ def.coor <- function(ce, k, h, w) { |
|
229 |
+ if (k == 1) |
|
230 |
+ return(ce) |
|
231 |
+ else if (k == 2) { |
|
232 |
+ r1 <- c(ce[1], ce[1]) |
|
233 |
+ r2 <- c(ce[2]+h*0.3, ce[2]-h*0.3) |
|
234 |
+ } |
|
235 |
+ else if (k == 3) { |
|
236 |
+ r1 <- c(ce[1], ce[1], ce[1]) |
|
237 |
+ r2 <- c(ce[2]+h*0.25, ce[2], ce[2]-h*0.25) |
|
238 |
+ } |
|
239 |
+ else if (k == 4) { |
|
240 |
+ r1 <- c(ce[1]-w*0.3, ce[1]+w*0.3, ce[1]+w*0.3, ce[1]-w*0.3) |
|
241 |
+ r2 <- c(ce[2]-h*0.3, ce[2]-h*0.3, ce[2]+h*0.3, ce[2]+h*0.3) |
|
242 |
+ } |
|
243 |
+ else { |
|
244 |
+ a <- 1 |
|
245 |
+ z <- seq(a, a+2*pi, len=k+1) |
|
246 |
+ z <- z[-1] |
|
247 |
+ r1 <- ce[1]+w/2.5*cos(z) |
|
248 |
+ r2 <- ce[2]+h/2.5*sin(z) |
|
249 |
+ } |
|
250 |
+ cbind(r1, r2) |
|
251 |
+ } |
|
252 |
+ |
|
253 |
+ plotGraph <- function (graph, coor=NULL, alpha=2.5, main="Some Graph", |
|
254 |
+ sorting) { |
|
255 |
+ |
|
256 |
+ ## Define the nodes and the length of the graph (number of nodes) |
|
257 |
+ v <- nodes(graph) |
|
258 |
+ n <- length(v) |
|
259 |
+ |
|
260 |
+ ## Create an empty draw device |
|
261 |
+ plot(c(0, 100), c(0, 100), type="n", axes=FALSE, xlab="", ylab="", |
|
262 |
+ main=main) |
|
263 |
+ |
|
264 |
+ ## Define an initial center to the graph |
|
265 |
+ center <- matrix(c(50, 50), ncol=2) |
|
266 |
+ |
|
267 |
+ ## Create an object of the locations for each node |
|
268 |
+ if (is.null(coor)) |
|
269 |
+ coor <- def.coor(center, n, 100, 100) |
|
270 |
+ |
|
271 |
+ ## Plot each node on the device |
|
272 |
+ plot.dots(coor, v, n) |
|
273 |
+ |
|
274 |
+ ## Locate the nodes to plot on the figure |
|
275 |
+ for (i in 1:n) { |
|
276 |
+ if(length(edgeL(graph)[[i]]$edges) > 0) { |
|
277 |
+ elo <- list(v[i], edgeL(graph)[[i]]$edges, |
|
278 |
+ as.numeric(edgeWeights(graph, i)[[1]])) |
|
279 |
+ draw.edges(coor, v, elo, alpha, sorting) |
|
280 |
+ } |
|
281 |
+ } |
|
282 |
+ colnames(coor) <- c("x", "y") |
|
283 |
+ return(invisible(coor)) |
|
284 |
+ } |
|
285 |
+ |
|
286 |
+ |
|
287 |
+ ## Ploting the graphs |
|
288 |
+ graph <- graphPath(x, cutPval) |
|
289 |
+ |
|
290 |
+ par(mfrow=c(1,3)) |
|
291 |
+ tmp <- plotGraph(graph[[1]], main=names[1], sorting="A") |
|
292 |
+ plotGraph(graph[[2]], coor=tmp, main=names[2], sorting="A") |
|
293 |
+ plotGraph(graph[[3]], coor=tmp, main=names[3], sorting="D") |
|
294 |
+ |
|
295 |
+} |
|
296 |
+ |
|
297 |
+ |
|
298 |
+## For maigesRelNetB class (circular graph with significative iterations) |
|
299 |
+plot.maigesRelNetB <- function(x=NULL, cutPval=0.05, cutCor=NULL, name=NULL, |
|
300 |
+...) { |
|
301 |
+ |
|
302 |
+ ## Some tests |
|
303 |
+ if(!is.null(cutPval) & !is.null(cutCor)) |
|
304 |
+ stop("You must specify only, cutPval or cutCor.") |
|
305 |
+ |
|
306 |
+ if(is.null(name)) |
|
307 |
+ name <- x@type |
|
308 |
+ |
|
309 |
+ ## Defining additional functions |
|
310 |
+ graphPath <- function(data=NULL, cuttoffCor=NULL, cuttoffP=NULL) { |
|
311 |
+ |
|
312 |
+ N <- length(rownames(data@Corr)) |
|
313 |
+ corObj <- data@Corr |
|
314 |
+ ## Construct graphs centered on the 1st table |
|
315 |
+ vertices <- rownames(corObj) |
|
316 |
+ arestas <- vector("list", length=length(vertices)) |
|
317 |
+ names(arestas) <- vertices |
|
318 |
+ for (i in 1:length(vertices)) { |
|
319 |
+ if(!is.null(cuttoffCor)) |
|
320 |
+ idx <- abs(corObj[i, ]) >= cuttoffCor |
|
321 |
+ if(!is.null(cuttoffP)) |
|
322 |
+ idx <- abs(data@Pval[i, ]) <= cuttoffP |
|
323 |
+ arestas[[i]] <- list(edges=vertices[idx], weights=unname(corObj[i, idx])) |
|
324 |
+ } |
|
325 |
+ |
|
326 |
+ ## Defining the object with the graphs |
|
327 |
+ Path <- new("graphNEL", vertices, edgeL=arestas) |
|
328 |
+ return(Path) |
|
329 |
+ } |
|
330 |
+ |
|
331 |
+ plot.dots <- function(xy, v, n) { |
|
332 |
+ text(xy[, 1], xy[, 2], v, cex=1.2, col="blue") |
|
333 |
+ } |
|
334 |
+ |
|
335 |
+ draw.edges <- function(coor, vertices, edges, alpha, sorting) { |
|
336 |
+ |
|
337 |
+ main <- edges[[1]] |
|
338 |
+ a <- coor[which(vertices == main), ] |
|
339 |
+ if(sorting == "A") |
|
340 |
+ strength <- order(abs(edges[[3]])) |
|
341 |
+ else |
|
342 |
+ strength <- order(abs(edges[[3]]), decreasing=TRUE) |
|
343 |
+ |
|
344 |
+ for (k in 1:length(edges[[2]])) { |
|
345 |
+ b <- coor[edges[[2]][k], ] |
|
346 |
+ ba <- b-a |
|
347 |
+ ba <- ba/sqrt(sum(ba*ba)) |
|
348 |
+ x <- a+ba*alpha |
|
349 |
+ y <- b-ba*alpha |
|
350 |
+ if (edges[[3]][k] > 0 ) |
|
351 |
+ color <- "red" |
|
352 |
+ else |
|
353 |
+ color <- "green" |
|
354 |
+ a1 <- c(x[1], y[1]) |
|
355 |
+ a2 <- c(x[2], y[2]) |
|
356 |
+ lines(a1, a2, lwd=strength[k], lty=1, col=color) |
|
357 |
+ } |
|
358 |
+ } |
|
359 |
+ |
|
360 |
+ def.coor <- function(ce, k, h, w) { |
|
361 |
+ if (k == 1) |
|
362 |
+ return(ce) |
|
363 |
+ else if (k == 2) { |
|
364 |
+ r1 <- c(ce[1], ce[1]) |
|
365 |
+ r2 <- c(ce[2]+h*0.3, ce[2]-h*0.3) |
|
366 |
+ } |
|
367 |
+ else if (k == 3) { |
|
368 |
+ r1 <- c(ce[1], ce[1], ce[1]) |
|
369 |
+ r2 <- c(ce[2]+h*0.25, ce[2], ce[2]-h*0.25) |
|
370 |
+ } |
|
371 |
+ else if (k == 4) { |
|
372 |
+ r1 <- c(ce[1]-w*0.3, ce[1]+w*0.3, ce[1]+w*0.3, ce[1]-w*0.3) |
|
373 |
+ r2 <- c(ce[2]-h*0.3, ce[2]-h*0.3, ce[2]+h*0.3, ce[2]+h*0.3) |
|
374 |
+ } |
|
375 |
+ else { |
|
376 |
+ a <- 1 |
|
377 |
+ z <- seq(a, a+2*pi, len=k+1) |
|
378 |
+ z <- z[-1] |
|
379 |
+ r1 <- ce[1]+w/2.5*cos(z) |
|
380 |
+ r2 <- ce[2]+h/2.5*sin(z) |
|
381 |
+ } |
|
382 |
+ cbind(r1, r2) |
|
383 |
+ } |
|
384 |
+ |
|
385 |
+ plotGraph <- function (graph, coor=NULL, alpha=2.5, main="Some Graph", |
|
386 |
+ sorting) { |
|
387 |
+ |
|
388 |
+ ## Define the nodes and the length of the graph (number of nodes) |
|
389 |
+ v <- nodes(graph) |
|
390 |
+ n <- length(v) |
|
391 |
+ |
|
392 |
+ ## Create an empty draw device |
|
393 |
+ plot(c(0, 100), c(0, 100), type="n", axes=FALSE, xlab="", ylab="", |
|
394 |
+ main=main) |
|
395 |
+ |
|
396 |
+ ## Define an initial center to the graph |
|
397 |
+ center <- matrix(c(50, 50), ncol=2) |
|
398 |
+ |
|
399 |
+ ## Create an object of the locations for each node |
|
400 |
+ if (is.null(coor)) { |
|
401 |
+ coor <- def.coor(center, n, 100, 100) |
|
402 |
+ } |
|
403 |
+ ## Plot each node on the device |
|
404 |
+ plot.dots(coor, v, n) |
|
405 |
+ ## Locate the nodes to plot on the figure |
|
406 |
+ for (i in 1:n) { |
|
407 |
+ if(length(edgeL(graph)[[i]]$edges) > 0) { |
|
408 |
+ elo <- list(v[i], edgeL(graph)[[i]]$edges, |
|
409 |
+ as.numeric(edgeWeights(graph, i)[[1]])) |
|
410 |
+ ##if(length(elo[[2]]) > 0) |
|
411 |
+ draw.edges(coor, v, elo, alpha, sorting) |
|
412 |
+ } |
|
413 |
+ } |
|
414 |
+ colnames(coor) <- c("x", "y") |
|
415 |
+ return(invisible(coor)) |
|
416 |
+ } |
|
417 |
+ |
|
418 |
+ |
|
419 |
+ if(!is.null(cutCor)) { |
|
420 |
+ ## geting maximum bootstrap value to use in cutCor |
|
421 |
+ if((is.character(cutCor)) & (cutCor == "max")) |
|
422 |
+ cutCor <- max(x@maxB[upper.tri(x@maxB)]) |
|
423 |
+ else if((cutCor < 0) | (cutCor >= 1)) |
|
424 |
+ stop("cutCor must a number in [0,1) or 'max'.") |
|
425 |
+ |
|
426 |
+ ## Ploting the graphs |
|
427 |
+ graph <- graphPath(x, cutCor, NULL) |
|
428 |
+ plotGraph(graph, main=name, sorting="A") |
|
429 |
+ } |
|
430 |
+ else { |
|
431 |
+ ## Ploting the graphs |
|
432 |
+ graph <- graphPath(x, NULL, cutPval) |
|
433 |
+ plotGraph(graph, main=name, sorting="A") |
|
434 |
+ } |
|
435 |
+} |
|
436 |
+ |
|
437 |
+ |
|
438 |
+## For maigesActMod class (heatmap of the significative results) |
|
439 |
+plot.maigesActMod <- function(x, type=c("S", "C")[2], keepEmpty=FALSE, ...) { |
|
440 |
+ |
|
441 |
+ ## Making some basic initial tests... |
|
442 |
+ if(is.null(x)) |
|
443 |
+ stop("You MUST specify an object generated by activeMod function.") |
|
444 |
+ if(!is.element(type, c("S", "C"))) |
|
445 |
+ stop("You must be 'C' or 'S'.") |
|
446 |
+ |
|
447 |
+ if(type == "S") { |
|
448 |
+ if(keepEmpty) |
|
449 |
+ table <- x@modBySamp |
|
450 |
+ else { |
|
451 |
+ idx <- apply(x@modBySamp != 0, 2, sum, na.rm=TRUE) != 0 |
|
452 |
+ if(sum(idx) < 2) |
|
453 |
+ stop("Less than 2 elements present significant results!") |
|
454 |
+ table <- x@modBySamp[, idx] |
|
455 |
+ } |
|
456 |
+ limite <- max(abs(range(table, na.rm=TRUE))) |
|
457 |
+ limite <- c(-limite, limite) |
|
458 |
+ idx1 <- order(rownames(table)) |
|
459 |
+ idx2 <- order.dendrogram(as.dendrogram(hclust(dist(t(table))))) |
|
460 |
+ |
|
461 |
+ heatmap(table[idx1, idx2], scale="none", col=maigesPack:::greenRed(), |
|
462 |
+ zlim=limite, Rowv=NA, Colv=NA, ...) |
|
463 |
+ |
|
464 |
+ } |
|
465 |
+ else if(type == "C") { |
|
466 |
+ if(keepEmpty) |
|
467 |
+ table <- x@modByCond |
|
468 |
+ else { |
|
469 |
+ idx <- apply(x@modByCond != 0, 2, sum, na.rm=TRUE) != 0 |
|
470 |
+ if(sum(idx) < 2) |
|
471 |
+ stop("Less than 2 elements present significant results!") |
|
472 |
+ table <- x@modByCond[, idx] |
|
473 |
+ } |
|
474 |
+ limite <- max(abs(range(table, na.rm=TRUE))) |
|
475 |
+ limite <- c(-limite, limite) |
|
476 |
+ idx1 <- order(rownames(table)) |
|
477 |
+ idx2 <- order.dendrogram(as.dendrogram(hclust(dist(t(table))))) |
|
478 |
+ |
|
479 |
+ heatmap(table[idx1, idx2], scale="none", col=maigesPack:::greenRed(), |
|
480 |
+ zlim=limite, Rowv=NA, Colv=NA, ...) |
|
481 |
+ |
|
482 |
+ } |
|
483 |
+} |
|
484 |
+ |
|
485 |
+ |
|
486 |
+## For maigesActNet class (heatmap of the significative results) |
|
487 |
+plot.maigesActNet <- function(x, type=c("score","p-value")[1], ...) { |
|
488 |
+ |
|
489 |
+ ## Making some basic initial tests... |
|
490 |
+ if(is.null(x)) |
|
491 |
+ stop("You MUST specify an object generated by activeNet function.") |
|
492 |
+ if(!is.element(type, c("score", "p-value"))) |
|
493 |
+ stop("You must be 'score' or 'p-value'.") |
|
494 |
+ |
|
495 |
+ if(type == "score") { |
|
496 |
+ limite <- max(x@scores, na.rm=TRUE) |
|
497 |
+ limite <- c(0, limite) |
|
498 |
+ idx <- order.dendrogram(as.dendrogram(hclust(dist(t(x@scores))))) |
|
499 |
+ |
|
500 |
+ heatmap(x@scores[, idx], scale="none", col=maigesPack:::blackBlue(), |
|
501 |
+ zlim=limite, Rowv=NA, Colv=NA, ...) |
|
502 |
+ |
|
503 |
+ } |
|
504 |
+ else { |
|
505 |
+ |
|
506 |
+ limite = max(-log10(x@Pvalues), na.rm=TRUE) |
|
507 |
+ limite = c(0, limite) |
|
508 |
+ |
|
509 |
+ idx <- order.dendrogram(as.dendrogram(hclust(dist(t(x@Pvalues))))) |
|
510 |
+ |
|
511 |
+ heatmap(-log10(x@Pvalues)[, idx], scale="none", |
|
512 |
+ col=maigesPack:::blackBlue(), zlim=limite, Rowv=NA, Colv=NA, ...) |
|
513 |
+ |
|
514 |
+ } |
|
515 |
+} |