Mercurial > repos > recetox > waveica
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 0:2461d20911c9 | 1:2bcfd5b450bb |
|---|---|
| 8 alpha, | 8 alpha, |
| 9 exclude_blanks | 9 exclude_blanks |
| 10 ) { | 10 ) { |
| 11 | 11 |
| 12 # get input from the Galaxy, preprocess data | 12 # get input from the Galaxy, preprocess data |
| 13 data <- read.csv(data, header = TRUE, row.names = "sample_name") | 13 data <- read.csv(data, header = TRUE, row.names = "sampleName") |
| 14 data <- preprocess_data(data) | 14 |
| 15 # sort data by injection order | |
| 16 data <- data[order(data$injectionOrder, decreasing = FALSE), ] | |
| 17 | |
| 18 data <- enumerate_groups(data) | |
| 15 | 19 |
| 16 # remove blanks from dataset | 20 # remove blanks from dataset |
| 17 if (exclude_blanks) { | 21 if (exclude_blanks) { |
| 18 data <- exclude_group(data) | 22 data <- exclude_group(data) |
| 19 } | 23 } |
| 37 | 41 |
| 38 return(normalized_data) | 42 return(normalized_data) |
| 39 } | 43 } |
| 40 | 44 |
| 41 | 45 |
| 42 # Sort data, set numerical values for groups | 46 # Match group labels with [blank/sample/qc] and enumerate them |
| 43 preprocess_data <- function(data) { | 47 enumerate_groups <- function(data) { |
| 44 # sort data by injection order | |
| 45 data <- data[order(data$injectionOrder, decreasing = FALSE), ] | |
| 46 | 48 |
| 47 data$class[data$class == "blank"] <- 0 | 49 data$sampleType[grepl("blank", tolower(data$sampleType))] <- 0 |
| 48 data$class[data$class == "sample"] <- 1 | 50 data$sampleType[grepl("sample", tolower(data$sampleType))] <- 1 |
| 49 data$class[data$class == "QC"] <- 2 | 51 data$sampleType[grepl("qc", tolower(data$sampleType))] <- 2 |
| 50 | 52 |
| 51 return(data) | 53 return(data) |
| 52 } | 54 } |
| 53 | 55 |
| 54 | 56 |
| 66 | 68 |
| 67 | 69 |
| 68 # Exclude blanks from a dataframe | 70 # Exclude blanks from a dataframe |
| 69 exclude_group <- function(data) { | 71 exclude_group <- function(data) { |
| 70 row_idx_to_exclude <- which(data$class %in% 0) | 72 row_idx_to_exclude <- which(data$class %in% 0) |
| 71 if (length(row_idx_to_exclude) > 1) { | 73 if (length(row_idx_to_exclude) > 0) { |
| 72 data_without_blanks <- data[-c(row_idx_to_exclude), ] | 74 data_without_blanks <- data[-c(row_idx_to_exclude), ] |
| 73 msg <- paste("Blank samples have been excluded from the dataframe.\n") | 75 msg <- paste("Blank samples have been excluded from the dataframe.\n") |
| 74 cat(msg) | 76 cat(msg) |
| 75 return(data_without_blanks) | 77 return(data_without_blanks) |
| 76 } | 78 } |
