BiopetQScript.scala 1.79 KB
Newer Older
1
2
3
package nl.lumc.sasc.biopet.core

import java.io.File
Peter van 't Hof's avatar
Peter van 't Hof committed
4
import java.io.PrintWriter
Peter van 't Hof's avatar
Peter van 't Hof committed
5
import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
Peter van 't Hof's avatar
Peter van 't Hof committed
6
import org.broadinstitute.gatk.utils.commandline.Argument
Peter van 't Hof's avatar
Peter van 't Hof committed
7
8
import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
9

10
trait BiopetQScript extends Configurable {
11

12
  @Argument(doc = "JSON config file(s)", fullName = "config_file", shortName = "config", required = false)
13
  val configfiles: List[File] = Nil
bow's avatar
bow committed
14

15
  @Argument(doc = "Output directory", fullName = "output_directory", shortName = "outDir", required = true)
16
  var outputDir: String = _
bow's avatar
bow committed
17

Peter van 't Hof's avatar
Peter van 't Hof committed
18
  @Argument(doc = "Use scatter defaults, env value BIOPET_CONFIG_SCATTER", shortName = "SC", required = false)
19
20
  var useScatterDefault: Boolean = false

bow's avatar
bow committed
21
22
  var outputFiles: Map[String, File] = Map()

Peter van 't Hof's avatar
Peter van 't Hof committed
23
  var qSettings: QSettings
bow's avatar
bow committed
24

25
26
  def init
  def biopetScript
bow's avatar
bow committed
27

28
  var functions: Seq[QFunction]
Peter van 't Hof's avatar
Peter van 't Hof committed
29

30
  final def script() {
31
    if (useScatterDefault) Config.global.loadDefaultScatterConfig
Peter van 't Hof's avatar
Peter van 't Hof committed
32
    if (!outputDir.endsWith("/")) outputDir += "/"
33
34
    init
    biopetScript
35
    for (function <- functions) function match {
Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
      case f: BiopetCommandLineFunctionTrait => f.afterGraph
      case _                                 =>
38
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
39
    val configReport = Config.global.getReport
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    val configReportFile = new File(outputDir + qSettings.runName + ".configreport.txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
41
    configReportFile.getParentFile.mkdir
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
44
45
    val writer = new PrintWriter(configReportFile)
    writer.write(configReport)
    writer.close()
    for (line <- configReport.split("\n")) logger.debug(line)
46
  }
bow's avatar
bow committed
47

48
  def add(functions: QFunction*) // Gets implemeted at org.broadinstitute.sting.queue.QScript
bow's avatar
bow committed
49
  def add(function: QFunction, isIntermediate: Boolean = false) {
50
51
52
    function.isIntermediate = isIntermediate
    add(function)
  }
bow's avatar
bow committed
53

54
}