From 8d1950103ae5ebb84629c80ee1d2ac82bcc85c9d Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Mon, 26 May 2014 17:34:10 +0200
Subject: [PATCH] Small changes on config setup

---
 .../nl/lumc/sasc/biopet/core/Config.scala     |  5 +-
 .../nl/lumc/sasc/biopet/wrappers/Bwa.scala    | 24 ++++-----
 .../nl/lumc/sasc/biopet/wrappers/Fastqc.scala | 35 +++++++++----
 .../nl/lumc/sasc/biopet/wrappers/Sickle.scala | 51 ++++++++++++++-----
 .../nl/lumc/sasc/biopet/wrappers/Star.scala   | 18 +++----
 .../nl/lumc/sasc/biopet/wrappers/Zcat.scala   |  1 +
 flexiprep/examples/test.json                  |  9 ++++
 .../pipelines/flexiprep/FastqSync.scala       | 34 -------------
 .../pipelines/flexiprep/FastqcToContams.scala | 28 ----------
 .../flexiprep/FastqcToQualtype.scala          | 26 ----------
 10 files changed, 96 insertions(+), 135 deletions(-)
 create mode 100644 flexiprep/examples/test.json
 delete mode 100644 flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqSync.scala
 delete mode 100644 flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToContams.scala
 delete mode 100644 flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToQualtype.scala

diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/core/Config.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/core/Config.scala
index 86419cb89..fcb564a90 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/core/Config.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/core/Config.scala
@@ -15,7 +15,10 @@ class Config(private var map: Map[String,Any]) extends Logging {
     var globalFile: String = System.getenv("QUEUE_CONFIG")
     if (globalFile != null) {
       var file: File = new File(globalFile)
-      if (file.exists()) loadConfigFile(file)
+      if (file.exists()) {
+        logger.info("Loading config file: " + file)
+        loadConfigFile(file)
+      }
       else logger.warn("QUEUE_CONFIG value  found but file does not exist, no glogal config is loaded")
     } else logger.warn("QUEUE_CONFIG value not found, no glogal config is loaded")
   }
diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Bwa.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Bwa.scala
index 51aa345d3..1c08a4f68 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Bwa.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Bwa.scala
@@ -10,27 +10,25 @@ class Bwa(val globalConfig: Config) extends CommandLineFunction {
   def this() = this(new Config(Map()))
   this.analysisName = "bwa"
   val config: Config = globalConfig.getAsConfig("bwa")
+  logger.debug("Config for " + this.analysisName + ": " + config)
 
-  @Argument(doc="Bwa executeble", shortName="bwa_exe", required=false) var bwa_exe: String = _
-  @Input(doc="The reference file for the bam files.", shortName="R") var referenceFile: File = _
+  @Argument(doc="Bwa executeble", shortName="bwa_exe", required=false) var bwa_exe: String = config.getAsString("exe", "/usr/local/bin/bwa")
+  @Input(doc="The reference file for the bam files.", shortName="R") var referenceFile: File = new File(config.getAsString("referenceFile"))
   @Input(doc="Fastq file R1", shortName="R1") var R1: File = _
   @Input(doc="Fastq file R2", shortName="R2", required=false) var R2: File = _
   @Output(doc="Output file SAM", shortName="output") var output: File = _
   
   @Argument(doc="Readgroup header", shortName="RG", required=false) var RG: String = _
-  @Argument(doc="M", shortName="M", required=false) var M: Boolean = false
+  @Argument(doc="M", shortName="M", required=false) var M: Boolean = config.getAsBoolean("M", true)
+  
+  jobResourceRequests :+= "h_vmem=" + config.getAsString("vmem", "6G")
+  
+  var threads: Int = config.getAsInt("threads", 8)
+  var maxThreads: Int = config.getAsInt("maxthreads", 24)
+  if (threads > maxThreads) threads = maxThreads
+  nCoresRequest = Option(threads)
   
   def init() {
-    bwa_exe = config.getAsString("exe", "/usr/local/bin/bwa")
-    M = config.getAsBoolean("M", true)
-    jobResourceRequests :+= "h_vmem=" + config.getAsString("vmem", "6G")
-    var threads: Int = config.getAsInt("threads", 8)
-    var maxThreads: Int = config.getAsInt("maxthreads", 24)
-    if (threads > maxThreads) threads = maxThreads
-    nCoresRequest = Option(threads)
-    
-    referenceFile = new File(config.getAsString("referenceFile"))
-    
     this.addJobReportBinding("version", getVersion)
   }
   
diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Fastqc.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Fastqc.scala
index f88be9c15..4a41ff7f5 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Fastqc.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Fastqc.scala
@@ -10,6 +10,7 @@ class Fastqc(val globalConfig: Config) extends CommandLineFunction {
   def this() = this(new Config(Map()))
   this.analysisName = "fastqc"
   val config: Config = globalConfig.getAsConfig("fastqc")
+  logger.debug("Config for " + this.analysisName + ": " + config)
   
   @Input(doc="fastqc executeble", shortName="Fastqc_Exe")
   var fastqc_exe: File = new File(config.getAsString("exe","/usr/local/FastQC/FastQC_v0.10.1/fastqc"))
@@ -25,10 +26,17 @@ class Fastqc(val globalConfig: Config) extends CommandLineFunction {
   @Input(doc="Fastq file", shortName="FQ") var fastqfile: File = _
   @Output(doc="Output", shortName="out") var output: File = _
   
-  def commandLine = {
+  if (config.contains("vmem")) jobResourceRequests :+= "h_vmem=" + config.getAsString("vmem")
+    
+  def init() {
     this.addJobReportBinding("version", getVersion)
-    if (config.contains("fastqc_exe")) fastqc_exe = new File(config.get("fastqc_exe").toString)
-    this.nCoresRequest = Option(threads)
+    var maxThreads: Int = config.getAsInt("maxthreads", 24)
+    if (threads > maxThreads) threads = maxThreads
+    nCoresRequest = Option(threads)
+  }
+  
+  def commandLine = {
+    init()
     required(fastqc_exe) + 
       optional("--java", java_exe) +
       optional("--threads",threads) +
@@ -43,17 +51,22 @@ class Fastqc(val globalConfig: Config) extends CommandLineFunction {
   }
   
   private var version: String = _
-  def getVersion : String = {
-    val REG = """FastQC (.*)""".r
-    if (version == null) for (line <- (fastqc_exe + " --version").!!.split("\n")) {
+  var versionCommand = fastqc_exe + " --version"
+  var versionRegex = """FastQC (.*)"""
+  def getVersion: String = getVersion(versionCommand, versionRegex)
+  def getVersion(cmd:String, regex:String) : String = {
+    val REG = regex.r
+    if (cmd.! != 0) {
+      logger.warn("Version command: '" + cmd + "' give a none-zero exit code, version not found")
+      return "NA"
+    }
+    for (line <- cmd.!!.split("\n")) {
       line match { 
-        case REG(m) => {
-            version = m
-            return version
-        }
+        case REG(m) => return m
         case _ =>
       }
     }
-    return version
+    logger.warn("Version command: '" + cmd + "' give a exit code 0 but no version was found, executeble oke?")
+    return "NA"
   }
 }
\ No newline at end of file
diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Sickle.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Sickle.scala
index 3c39d8760..ac4db136f 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Sickle.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Sickle.scala
@@ -11,23 +11,28 @@ class Sickle(val globalConfig: Config) extends CommandLineFunction {
   def this() = this(new Config(Map()))
   this.analysisName = "sickle"
   val config: Config = globalConfig.getAsConfig("sickle")
+  logger.debug("Config for " + this.analysisName + ": " + config)
   
-  @Input(doc="Sickle exe", required=false) var sickle_exe: File = new File("/usr/local/bin/sickle")
+  @Input(doc="Sickle exe", required=false) var sickle_exe: File = new File(config.getAsString("exe", "/usr/local/bin/sickle"))
   @Input(doc="R1 input") var input_R1: File = null
   @Input(doc="R2 input", required=false) var input_R2: File = null
   @Output(doc="R1 output") var output_R1: File = null
   @Output(doc="R2 output", required=false) var output_R2: File = null
   @Output(doc="singles output", required=false) var output_singles: File = null
   @Output(doc="stats output") var output_stats: File = null
-
   @Input(doc="qualityType file", required=false) var qualityTypeFile: File = null
-  var qualityType: String = config.getAsString("qualitytype", null)
+  @Argument(doc="Quality Type", required=false) var qualityType: String = config.getAsString("qualitytype", null)
+  
   var defaultQualityType: String = config.getAsString("defaultqualitytype", "sanger")
-
-  def commandLine = {
+  
+  def init() {
     this.addJobReportBinding("version", getVersion)
     this.getQualityTypeFromFile
     if (qualityType == null && defaultQualityType != null) qualityType = defaultQualityType
+  }
+  
+  def commandLine = {
+    init()
     var cmd: String = required(sickle_exe)
     if (input_R2 != null) {
       cmd += required("pe") +
@@ -54,18 +59,38 @@ class Sickle(val globalConfig: Config) extends CommandLineFunction {
     }
   }
   
+//  private var version: String = _
+//  def getVersion : String = {
+//    val REG = """sickle version (.*)""".r
+//    if (version == null) for (line <- (sickle_exe + " --version").!!.split("\n")) {
+//      line match { 
+//        case REG(m) => {
+//            version = m
+//            return version
+//        }
+//        case _ =>
+//      }
+//    }
+//    return version
+//  }
+  
   private var version: String = _
-  def getVersion : String = {
-    val REG = """sickle version (.*)""".r
-    if (version == null) for (line <- (sickle_exe + " --version").!!.split("\n")) {
+  var versionCommand = sickle_exe + " --version"
+  var versionRegex = """sickle version (.*)"""
+  def getVersion: String = getVersion(versionCommand, versionRegex)
+  def getVersion(cmd:String, regex:String) : String = {
+    val REG = regex.r
+    if (cmd.! != 0) {
+      logger.warn("Version command: '" + cmd + "' give a none-zero exit code, version not found")
+      return "NA"
+    }
+    for (line <- cmd.!!.split("\n")) {
       line match { 
-        case REG(m) => {
-            version = m
-            return version
-        }
+        case REG(m) => return m
         case _ =>
       }
     }
-    return version
+    logger.warn("Version command: '" + cmd + "' give a exit code 0 but no version was found, executeble oke?")
+    return "NA"
   }
 }
\ No newline at end of file
diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Star.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Star.scala
index c6c241b6b..6580013f8 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Star.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Star.scala
@@ -10,30 +10,30 @@ class Star(val globalConfig: Config) extends CommandLineFunction {
   def this() = this(new Config(Map()))
   this.analysisName = "STAR"
   val config: Config = globalConfig.getAsConfig("star")
-
+  logger.debug("Config for " + this.analysisName + ": " + config)
+  
   @Argument(doc="STAR executeble", shortName="star_exe", required=false)
   var star_exe: String = config.getAsString("exe", "/usr/local/bin/STAR")
   @Input(doc="The reference file for the bam files.", shortName="R") var referenceFile: File = new File(config.getAsString("referenceFile"))
   @Input(doc="Fastq file R1", shortName="R1") var R1: File = _
   @Input(doc="Fastq file R2", shortName="R2", required=false) var R2: File = _
   @Argument(doc="Output Directory", shortName="outputDir") var outputDir: String = _
-  @Argument(doc="GenomeDir", required=false) var genomeDir: String = _
-  if (genomeDir == null) genomeDir = config.getAsString("genomeDir", referenceFile.getParent + "/star")
-  
+  @Argument(doc="GenomeDir", required=false) var genomeDir: String = config.getAsString("genomeDir", referenceFile.getParent + "/star")
   @Argument(doc="STAR runmode", shortName="runmode", required=false) var runmode: String = _
+  @Output var outputSam: File = new File(outputDir + "/Aligned.out.sam")
   
-  this.addJobReportBinding("version", "NA")
-
   jobResourceRequests :+= "h_vmem=" + config.getAsString("vmem", "6G")
   var threads: Int = config.getAsInt("threads", 8)
   var maxThreads: Int = config.getAsInt("maxthreads", 24)
   if (threads > maxThreads) threads = maxThreads
   nCoresRequest = Option(threads)
-
-  @Output var outputSam: File = new File(outputDir + "/Aligned.out.sam")
+  
+  def init() {
+    this.addJobReportBinding("version", "NA")
+  }
   
   def commandLine : String= {
-    //init()
+    init()
     var cmd: String = required("cd",outputDir) + "&&" + required(star_exe)
     if (runmode != null && runmode == "genomeGenerate") { // Create index
       cmd += required("--runmode", runmode) +
diff --git a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Zcat.scala b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Zcat.scala
index f307616d3..8c0e3de2d 100644
--- a/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Zcat.scala
+++ b/biopet-framework/src/main/java/nl/lumc/sasc/biopet/wrappers/Zcat.scala
@@ -9,6 +9,7 @@ class Zcat(val globalConfig: Config) extends CommandLineFunction {
     def this() = this(new Config(Map()))
     this.analysisName = "zcat"
     val config: Config = globalConfig.getAsConfig("zcat")
+    logger.debug("Config for " + this.analysisName + ": " + config)
 	  
     @Input(doc="Zipped file") var in: File = _
     @Output(doc="Unzipped file") var out: File = _
diff --git a/flexiprep/examples/test.json b/flexiprep/examples/test.json
new file mode 100644
index 000000000..59469ffd4
--- /dev/null
+++ b/flexiprep/examples/test.json
@@ -0,0 +1,9 @@
+{
+    "fastqc": { "exe": "/home/pjvan_thof/Downloads/FastQC/fastqc" },
+    
+    "flexiprep": {
+        "fastqc": {"exe":"/home/pjvan_thof/pipelines/test/test"},
+        "cutadapt": {"exe":"/home/pjvan_thof/pipelines/test/test"},
+        "sickle": {"exe":"/home/pjvan_thof/pipelines/test/test"}
+    }
+}
diff --git a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqSync.scala b/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqSync.scala
deleted file mode 100644
index b33d93384..000000000
--- a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqSync.scala
+++ /dev/null
@@ -1,34 +0,0 @@
-package nl.lumc.sasc.biopet.pipelines.flexiprep
-
-import nl.lumc.sasc.biopet.core._
-import org.broadinstitute.sting.queue.function.CommandLineFunction
-import org.broadinstitute.sting.commandline._
-import java.io.File
-
-class FastqSync(private var config: Config) extends CommandLineFunction {
-  def this() = this(new Config(Map()))
-  analysisName = "FastqSync"
-  
-  @Argument(doc="Pyhton exe", shortName="script") var python_exe: String = "python"
-  @Input(doc="Pyhton script", shortName="script")
-  var python_script: File = new File("/home/jfjlaros/projects/ngs-misc/trunk/src/sync_paired_end_reads.py")
-  
-  @Input(doc="Start fastq") var input_start_fastq: File = _
-  @Input(doc="R1 input") var input_R1: File = _
-  @Input(doc="R2 input") var input_R2: File = _
-  @Output(doc="R1 output") var output_R1: File = _
-  @Output(doc="R2 output") var output_R2: File = _
-  @Output(doc="stats output") var output_stats: File = _
-  
-  def commandLine = {
-    required(python_exe) + 
-    required(python_script) +
-    required(input_start_fastq) +
-    required(input_R1) +
-    required(input_R2) +
-    required(output_R1) +
-    required(output_R2) +
-    " > " +
-    required(output_stats)
-  }
-}
\ No newline at end of file
diff --git a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToContams.scala b/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToContams.scala
deleted file mode 100644
index a17196301..000000000
--- a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToContams.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-package nl.lumc.sasc.biopet.pipelines.flexiprep
-
-import nl.lumc.sasc.biopet.core._
-import org.broadinstitute.sting.queue.function.CommandLineFunction
-import org.broadinstitute.sting.commandline._
-import java.io.File
-
-class FastqcToContams(private var config: Config) extends CommandLineFunction {
-  def this() = this(new Config(Map()))
-  analysisName = "getContams"
-  
-  @Argument(doc="Pyhton exe", shortName="script") var python_exe: String = "python"
-  @Input(doc="Pyhton script", shortName="script")
-  var python_script: File = new File("/data/DIV5/SASC/project-057-Florentine/analysis/pipelines/magpie/modules/gatk01/modules/flexiprep/scripts/fastqc_contam.py")
-  @Input(doc="Fastqc output", shortName="fastqc", required=true) var fastqc_output: File = _
-  @Input(doc="Contams input", shortName="fastqc", required=true) var contams_file: File = _
-  @Output(doc="Output file", shortName="out", required=true) var out: File = _
-  
-  
-  def commandLine = {
-    required(python_exe) + 
-    required(python_script) +
-    required(fastqc_output.getParent()) +
-    required("-c",contams_file) + 
-    " > " +
-    required(out)
-  }
-}
\ No newline at end of file
diff --git a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToQualtype.scala b/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToQualtype.scala
deleted file mode 100644
index 6227a49e6..000000000
--- a/flexiprep/src/main/java/nl/lumc/sasc/biopet/pipelines/flexiprep/FastqcToQualtype.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-package nl.lumc.sasc.biopet.pipelines.flexiprep
-
-import nl.lumc.sasc.biopet.core._
-import org.broadinstitute.sting.queue.function.CommandLineFunction
-import org.broadinstitute.sting.commandline._
-import java.io.File
-
-class FastqcToQualtype(private var config: Config) extends CommandLineFunction {
-  def this() = this(new Config(Map()))
-  analysisName = "getQualtype"
-  
-  @Argument(doc="Pyhton exe", shortName="script") var python_exe: String = "python"
-  @Input(doc="Pyhton script", shortName="script")
-  var python_script: File = new File("/data/DIV5/SASC/project-057-Florentine/analysis/pipelines/magpie/modules/gatk01/modules/flexiprep/scripts/qual_type_sickle.py")
-  @Input(doc="Fastqc output", shortName="fastqc", required=true) var fastqc_output: File = _
-  @Output(doc="Output file", shortName="out", required=true) var out: File = _
-  
-  
-  def commandLine = {
-    required(python_exe) + 
-    required(python_script) +
-    required(fastqc_output.getParent()) +
-    " > " +
-    required(out)
-  }
-}
\ No newline at end of file
-- 
GitLab