comparison ASCA.PlotScoresPerLevel_w4m.R @ 0:93312041f1d5 draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/ascaw4m commit 7ea9b0f8abc5a60c2c04fd2098788497f14766b6
author marie-tremblay-metatoul
date Fri, 21 Sep 2018 05:51:14 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:93312041f1d5
1 ASCA.PlotScoresPerLevel_w4m <- function (asca, ee, pcs="1,2", interaction=0, factorName="", factorModalite)
2 {
3 pcs <- as.numeric(strsplit(pcs, split=",")[[1]])
4 y <- (asca[[ee]]$means.matrix + asca$remainder) %*% asca[[ee]]$svd$v
5 t.list.x <- list()
6 t.list.y <- list()
7 list.color.pattern <- list()
8 color.per.variable <- rep(0, dim(asca$data)[1])
9 pattern.per.variable <- rep(0, dim(asca$data)[1])
10 kColOptions <- c(24, 552, 254, 26, 84, 51, 652, 68, 76, 96,
11 10, 60, 33, 245, 147, 12, 26, 164, 181, 52, 512, 344,
12 201, 111)
13 kPointOptions <- 1:30
14 for (p in 1:dim(asca[[ee]]$level.combinations$row.pattern)[1]) {
15 if (length(asca[[ee]]$level.combinations$row.pattern[p,
16 ]) == 1) {
17 list.color.pattern[[p]] <- c(kColOptions[p], kPointOptions[p])
18 }
19 else if (length(asca[[ee]]$level.combinations$row.pattern[p,
20 ]) == 2) {
21 list.color.pattern[[p]] <- c(kColOptions[asca[[ee]]$level.combinations$row.pattern[p,
22 1]], kPointOptions[asca[[ee]]$level.combinations$row.pattern[p,
23 2]])
24 }
25 else {
26 list.color.pattern[[p]] <- c(kColOptions[asca[[ee]]$level.combinations$row.pattern[p,
27 1]]%%9, floor(kPointOptions[asca[[ee]]$level.combinations$row.pattern[p,
28 2]]/9))
29 }
30 color.per.variable[asca[[ee]]$level.combinations$indices.per.pattern[[p]]] <- list.color.pattern[[p]][1]
31 pattern.per.variable[asca[[ee]]$level.combinations$indices.per.pattern[[p]]] <- list.color.pattern[[p]][2]
32 t.list.x[[p]] <- y[asca[[ee]]$level.combinations$indices.per.pattern[[p]],
33 pcs[1]]
34 t.list.y[[p]] <- y[asca[[ee]]$level.combinations$indices.per.pattern[[p]],
35 pcs[2]]
36 }
37 legend.colors.patterns <- do.call(rbind, list.color.pattern)
38 if (interaction != 1){
39 titre <- paste("PC", pcs[1], " vs PC", pcs[2], " - Factor ", factorName, sep="")
40 }else {
41 titre <- paste("PC", pcs[1], " vs PC", pcs[2], " - Interaction", sep="")
42 }
43 plot(asca[[ee]]$svd$t[, pcs[1]], asca[[ee]]$svd$t[, pcs[2]],
44 xlim=range(c(min(unlist(t.list.x)), max(unlist(t.list.x)))),
45 ylim=range(c(min(unlist(t.list.y)), max(unlist(t.list.y)))),
46 main=titre,
47 xlab=paste("PC", pcs[1], " (", formatC(asca[[ee]]$svd$var.explained[pcs[1]] * 100, digits=2, format="f"), "%)", sep=""),
48 ylab=paste("PC", pcs[2], " (", formatC(asca[[ee]]$svd$var.explained[pcs[2]] * 100, digits=2, format="f"), "%)", sep=""),
49 cex=1.5, lwd=3, col=colors()[color.per.variable],
50 pch=pattern.per.variable)
51 # if (interaction != 1){
52 legend(x="bottomright", legend=factorModalite,
53 cex=0.8, col=colors()[legend.colors.patterns[, 1]], pch=legend.colors.patterns[, 2])
54 # }
55 # else {
56 # legend(x="bottomright", apply(asca[[ee]]$level.combinations$row.patterns, 1, paste, collapse=" "),
57 # cex=0.8, col=colors()[legend.colors.patterns[, 1]], pch=legend.colors.patterns[, 2])
58 # }
59
60 for (p in 1:length(t.list.x)) {
61 points(t.list.x[[p]], t.list.y[[p]], col=colors()[list.color.pattern[[p]][1]],
62 pch=list.color.pattern[[p]][2])
63 }
64 }