BiopetQScript.scala 2.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
 * A dual licensing mode is applied. The source code within this project that are
 * not part of GATK Queue is freely available for non-commercial use under an AGPL
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
16
17
18
package nl.lumc.sasc.biopet.core

import java.io.File
Peter van 't Hof's avatar
Peter van 't Hof committed
19
import java.io.PrintWriter
Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import org.broadinstitute.gatk.utils.commandline.Argument
Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
24
import org.broadinstitute.gatk.queue.function.scattergather.ScatterGatherableFunction
25
import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging }
26

27
trait BiopetQScript extends Configurable with GatkLogging {
28

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

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

35
36
  @Argument(doc = "Disable all scatters", shortName = "DSC", required = false)
  var disableScatterDefault: Boolean = false
37

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

Peter van 't Hof's avatar
Peter van 't Hof committed
40
  var qSettings: QSettings
bow's avatar
bow committed
41

42
43
  def init
  def biopetScript
bow's avatar
bow committed
44

45
  var functions: Seq[QFunction]
Peter van 't Hof's avatar
Peter van 't Hof committed
46

47
  final def script() {
Peter van 't Hof's avatar
Peter van 't Hof committed
48
    if (!outputDir.endsWith("/")) outputDir += "/"
49
50
    init
    biopetScript
51
52
53
54
55

    if (disableScatterDefault) for (function <- functions) function match {
      case f: ScatterGatherableFunction => f.scatterCount = 1
      case _                            =>
    }
56
    for (function <- functions) function match {
Peter van 't Hof's avatar
Peter van 't Hof committed
57
58
      case f: BiopetCommandLineFunctionTrait => f.afterGraph
      case _                                 =>
59
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
60
    val configReport = Config.global.getReport
Peter van 't Hof's avatar
Peter van 't Hof committed
61
    val configReportFile = new File(outputDir + qSettings.runName + ".configreport.txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
62
    configReportFile.getParentFile.mkdir
Peter van 't Hof's avatar
Peter van 't Hof committed
63
64
65
    val writer = new PrintWriter(configReportFile)
    writer.write(configReport)
    writer.close()
66
    Config.global.writeReport(qSettings.runName, outputDir + ".log/" + qSettings.runName)
Peter van 't Hof's avatar
Peter van 't Hof committed
67
    for (line <- configReport.split("\n")) logger.debug(line)
68
  }
bow's avatar
bow committed
69

70
  def add(functions: QFunction*) // Gets implemeted at org.broadinstitute.sting.queue.QScript
bow's avatar
bow committed
71
  def add(function: QFunction, isIntermediate: Boolean = false) {
72
73
74
    function.isIntermediate = isIntermediate
    add(function)
  }
bow's avatar
bow committed
75

76
}