Mercurial > repos > eschen42 > w4mcorcov
annotate w4mcorcov_calc.R @ 1:0c2ad44b6c9c draft
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
author | eschen42 |
---|---|
date | Sun, 22 Oct 2017 18:47:57 -0400 |
parents | 23f9fad4edfc |
children | e03582f26617 |
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 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
10 do_detail_plot <- function(x_dataMatrix, x_predictor, x_is_match, x_algorithm, x_prefix, x_show_labels, x_progress = print, x_env) { |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
11 off <- function(x) if (x_show_labels == "0") x else 0 |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
12 if (x_is_match && ncol(x_dataMatrix) > 0 && length(unique(x_predictor))> 1) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
13 my_oplsda <- opls( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
14 x = x_dataMatrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
15 , y = x_predictor |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
16 , algoC = x_algorithm |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
17 , predI = 1 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
18 , 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
|
19 , printL = FALSE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
20 , plotL = FALSE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
21 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
22 my_oplsda_suppLs_y_levels <- levels(as.factor(my_oplsda@suppLs$y)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
23 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
|
24 fctr_lvl_2 <- my_oplsda_suppLs_y_levels[2] |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
25 my_cor_vs_cov <- cor_vs_cov( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
26 matrix_x = x_dataMatrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
27 , ropls_x = my_oplsda |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
28 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
29 with( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
30 my_cor_vs_cov |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
31 , { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
32 min_x <- min(covariance) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
33 max_x <- max(covariance) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
34 lim_x <- max(sapply(X=c(min_x, max_x), FUN=abs)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
35 covariance <- covariance / lim_x |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
36 lim_x <- 1.2 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
37 main_label <- sprintf("%s for levels %s versus %s", x_prefix, 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
|
38 main_cex <- min(1.0, 46.0/nchar(main_label)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
39 # "It is generally accepted that a variable should be selected if vj>1, [27–29], |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
40 # but a proper threshold between 0.83 and 1.21 can yield more relevant variables according to [28]." |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
41 # (Mehmood 2012 doi:10.1186/1748-7188-6-27) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
42 vipco <- pmax(0, pmin(1,(vip4p-0.83)/(1.21-0.83))) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
43 alpha <- 0.1 + 0.4 * vipco |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
44 red <- as.numeric(correlation > 0) * vipco |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
45 blue <- as.numeric(correlation < 0) * vipco |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
46 plus_cor <- correlation |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
47 plus_cov <- covariance |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
48 cex <- 0.75 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
49 plot( |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
50 y = plus_cor |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
51 , x = plus_cov |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
52 , type="p" |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
53 , xlim=c(-lim_x, lim_x + off(0.1)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
54 , ylim=c(-1.0 - off(0.1), 1.0) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
55 , xlab = sprintf("relative covariance(feature,t1)") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
56 , ylab = sprintf("correlation(feature,t1)") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
57 , main = main_label |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
58 , cex.main = main_cex |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
59 , cex = cex |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
60 , pch = 16 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
61 , col = rgb(blue = blue, red = red, green = 0, alpha = alpha) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
62 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
63 low_x <- -0.7 * lim_x |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
64 high_x <- 0.7 * lim_x |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
65 text(x = low_x, y = -0.05, labels = fctr_lvl_1) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
66 text(x = high_x, y = 0.05, labels = fctr_lvl_2) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
67 if ( x_show_labels != "0" ) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
68 my_loadp <- loadp |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
69 my_loado <- loado |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
70 names(my_loadp) <- tsv1$featureID |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
71 names(my_loado) <- tsv1$featureID |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
72 if ( x_show_labels == "ALL" ) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
73 n_labels <- length(loadp) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
74 } else { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
75 n_labels <- as.numeric(x_show_labels) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
76 } |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
77 n_labels <- min( n_labels, (1 + length(loadp)) / 2 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
78 labels_to_show <- c( |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
79 names(head(sort(my_loadp),n = n_labels)) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
80 , names(head(sort(my_loado),n = n_labels)) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
81 , names(tail(sort(my_loadp),n = n_labels)) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
82 , names(tail(sort(my_loado),n = n_labels)) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
83 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
84 labels <- unname(sapply( X = tsv1$featureID, FUN = function(x) if( x %in% labels_to_show ) x else "" )) |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
85 text( |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
86 y = plus_cor - 0.013 |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
87 , x = plus_cov + 0.020 |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
88 , cex = 0.3 |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
89 , labels = labels |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
90 , col = rgb(blue = blue, red = red, green = 0, alpha = 0.2 + 0.8 * alpha) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
91 , srt = -30 # slant 30 degrees downward |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
92 , adj = 0 # left-justified |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
93 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
94 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
95 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
96 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
97 typeVc <- c("correlation", # 1 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
98 "outlier", # 2 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
99 "overview", # 3 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
100 "permutation", # 4 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
101 "predict-train", # 5 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
102 "predict-test", # 6 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
103 "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
|
104 "x-loading", # 8 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
105 "x-score", # 9 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
106 "x-variance", # 10 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
107 "xy-score", # 11 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
108 "xy-weight" # 12 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
109 ) # [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
|
110 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
|
111 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
|
112 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
113 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
|
114 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
115 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
|
116 if (my_type %in% typeVc) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
117 # print(sprintf("plotting type %s", my_type)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
118 plot( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
119 x = my_oplsda |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
120 , typeVc = my_type |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
121 , parCexN = 0.4 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
122 , parDevNewL = FALSE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
123 , parLayL = TRUE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
124 , parEllipsesL = TRUE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
125 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
126 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
127 # print("plotting dummy graph") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
128 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
|
129 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
|
130 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
131 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
132 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
|
133 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
134 # x_progress(sprintf("x_is_match = %s, ncol(x_dataMatrix) = %d, length(unique(x_predictor)) = %d",x_is_match, ncol(x_dataMatrix), length(unique(x_predictor)))) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
135 return (NULL) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
136 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
137 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
138 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
139 # S-PLOT and OPLS reference: 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
|
140 corcov_calc <- function(calc_env, failure_action = stop, progress_action = function(x){}, corcov_tsv_action = function(t){}, salience_tsv_action = function(t){}) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
141 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
|
142 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
|
143 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
144 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
145 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
|
146 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
|
147 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
148 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
149 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
|
150 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
|
151 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
152 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
153 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
154 # 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 pairSigFeatOnly <- calc_env$pairSigFeatOnly |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
160 facC <- calc_env$facC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
161 tesC <- calc_env$tesC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
162 # 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
|
163 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
|
164 # 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
|
165 matchingC <- calc_env$matchingC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
166 labelFeatures <- calc_env$labelFeatures |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
167 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
168 # arg/env checking |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
169 if (!(facC %in% names(smpl_metadata))) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
170 failure_action(sprintf("bad parameter! Factor name '%s' not found in sampleMetadata", facC)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
171 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
172 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
173 |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
174 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
|
175 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
|
176 mz_lookup <- function(feature) unname(mz[feature]) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
177 |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
178 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
|
179 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
|
180 rt_lookup <- function(feature) unname(rt[feature]) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
181 |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
182 # 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
|
183 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
|
184 data_matrix = data_matrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
185 , 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
|
186 , failure_action = failure_action |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
187 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
188 salience_tsv_action({ |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
189 my_df <- data.frame( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
190 featureID = salience_df$feature |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
191 , 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
|
192 , 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
|
193 , 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
|
194 , 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
|
195 , 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
|
196 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
197 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
|
198 }) |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
199 |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
200 # transform wildcards to regexen |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
201 if (matchingC == "wildcard") { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
202 # 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
|
203 levCSV <- gsub("[.]", "[.]", levCSV) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
204 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
|
205 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
|
206 levCSV <- paste(levCSV, collapse = ",") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
207 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
208 # 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
|
209 isLevelSelected <- function(lvl) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
210 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
|
211 return( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
212 Reduce( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
213 f = "||" |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
214 , x = sapply( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
215 X = strsplit( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
216 x = levCSV |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
217 , split = "," |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
218 , fixed = TRUE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
219 )[[1]] |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
220 , FUN = matchFun |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
221 , lvl |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
222 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
223 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
224 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
225 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
226 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
227 # transpose matrix because ropls matrix is the transpose of XCMS matrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
228 # Wiklund_2008 centers and pareto-scales data before OPLS-DA S-plot |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
229 # center |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
230 cdm <- center_colmeans(t(data_matrix)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
231 # pareto-scale |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
232 my_scale <- sqrt(apply(cdm, 2, sd, na.rm=TRUE)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
233 scdm <- sweep(cdm, 2, my_scale, "/") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
234 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
235 # 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
|
236 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
|
237 # 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
|
238 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
|
239 # 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
|
240 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
|
241 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
242 # 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
|
243 # - feature ID |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
244 # - value1 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
245 # - value2 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
246 # - Wiklund_2008 correlation |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
247 # - Wiklund_2008 covariance |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
248 # - Wiklund_2008 VIP |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
249 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
|
250 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
251 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
252 did_plot <- FALSE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
253 if (tesC != "none") { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
254 # 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
|
255 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
|
256 if ( ! Reduce( f = "||", x = grepl(tesC, the_colnames) ) ) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
257 failure_action(sprintf("bad parameter! variableMetadata must contain results of W4M Univariate test '%s'.", tesC)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
258 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
259 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
260 col_matches <- lapply( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
261 X = the_colnames, |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
262 FUN = function(x) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
263 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
|
264 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
265 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
266 ## 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
|
267 # 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
|
268 level_union <- c() |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 # 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
|
273 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
|
274 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
|
275 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
|
276 # 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
|
277 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
|
278 if (is_match) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
279 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
|
280 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
281 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
282 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
283 level_union <- unique(sort(level_union)) |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
284 overall_significant <- 1 == ( if (intersample_sig_col %in% colnames(vrbl_metadata)) vrbl_metadata[,intersample_sig_col] else TRUE ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 col_selector <- vrbl_metadata_names[ overall_significant ] |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
289 my_matrix <- scdm[ 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
|
290 plot_action <- function(fctr_lvl_1, fctr_lvl_2) { |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
291 progress_action(sprintf("calculating/plotting contrast of %s vs. %s", 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
|
292 predictor <- sapply( X = chosen_facC, FUN = function(fac) if ( fac == fctr_lvl_1 ) fctr_lvl_1 else fctr_lvl_2 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
293 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
|
294 x_dataMatrix = my_matrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
295 , x_predictor = predictor |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
296 , x_is_match = is_match |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
297 , x_algorithm = algoC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
298 , x_prefix = if (pairSigFeatOnly) "Significantly contrasting features" else "Significant features" |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
299 , x_show_labels = labelFeatures |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
300 , x_progress = progress_action |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
301 , x_env = calc_env |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
302 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
303 if ( is.null(my_cor_cov) ) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
304 progress_action("NOTHING TO PLOT.") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
305 } else { |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
306 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
|
307 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
|
308 my_tsv$rt <- rt_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
|
309 my_tsv["level1Level2Sig"] <- vrbl_metadata[ match(my_tsv$featureID, vrbl_metadata_names), vrbl_metadata_col ] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
310 tsv <<- my_tsv |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
311 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
|
312 did_plot <<- TRUE |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
313 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
314 } |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 } |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
320 } else { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
321 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
|
322 } |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
323 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
324 |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
325 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
|
326 ## 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
|
327 # 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
|
328 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
|
329 # 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
|
330 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
|
331 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
|
332 # 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
|
333 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
|
334 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
|
335 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
|
336 # 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
|
337 is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
338 progress_action(sprintf("calculating/plotting contrast of %s vs. %s", 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
|
339 # TODO delete next line displaying currently-processed column |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
340 # cat(sprintf("%s %s %s %s\n", vrbl_metadata_col, fctr_lvl_1, fctr_lvl_2, is_match)) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
341 # choose only samples with one of the two factors for this column |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
342 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
|
343 predictor <- smpl_metadata_facC[chosen_samples] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
344 # extract only the significantly-varying features and the chosen samples |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
345 fully_significant <- 1 == vrbl_metadata[,vrbl_metadata_col] * ( if (intersample_sig_col %in% colnames(vrbl_metadata)) vrbl_metadata[,intersample_sig_col] else TRUE ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
346 col_selector <- vrbl_metadata_names[ if ( pairSigFeatOnly ) fully_significant else overall_significant ] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
347 my_matrix <- scdm[ chosen_samples, col_selector, drop = FALSE ] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
348 my_cor_cov <- do_detail_plot( |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
349 x_dataMatrix = my_matrix |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
350 , x_predictor = predictor |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
351 , x_is_match = is_match |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
352 , x_algorithm = algoC |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
353 , x_prefix = if (pairSigFeatOnly) "Significantly contrasting features" else "Significant features" |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
354 , x_show_labels = labelFeatures |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
355 , x_progress = progress_action |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
356 , x_env = calc_env |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
357 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
358 if ( is.null(my_cor_cov) ) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
359 progress_action("NOTHING TO PLOT.") |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
360 } else { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
361 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
|
362 tsv$mz <- mz_lookup(tsv$featureID) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
363 tsv$rt <- rt_lookup(tsv$featureID) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
364 tsv["level1Level2Sig"] <- vrbl_metadata[ match(tsv$featureID, vrbl_metadata_names), vrbl_metadata_col ] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
365 corcov_tsv_action(tsv) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
366 did_plot <- TRUE |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
367 } |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
368 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
369 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
370 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
371 } else { # tesC == "none" |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
372 level_union <- unique(sort(smpl_metadata_facC)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
373 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
|
374 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
|
375 ## 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
|
376 completed <- c() |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
377 lapply( |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
378 X = level_union |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
379 , FUN = function(x) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
380 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
|
381 fctr_lvl_2 <- { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
382 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
|
383 return("DUMMY") |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
384 # strF(completed) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
385 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
|
386 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
|
387 } |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
388 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
|
389 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
|
390 # print( sprintf("sum(chosen_samples) %d, factor_level_2 %s", sum(chosen_samples), fctr_lvl_2) ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
391 progress_action(sprintf("calculating/plotting contrast of %s vs. %s", 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
|
392 if (length(unique(chosen_samples)) < 1) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
393 progress_action("NOTHING TO PLOT...") |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
394 } else { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
395 chosen_facC <- as.character(smpl_metadata_facC[chosen_samples]) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
396 predictor <- sapply( X = chosen_facC, FUN = function(fac) if ( fac == fctr_lvl_1 ) fctr_lvl_1 else fctr_lvl_2 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
397 my_matrix <- scdm[ chosen_samples, , drop = FALSE ] |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
398 # 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
|
399 is_match <- isLevelSelected(fctr_lvl_1) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
400 my_cor_cov <- do_detail_plot( |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
401 x_dataMatrix = my_matrix |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
402 , x_predictor = predictor |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
403 , x_is_match = is_match |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
404 , x_algorithm = algoC |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
405 , x_prefix = "Features" |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
406 , x_show_labels = labelFeatures |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
407 , x_progress = progress_action |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
408 , x_env = calc_env |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
409 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
410 if ( is.null(my_cor_cov) ) { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
411 progress_action("NOTHING TO PLOT") |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
412 } else { |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
413 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
|
414 tsv$mz <- mz_lookup(tsv$featureID) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
415 tsv$rt <- rt_lookup(tsv$featureID) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
416 corcov_tsv_action(tsv) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
417 did_plot <<- TRUE |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
418 } |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
419 } |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
420 #print("baz") |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
421 "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
|
422 } |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
423 ) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
424 } |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
425 ## 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
|
426 completed <- c() |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
427 utils::combn( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
428 x = level_union |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
429 , m = 2 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
430 , FUN = function(x) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 # print( sprintf("sum(chosen_samples) %d, factor_level_2 %s", sum(chosen_samples), fctr_lvl_2) ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
435 progress_action(sprintf("calculating/plotting contrast of %s vs. %s", 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
|
436 if (length(unique(chosen_samples)) < 1) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
437 progress_action("NOTHING TO PLOT...") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
438 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
439 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
|
440 predictor <- chosen_facC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
441 my_matrix <- scdm[ chosen_samples, , drop = FALSE ] |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
442 # 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
|
443 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
|
444 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
|
445 x_dataMatrix = my_matrix |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
446 , x_predictor = predictor |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
447 , x_is_match = is_match |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
448 , x_algorithm = algoC |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
449 , x_prefix = "Features" |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
450 , x_show_labels = labelFeatures |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
451 , x_progress = progress_action |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
452 , x_env = calc_env |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
453 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
454 if ( is.null(my_cor_cov) ) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
455 progress_action("NOTHING TO PLOT") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
456 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
457 tsv <- my_cor_cov$tsv1 |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
458 tsv$mz <- mz_lookup(tsv$featureID) |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
459 tsv$rt <- rt_lookup(tsv$featureID) |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
460 corcov_tsv_action(tsv) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
461 did_plot <<- TRUE |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
462 } |
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 #print("baz") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
465 "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
|
466 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
467 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
468 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
469 progress_action("NOTHING TO PLOT....") |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
470 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
471 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
472 if (!did_plot) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
473 failure_action(sprintf("bad parameter! sampleMetadata must have at least two levels of factor '%s' matching '%s'", facC, originalLevCSV)) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
474 return ( FALSE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
475 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
476 return ( TRUE ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
477 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
478 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
479 # 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
|
480 # Adapted from: |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
481 # 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
|
482 # 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
|
483 # https://github.com/HegemanLab/extra_tools/blob/master/generic_PCA.R |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
484 cor_vs_cov <- function(matrix_x, ropls_x) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
485 x_class <- class(ropls_x) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
486 if ( !( as.character(x_class) == "opls" ) ) { # || !( attr(class(x_class),"package") == "ropls" ) ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
487 stop( "cor_vs_cov: Expected ropls_x to be of class ropls::opls but instead it was of class ", as.character(x_class) ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
488 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
489 result <- list() |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
490 # 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
|
491 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
|
492 # 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
|
493 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
|
494 mag_xi <- sapply(X = 1:ncol(matrix_x), FUN = function(x) mag(matrix_x[,x])) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
495 score_matrix <- ropls_x@scoreMN |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
496 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
|
497 score_matrix_magnitude <- mag(score_matrix) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
498 result$covariance <- score_matrix_transposed %*% matrix_x / ( score_matrix_magnitude * score_matrix_magnitude ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
499 result$correlation <- score_matrix_transposed %*% matrix_x / ( score_matrix_magnitude * mag_xi ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
500 } else { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
501 # 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
|
502 # 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
|
503 # scoreMN - Numerical matrix of x scores (T; dimensions: nrow(x) x predI) X = TP' + E; Y = TC' + F |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
504 score_matrix <- ropls_x@scoreMN |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
505 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
|
506 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
|
507 result$covariance <- sapply( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
508 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
|
509 , 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
|
510 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
511 score_sd <- sapply( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
512 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
|
513 , 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
|
514 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
515 # 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
|
516 xSdVn <- ropls_x@xSdVn |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
517 result$correlation <- sapply( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
518 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
|
519 , FUN = function(x) { |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
520 ( 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
|
521 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
522 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
523 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
524 result$correlation <- result$correlation[1,,drop = TRUE] |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
525 result$covariance <- result$covariance[1,,drop = TRUE] |
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 # 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
|
528 # 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 # get the level names |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 # print(sprintf("sd(covariance) = %f; sd(correlation) = %f", sd(result$covariance), sd(result$correlation))) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
541 superresult <- list() |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
542 if (length(result$vip4o) == 0) result$vip4o <- NA |
1
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
543 greaterLevel <- sapply( X = result$correlation, FUN = function(my_corr) if ( my_corr < 0 ) fctr_lvl_1 else fctr_lvl_2 ) |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
544 superresult$tsv1 <- data.frame( |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
545 featureID = names(ropls_x@vipVn) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
546 , factorLevel1 = result$level1 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
547 , 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
|
548 , greaterLevel = greaterLevel |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
549 , correlation = result$correlation |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
550 , covariance = result$covariance |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
551 , vip4p = result$vip4p |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
552 , 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
|
553 , loadp = result$loadp |
0c2ad44b6c9c
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 01d4a951cf09e7b88fcec96b8043bc7568cc5c92
eschen42
parents:
0
diff
changeset
|
554 , loado = result$loado |
0
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
555 , row.names = NULL |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
556 ) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
557 rownames(superresult$tsv1) <- superresult$tsv1$featureID |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
558 superresult$covariance <- result$covariance |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
559 superresult$correlation <- result$correlation |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
560 superresult$vip4p <- result$vip4p |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 superresult$details <- result |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
565 # #print(superresult$tsv1) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
566 result$superresult <- superresult |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
567 # Include thise 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
|
568 result$oplsda <- ropls_x |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
569 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
|
570 return (superresult) |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
571 } |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
572 |
23f9fad4edfc
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
eschen42
parents:
diff
changeset
|
573 |