From 4b6d158f7f83c0df76f0dc1fc89e5ef0d677029b Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Fri, 24 Oct 2014 15:58:54 +0200
Subject: [PATCH] Added FastqSplitter to exe

---
 .../sasc/biopet/core/BiopetExecutable.scala   |  3 ++-
 .../sasc/biopet/tools/FastqSplitter.scala     | 27 +++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/BiopetExecutable.scala b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/BiopetExecutable.scala
index d0134fd84..172e12d2b 100644
--- a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/BiopetExecutable.scala
+++ b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/BiopetExecutable.scala
@@ -28,7 +28,8 @@ object BiopetExecutable {
       nl.lumc.sasc.biopet.tools.VcfFilter,
       nl.lumc.sasc.biopet.tools.FindRepeatsPacBio,
       nl.lumc.sasc.biopet.tools.BedToInterval,
-      nl.lumc.sasc.biopet.tools.MpileupToVcf)
+      nl.lumc.sasc.biopet.tools.MpileupToVcf,
+      nl.lumc.sasc.biopet.tools.FastqSplitter)
   )
   
   /**
diff --git a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/FastqSplitter.scala b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/FastqSplitter.scala
index 66cb83cc5..c59d8a246 100644
--- a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/FastqSplitter.scala
+++ b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/FastqSplitter.scala
@@ -4,6 +4,7 @@ import java.io.{ BufferedInputStream, File, FileInputStream, PrintWriter }
 import java.util.zip.GZIPInputStream
 import nl.lumc.sasc.biopet.core.BiopetJavaCommandLineFunction
 import scala.io.Source
+import nl.lumc.sasc.biopet.core.ToolCommand
 import nl.lumc.sasc.biopet.core.config.Configurable
 import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
 
@@ -19,24 +20,34 @@ class FastqSplitter(val root: Configurable) extends BiopetJavaCommandLineFunctio
   override val defaultVmem = "8G"
   memoryLimit = Option(4.0)
 
-  override def commandLine = super.commandLine + required(input) + repeat(output)
+  override def commandLine = super.commandLine + required("-I", input) + repeat("-o", output)
 }
 
-object FastqSplitter {
+object FastqSplitter extends ToolCommand {
+  case class Args (inputFile:File = null, outputFile:List[File] = Nil) extends AbstractArgs
+
+  class OptParser extends AbstractOptParser {
+    opt[File]('I', "inputFile") required() valueName("<file>") action { (x, c) =>
+      c.copy(inputFile = x) } text("out is a required file property")
+    opt[File]('o', "output") required() unbounded() valueName("<file>") action { (x, c) =>
+      c.copy(outputFile = x :: c.outputFile) } text("out is a required file property")
+  }
+  
   /**
    * @param args the command line arguments
    */
   def main(args: Array[String]): Unit = {
+    val argsParser = new OptParser
+    val commandArgs: Args = argsParser.parse(args, Args()) getOrElse sys.exit(1)  
+    
     val groupsize = 100
-    val input = new File(args.head)
-    val output: Array[PrintWriter] = new Array[PrintWriter](args.tail.size)
-    for (t <- 1 to args.tail.size) output(t - 1) = new PrintWriter(args(t))
+    val output = for (file <- commandArgs.outputFile) yield new PrintWriter(file)
     val inputStream = {
-      if (input.getName.endsWith(".gz") || input.getName.endsWith(".gzip")) Source.fromInputStream(
+      if (commandArgs.inputFile.getName.endsWith(".gz") || commandArgs.inputFile.getName.endsWith(".gzip")) Source.fromInputStream(
         new GZIPInputStream(
           new BufferedInputStream(
-            new FileInputStream(input)))).bufferedReader
-      else Source.fromFile(input).bufferedReader
+            new FileInputStream(commandArgs.inputFile)))).bufferedReader
+      else Source.fromFile(commandArgs.inputFile).bufferedReader
     }
     while (inputStream.ready) {
       for (writter <- output) {
-- 
GitLab