diff edger.R @ 14:070900306913 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/edger commit 0c79416d9612d0ebdcb7c3c0543d510e11bb0774
author iuc
date Wed, 11 Oct 2023 11:13:07 +0000
parents 0cb907a2a810
children 5bf899c13979
line wrap: on
line diff
--- a/edger.R	Wed Sep 27 19:53:04 2023 +0000
+++ b/edger.R	Wed Oct 11 11:13:07 2023 +0000
@@ -8,6 +8,7 @@
 #       matrixPath", "m", 2, "character"    -Path to count matrix
 #       factFile", "f", 2, "character"      -Path to factor information file
 #       factInput", "i", 2, "character"     -String containing factors if manually input
+#       formula", "F", 2, "character".      -String containing a formula to override default use of factInput
 #       annoPath", "a", 2, "character"      -Path to input containing gene annotations
 #       contrastData", "C", 1, "character"  -String containing contrasts of interest
 #       cpmReq", "c", 2, "double"           -Float specifying cpm requirement
@@ -159,6 +160,7 @@
   "filesPath", "j", 2, "character",
   "matrixPath", "m", 2, "character",
   "factFile", "f", 2, "character",
+  "formula", "F", 2, "character",
   "factInput", "i", 2, "character",
   "annoPath", "a", 2, "character",
   "contrastData", "C", 1, "character",
@@ -312,8 +314,13 @@
 out_path <- opt$outPath
 dir.create(out_path, showWarnings = FALSE)
 
-# Split up contrasts separated by comma into a vector then sanitise
-contrast_data <- unlist(strsplit(opt$contrastData, split = ","))
+# Check if contrastData is a file or not
+if (file.exists(opt$contrastData)) {
+  contrast_data <- unlist(read.table(opt$contrastData, sep = "\t", header = TRUE)[[1]])
+} else {
+  # Split up contrasts separated by comma into a vector then sanitise
+  contrast_data <- unlist(strsplit(opt$contrastData, split = ","))
+}
 contrast_data <- sanitise_equation(contrast_data)
 contrast_data <- gsub(" ", ".", contrast_data, fixed = TRUE)
 
@@ -397,10 +404,17 @@
 data$genes <- genes
 
 
-
-formula <- "~0"
-for (i in seq_along(factor_list)) {
-  formula <- paste(formula, factor_list[i], sep = "+")
+if (!is.null(opt$formula)) {
+  formula <- opt$formula
+  # sanitisation can be getting rid of the "~"
+  if (!startsWith(formula, "~")) {
+    formula <- paste0("~", formula)
+  }
+} else {
+  formula <- "~0"
+  for (i in seq_along(factor_list)) {
+    formula <- paste(formula, factor_list[i], sep = "+")
+  }
 }
 
 formula <- formula(formula)