From b52170d6643c857009f9d66b78e20c4832f4b457 Mon Sep 17 00:00:00 2001
From: DavyCats <davycats.dc@gmail.com>
Date: Thu, 24 May 2018 13:50:58 +0200
Subject: [PATCH] change R script

---
 mergecounts.wdl | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/mergecounts.wdl b/mergecounts.wdl
index e93068e..8aa2a92 100644
--- a/mergecounts.wdl
+++ b/mergecounts.wdl
@@ -3,8 +3,9 @@ task MergeCounts {
 
     Array[File] inputFiles
     String outputFile
-    String idVar
-    String measurementVar
+    Int featureColumn
+    Int valueColumn
+    Boolean inputHasHeader
 
     # Based on a script by Szymon Kielbasa/Ioannis Moustakas
     command <<<
@@ -17,15 +18,22 @@ task MergeCounts {
 
             listOfFiles <- c("${sep='", "' inputFiles}")
 
+            valueI <- ${valueColumn}
+            featureI <- ${featureColumn}
+            header <- ${true="TRUE" false="FALSE" inputHasHeader}
+
             d <- do.call(rbind, lapply(listOfFiles, function(file){
-                d <- read.table(file, header=TRUE, comment.char="#")
-                colI <- grep(${measurementVar}, colnames(d))
-                colnames(d)[colI] <- strsplit(file, "/")[[1]][3]
-                d <- d %>% melt(id.vars=${idVar}, measure.vars=colI,
-                    variable.name="sample", value.name="count")
+                d <- read.table(file, header=header, comment.char="#")
+
+                splitPath <- strsplit(file, "/")[[1]]
+                colnames(d)[valueI] <- sub("\\\.[^\\\.]*$", "",
+                    splitPath[length(splitPath)])
+                colnames(d)[featureI] <- "feature"
+
+                d <- d %>% melt(id.vars=featureI, variable.name="sample", value.name="count")
             }))
 
-            d <- d %>% dcast(paste0(${idVar}, " ~ sample"), value.var="count")
+            d <- d %>% dcast(feature ~ sample, value.var="count")
             write.table(d, sep="\t", quote=FALSE, row.names=FALSE)
         CODE
     >>>
-- 
GitLab