From b6b2b73ed31e2fa023b92adc9414083f79d435df Mon Sep 17 00:00:00 2001 From: DavyCats <davycats.dc@gmail.com> Date: Tue, 20 Mar 2018 10:09:45 +0100 Subject: [PATCH] change to heredoc --- mergecounts.wdl | 28 ++++++++++++++++++++-------- scripts/merge_counts.R | 28 ---------------------------- 2 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 scripts/merge_counts.R diff --git a/mergecounts.wdl b/mergecounts.wdl index c71247d..de4bee4 100644 --- a/mergecounts.wdl +++ b/mergecounts.wdl @@ -3,15 +3,27 @@ task MergeCounts { String outputFile String idVar String measurementVar - File script - command { - Rscript ${script} \ - ${idVar} \ - ${measurementVar} \ - ${sep=" " inputFiles} \ - > ${outputFile} - } + # Based on a script by Szymon Kielbasa/Ioannis Moustakas + command <<< + R --no-save --slave <<CODE > ${outputFile} + library(dplyr) + library(reshape2) + + listOfFiles <- c("${sep='", "' inputFiles}") + + 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 <- d %>% dcast(paste0(${idVar}, " ~ sample"), value.var="count") + write.table(d, sep="\t", quote=FALSE, row.names=FALSE) + CODE + >>> output { File mergedCounts = outputFile diff --git a/scripts/merge_counts.R b/scripts/merge_counts.R deleted file mode 100644 index 8963994..0000000 --- a/scripts/merge_counts.R +++ /dev/null @@ -1,28 +0,0 @@ -# Author: Ioannis Moustakas, i.moustakas@lumc.nl (Based on a script by Szymon Kielbasa) -# Modified by: Davy Cats, d.cats@lumc.nl -# Title: Merge count files from featureCouns output -# Use: Rscript merge_counts.R columnIDToMergeOn columnIDBeingMerged listOfFilesToBeMerged... > outputFile - -### Load Packages -library(dplyr) -library(reshape2) - -### load arguments from the command line -args <- commandArgs(trailingOnly=TRUE) -idVars <- args[1] -measureVars <- args[2] -listOfFiles <- args[3:length(args)] - -### Iterate over the list of files that are being merged and -### change the column name to the sample name -d <- do.call(rbind, lapply(listOfFiles, function(file){ - d <- read.table(file, header=TRUE, comment.char="#") - colI <- grep(measureVars, colnames(d)) - colnames(d)[colI] <- strsplit(file, "/")[[1]][3] - d <- d %>% melt(id.vars=idVars, measure.vars=colI, - variable.name="sample", value.name="count") -})) - -### Reformat the data frame and output (in STDOUT) the merged table. -d <- d %>% dcast(paste0(idVars, " ~ sample"), value.var="count") -write.table(d, sep="\t", quote=FALSE, row.names=FALSE) -- GitLab