annotate waveica_wrapper.R @ 8:bf32ae95a06f draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 44e9371974b176490222f96d532df2421571cbaa
author recetox
date Tue, 06 Aug 2024 14:27:48 +0000
parents 1a2aeb8137bf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
2 data <- read_data(file, ft_ext)
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
3
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
4 if (transpose) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
5 col_names <- c("sampleName", data[[1]])
7
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
6 data <- tranpose_data(data, col_names)
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
7 }
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
8
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
9 if (!is.na(metadata)) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
10 mt_data <- read_data(metadata, mt_ext)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
11 data <- merge(mt_data, data, by = "sampleName")
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
12 }
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
13
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
14 return(data)
1
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 read_data <- function(file, ext) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
18 if (ext == "csv") {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
19 data <- read.csv(file, header = TRUE)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
20 } else if (ext == "tsv") {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
21 data <- read.csv(file, header = TRUE, sep = "\t")
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
22 } else {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
23 data <- arrow::read_parquet(file)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
24 }
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
25
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
26 return(data)
1
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 waveica <- function(file,
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
30 metadata = NA,
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
31 ext,
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
32 transpose = FALSE,
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
33 wavelet_filter,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
34 wavelet_length,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
35 k,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
36 t,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
37 t2,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
38 alpha,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
39 exclude_blanks) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
40 # get input from the Galaxy, preprocess data
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
41 ext <- strsplit(x = ext, split = "\\,")[[1]]
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
42
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
43 ft_ext <- ext[1]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
44 mt_ext <- ext[2]
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
45
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
46 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
47
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
48 required_columns <- c(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
49 "sampleName", "class", "sampleType",
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
50 "injectionOrder", "batch"
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
51 )
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
52 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
53
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
54 data <- sort_by_injection_order(data)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
55
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
56 # separate data into features, batch and group
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
57 feature_columns <- colnames(data)[!colnames(data) %in% required_columns]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
58 features <- data[, feature_columns]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
59 group <- enumerate_groups(as.character(data$sampleType))
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
60 batch <- data$batch
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
61
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
62 # run WaveICA
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
63 features <- recetox.waveica::waveica(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
64 data = features,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
65 wf = get_wf(wavelet_filter, wavelet_length),
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
66 batch = batch,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
67 group = group,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
68 K = k,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
69 t = t,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
70 t2 = t2,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
71 alpha = alpha
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
72 )
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
73
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
74 data[, feature_columns] <- features
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
75
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
76 # remove blanks from dataset
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
77 if (exclude_blanks) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
78 data <- exclude_group(data, group)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
79 }
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
80
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
81 return(data)
0
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
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
84 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
85 metadata = NA,
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
86 ext,
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
87 transpose = FALSE,
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
88 wavelet_filter,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
89 wavelet_length,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
90 k,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
91 alpha,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
92 cutoff,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
93 exclude_blanks) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
94 # get input from the Galaxy, preprocess data
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
95 ext <- strsplit(x = ext, split = "\\,")[[1]]
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
96
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
97 ft_ext <- ext[1]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
98 mt_ext <- ext[2]
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
99
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
100 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
101
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
102 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder")
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
103 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
104
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
105 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
106
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
107 data <- sort_by_injection_order(data)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
108
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
109 feature_columns <- colnames(data)[!colnames(data) %in% c(required_columns, optional_columns)]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
110 features <- data[, feature_columns]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
111 injection_order <- data$injectionOrder
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
112
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
113 # run WaveICA
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
114 features <- recetox.waveica::waveica_nonbatchwise(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
115 data = features,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
116 wf = get_wf(wavelet_filter, wavelet_length),
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
117 injection_order = injection_order,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
118 K = k,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
119 alpha = alpha,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
120 cutoff = cutoff
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
121 )
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
122
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
123 data[, feature_columns] <- features
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
124 group <- enumerate_groups(as.character(data$sampleType))
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
125 # remove blanks from dataset
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
126 if (exclude_blanks) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
127 data <- exclude_group(data, group)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
128 }
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
129
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
130 return(data)
0
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 sort_by_injection_order <- function(data) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
134 if ("batch" %in% colnames(data)) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
135 data <- data[order(data[, "batch"], data[, "injectionOrder"], decreasing = FALSE), ]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
136 } else {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
137 data <- data[order(data[, "injectionOrder"], decreasing = FALSE), ]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
138 }
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
139 return(data)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
140 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
141
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
142 verify_input_dataframe <- function(data, required_columns) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
143 if (anyNA(data)) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
144 stop("Error: dataframe cannot contain NULL values!
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
145 Make sure that your dataframe does not contain empty cells")
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
146 } else if (!all(required_columns %in% colnames(data))) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
147 stop(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
148 "Error: missing metadata!
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
149 Make sure that the following columns are present in your dataframe: ",
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
150 paste(required_columns, collapse = ", ")
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
151 )
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
152 }
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
153
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
154 data <- verify_column_types(data, required_columns)
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
155
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
156 return(data)
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
157 }
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 verify_column_types <- function(data, required_columns) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
160 # Specify the column names and their expected types
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
161 column_types <- list(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
162 "sampleName" = c("character", "factor"),
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
163 "class" = c("character", "factor", "integer"),
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
164 "sampleType" = c("character", "factor"),
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
165 "injectionOrder" = "integer",
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
166 "batch" = "integer"
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
167 )
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
168
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
169 column_types <- column_types[required_columns]
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
170
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
171 for (col_name in names(data)) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
172 actual_type <- class(data[[col_name]])
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
173 if (col_name %in% names(column_types)) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
174 expected_types <- column_types[[col_name]]
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
175
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
176 if (!actual_type %in% expected_types) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
177 stop(
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
178 "Column ", col_name, " is of type ", actual_type,
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
179 " but expected type is ",
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
180 paste(expected_types, collapse = " or "), "\n"
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
181 )
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
182 }
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
183 } else {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
184 if (actual_type != "numeric") {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
185 data[[col_name]] <- as.numeric(as.character(data[[col_name]]))
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
186 }
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
187 }
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
188 }
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
189 return(data)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
190 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
191
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
192 # 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
193 enumerate_groups <- function(group) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
194 group[grepl("blank", tolower(group))] <- 0
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
195 group[grepl("sample", tolower(group))] <- 1
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
196 group[grepl("qc", tolower(group))] <- 2
8
bf32ae95a06f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 44e9371974b176490222f96d532df2421571cbaa
recetox
parents: 7
diff changeset
197 group[grepl("standard", tolower(group))] <- 3
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
198
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
199 return(group)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
200 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
201
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
202 # 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
203 get_wf <- function(wavelet_filter, wavelet_length) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
204 wf <- paste(wavelet_filter, wavelet_length, sep = "")
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
205
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
206 # exception to the wavelet function
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
207 if (wf == "d2") {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
208 wf <- "haar"
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
209 }
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
210
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
211 return(wf)
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
212 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
213
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
214 # 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
215 exclude_group <- function(data, group) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
216 row_idx_to_exclude <- which(group %in% 0)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
217 if (length(row_idx_to_exclude) > 0) {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
218 data_without_blanks <- data[-c(row_idx_to_exclude), ]
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
219 cat("Blank samples have been excluded from the dataframe.\n")
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
220 return(data_without_blanks)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
221 } else {
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
222 return(data)
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
223 }
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
224 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
225
7
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
226 store_data <- function(data, feature_output, metadata_output, ext, split_output = FALSE) {
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
227 if (ext == "parquet") {
7
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
228 if (split_output == TRUE) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
229 split_df <- split_output(data)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
230 arrow::write_parquet(split_df$metadata, metadata_output)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
231 arrow::write_parquet(split_df$feature_table, feature_output)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
232 } else {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
233 arrow::write_parquet(data, feature_output)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
234 }
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
235 } else {
7
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
236 if (split_output == TRUE) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
237 split_df <- split_output(data)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
238 write.table(split_df$metadata,
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
239 file = metadata_output, sep = "\t",
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
240 row.names = FALSE, quote = FALSE
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
241 )
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
242 write.table(split_df$feature_table,
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
243 file = feature_output, sep = "\t",
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
244 row.names = FALSE, quote = FALSE
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
245 )
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
246 } else {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
247 write.table(data,
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
248 file = feature_output, sep = "\t",
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
249 row.names = FALSE, quote = FALSE
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
250 )
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
251 }
6
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
252 }
071a424241ec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 5
diff changeset
253 cat("Normalization has been completed.\n")
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
254 }
7
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
255
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
256 split_output <- function(df) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
257 required_columns_set1 <- c("sampleName", "class", "sampleType", "injectionOrder", "batch")
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
258 required_columns_set2 <- c("sampleName", "class", "sampleType", "injectionOrder")
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
259
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
260 if (all(required_columns_set1 %in% colnames(df))) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
261 metadata_df <- df[, required_columns_set1, drop = FALSE]
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
262 df <- df[, -c(2:5)]
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
263 } else if (all(required_columns_set2 %in% colnames(df))) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
264 metadata_df <- df[, required_columns_set2, drop = FALSE]
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
265 df <- df[, -c(2:4)]
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
266 } else {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
267 stop("Neither set of required columns is present in the dataframe.")
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
268 }
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
269
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
270 # Transpose the feature table
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
271 col_names <- c("id", as.vector(df[[1]]))
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
272 feature_table <- tranpose_data(df, col_names)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
273
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
274 return(list(metadata = metadata_df, feature_table = feature_table))
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
275 }
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
276
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
277 tranpose_data <- function(data, column_names) {
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
278 t_data <- data[-1]
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
279 t_data <- t(t_data)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
280 tranposed_data <- data.frame(rownames(t_data), t_data)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
281 colnames(tranposed_data) <- column_names
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
282
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
283 return(tranposed_data)
1a2aeb8137bf planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 013d7c85fa9d77b8a27d194b350cd6b2d127a80f
recetox
parents: 6
diff changeset
284 }