diff waveica_wrapper.R @ 1:2bcfd5b450bb draft

"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/waveica commit c52cdb1ab3c4e65ce3b55e29739f16abb8bfd6eb"
author recetox
date Wed, 28 Jul 2021 11:58:20 +0000
parents 2461d20911c9
children d08deef1eb44
line wrap: on
line diff
--- a/waveica_wrapper.R	Thu Mar 18 15:53:38 2021 +0000
+++ b/waveica_wrapper.R	Wed Jul 28 11:58:20 2021 +0000
@@ -10,8 +10,12 @@
 ) {
 
     # get input from the Galaxy, preprocess data
-    data <- read.csv(data, header = TRUE, row.names = "sample_name")
-    data <- preprocess_data(data)
+    data <- read.csv(data, header = TRUE, row.names = "sampleName")
+
+    # sort data by injection order
+    data <- data[order(data$injectionOrder, decreasing = FALSE), ]
+
+    data <- enumerate_groups(data)
 
     # remove blanks from dataset
     if (exclude_blanks) {
@@ -39,14 +43,12 @@
 }
 
 
-# Sort data, set numerical values for groups
-preprocess_data <- function(data) {
-    # sort data by injection order
-    data <- data[order(data$injectionOrder, decreasing = FALSE), ]
+# Match group labels with [blank/sample/qc] and enumerate them
+enumerate_groups <- function(data) {
 
-    data$class[data$class == "blank"] <- 0
-    data$class[data$class == "sample"] <- 1
-    data$class[data$class == "QC"] <- 2
+    data$sampleType[grepl("blank", tolower(data$sampleType))] <- 0
+    data$sampleType[grepl("sample", tolower(data$sampleType))] <- 1
+    data$sampleType[grepl("qc", tolower(data$sampleType))] <- 2
 
     return(data)
 }
@@ -68,7 +70,7 @@
 # Exclude blanks from a dataframe
 exclude_group <- function(data) {
     row_idx_to_exclude <- which(data$class %in% 0)
-    if (length(row_idx_to_exclude) > 1) {
+    if (length(row_idx_to_exclude) > 0) {
         data_without_blanks <- data[-c(row_idx_to_exclude), ]
         msg <- paste("Blank samples have been excluded from the dataframe.\n")
         cat(msg)