annotate w4mcorcov_calc.R @ 11:ddcc33ff3205 draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
author eschen42
date Wed, 05 Sep 2018 22:31:21 -0400
parents 066b1f409e9f
children ddaf84e15d06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
1 # center with 'colMeans()' - ref: http://gastonsanchez.com/visually-enforced/how-to/2014/01/15/Center-data-in-R/
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
2 center_colmeans <- function(x) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
3 xcenter = colMeans(x)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
4 x - rep(xcenter, rep.int(nrow(x), ncol(x)))
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
5 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
6
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
7 #### OPLS-DA
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
8 algoC <- "nipals"
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
9
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
10 do_detail_plot <- function(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
11 x_dataMatrix
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
12 , x_predictor
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
13 , x_is_match
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
14 , x_algorithm
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
15 , x_prefix
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
16 , x_show_labels
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
17 , x_progress = print
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
18 , x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
19 , x_crossval_i
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
20 ) {
2
e03582f26617 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 7682e8e7ae2bfb926d94b414b9a1649389f33582
eschen42
parents: 1
diff changeset
21 off <- function(x) if (x_show_labels == "0") 0 else x
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
22 if ( x_is_match
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
23 && ncol(x_dataMatrix) > 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
24 && length(unique(x_predictor))> 1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
25 && x_crossval_i < nrow(x_dataMatrix)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
26 ) {
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
27 my_oplsda <- opls(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
28 x = x_dataMatrix
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
29 , y = x_predictor
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
30 , algoC = x_algorithm
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
31 , predI = 1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
32 , orthoI = if (ncol(x_dataMatrix) > 1) 1 else 0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
33 , printL = FALSE
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
34 , plotL = FALSE
3
5aaab36bc523 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 88004a3cf8868d68da1ec5bd2c1be53746350367
eschen42
parents: 2
diff changeset
35 , crossvalI = x_crossval_i
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
36 , scaleC = "pareto" # data centered and pareto scaled here only. This line fixes issue #2.
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
37 )
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
38 # strip out variables having negligible variance
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
39 x_dataMatrix <- x_dataMatrix[,names(my_oplsda@vipVn), drop = FALSE]
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
40 my_oplsda_suppLs_y_levels <- levels(as.factor(my_oplsda@suppLs$y))
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
41 # x_progress(strF(x_dataMatrix))
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
42 # x_progress(strF(my_oplsda))
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
43 #x_progress(head(my_oplsda_suppLs_y_levels))
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
44 #x_progress(unique(my_oplsda_suppLs_y_levels))
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
45 fctr_lvl_1 <- my_oplsda_suppLs_y_levels[1]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
46 fctr_lvl_2 <- my_oplsda_suppLs_y_levels[2]
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
47 do_s_plot <- function(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
48 x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
49 , predictor_projection_x = TRUE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
50 , cplot_x = FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
51 , cor_vs_cov_x = NULL
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
52 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
53 {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
54 #print(ls(x_env)) # "cplot_y" etc
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
55 #print(str(x_env$cplot_y)) # chr "covariance"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
56 if (cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
57 #print(x_env$cplot_y) # "covariance"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
58 cplot_y_correlation <- (x_env$cplot_y == "correlation")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
59 #print(cplot_y_correlation) # FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
60 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
61 if (is.null(cor_vs_cov_x)) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
62 my_cor_vs_cov <- cor_vs_cov(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
63 matrix_x = x_dataMatrix
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
64 , ropls_x = my_oplsda
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
65 , predictor_projection_x = predictor_projection_x
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
66 , x_progress
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
67 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
68 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
69 my_cor_vs_cov <- cor_vs_cov_x
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
70 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
71 # print("str(my_cor_vs_cov)")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
72 # str(my_cor_vs_cov)
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
73 if (is.null(my_cor_vs_cov) || sum(!is.na(my_cor_vs_cov$tsv1$covariance)) < 2) {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
74 if (is.null(cor_vs_cov_x)) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
75 x_progress("No cor_vs_cov data produced")
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
76 }
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
77 plot(x=1, y=1, xaxt="n", yaxt="n", xlab="", ylab="", type="n")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
78 text(x=1, y=1, labels="too few covariance data")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
79 return(my_cor_vs_cov)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
80 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
81 with(
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
82 my_cor_vs_cov
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
83 , {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
84 min_x <- min(covariance, na.rm = TRUE)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
85 max_x <- max(covariance, na.rm = TRUE)
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
86 lim_x <- max(sapply(X=c(min_x, max_x), FUN=abs))
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
87 covariance <- covariance / lim_x
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
88 lim_x <- 1.2
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
89 # "It is generally accepted that a variable should be selected if vj>1, [27–29],
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
90 # but a proper threshold between 0.83 and 1.21 can yield more relevant variables according to [28]."
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
91 # (Mehmood 2012 doi:10.1186/1748-7188-6-27)
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
92 plus_cor <- correlation
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
93 plus_cov <- covariance
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
94 cex <- 0.65
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
95 which_projection <- if (projection == 1) "t1" else "o1"
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
96 which_loading <- if (projection == 1) "parallel" else "orthogonal"
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
97 if (projection == 1) { # predictor-projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
98 vipcp <- pmax(0, pmin(1,(vip4p-0.83)/(1.21-0.83)))
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
99 if (!cplot_x) { # S-plot predictor-projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
100 my_xlab <- "relative covariance(feature,t1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
101 my_x <- plus_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
102 my_ylab <- "correlation(feature,t1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
103 my_y <- plus_cor
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
104 } else { # C-plot predictor-projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
105 my_xlab <- "variable importance in predictor-projection"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
106 my_x <- vip4p
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
107 if (cplot_y_correlation) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
108 my_ylab <- "correlation(feature,t1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
109 my_y <- plus_cor
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
110 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
111 my_ylab <- "relative covariance(feature,t1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
112 my_y <- plus_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
113 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
114 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
115 if (cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
116 lim_x <- max(my_x, na.rm = TRUE) * 1.1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
117 my_xlim <- c( 0, lim_x + off(0.2) )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
118 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
119 my_xlim <- c( -lim_x - off(0.2), lim_x + off(0.2) )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
120 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
121 my_ylim <- c( -1.0 - off(0.2), 1.0 + off(0.2) )
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
122 my_load_distal <- loadp
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
123 my_load_proximal <- loado
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
124 red <- as.numeric(correlation > 0) * vipcp
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
125 blue <- as.numeric(correlation < 0) * vipcp
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
126 alpha <- 0.1 + 0.4 * vipcp
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
127 red[is.na(red)] <- 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
128 blue[is.na(blue)] <- 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
129 alpha[is.na(alpha)] <- 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
130 my_col <- rgb(blue = blue, red = red, green = 0, alpha = alpha)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
131 main_label <- sprintf("%s for level %s versus %s"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
132 , x_prefix, fctr_lvl_1, fctr_lvl_2)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
133 } else { # orthogonal projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
134 vipco <- pmax(0, pmin(1,(vip4o-0.83)/(1.21-0.83)))
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
135 if (!cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
136 my_xlab <- "relative covariance(feature,to1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
137 my_x <- -plus_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
138 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
139 my_xlab <- "variable importance in orthogonal projection"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
140 my_x <- vip4o
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
141 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
142 if (!cplot_x) { # S-plot orthogonal projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
143 my_xlim <- c( -lim_x - off(0.2), lim_x + off(0.2) )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
144 my_ylab <- "correlation(feature,to1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
145 my_y <- plus_cor
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
146 } else { # C-plot orthogonal projection
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
147 lim_x <- max(my_x, na.rm = TRUE) * 1.1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
148 my_xlim <- c( 0, lim_x + off(0.2) )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
149 if (cplot_y_correlation) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
150 my_ylab <- "correlation(feature,to1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
151 my_y <- plus_cor
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
152 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
153 my_ylab <- "relative covariance(feature,to1)"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
154 my_y <- plus_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
155 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
156 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
157 my_ylim <- c( -1.0 - off(0.2), 1.0 + off(0.2) )
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
158 my_load_distal <- loado
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
159 my_load_proximal <- loadp
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
160 alpha <- 0.1 + 0.4 * vipco
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
161 alpha[is.na(alpha)] <- 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
162 my_col <- rgb(blue = 0, red = 0, green = 0, alpha = alpha)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
163 main_label <- sprintf(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
164 "Features influencing orthogonal projection for %s versus %s"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
165 , fctr_lvl_1, fctr_lvl_2)
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
166 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
167 main_cex <- min(1.0, 46.0/nchar(main_label))
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
168 my_feature_label_slant <- -30 # slant feature labels 30 degrees downward
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
169 plot(
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
170 y = my_y
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
171 , x = my_x
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
172 , type = "p"
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
173 , xlim = my_xlim
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
174 , ylim = my_ylim
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
175 , xlab = my_xlab
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
176 , ylab = my_ylab
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
177 , main = main_label
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
178 , cex.main = main_cex
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
179 , cex = cex
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
180 , pch = 16
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
181 , col = my_col
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
182 )
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
183 low_x <- -0.7 * lim_x
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
184 high_x <- 0.7 * lim_x
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
185 if (projection == 1 && !cplot_x) {
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
186 text(x = low_x, y = -0.05, labels = fctr_lvl_1, col = "blue")
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
187 text(x = high_x, y = 0.05, labels = fctr_lvl_2, col = "red")
2
e03582f26617 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 7682e8e7ae2bfb926d94b414b9a1649389f33582
eschen42
parents: 1
diff changeset
188 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
189 if ( x_show_labels != "0" ) {
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
190 names(my_load_distal) <- tsv1$featureID
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
191 names(my_load_proximal) <- tsv1$featureID
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
192 if ( x_show_labels == "ALL" ) {
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
193 n_labels <- length(my_load_distal)
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
194 } else {
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
195 n_labels <- as.numeric(x_show_labels)
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
196 }
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
197 n_labels <- min( n_labels, (1 + length(my_load_distal)) / 2 )
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
198 labels_to_show <- c(
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
199 names(head(sort(my_load_distal),n = n_labels))
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
200 , names(tail(sort(my_load_distal),n = n_labels))
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
201 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
202 labels <- unname(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
203 sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
204 X = tsv1$featureID
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
205 , FUN = function(x) if( x %in% labels_to_show ) x else ""
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
206 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
207 )
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
208 x_text_offset <- 0.024
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
209 y_text_off <- 0.017
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
210 if (!cplot_x) { # S-plot
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
211 y_text_offset <- if (projection == 1) -y_text_off else y_text_off
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
212 } else { # C-plot
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
213 y_text_offset <-
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
214 sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
215 X = (my_y > 0)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
216 , FUN = function(x) { if (x) y_text_off else -y_text_off }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
217 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
218 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
219 label_features <- function(x_arg, y_arg, labels_arg, slant_arg) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
220 # print("str(x_arg)")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
221 # print(str(x_arg))
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
222 # print("str(y_arg)")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
223 # print(str(y_arg))
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
224 # print("str(labels_arg)")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
225 # print(str(labels_arg))
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
226 if (length(labels_arg) > 0) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
227 unique_slant <- unique(slant_arg)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
228 if (length(unique_slant) == 1) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
229 text(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
230 y = y_arg
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
231 , x = x_arg + x_text_offset
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
232 , cex = 0.4
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
233 , labels = labels_arg
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
234 , col = rgb(blue = 0, red = 0, green = 0, alpha = 0.5) # grey semi-transparent labels
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
235 , srt = slant_arg
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
236 , adj = 0 # left-justified
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
237 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
238 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
239 for (slant in unique_slant) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
240 text(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
241 y = y_arg[slant_arg == slant]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
242 , x = x_arg[slant_arg == slant] + x_text_offset
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
243 , cex = 0.4
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
244 , labels = labels_arg[slant_arg == slant]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
245 , col = rgb(blue = 0, red = 0, green = 0, alpha = 0.5) # grey semi-transparent labels
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
246 , srt = slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
247 , adj = 0 # left-justified
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
248 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
249 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
250 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
251 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
252 }
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
253 if (!cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
254 my_slant <- (if (projection == 1) 1 else -1) * my_feature_label_slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
255 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
256 my_slant <- sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
257 X = (my_y > 0)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
258 , FUN = function(x) if (x) 2 else -2
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
259 ) * my_feature_label_slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
260 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
261 if (length(my_x) > 1) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
262 label_features(
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
263 x_arg = my_x [my_x > 0]
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
264 , y_arg = my_y [my_x > 0] - y_text_offset
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
265 , labels_arg = labels[my_x > 0]
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
266 , slant_arg = (if (!cplot_x) -my_slant else (my_slant))
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
267 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
268 if (!cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
269 label_features(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
270 x_arg = my_x [my_x < 0]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
271 , y_arg = my_y [my_x < 0] + y_text_offset
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
272 , labels_arg = labels[my_x < 0]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
273 , slant_arg = my_slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
274 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
275 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
276 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
277 if (!cplot_x) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
278 my_slant <- (if (my_x > 1) -1 else 1) * my_slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
279 my_y_arg = my_y + (if (my_x > 1) -1 else 1) * y_text_offset
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
280 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
281 my_slant <- (if (my_y > 1) -1 else 1) * my_slant
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
282 my_y_arg = my_y + (if (my_y > 1) -1 else 1) * y_text_offset
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
283 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
284 label_features(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
285 x_arg = my_x
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
286 , y_arg = my_y_arg
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
287 , labels_arg = labels
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
288 , slant_arg = my_slant
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
289 )
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
290 }
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
291 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
292 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
293 )
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
294 return (my_cor_vs_cov)
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
295 }
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
296 my_cor_vs_cov <- do_s_plot(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
297 x_env = x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
298 , predictor_projection_x = TRUE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
299 , cplot_x = FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
300 )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
301 typeVc <- c("correlation", # 1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
302 "outlier", # 2
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
303 "overview", # 3
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
304 "permutation", # 4
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
305 "predict-train", # 5
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
306 "predict-test", # 6
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
307 "summary", # 7 = c(2,3,4,9)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
308 "x-loading", # 8
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
309 "x-score", # 9
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
310 "x-variance", # 10
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
311 "xy-score", # 11
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
312 "xy-weight" # 12
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
313 ) # [c(3,8,9)] # [c(4,3,8,9)]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
314 if ( length(my_oplsda@orthoVipVn) > 0 ) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
315 my_typevc <- typeVc[c(9,3,8)]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
316 } else {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
317 my_typevc <- c("(dummy)","overview","(dummy)")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
318 }
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
319 my_ortho_cor_vs_cov_exists <- FALSE
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
320 for (my_type in my_typevc) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
321 if (my_type %in% typeVc) {
4
8bba31f628da planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 8f2dc8b66666340275cd8967e09c504720528462
eschen42
parents: 3
diff changeset
322 tryCatch({
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
323 if ( my_type != "x-loading" ) {
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
324 plot(
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
325 x = my_oplsda
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
326 , typeVc = my_type
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
327 , parCexN = 0.4
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
328 , parDevNewL = FALSE
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
329 , parLayL = TRUE
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
330 , parEllipsesL = TRUE
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
331 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
332 if (my_type == "overview") {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
333 sub_label <- sprintf("%s versus %s", fctr_lvl_1, fctr_lvl_2)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
334 title(sub = sub_label)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
335 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
336 } else {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
337 my_ortho_cor_vs_cov <- do_s_plot(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
338 x_env = x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
339 , predictor_projection_x = FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
340 , cplot_x = FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
341 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
342 my_ortho_cor_vs_cov_exists <- TRUE
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
343 }
4
8bba31f628da planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 8f2dc8b66666340275cd8967e09c504720528462
eschen42
parents: 3
diff changeset
344 }, error = function(e) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
345 x_progress(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
346 sprintf(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
347 "factor level %s or %s may have only one sample - %s"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
348 , fctr_lvl_1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
349 , fctr_lvl_2
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
350 , e$message
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
351 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
352 )
4
8bba31f628da planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 8f2dc8b66666340275cd8967e09c504720528462
eschen42
parents: 3
diff changeset
353 })
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
354 } else {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
355 plot(x=1, y=1, xaxt="n", yaxt="n", xlab="", ylab="", type="n")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
356 text(x=1, y=1, labels="no orthogonal projection is possible")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
357 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
358 }
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
359 cplot_p <- x_env$cplot_p
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
360 cplot_o <- x_env$cplot_o
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
361 if (cplot_p || cplot_o) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
362 if (cplot_p) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
363 do_s_plot(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
364 x_env = x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
365 , predictor_projection_x = TRUE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
366 , cplot_x = TRUE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
367 , cor_vs_cov_x = my_cor_vs_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
368 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
369 did_plots <- 1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
370 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
371 did_plots <- 0
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
372 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
373 if (cplot_o) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
374 if (my_ortho_cor_vs_cov_exists) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
375 do_s_plot(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
376 x_env = x_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
377 , predictor_projection_x = FALSE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
378 , cplot_x = TRUE
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
379 , cor_vs_cov_x = my_ortho_cor_vs_cov
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
380 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
381 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
382 plot(x=1, y=1, xaxt="n", yaxt="n", xlab="", ylab="", type="n")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
383 text(x=1, y=1, labels="no orthogonal projection is possible")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
384 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
385 did_plots <- 1 + did_plots
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
386 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
387 if (did_plots == 1) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
388 plot(x=1, y=1, xaxt="n", yaxt="n", xlab="", ylab="", type="n", fg = "white")
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
389 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
390 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
391 return (my_cor_vs_cov)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
392 } else {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
393 return (NULL)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
394 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
395 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
396
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
397 # S-PLOT and OPLS reference: Wiklund_2008 doi:10.1021/ac0713510
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
398 corcov_calc <- function(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
399 calc_env
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
400 , failure_action = stop
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
401 , progress_action = function(x) { }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
402 , corcov_tsv_action = function(t) { }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
403 , salience_tsv_action = function(t) { }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
404 , extra_plots = c()
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
405 ) {
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
406 if ( ! is.environment(calc_env) ) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
407 failure_action("corcov_calc: fatal error - 'calc_env' is not an environment")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
408 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
409 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
410 if ( ! is.function(corcov_tsv_action) ) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
411 failure_action("corcov_calc: fatal error - 'corcov_tsv_action' is not a function")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
412 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
413 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
414 if ( ! is.function(salience_tsv_action) ) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
415 failure_action("salience_calc: fatal error - 'salience_tsv_action' is not a function")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
416 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
417 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
418
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
419 # extract parameters from the environment
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
420 vrbl_metadata <- calc_env$vrbl_metadata
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
421 vrbl_metadata_names <- vrbl_metadata[,1]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
422 smpl_metadata <- calc_env$smpl_metadata
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
423 data_matrix <- calc_env$data_matrix
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
424 pairSigFeatOnly <- calc_env$pairSigFeatOnly
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
425 facC <- calc_env$facC
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
426 tesC <- calc_env$tesC
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
427 # extract the levels from the environment
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
428 originalLevCSV <- levCSV <- calc_env$levCSV
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
429 # matchingC is one of { "none", "wildcard", "regex" }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
430 matchingC <- calc_env$matchingC
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
431 labelFeatures <- calc_env$labelFeatures
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
432
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
433 # arg/env checking
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
434 if (!(facC %in% names(smpl_metadata))) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
435 failure_action(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
436 sprintf("bad parameter! Factor name '%s' not found in sampleMetadata"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
437 , facC))
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
438 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
439 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
440
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
441 mz <- vrbl_metadata$mz
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
442 names(mz) <- vrbl_metadata$variableMetadata
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
443 mz_lookup <- function(feature) unname(mz[feature])
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
444
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
445 rt <- vrbl_metadata$rt
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
446 names(rt) <- vrbl_metadata$variableMetadata
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
447 rt_lookup <- function(feature) unname(rt[feature])
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
448
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
449 # calculate salience_df as data.frame(feature, max_level, max_median, max_rcv, mean_median, salience, salient_rcv)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
450 salience_df <- calc_env$salience_df <- w4msalience(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
451 data_matrix = data_matrix
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
452 , sample_class = smpl_metadata[,facC]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
453 , failure_action = failure_action
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
454 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
455 salience_tsv_action({
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
456 my_df <- data.frame(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
457 featureID = salience_df$feature
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
458 , salientLevel = salience_df$max_level
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
459 , salientRCV = salience_df$salient_rcv
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
460 , salience = salience_df$salience
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
461 , mz = mz_lookup(salience_df$feature)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
462 , rt = rt_lookup(salience_df$feature)
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
463 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
464 my_df[order(-my_df$salience),]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
465 })
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
466
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
467 # transform wildcards to regexen
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
468 if (matchingC == "wildcard") {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
469 # strsplit(x = "hello,wild,world", split = ",")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
470 levCSV <- gsub("[.]", "[.]", levCSV)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
471 levCSV <- strsplit(x = levCSV, split = ",")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
472 levCSV <- sapply(levCSV, utils::glob2rx, trim.tail = FALSE)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
473 levCSV <- paste(levCSV, collapse = ",")
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
474 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
475 # function to determine whether level is a member of levCSV
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
476 isLevelSelected <- function(lvl) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
477 matchFun <- if (matchingC != "none") grepl else `==`
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
478 return(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
479 Reduce(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
480 f = "||"
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
481 , x = sapply(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
482 X = strsplit(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
483 x = levCSV
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
484 , split = ","
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
485 , fixed = TRUE
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
486 )[[1]]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
487 , FUN = matchFun
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
488 , lvl
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
489 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
490 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
491 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
492 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
493
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
494 # transpose matrix because ropls matrix is the transpose of XCMS matrix
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
495 tdm <- t(data_matrix)
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
496 # Wiklund_2008 centers and pareto-scales data before OPLS-DA S-plot
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
497 # However, data should be neither centered nor pareto scaled here because ropls::opls does that; this fixes issue #2.
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
498
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
499 # pattern to match column names like k10_kruskal_k4.k3_sig
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
500 col_pattern <- sprintf('^%s_%s_(.*)[.](.*)_sig$', facC, tesC)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
501 # column name like k10_kruskal_sig
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
502 intersample_sig_col <- sprintf('%s_%s_sig', facC, tesC)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
503 # get the facC column from sampleMetadata, dropping to one dimension
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
504 smpl_metadata_facC <- smpl_metadata[,facC]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
505
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
506 # allocate a slot in the environment for the contrast_list, each element of which will be a data.frame with this structure:
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
507 # - feature ID
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
508 # - value1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
509 # - value2
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
510 # - Wiklund_2008 correlation
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
511 # - Wiklund_2008 covariance
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
512 # - Wiklund_2008 VIP
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
513 calc_env$contrast_list <- list()
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
514
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
515
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
516 did_plot <- FALSE
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
517 if (tesC != "none") {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
518 # for each column name, extract the parts of the name matched by 'col_pattern', if any
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
519 the_colnames <- colnames(vrbl_metadata)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
520 if ( ! Reduce( f = "||", x = grepl(tesC, the_colnames) ) ) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
521 failure_action(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
522 sprintf(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
523 "bad parameter! variableMetadata must contain results of W4M Univariate test '%s'."
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
524 , tesC))
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
525 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
526 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
527 col_matches <- lapply(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
528 X = the_colnames,
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
529 FUN = function(x) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
530 regmatches( x, regexec(col_pattern, x) )[[1]]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
531 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
532 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
533 ## first contrast each selected level with all other levels combined into one "super-level" ##
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
534 # process columns matching the pattern
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
535 level_union <- c()
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
536 for (i in 1:length(col_matches)) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
537 col_match <- col_matches[[i]]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
538 if (length(col_match) > 0) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
539 # it's an actual match; extract the pieces, e.g., k10_kruskal_k4.k3_sig
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
540 vrbl_metadata_col <- col_match[1] # ^^^^^^^^^^^^^^^^^^^^^ # Column name
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
541 fctr_lvl_1 <- col_match[2] # ^^ # Factor-level 1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
542 fctr_lvl_2 <- col_match[3] # ^^ # Factor-level 2
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
543 # only process this column if both factors are members of lvlCSV
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
544 is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
545 if (is_match) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
546 level_union <- c(level_union, col_match[2], col_match[3])
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
547 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
548 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
549 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
550 level_union <- unique(sort(level_union))
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
551 overall_significant <- 1 == (
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
552 if (intersample_sig_col %in% colnames(vrbl_metadata)) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
553 vrbl_metadata[,intersample_sig_col]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
554 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
555 1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
556 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
557 )
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
558 if ( length(level_union) > 2 ) {
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
559 chosen_samples <- smpl_metadata_facC %in% level_union
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
560 chosen_facC <- as.character(smpl_metadata_facC[chosen_samples])
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
561 col_selector <- vrbl_metadata_names[ overall_significant ]
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
562 my_matrix <- tdm[ chosen_samples, col_selector, drop = FALSE ]
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
563 plot_action <- function(fctr_lvl_1, fctr_lvl_2) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
564 progress_action(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
565 sprintf("calculating/plotting contrast of %s vs. %s"
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
566 , fctr_lvl_1, fctr_lvl_2)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
567 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
568 predictor <- sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
569 X = chosen_facC
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
570 , FUN = function(fac) if ( fac == fctr_lvl_1 ) fctr_lvl_1 else fctr_lvl_2
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
571 )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
572 my_cor_cov <- do_detail_plot(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
573 x_dataMatrix = my_matrix
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
574 , x_predictor = predictor
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
575 , x_is_match = TRUE
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
576 , x_algorithm = algoC
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
577 , x_prefix = if (pairSigFeatOnly) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
578 "Significantly contrasting features"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
579 } else {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
580 "Significant features"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
581 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
582 , x_show_labels = labelFeatures
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
583 , x_progress = progress_action
4
8bba31f628da planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 8f2dc8b66666340275cd8967e09c504720528462
eschen42
parents: 3
diff changeset
584 , x_crossval_i = min(7, length(chosen_samples))
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
585 , x_env = calc_env
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
586 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
587 if ( is.null(my_cor_cov) ) {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
588 progress_action("NOTHING TO PLOT")
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
589 } else {
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
590 my_tsv <- my_cor_cov$tsv1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
591 my_tsv$mz <- mz_lookup(my_tsv$featureID)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
592 my_tsv$rt <- rt_lookup(my_tsv$featureID)
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
593 my_tsv["level1Level2Sig"] <- vrbl_metadata[
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
594 match(my_tsv$featureID, vrbl_metadata_names)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
595 , vrbl_metadata_col
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
596 ]
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
597 tsv <<- my_tsv
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
598 corcov_tsv_action(tsv)
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
599 did_plot <<- TRUE
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
600 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
601 }
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
602 if ( length(level_union) != 2 ) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
603 fctr_lvl_2 <- "other"
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
604 for ( fctr_lvl_1 in level_union[1:length(level_union)] ) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
605 plot_action(fctr_lvl_1, fctr_lvl_2)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
606 }
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
607 } else {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
608 plot_action(fctr_lvl_1 = level_union[1], fctr_lvl_2 = level_union[2])
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
609 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
610 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
611
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
612 if ( length(level_union) > 1 ) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
613 ## next, contrast each selected level with each of the other levels individually ##
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
614 # process columns matching the pattern
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
615 for (i in 1:length(col_matches)) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
616 # for each potential match of the pattern
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
617 col_match <- col_matches[[i]]
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
618 if (length(col_match) > 0) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
619 # it's an actual match; extract the pieces, e.g., k10_kruskal_k4.k3_sig
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
620 vrbl_metadata_col <- col_match[1] # ^^^^^^^^^^^^^^^^^^^^^ # Column name
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
621 fctr_lvl_1 <- col_match[2] # ^^ # Factor-level 1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
622 fctr_lvl_2 <- col_match[3] # ^^ # Factor-level 2
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
623 # only process this column if both factors are members of lvlCSV
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
624 is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2)
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
625 if (is_match) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
626 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
627 sprintf("calculating/plotting contrast of %s vs. %s."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
628 , fctr_lvl_1, fctr_lvl_2
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
629 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
630 )
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
631 # choose only samples with one of the two factors for this column
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
632 chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
633 predictor <- smpl_metadata_facC[chosen_samples]
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
634 # extract only the significantly-varying features and the chosen samples
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
635 fully_significant <- 1 == vrbl_metadata[,vrbl_metadata_col] *
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
636 ( if (intersample_sig_col %in% colnames(vrbl_metadata)) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
637 vrbl_metadata[,intersample_sig_col]
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
638 } else {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
639 1
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
640 }
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
641 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
642 col_selector <- vrbl_metadata_names[
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
643 if ( pairSigFeatOnly ) fully_significant else overall_significant
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
644 ]
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
645 my_matrix <- tdm[ chosen_samples, col_selector, drop = FALSE ]
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
646 my_cor_cov <- do_detail_plot(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
647 x_dataMatrix = my_matrix
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
648 , x_predictor = predictor
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
649 , x_is_match = is_match
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
650 , x_algorithm = algoC
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
651 , x_prefix = if (pairSigFeatOnly) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
652 "Significantly contrasting features"
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
653 } else {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
654 "Significant features"
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
655 }
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
656 , x_show_labels = labelFeatures
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
657 , x_progress = progress_action
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
658 , x_crossval_i = min(7, length(chosen_samples))
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
659 , x_env = calc_env
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
660 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
661 if ( is.null(my_cor_cov) ) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
662 progress_action("NOTHING TO PLOT.")
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
663 } else {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
664 tsv <- my_cor_cov$tsv1
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
665 tsv$mz <- mz_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
666 tsv$rt <- rt_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
667 tsv["level1Level2Sig"] <- vrbl_metadata[
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
668 match(tsv$featureID, vrbl_metadata_names)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
669 , vrbl_metadata_col
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
670 ]
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
671 corcov_tsv_action(tsv)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
672 did_plot <- TRUE
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
673 }
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
674 } else {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
675 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
676 sprintf("skipping contrast of %s vs. %s."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
677 , fctr_lvl_1, fctr_lvl_2
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
678 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
679 )
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
680 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
681 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
682 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
683 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
684 } else { # tesC == "none"
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
685 # find all the levels for factor facC in sampleMetadata
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
686 level_union <- unique(sort(smpl_metadata_facC))
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
687 # identify the selected levels for factor facC from sampleMetadata
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
688 level_include <- sapply(X = level_union, FUN = isLevelSelected)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
689 # discard the non-selected levels for factor facC
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
690 level_union <- level_union[level_include]
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
691 if ( length(level_union) > 1 ) {
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
692 if ( length(level_union) > 2 ) {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
693 ## pass 1 - contrast each selected level with all other levels combined into one "super-level" ##
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
694 completed <- c()
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
695 lapply(
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
696 X = level_union
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
697 , FUN = function(x) {
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
698 fctr_lvl_1 <- x[1]
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
699 fctr_lvl_2 <- {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
700 if ( fctr_lvl_1 %in% completed )
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
701 return("DUMMY")
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
702 # strF(completed)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
703 completed <<- c(completed, fctr_lvl_1)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
704 setdiff(level_union, fctr_lvl_1)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
705 }
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
706 chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
707 fctr_lvl_2 <- "other"
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
708 if (length(unique(chosen_samples)) < 1) {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
709 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
710 sprintf("Skipping contrast of %s vs. %s; there are no chosen samples."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
711 , fctr_lvl_1, fctr_lvl_2)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
712 )
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
713 } else {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
714 chosen_facC <- as.character(smpl_metadata_facC[chosen_samples])
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
715 predictor <- sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
716 X = chosen_facC
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
717 , FUN = function(fac) {
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
718 if ( fac == fctr_lvl_1 ) fctr_lvl_1 else fctr_lvl_2
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
719 }
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
720 )
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
721 my_matrix <- tdm[ chosen_samples, , drop = FALSE ]
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
722 # only process this column if both factors are members of lvlCSV
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
723 is_match <- isLevelSelected(fctr_lvl_1)
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
724 if (is_match) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
725 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
726 sprintf("Calculating/plotting contrast of %s vs. %s"
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
727 , fctr_lvl_1, fctr_lvl_2)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
728 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
729 my_cor_cov <- do_detail_plot(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
730 x_dataMatrix = my_matrix
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
731 , x_predictor = predictor
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
732 , x_is_match = is_match
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
733 , x_algorithm = algoC
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
734 , x_prefix = "Features"
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
735 , x_show_labels = labelFeatures
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
736 , x_progress = progress_action
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
737 , x_crossval_i = min(7, length(chosen_samples))
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
738 , x_env = calc_env
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
739 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
740 if ( is.null(my_cor_cov) ) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
741 progress_action("NOTHING TO PLOT...")
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
742 } else {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
743 tsv <- my_cor_cov$tsv1
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
744 tsv$mz <- mz_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
745 tsv$rt <- rt_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
746 corcov_tsv_action(tsv)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
747 did_plot <<- TRUE
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
748 }
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
749 } else {
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
750 }
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
751 }
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
752 "dummy" # need to return a value; otherwise combn fails with an error
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
753 }
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
754 )
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
755 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
756 ## pass 2 - contrast each selected level with each of the other levels individually ##
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
757 completed <- c()
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
758 utils::combn(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
759 x = level_union
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
760 , m = 2
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
761 , FUN = function(x) {
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
762 fctr_lvl_1 <- x[1]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
763 fctr_lvl_2 <- x[2]
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
764 chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
765 if (length(unique(chosen_samples)) < 1) {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
766 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
767 sprintf("Skipping contrast of %s vs. %s. - There are no chosen samples."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
768 , fctr_lvl_1, fctr_lvl_2
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
769 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
770 )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
771 } else {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
772 chosen_facC <- as.character(smpl_metadata_facC[chosen_samples])
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
773 predictor <- chosen_facC
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
774 my_matrix <- tdm[ chosen_samples, , drop = FALSE ]
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
775 # only process this column if both factors are members of lvlCSV
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
776 is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2)
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
777 if (is_match) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
778 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
779 sprintf("Calculating/plotting contrast of %s vs. %s."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
780 , fctr_lvl_1, fctr_lvl_2)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
781 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
782 my_cor_cov <- do_detail_plot(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
783 x_dataMatrix = my_matrix
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
784 , x_predictor = predictor
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
785 , x_is_match = is_match
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
786 , x_algorithm = algoC
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
787 , x_prefix = "Features"
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
788 , x_show_labels = labelFeatures
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
789 , x_progress = progress_action
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
790 , x_crossval_i = min(7, length(chosen_samples))
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
791 , x_env = calc_env
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
792 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
793 if ( is.null(my_cor_cov) ) {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
794 progress_action("NOTHING TO PLOT.....")
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
795 } else {
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
796 tsv <- my_cor_cov$tsv1
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
797 tsv$mz <- mz_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
798 tsv$rt <- rt_lookup(tsv$featureID)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
799 corcov_tsv_action(tsv)
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
800 did_plot <<- TRUE
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
801 }
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
802 } else {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
803 progress_action(
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
804 sprintf("Skipping contrast of %s vs. %s."
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
805 , fctr_lvl_1, fctr_lvl_2
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
806 )
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
807 )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
808 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
809 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
810 "dummy" # need to return a value; otherwise combn fails with an error
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
811 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
812 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
813 } else {
11
ddcc33ff3205 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
eschen42
parents: 7
diff changeset
814 progress_action("NOTHING TO PLOT......")
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
815 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
816 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
817 if (!did_plot) {
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
818 failure_action(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
819 sprintf(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
820 "bad parameter! sampleMetadata must have at least two levels of factor '%s' matching '%s'"
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
821 , facC, originalLevCSV))
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
822 return ( FALSE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
823 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
824 return ( TRUE )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
825 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
826
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
827 # Calculate data for correlation-versus-covariance plot
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
828 # Adapted from:
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
829 # Wiklund_2008 doi:10.1021/ac0713510
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
830 # Galindo_Prieto_2014 doi:10.1002/cem.2627
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
831 # https://github.com/HegemanLab/extra_tools/blob/master/generic_PCA.R
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
832 cor_vs_cov <- function(
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
833 matrix_x
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
834 , ropls_x
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
835 , predictor_projection_x = TRUE
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
836 , x_progress = print
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
837 ) {
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
838 tryCatch({
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
839 return(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
840 cor_vs_cov_try( matrix_x, ropls_x, predictor_projection_x, x_progress)
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
841 )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
842 }, error = function(e) {
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
843 x_progress(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
844 sprintf(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
845 "cor_vs_cov fatal error - %s"
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
846 , as.character(e) # e$message
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
847 )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
848 )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
849 return ( NULL )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
850 })
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
851 }
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
852
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
853 cor_vs_cov_try <- function(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
854 matrix_x
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
855 , ropls_x
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
856 , predictor_projection_x = TRUE
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
857 , x_progress = print
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
858 ) {
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
859 x_class <- class(ropls_x)
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
860 if ( !( as.character(x_class) == "opls" ) ) { # || !( attr(class(x_class),"package") == "ropls" ) )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
861 stop(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
862 paste(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
863 "cor_vs_cov: Expected ropls_x to be of class ropls::opls but instead it was of class "
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
864 , as.character(x_class)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
865 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
866 )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
867 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
868 result <- list()
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
869 result$projection <- projection <- if (predictor_projection_x) 1 else 2
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
870 # suppLs$algoC - Character: algorithm used - "svd" for singular value decomposition; "nipals" for NIPALS
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
871 if ( ropls_x@suppLs$algoC == "nipals") {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
872 # Equations (1) and (2) from *Supplement to* Wiklund 2008, doi:10.1021/ac0713510
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
873 mag <- function(one_dimensional) sqrt(sum(one_dimensional * one_dimensional))
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
874 mag_xi <- sapply(X = 1:ncol(matrix_x), FUN = function(x) mag(matrix_x[,x]))
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
875 if (predictor_projection_x)
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
876 score_matrix <- ropls_x@scoreMN
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
877 else
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
878 score_matrix <- ropls_x@orthoScoreMN
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
879 score_matrix_transposed <- t(score_matrix)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
880 score_matrix_magnitude <- mag(score_matrix)
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
881 result$covariance <-
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
882 score_matrix_transposed %*% matrix_x / ( score_matrix_magnitude * score_matrix_magnitude )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
883 result$correlation <-
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
884 score_matrix_transposed %*% matrix_x / ( score_matrix_magnitude * mag_xi )
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
885 } else {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
886 # WARNING - untested code - I don't have test data to exercise this branch
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
887 # Equations (1) and (2) from Wiklund 2008, doi:10.1021/ac0713510
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
888 # scoreMN - Numerical matrix of x scores (T; dimensions: nrow(x) x predI) X = TP' + E; Y = TC' + F
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
889 if (predictor_projection_x)
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
890 score_matrix <- ropls_x@scoreMN
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
891 else
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
892 score_matrix <- ropls_x@orthoScoreMN
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
893 score_matrix_transposed <- t(score_matrix)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
894 cov_divisor <- nrow(matrix_x) - 1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
895 result$covariance <- sapply(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
896 X = 1:ncol(matrix_x)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
897 , FUN = function(x) score_matrix_transposed %*% matrix_x[,x] / cov_divisor
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
898 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
899 score_sd <- sapply(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
900 X = 1:ncol(score_matrix)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
901 , FUN = function(x) sd(score_matrix[,x])
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
902 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
903 # xSdVn - Numerical vector: variable standard deviations of the 'x' matrix
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
904 xSdVn <- ropls_x@xSdVn
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
905 result$correlation <- sapply(
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
906 X = 1:ncol(matrix_x)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
907 , FUN = function(x) {
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
908 ( score_matrix_transposed / score_sd ) %*% ( matrix_x[,x] / (xSdVn[x] * cov_divisor) )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
909 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
910 )
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
911 }
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
912 result$correlation <- result$correlation[ 1, , drop = TRUE ]
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
913 result$covariance <- result$covariance [ 1, , drop = TRUE ]
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
914
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
915 # Variant 4 of Variable Influence on Projection for OPLS from Galindo_Prieto_2014
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
916 # Length = number of features; labels = feature identifiers. (The same is true for $correlation and $covariance.)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
917 result$vip4p <- as.numeric(ropls_x@vipVn)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
918 result$vip4o <- as.numeric(ropls_x@orthoVipVn)
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
919 result$loadp <- as.numeric(ropls_x@loadingMN)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
920 result$loado <- as.numeric(ropls_x@orthoLoadingMN)
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
921 # get the level names
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
922 level_names <- sort(levels(as.factor(ropls_x@suppLs$y)))
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
923 fctr_lvl_1 <- level_names[1]
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
924 fctr_lvl_2 <- level_names[2]
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
925 feature_count <- length(ropls_x@vipVn)
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
926 result$level1 <- rep.int(x = fctr_lvl_1, times = feature_count)
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
927 result$level2 <- rep.int(x = fctr_lvl_2, times = feature_count)
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
928 superresult <- list()
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
929 if (length(result$vip4o) == 0) result$vip4o <- NA
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
930 greaterLevel <- sapply(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
931 X = result$correlation
7
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
932 , FUN = function(my_corr)
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
933 tryCatch({
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
934 if ( is.nan( my_corr ) ) {
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
935 print("my_corr is NaN")
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
936 NA
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
937 } else {
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
938 if ( my_corr < 0 ) fctr_lvl_1 else fctr_lvl_2
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
939 }
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
940 }, error = function(e) {
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
941 x_progress(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
942 sprintf(
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
943 "cor_vs_cov -> sapply: error - substituting NA - %s"
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
944 , as.character(e)
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
945 )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
946 )
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
947 NA
066b1f409e9f planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit e73fabe1b3c871abbcb2e89914c181149c8e2066
eschen42
parents: 6
diff changeset
948 })
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
949 )
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
950
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
951 # begin fixes for https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/issues/1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
952 featureID <- names(ropls_x@vipVn)
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
953 greaterLevel <- greaterLevel[featureID]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
954 result$correlation <- result$correlation[featureID]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
955 result$covariance <- result$covariance[featureID]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
956 # end fixes for https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/issues/1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
957
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
958 tsv1 <- data.frame(
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
959 featureID = featureID
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
960 , factorLevel1 = result$level1
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
961 , factorLevel2 = result$level2
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
962 , greaterLevel = greaterLevel
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
963 , projection = result$projection
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
964 , correlation = result$correlation
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
965 , covariance = result$covariance
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
966 , vip4p = result$vip4p
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
967 , vip4o = result$vip4o
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
968 , loadp = result$loadp
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
969 , loado = result$loado
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
970 , row.names = NULL
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
971 )
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
972 tsv1 <- tsv1[!is.na(tsv1$correlation),]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
973 tsv1 <- tsv1[!is.na(tsv1$covariance),]
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
974 superresult$tsv1 <- tsv1
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
975 rownames(superresult$tsv1) <- tsv1$featureID
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
976 superresult$projection <- result$projection
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
977 superresult$covariance <- result$covariance
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
978 superresult$correlation <- result$correlation
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
979 superresult$vip4p <- result$vip4p
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
980 superresult$vip4o <- result$vip4o
1
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
981 superresult$loadp <- result$loadp
0c2ad44b6c9c planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents: 0
diff changeset
982 superresult$loado <- result$loado
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
983 superresult$details <- result
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
984 result$superresult <- superresult
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
985 # Include thise in case future consumers of this routine want to use it in currently unanticipated ways
6
7bd523ca1f9a planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
eschen42
parents: 5
diff changeset
986 result$oplsda <- ropls_x
0
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
987 result$predictor <- ropls_x@suppLs$y # in case future consumers of this routine want to use it in currently unanticipated ways
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
988 return (superresult)
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
989 }
23f9fad4edfc planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff changeset
990
5
50f60f94c034 planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
eschen42
parents: 4
diff changeset
991 # vim: sw=2 ts=2 et :