Mercurial > repos > recetox > waveica
annotate waveica_wrapper.R @ 4:8b55efc7d117 draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
| author | recetox |
|---|---|
| date | Mon, 10 Jan 2022 16:01:35 +0000 |
| parents | d08deef1eb44 |
| children | cf3f2f964d80 |
| rev | line source |
|---|---|
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
1 waveica <- function(data, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
2 wavelet_filter, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
3 wavelet_length, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
4 k, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
5 t, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
6 t2, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
7 alpha, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
8 exclude_blanks) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
9 |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
10 # get input from the Galaxy, preprocess data |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
11 data <- read.csv(data, header = TRUE) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
12 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
13 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder", "batch") |
|
4
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
14 verify_input_dataframe(data, required_columns) |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
15 |
|
4
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
16 data <- sort_by_injection_order(data) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
17 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
18 # separate data into features, batch and group |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
19 feature_columns <- colnames(data)[!colnames(data) %in% required_columns] |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
20 features <- data[, feature_columns] |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
21 group <- enumerate_groups(as.character(data$sampleType)) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
22 batch <- data$batch |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
23 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
24 # run WaveICA |
|
4
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
25 features <- recetox.waveica::waveica( |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
26 data = features, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
27 wf = get_wf(wavelet_filter, wavelet_length), |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
28 batch = batch, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
29 group = group, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
30 K = k, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
31 t = t, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
32 t2 = t2, |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
33 alpha = alpha |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
34 ) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
35 |
|
4
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
36 data[, feature_columns] <- features |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
37 |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
38 # remove blanks from dataset |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
39 if (exclude_blanks) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
40 data <- exclude_group(data, group) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
41 } |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
42 |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
43 return(data) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
44 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
45 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
46 |
|
4
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
47 waveica_singlebatch <- function(data, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
48 wavelet_filter, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
49 wavelet_length, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
50 k, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
51 alpha, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
52 cutoff, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
53 exclude_blanks) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
54 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
55 # get input from the Galaxy, preprocess data |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
56 data <- read.csv(data, header = TRUE) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
57 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
58 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder") |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
59 optional_columns <- c("batch") |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
60 verify_input_dataframe(data, required_columns) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
61 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
62 data <- sort_by_injection_order(data) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
63 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
64 feature_columns <- colnames(data)[!colnames(data) %in% c(required_columns, optional_columns)] |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
65 features <- data[, feature_columns] |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
66 injection_order <- data$injectionOrder |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
67 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
68 # run WaveICA |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
69 features <- recetox.waveica::waveica_nonbatchwise( |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
70 data = features, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
71 wf = get_wf(wavelet_filter, wavelet_length), |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
72 injection_order = injection_order, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
73 K = k, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
74 alpha = alpha, |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
75 cutoff = cutoff |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
76 ) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
77 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
78 data[, feature_columns] <- features |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
79 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
80 # remove blanks from dataset |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
81 if (exclude_blanks) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
82 data <- exclude_group(data, group) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
83 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
84 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
85 return(data) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
86 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
87 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
88 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
89 sort_by_injection_order <- function(data) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
90 if ("batch" %in% colnames(data)) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
91 data <- data[order(data[, "batch"], |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
92 data[, "injectionOrder"], |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
93 decreasing = FALSE |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
94 ), ] |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
95 } else { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
96 data <- data[order(data[, "injectionOrder"], |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
97 decreasing = FALSE |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
98 ), ] |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
99 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
100 return(data) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
101 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
102 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
103 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
104 verify_input_dataframe <- function(data, required_columns) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
105 if (anyNA(data)) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
106 stop("Error: dataframe cannot contain NULL values! |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
107 Make sure that your dataframe does not contain empty cells") |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
108 } else if (!all(required_columns %in% colnames(data))) { |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
109 stop("Error: missing metadata! |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
110 Make sure that the following columns are present in your dataframe: ", paste(required_columns, collapse = ", ")) |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
111 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
112 } |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
113 |
|
8b55efc7d117
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit aa8206a01efc1813f2586584782f28a73a17fe86"
recetox
parents:
2
diff
changeset
|
114 |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
115 # Match group labels with [blank/sample/qc] and enumerate them |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
116 enumerate_groups <- function(group) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
117 group[grepl("blank", tolower(group))] <- 0 |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
118 group[grepl("sample", tolower(group))] <- 1 |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
119 group[grepl("qc", tolower(group))] <- 2 |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
120 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
121 return(group) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
122 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
123 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
124 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
125 # Create appropriate input for R wavelets function |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
126 get_wf <- function(wavelet_filter, wavelet_length) { |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
127 wf <- paste(wavelet_filter, wavelet_length, sep = "") |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
128 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
129 # exception to the wavelet function |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
130 if (wf == "d2") { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
131 wf <- "haar" |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
132 } |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
133 |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
134 return(wf) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
135 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
136 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
137 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
138 # Exclude blanks from a dataframe |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
139 exclude_group <- function(data, group) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
140 row_idx_to_exclude <- which(group %in% 0) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
141 if (length(row_idx_to_exclude) > 0) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
142 data_without_blanks <- data[-c(row_idx_to_exclude), ] |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
143 cat("Blank samples have been excluded from the dataframe.\n") |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
144 return(data_without_blanks) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
145 } else { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
146 return(data) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
147 } |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
148 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
149 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
150 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
151 # Store output of WaveICA in a tsv file |
|
2
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
152 store_data <- function(data, output) { |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
153 write.table(data, file = output, sep = "\t", row.names = FALSE, quote = FALSE) |
|
d08deef1eb44
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit e33ef984e78721ed37d825c6672795a539a461e1"
recetox
parents:
1
diff
changeset
|
154 cat("Normalization has been completed.\n") |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
155 } |
