diff ruvseq.R @ 4:3a083c78896e draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ruvseq commit 30117fce22f3771c9c0c13e70c3ad14b694de6e2
author iuc
date Fri, 21 Apr 2023 14:09:17 +0000
parents fed9d0350d72
children
line wrap: on
line diff
--- a/ruvseq.R	Fri Jul 23 22:37:45 2021 +0000
+++ b/ruvseq.R	Fri Apr 21 14:09:17 2023 +0000
@@ -1,7 +1,8 @@
 # setup R error handling to go to stderr
 library("getopt")
-options(show.error.messages = F, error = function() {
-  cat(geterrmessage(), file = stderr()); q("no", 1, F)
+options(show.error.messages = FALSE, error = function() {
+  cat(geterrmessage(), file = stderr())
+  q("no", 1, FALSE)
 })
 options(stringAsFactors = FALSE, useFancyQuotes = FALSE)
 
@@ -17,7 +18,8 @@
     "plots", "p", 1, "character",
     "header", "H", 0, "logical",
     "txtype", "y", 1, "character",
-    "tx2gene", "x", 1, "character"), # a space-sep tx-to-gene map or GTF file (auto detect .gtf/.GTF)
+    "tx2gene", "x", 1, "character", # a space-sep tx-to-gene map or GTF file (auto detect .gtf/.GTF)
+    "ruv_ncounts", "ruv_ncounts", 0, "logical"),
     byrow = TRUE, ncol = 4)
 
   opt <- getopt(spec)
@@ -155,6 +157,7 @@
 min_k <- opt$min_k
 max_k <- opt$max_k
 min_c <- opt$min_mean_count
+ruv_ncounts <- ifelse(is.null(opt$ruv_ncounts), FALSE, TRUE)
 sample_json <- fromJSON(opt$sample_json)
 sample_paths <- sample_json$path
 sample_names <- sample_json$label
@@ -183,8 +186,14 @@
     df <- data.frame(identifier = rownames(unwanted_variation))
     df <- cbind(df, unwanted_variation)
     colnames(df)[2] <- "condition"
-    write.table(df, file = paste0("batch_effects_", name, ".tabular"),  sep = "\t", quote = F, row.names = F)
+    write.table(df, file = paste0("uv_batch_effects_", name, ".tabular"),  sep = "\t", quote = FALSE, row.names = FALSE)
+    if (ruv_ncounts) {
+      ruvnorm_counts <- normCounts(set)
+      ruvnorm_df <- data.frame(geneID = rownames(ruvnorm_counts), ruvnorm_counts)
+      write.table(ruvnorm_df, file = paste0("ruv_norm_counts_", name, ".tabular"),  sep = "\t", quote = FALSE, row.names = FALSE)
+    }
   }
+
 }
 
 # close the plot device