Mercurial > repos > recetox > waveica
annotate waveica_wrapper.R @ 1:2bcfd5b450bb draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
| author | recetox |
|---|---|
| date | Wed, 28 Jul 2021 11:58:20 +0000 |
| parents | 2461d20911c9 |
| children | d08deef1eb44 |
| rev | line source |
|---|---|
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
1 waveica <- function( |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
2 data, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
3 wavelet_filter, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
4 wavelet_length, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
5 k, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
6 t, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
7 t2, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
8 alpha, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
9 exclude_blanks |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
10 ) { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
11 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
12 # get input from the Galaxy, preprocess data |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
13 data <- read.csv(data, header = TRUE, row.names = "sampleName") |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
14 |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
15 # sort data by injection order |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
16 data <- data[order(data$injectionOrder, decreasing = FALSE), ] |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
17 |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
18 data <- enumerate_groups(data) |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
19 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
20 # remove blanks from dataset |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
21 if (exclude_blanks) { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
22 data <- exclude_group(data) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
23 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
24 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
25 # separate data into features, batch and group |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
26 features <- data[, -c(1:4)] |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
27 group <- as.numeric(data$class) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
28 batch <- data$batch |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
29 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
30 # run WaveICA |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
31 normalized_data <- WaveICA::WaveICA( |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
32 data = features, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
33 wf = get_wf(wavelet_filter, wavelet_length), |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
34 batch = batch, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
35 group = group, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
36 K = k, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
37 t = t, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
38 t2 = t2, |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
39 alpha = alpha |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
40 ) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
41 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
42 return(normalized_data) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
43 } |
|
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 |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
46 # Match group labels with [blank/sample/qc] and enumerate them |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
47 enumerate_groups <- function(data) { |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
48 |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
49 data$sampleType[grepl("blank", tolower(data$sampleType))] <- 0 |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
50 data$sampleType[grepl("sample", tolower(data$sampleType))] <- 1 |
|
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
51 data$sampleType[grepl("qc", tolower(data$sampleType))] <- 2 |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
52 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
53 return(data) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
54 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
55 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
56 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
57 # 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
|
58 get_wf <- function(wavelet_filter, wavelet_length) { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
59 wf <- paste(wavelet_filter, wavelet_length, sep = "") |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
60 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
61 # exception to the wavelet function |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
62 if (wf == "d2") { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
63 wf <- "haar" |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
64 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
65 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
66 return(wf) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
67 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
68 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
69 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
70 # Exclude blanks from a dataframe |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
71 exclude_group <- function(data) { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
72 row_idx_to_exclude <- which(data$class %in% 0) |
|
1
2bcfd5b450bb
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
recetox
parents:
0
diff
changeset
|
73 if (length(row_idx_to_exclude) > 0) { |
|
0
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
74 data_without_blanks <- data[-c(row_idx_to_exclude), ] |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
75 msg <- paste("Blank samples have been excluded from the dataframe.\n") |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
76 cat(msg) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
77 return(data_without_blanks) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
78 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
79 else { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
80 return(data) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
81 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
82 } |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
83 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
84 |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
85 # Store output of WaveICA in a tsv file |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
86 store_data <- function(normalized_data, output) { |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
87 write.table(normalized_data, file = output, sep = "\t", col.names = NA) |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
88 cat("Normalization has been completed.\n") |
|
2461d20911c9
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 91376ea7a6736351b0cc086ca1bc6c553fdcda97"
recetox
parents:
diff
changeset
|
89 } |
