Kopisu.scala 3.55 KB
Newer Older
Wai Yi Leung's avatar
Wai Yi Leung committed
1
2
3
4
5
6
7
8
9
10
/**
 * 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
 *
11
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
Wai Yi Leung's avatar
Wai Yi Leung committed
12
13
14
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
Wai Yi Leung's avatar
Wai Yi Leung committed
15
package nl.lumc.sasc.biopet.pipelines.kopisu
Wai Yi Leung's avatar
Wai Yi Leung committed
16

Peter van 't Hof's avatar
Peter van 't Hof committed
17
import nl.lumc.sasc.biopet.core.summary.SummaryQScript
Sander Bollen's avatar
Sander Bollen committed
18
19
20
import nl.lumc.sasc.biopet.core.{ PipelineCommand, Reference }
import nl.lumc.sasc.biopet.pipelines.kopisu.methods.{ CnmopsMethod, ConiferMethod, FreecMethod, XhmmMethod }
import nl.lumc.sasc.biopet.utils.{ BamUtils, Logging }
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.utils.config.Configurable
Wai Yi Leung's avatar
Wai Yi Leung committed
22
import org.broadinstitute.gatk.queue.QScript
23

Peter van 't Hof's avatar
Peter van 't Hof committed
24
import scala.language.reflectiveCalls
Wai Yi Leung's avatar
Wai Yi Leung committed
25

Peter van 't Hof's avatar
Peter van 't Hof committed
26
class Kopisu(val root: Configurable) extends QScript with SummaryQScript with Reference {
27
  qscript =>
Wai Yi Leung's avatar
Wai Yi Leung committed
28
29
  def this() = this(null)

30
  @Input(doc = "Bam files (should be deduped bams)", shortName = "BAM", required = true)
Wai Yi Leung's avatar
Wai Yi Leung committed
31
  protected[kopisu] var inputBamsArg: List[File] = Nil
32
33

  var inputBams: Map[String, File] = Map()
Wai Yi Leung's avatar
Wai Yi Leung committed
34

35
  def init(): Unit = {
36
    if (inputBamsArg.nonEmpty) inputBams = BamUtils.sampleBamMap(inputBamsArg)
Peter van 't Hof's avatar
Peter van 't Hof committed
37
    if (inputBams.isEmpty) Logging.addError("No input bams found")
38
  }
Wai Yi Leung's avatar
Wai Yi Leung committed
39

Peter van 't Hof's avatar
Peter van 't Hof committed
40
41
42
43
  lazy val freecMethod = if (config("use_freec_method", default = true)) {
    Some(new FreecMethod(this))
  } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46
47
  lazy val coniferMethod = if (config("use_conifer_method", default = false)) {
    Some(new ConiferMethod(this))
  } else None

48
49
50
51
  lazy val cnMopsMethod = if (config("use_cnmops_method", default = false)) {
    Some(new CnmopsMethod(this))
  } else None

Sander Bollen's avatar
Sander Bollen committed
52
53
54
55
  lazy val xhmmMethod = if (config("use_xhmm_method", default = false)) {
    Some(new XhmmMethod(this))
  } else None

56
  // This script is in fact FreeC only.
Wai Yi Leung's avatar
Wai Yi Leung committed
57
  def biopetScript() {
Sander Bollen's avatar
Sander Bollen committed
58
    if (freecMethod.isEmpty && coniferMethod.isEmpty && cnMopsMethod.isEmpty && xhmmMethod.isEmpty) Logging.addError("No CNV method selected")
Peter van 't Hof's avatar
Peter van 't Hof committed
59

Peter van 't Hof's avatar
Peter van 't Hof committed
60
61
62
63
64
    freecMethod.foreach { method =>
      method.inputBams = inputBams
      method.outputDir = new File(outputDir, "freec_method")
      add(method)
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
65

Peter van 't Hof's avatar
Peter van 't Hof committed
66
67
68
69
70
71
    coniferMethod.foreach { method =>
      method.inputBams = inputBams
      method.outputDir = new File(outputDir, "conifer_method")
      add(method)
    }

72
73
74
75
76
77
    cnMopsMethod.foreach { method =>
      method.inputBams = inputBams
      method.outputDir = new File(outputDir, "cnmops_method")
      add(method)
    }

Sander Bollen's avatar
Sander Bollen committed
78
    xhmmMethod.foreach { method =>
Sander Bollen's avatar
Sander Bollen committed
79
      method.inputBams = inputBams
Sander Bollen's avatar
Sander Bollen committed
80
      method.outputDir = new File(outputDir, "xhmm_method")
Sander Bollen's avatar
Sander Bollen committed
81
      add(method)
Sander Bollen's avatar
Sander Bollen committed
82
83
    }

Peter van 't Hof's avatar
Peter van 't Hof committed
84
    addSummaryJobs()
Peter van 't Hof's avatar
Peter van 't Hof committed
85
  }
Wai Yi Leung's avatar
Wai Yi Leung committed
86

Peter van 't Hof's avatar
Peter van 't Hof committed
87
88
89
  /** Must return a map with used settings for this pipeline */
  def summarySettings: Map[String, Any] = Map(
    "reference" -> referenceSummary,
90
91
    "freec_method" -> freecMethod.isDefined,
    "conifer_method" -> coniferMethod.isDefined,
Sander Bollen's avatar
Sander Bollen committed
92
93
    "cnmops_method" -> cnMopsMethod.isDefined,
    "xhmm_method" -> xhmmMethod.isDefined
Peter van 't Hof's avatar
Peter van 't Hof committed
94
  )
Peter van 't Hof's avatar
Peter van 't Hof committed
95

Peter van 't Hof's avatar
Peter van 't Hof committed
96
97
  /** File to put in the summary for thie pipeline */
  def summaryFiles: Map[String, File] = inputBams.map(x => s"inputbam_${x._1}" -> x._2)
Peter van 't Hof's avatar
Peter van 't Hof committed
98

Peter van 't Hof's avatar
Peter van 't Hof committed
99
100
  /** Name of summary output file */
  def summaryFile: File = new File(outputDir, "kopisu.summary.json")
Wai Yi Leung's avatar
Wai Yi Leung committed
101
102
103
}

object Kopisu extends PipelineCommand