comparison waveica_wrapper.R @ 1:b77023c41c76 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit d82e7dad96bebe9424ac7bf490e2786d82c3681a
author recetox
date Thu, 29 Sep 2022 15:21:04 +0000
parents 328710890963
children 6480c6d5fa36
comparison
equal deleted inserted replaced
0:328710890963 1:b77023c41c76
1 waveica <- function(data, 1 read_file <- function(file, metadata, ft_ext, mt_ext) {
2 data <- read_data(file, ft_ext)
3
4 if (!is.na(metadata)) {
5 mt_data <- read_data(metadata, mt_ext)
6 data <- merge(mt_data, data, by = "sampleName")
7 }
8
9 return(data)
10 }
11
12 read_data <- function(file, ext) {
13 if (ext == "csv") {
14 data <- read.csv(file, header = TRUE)
15 } else if (ext == "tsv") {
16 data <- read.csv(file, header = TRUE, sep = "\t")
17 } else {
18 data <- arrow::read_parquet(file)
19 }
20
21 return(data)
22 }
23
24 waveica <- function(file,
25 metadata = NA,
26 ext,
2 wavelet_filter, 27 wavelet_filter,
3 wavelet_length, 28 wavelet_length,
4 k, 29 k,
5 t, 30 t,
6 t2, 31 t2,
7 alpha, 32 alpha,
8 exclude_blanks) { 33 exclude_blanks) {
9 34
10 # get input from the Galaxy, preprocess data 35 # get input from the Galaxy, preprocess data
11 data <- read.csv(data, header = TRUE) 36 ext <- strsplit(x = ext, split = "\\,")[[1]]
37
38 ft_ext <- ext[1]
39 mt_ext <- ext[2]
40
41 data <- read_file(file, metadata, ft_ext, mt_ext)
12 42
13 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder", "batch") 43 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder", "batch")
14 verify_input_dataframe(data, required_columns) 44 verify_input_dataframe(data, required_columns)
15 45
16 data <- sort_by_injection_order(data) 46 data <- sort_by_injection_order(data)
41 } 71 }
42 72
43 return(data) 73 return(data)
44 } 74 }
45 75
46 76 waveica_singlebatch <- function(file,
47 waveica_singlebatch <- function(data, 77 metadata = NA,
78 ext,
48 wavelet_filter, 79 wavelet_filter,
49 wavelet_length, 80 wavelet_length,
50 k, 81 k,
51 alpha, 82 alpha,
52 cutoff, 83 cutoff,
53 exclude_blanks) { 84 exclude_blanks) {
54 85
55 # get input from the Galaxy, preprocess data 86 # get input from the Galaxy, preprocess data
56 data <- read.csv(data, header = TRUE) 87 ext <- strsplit(x = ext, split = "\\,")[[1]]
88
89 ft_ext <- ext[1]
90 mt_ext <- ext[2]
91
92 data <- read_file(file, metadata, ft_ext, mt_ext)
57 93
58 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder") 94 required_columns <- c("sampleName", "class", "sampleType", "injectionOrder")
59 optional_columns <- c("batch") 95 optional_columns <- c("batch")
60 verify_input_dataframe(data, required_columns) 96 verify_input_dataframe(data, required_columns)
61 97
145 } else { 181 } else {
146 return(data) 182 return(data)
147 } 183 }
148 } 184 }
149 185
150 186 store_data <- function(data, output, ext) {
151 # Store output of WaveICA in a tsv file 187 if (ext == "csv") {
152 store_data <- function(data, output) { 188 write.csv(data, file = output, row.names = FALSE, quote = FALSE)
153 write.table(data, file = output, sep = "\t", row.names = FALSE, quote = FALSE) 189 } else if (ext == "tsv") {
190 write.table(data, file = output, sep = "\t", row.names = FALSE, quote = FALSE)
191 } else {
192 arrow::write_parquet(data, sink = output)
193 }
154 cat("Normalization has been completed.\n") 194 cat("Normalization has been completed.\n")
155 } 195 }