BiopetQScript.scala 3.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
19

Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.utils.config.Configurable
21
import nl.lumc.sasc.biopet.core.report.ReportBuilderExtension
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.utils.Logging
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
25
import org.broadinstitute.gatk.queue.function.scattergather.ScatterGatherableFunction
Peter van 't Hof's avatar
Peter van 't Hof committed
26
import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging }
27
28
import org.broadinstitute.gatk.utils.commandline.Argument

29
import scala.collection.mutable.ListBuffer
30

Peter van 't Hof's avatar
Peter van 't Hof committed
31
/** Base for biopet pipeline */
32
trait BiopetQScript extends Configurable with GatkLogging {
33

34
  @Argument(doc = "JSON / YAML config file(s)", fullName = "config_file", shortName = "config", required = false)
35
  val configfiles: List[File] = Nil
bow's avatar
bow committed
36

37
  @Argument(doc = "Config values, value should be formatted like 'key=value' or 'path:path:key=value'", fullName = "config_value", shortName = "cv", required = false)
38
39
  val configValues: List[String] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
40
  /** Output directory of pipeline */
Peter van 't Hof's avatar
Peter van 't Hof committed
41
  var outputDir: File = {
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
    if (config.contains("output_dir", path = Nil)) config("output_dir", path = Nil).asFile
    else new File(".")
44
  }
bow's avatar
bow committed
45

46
  @Argument(doc = "Disable all scatters", shortName = "DSC", required = false)
47
  var disableScatter: Boolean = false
48

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

Peter van 't Hof's avatar
Peter van 't Hof committed
51
  /** Get implemented from org.broadinstitute.gatk.queue.QScript */
Peter van 't Hof's avatar
Peter van 't Hof committed
52
  var qSettings: QSettings
bow's avatar
bow committed
53

Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
56
57
  /** Get implemented from org.broadinstitute.gatk.queue.QScript */
  var functions: Seq[QFunction]

  /** Init for pipeline */
58
  def init()
bow's avatar
bow committed
59

Peter van 't Hof's avatar
Peter van 't Hof committed
60
  /** Pipeline itself */
61
  def biopetScript()
Peter van 't Hof's avatar
Peter van 't Hof committed
62

63
64
65
  /** Returns the extension to make the report */
  def reportClass: Option[ReportBuilderExtension] = None

Peter van 't Hof's avatar
Peter van 't Hof committed
66
  /** Script from queue itself, final to force some checks for each pipeline and write report */
67
  final def script() {
Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
    outputDir = config("output_dir")
    outputDir = outputDir.getAbsoluteFile
70
71
    init()
    biopetScript()
72

73
    if (disableScatter) for (function <- functions) function match {
74
75
76
      case f: ScatterGatherableFunction => f.scatterCount = 1
      case _                            =>
    }
77
    for (function <- functions) function match {
78
      case f: BiopetCommandLineFunction =>
79
80
        f.preProcessExecutable()
        f.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
81
        f.commandLine
Peter van 't Hof's avatar
Peter van 't Hof committed
82
      case _ =>
83
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
84

Peter van 't Hof's avatar
Peter van 't Hof committed
85
86
    if (outputDir.getParentFile.canWrite || (outputDir.exists && outputDir.canWrite))
      globalConfig.writeReport(qSettings.runName, new File(outputDir, ".log/" + qSettings.runName))
Peter van 't Hof's avatar
Peter van 't Hof committed
87
    else Logging.addError("Parent of output dir: '" + outputDir.getParent + "' is not writeable, outputdir can not be created")
88

89
90
    reportClass.foreach(add(_))

Peter van 't Hof's avatar
Peter van 't Hof committed
91
    Logging.checkErrors()
92
  }
bow's avatar
bow committed
93

Peter van 't Hof's avatar
Peter van 't Hof committed
94
95
96
  /** Get implemented from org.broadinstitute.gatk.queue.QScript */
  def add(functions: QFunction*)

97
  /** Get implemented from org.broadinstitute.gatk.queue.QScript */
Peter van 't Hof's avatar
Peter van 't Hof committed
98
  def addAll(functions: scala.Traversable[org.broadinstitute.gatk.queue.function.QFunction])
99

100
  /** Function to set isIntermediate and add in 1 line */
bow's avatar
bow committed
101
  def add(function: QFunction, isIntermediate: Boolean = false) {
102
103
104
    function.isIntermediate = isIntermediate
    add(function)
  }
105
}