Mercurial > repos > recetox > waveica
annotate waveica_wrapper.R @ 5:e424fa636281 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 7f555d50250b4664e8e0d7e0f8794e505c175502
author | recetox |
---|---|
date | Mon, 20 May 2024 09:20:13 +0000 |
parents | 425c0494ec2d |
children | 071a424241ec |
rev | line source |
---|---|
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
1 read_file <- function(file, metadata, ft_ext, mt_ext, transpose) { |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
2 data <- read_data(file, ft_ext) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
3 |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
4 if (transpose) { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
5 col_names <- c("sampleName", data[[1]]) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
6 t_data <- data[-1] |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
7 t_data <- t(t_data) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
8 data <- data.frame(rownames(t_data), t_data) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
9 colnames(data) <- col_names |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
10 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
11 |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
12 if (!is.na(metadata)) { |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
13 mt_data <- read_data(metadata, mt_ext) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
14 data <- merge(mt_data, data, by = "sampleName") |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
15 } |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
16 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
17 return(data) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
18 } |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
19 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
20 read_data <- function(file, ext) { |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
21 if (ext == "csv") { |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
22 data <- read.csv(file, header = TRUE) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
23 } else if (ext == "tsv") { |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
24 data <- read.csv(file, header = TRUE, sep = "\t") |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
25 } else { |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
26 data <- arrow::read_parquet(file) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
27 } |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
28 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
29 return(data) |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
30 } |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
31 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
32 waveica <- function(file, |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
33 metadata = NA, |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
34 ext, |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
35 transpose = FALSE, |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
36 wavelet_filter, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
37 wavelet_length, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
38 k, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
39 t, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
40 t2, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
41 alpha, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
42 exclude_blanks) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
43 # get input from the Galaxy, preprocess data |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
44 ext <- strsplit(x = ext, split = "\\,")[[1]] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
45 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
46 ft_ext <- ext[1] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
47 mt_ext <- ext[2] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
48 |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
49 data <- read_file(file, metadata, ft_ext, mt_ext, transpose) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
50 |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
51 required_columns <- c( |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
52 "sampleName", "class", "sampleType", |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
53 "injectionOrder", "batch" |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
54 ) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
55 data <- verify_input_dataframe(data, required_columns) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
56 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
57 data <- sort_by_injection_order(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
58 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
59 # separate data into features, batch and group |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
60 feature_columns <- colnames(data)[!colnames(data) %in% required_columns] |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
61 features <- data[, feature_columns] |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
62 group <- enumerate_groups(as.character(data$sampleType)) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
63 batch <- data$batch |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
64 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
65 # run WaveICA |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
66 features <- recetox.waveica::waveica( |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
67 data = features, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
68 wf = get_wf(wavelet_filter, wavelet_length), |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
69 batch = batch, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
70 group = group, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
71 K = k, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
72 t = t, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
73 t2 = t2, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
74 alpha = alpha |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
75 ) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
76 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
77 data[, feature_columns] <- features |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
78 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
79 # remove blanks from dataset |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
80 if (exclude_blanks) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
81 data <- exclude_group(data, group) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
82 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
83 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
84 return(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
85 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
86 |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
87 waveica_singlebatch <- function(file, |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
88 metadata = NA, |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
89 ext, |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
90 transpose = FALSE, |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
91 wavelet_filter, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
92 wavelet_length, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
93 k, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
94 alpha, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
95 cutoff, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
96 exclude_blanks) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
97 # get input from the Galaxy, preprocess data |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
98 ext <- strsplit(x = ext, split = "\\,")[[1]] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
99 |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
100 ft_ext <- ext[1] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
101 mt_ext <- ext[2] |
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
102 |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
103 data <- read_file(file, metadata, ft_ext, mt_ext, transpose) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
104 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
105 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder") |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
106 optional_columns <- c("batch") |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
107 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
108 data <- verify_input_dataframe(data, required_columns) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
109 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
110 data <- sort_by_injection_order(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
111 |
3
dbbedb14b44c
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents:
2
diff
changeset
|
112 feature_columns <- colnames(data)[!colnames(data) %in% c(required_columns, optional_columns)] |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
113 features <- data[, feature_columns] |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
114 injection_order <- data$injectionOrder |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
115 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
116 # run WaveICA |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
117 features <- recetox.waveica::waveica_nonbatchwise( |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
118 data = features, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
119 wf = get_wf(wavelet_filter, wavelet_length), |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
120 injection_order = injection_order, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
121 K = k, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
122 alpha = alpha, |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
123 cutoff = cutoff |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
124 ) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
125 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
126 data[, feature_columns] <- features |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
127 group <- enumerate_groups(as.character(data$sampleType)) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
128 # remove blanks from dataset |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
129 if (exclude_blanks) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
130 data <- exclude_group(data, group) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
131 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
132 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
133 return(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
134 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
135 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
136 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
137 sort_by_injection_order <- function(data) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
138 if ("batch" %in% colnames(data)) { |
3
dbbedb14b44c
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents:
2
diff
changeset
|
139 data <- data[order(data[, "batch"], data[, "injectionOrder"], decreasing = FALSE), ] |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
140 } else { |
3
dbbedb14b44c
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents:
2
diff
changeset
|
141 data <- data[order(data[, "injectionOrder"], decreasing = FALSE), ] |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
142 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
143 return(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
144 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
145 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
146 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
147 verify_input_dataframe <- function(data, required_columns) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
148 if (anyNA(data)) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
149 stop("Error: dataframe cannot contain NULL values! |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
150 Make sure that your dataframe does not contain empty cells") |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
151 } else if (!all(required_columns %in% colnames(data))) { |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
152 stop( |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
153 "Error: missing metadata! |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
154 Make sure that the following columns are present in your dataframe: ", |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
155 paste(required_columns, collapse = ", ") |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
156 ) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
157 } |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
158 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
159 data <- verify_column_types(data, required_columns) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
160 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
161 return(data) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
162 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
163 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
164 verify_column_types <- function(data, required_columns) { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
165 # Specify the column names and their expected types |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
166 column_types <- list( |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
167 "sampleName" = c("character", "factor"), |
5
e424fa636281
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 7f555d50250b4664e8e0d7e0f8794e505c175502
recetox
parents:
4
diff
changeset
|
168 "class" = c("character", "factor", "integer"), |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
169 "sampleType" = c("character", "factor"), |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
170 "injectionOrder" = "integer", |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
171 "batch" = "integer" |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
172 ) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
173 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
174 column_types <- column_types[required_columns] |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
175 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
176 for (col_name in names(data)) { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
177 actual_type <- class(data[[col_name]]) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
178 if (col_name %in% names(column_types)) { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
179 expected_types <- column_types[[col_name]] |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
180 |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
181 if (!actual_type %in% expected_types) { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
182 stop( |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
183 "Column ", col_name, " is of type ", actual_type, |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
184 " but expected type is ", |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
185 paste(expected_types, collapse = " or "), "\n" |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
186 ) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
187 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
188 } else { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
189 if (actual_type != "numeric") { |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
190 data[[col_name]] <- as.numeric(as.character(data[[col_name]])) |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
191 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
192 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
193 } |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
194 return(data) |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
195 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
196 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
197 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
198 # Match group labels with [blank/sample/qc] and enumerate them |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
199 enumerate_groups <- function(group) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
200 group[grepl("blank", tolower(group))] <- 0 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
201 group[grepl("sample", tolower(group))] <- 1 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
202 group[grepl("qc", tolower(group))] <- 2 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
203 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
204 return(group) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
205 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
206 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
207 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
208 # Create appropriate input for R wavelets function |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
209 get_wf <- function(wavelet_filter, wavelet_length) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
210 wf <- paste(wavelet_filter, wavelet_length, sep = "") |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
211 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
212 # exception to the wavelet function |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
213 if (wf == "d2") { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
214 wf <- "haar" |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
215 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
216 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
217 return(wf) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
218 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
219 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
220 |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
221 # Exclude blanks from a dataframe |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
222 exclude_group <- function(data, group) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
223 row_idx_to_exclude <- which(group %in% 0) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
224 if (length(row_idx_to_exclude) > 0) { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
225 data_without_blanks <- data[-c(row_idx_to_exclude), ] |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
226 cat("Blank samples have been excluded from the dataframe.\n") |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
227 return(data_without_blanks) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
228 } else { |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
229 return(data) |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
230 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
231 } |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
232 |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
233 store_data <- function(data, output, ext) { |
4
425c0494ec2d
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 84de3bc96ad2859d87c70ba94d8ceb0b2bc2a0da
recetox
parents:
3
diff
changeset
|
234 if (ext == "parquet") { |
425c0494ec2d
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 84de3bc96ad2859d87c70ba94d8ceb0b2bc2a0da
recetox
parents:
3
diff
changeset
|
235 arrow::write_parquet(data, output) |
425c0494ec2d
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 84de3bc96ad2859d87c70ba94d8ceb0b2bc2a0da
recetox
parents:
3
diff
changeset
|
236 } else { |
2
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
237 write.table(data, |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
238 file = output, sep = "\t", |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
239 row.names = FALSE, quote = FALSE |
6480c6d5fa36
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents:
1
diff
changeset
|
240 ) |
1
b77023c41c76
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents:
0
diff
changeset
|
241 } |
0
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
242 cat("Normalization has been completed.\n") |
328710890963
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff
changeset
|
243 } |