annotate execute_dwt_var_perFeature.R @ 3:6c29c7e347e8 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
author devteam
date Mon, 06 Jul 2020 20:34:27 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
1 #####################################################################
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
2 ## plot multiscale wavelet variance
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
3 ## create null bands by permuting the original data series
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
4 ## generate plots and table of wavelet variance including p-values
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
5 #######################################################################
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
6 options(echo = FALSE)
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
7 library("wavethresh");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
8 library("waveslim");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
9 library("bitops");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
10
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
11 ## to determine if data is properly formatted 2^N observations
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
12 is_power2 <- function(x) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
13 x && !(bitops::bitAnd(x, x - 1));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
14 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
15
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
16 ## dwt : discrete wavelet transform using Haar wavelet filter, simplest wavelet function but later can modify to let user-define the wavelet filter function
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
17 dwt_var_permut_get_max <- function(data, names, alpha, filter = 1, family = "DaubExPhase", bc = "symmetric", method = "kendall", wf = "haar", boundary = "reflection") {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
18 title <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
19 final_pvalue <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
20 j <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
21 scale <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
22 out <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
23
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
24 print(class(data));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
25 print(names);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
26 print(alpha);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
27
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
28 par(mar = c(5, 4, 4, 3), oma = c(4, 4, 3, 2), xaxt = "s", cex = 1, las = 1);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
29
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
30 title <- c("Wavelet", "Variance", "Pvalue", "Test");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
31 print(title);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
32
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
33 for (i in seq_len(length(names))) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
34 temp <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
35 results <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
36 wave1_dwt <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
37
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
38 ## if data fails formatting check, do something
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
39 print(is.numeric(as.matrix(data)[, i]));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
40 if (!is.numeric(as.matrix(data)[, i])) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
41 stop("data must be a numeric vector");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
42 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
43 print(length(as.matrix(data)[, i]));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
44 print(is_power2(length(as.matrix(data)[, i])));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
45 if (!is_power2(length(as.matrix(data)[, i]))) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
46 stop("data length must be a power of two");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
47 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
48 j <- wavethresh::wd(as.matrix(data)[, i], filter.number = filter, family = family, bc = bc)$nlevels;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
49 print(j);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
50 temp <- vector(length = j);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
51 wave1_dwt <- waveslim::dwt(as.matrix(data)[, i], wf = wf, j, boundary = boundary);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
52
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
53 temp <- waveslim::wave.variance(wave1_dwt)[- (j + 1), 1];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
54 print(temp);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
55
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
56 ##permutations code :
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
57 feature1 <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
58 null <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
59 var_lower <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
60 limit_lower <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
61 var_upper <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
62 limit_upper <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
63 med <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
64
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
65 limit_lower <- alpha / 2 * 1000;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
66 print(limit_lower);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
67 limit_upper <- (1 - alpha / 2) * 1000;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
68 print(limit_upper);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
69
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
70 feature1 <- as.matrix(data)[, i];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
71 for (k in 1:1000) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
72 nk_1 <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
73 null_levels <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
74 var <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
75 null_wave1 <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
76
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
77 nk_1 <- sample(feature1, length(feature1), replace = FALSE);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
78 null_levels <- wavethresh::wd(nk_1, filter.number = filter, family = family, bc = bc)$nlevels;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
79 var <- vector(length = length(null_levels));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
80 null_wave1 <- waveslim::dwt(nk_1, wf = wf, j, boundary = boundary);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
81 var <- waveslim::wave.variance(null_wave1)[- (null_levels + 1), 1];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
82 null <- rbind(null, var);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
83 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
84 null <- apply(null, 2, sort, na.last = TRUE);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
85 var_lower <- null[limit_lower, ];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
86 var_upper <- null[limit_upper, ];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
87 med <- (apply(null, 2, median, na.rm = TRUE));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
88
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
89 ## plot
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
90 results <- cbind(temp, var_lower, var_upper);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
91 print(results);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
92 matplot(results, type = "b", pch = "*", lty = 1, col = c(1, 2, 2), xaxt = "n", xlab = "Wavelet Scale", ylab = "Wavelet variance");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
93 mtext(names[i], side = 3, line = 0.5, cex = 1);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
94 axis(1, at = 1:j, labels = c(2 ^ (0:(j - 1))), las = 3, cex.axis = 1);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
95
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
96 ## get pvalues by comparison to null distribution
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
97 for (m in seq_len(length(temp))) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
98 print(paste("scale", m, sep = " "));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
99 print(paste("var", temp[m], sep = " "));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
100 print(paste("med", med[m], sep = " "));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
101 pv <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
102 tail <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
103 scale <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
104 scale <- 2 ^ (m - 1);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
105 if (temp[m] >= med[m]) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
106 ## R tail test
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
107 print("R");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
108 tail <- "R";
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
109 pv <- (length(which(null[, m] >= temp[m]))) / (length(na.exclude(null[, m])));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
110 } else {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
111 if (temp[m] < med[m]) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
112 ## L tail test
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
113 print("L");
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
114 tail <- "L";
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
115 pv <- (length(which(null[, m] <= temp[m]))) / (length(na.exclude(null[, m])));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
116 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
117 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
118 print(pv);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
119 out <- rbind(out, c(paste("Scale", scale, sep = "_"), format(temp[m], digits = 3), pv, tail));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
120 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
121 final_pvalue <- rbind(final_pvalue, out);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
122 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
123 colnames(final_pvalue) <- title;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
124 return(final_pvalue);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
125 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
126
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
127 ## execute
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
128 ## read in data
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
129 args <- commandArgs(trailingOnly = TRUE)
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
130
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
131 data_test <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
132 final <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
133 sub <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
134 sub_names <- NULL;
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
135 data_test <- read.delim(args[1], header = FALSE);
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
136 pdf(file = args[5], width = 11, height = 8)
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
137 for (f in strsplit(args[2], ",")) {
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
138 f <- as.integer(f)
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
139 if (f > ncol(data_test))
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
140 stop(paste("column", f, "doesn't exist"));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
141 sub <- data_test[, f];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
142 sub_names <- colnames(data_test)[f];
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
143 final <- rbind(final, dwt_var_permut_get_max(sub, sub_names, as.double(args[3])));
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
144 }
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
145
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
146 dev.off();
6c29c7e347e8 "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/dwt_var_perfeature commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
devteam
parents:
diff changeset
147 write.table(final, file = args[4], sep = "\t", quote = FALSE, row.names = FALSE);