annotate waveica_wrapper.R @ 2:6480c6d5fa36 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
author recetox
date Fri, 23 Jun 2023 07:27:29 +0000
parents b77023c41c76
children dbbedb14b44c
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) {
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
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
112 feature_columns <- colnames(data)[!colnames(data) %in%
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
113 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
114 features <- data[, feature_columns]
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
115 injection_order <- data$injectionOrder
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
116
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
117 # run WaveICA
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
118 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
119 data = features,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
120 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
121 injection_order = injection_order,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
122 K = k,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
123 alpha = alpha,
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
124 cutoff = cutoff
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
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
127 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
128 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
129 # remove blanks from dataset
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
130 if (exclude_blanks) {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
131 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
132 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
133
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
134 return(data)
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
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
138 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
139 if ("batch" %in% colnames(data)) {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
140 data <- data[order(data[, "batch"],
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
141 data[, "injectionOrder"],
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
142 decreasing = FALSE
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
143 ), ]
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
144 } else {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
145 data <- data[order(data[, "injectionOrder"],
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
146 decreasing = FALSE
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
147 ), ]
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
148 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
149 return(data)
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
150 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
151
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
152
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
153 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
154 if (anyNA(data)) {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
155 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
156 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
157 } 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
158 stop(
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
159 "Error: missing metadata!
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
160 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
161 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
162 )
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
163 }
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
164
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
165 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
166
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
167 return(data)
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
168 }
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
169
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
170 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
171 # 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
172 column_types <- list(
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
173 "sampleName" = c("character", "factor"),
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
174 "class" = c("character", "factor"),
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
175 "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
176 "injectionOrder" = "integer",
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
177 "batch" = "integer"
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
178 )
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
179
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
180 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
181
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
182 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
183 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
184 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
185 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
186
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
187 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
188 stop(
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
189 "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
190 " 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
191 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
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 } else {
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
195 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
196 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
197 }
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
198 }
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
199 }
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
200 return(data)
0
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
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 # 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
205 enumerate_groups <- function(group) {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
206 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
207 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
208 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
209
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
210 return(group)
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
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 # 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
215 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
216 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
217
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
218 # 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
219 if (wf == "d2") {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
220 wf <- "haar"
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
221 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
222
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
223 return(wf)
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
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
226
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
227 # 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
228 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
229 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
230 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
231 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
232 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
233 return(data_without_blanks)
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
234 } else {
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
235 return(data)
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
236 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
237 }
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
238
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
239 store_data <- function(data, output, ext) {
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
240 if (ext == "csv") {
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
241 write.csv(data, file = output, row.names = FALSE, quote = FALSE)
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
242 } else if (ext == "tsv") {
2
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
243 write.table(data,
6480c6d5fa36 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 77bea6c84c5a932fa203723d4d5fea6147f06505
recetox
parents: 1
diff changeset
244 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
245 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
246 )
1
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
247 } else {
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
248 arrow::write_parquet(data, sink = output)
b77023c41c76 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
recetox
parents: 0
diff changeset
249 }
0
328710890963 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit 98e541a75678eee749261630610b946c258fd5f3"
recetox
parents:
diff changeset
250 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
251 }