ShivaTrait.scala 5.89 KB
Newer Older
bow's avatar
bow committed
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.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
16
17
package nl.lumc.sasc.biopet.pipelines.shiva

18
19
import nl.lumc.sasc.biopet.core.Reference
import nl.lumc.sasc.biopet.pipelines.bammetrics.TargetRegions
Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.pipelines.mapping.{ MultisampleMappingTrait }
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.pipelines.toucan.Toucan
22
import org.broadinstitute.gatk.queue.QScript
Peter van 't Hof's avatar
Peter van 't Hof committed
23

Peter van 't Hof's avatar
Peter van 't Hof committed
24
/**
Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
 * This is a trait for the Shiva pipeline
 *
Peter van 't Hof's avatar
Peter van 't Hof committed
27
28
 * Created by pjvan_thof on 2/26/15.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
29
trait ShivaTrait extends MultisampleMappingTrait with Reference with TargetRegions { qscript: QScript =>
Peter van 't Hof's avatar
Peter van 't Hof committed
30

31
32
33
34
35
36
37
  override def reportClass = {
    val shiva = new ShivaReport(this)
    shiva.outputDir = new File(outputDir, "report")
    shiva.summaryFile = summaryFile
    Some(shiva)
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
38
  /** Method to make the variantcalling submodule of shiva */
39
  def makeVariantcalling(multisample: Boolean = false): ShivaVariantcallingTrait = {
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    if (multisample) new ShivaVariantcalling(qscript) {
Peter van 't Hof's avatar
Peter van 't Hof committed
41
      override def namePrefix = "multisample"
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
44
45
46
47
48
49
      override def configName = "shivavariantcalling"
      override def configPath: List[String] = super.configPath ::: "multisample" :: Nil
    }
    else new ShivaVariantcalling(qscript) {
      override def configName = "shivavariantcalling"
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
50
  /** Method to make a sample */
51
  override def makeSample(id: String) = new this.Sample(id)
52

Peter van 't Hof's avatar
Peter van 't Hof committed
53
  /** Class that will generate jobs for a sample */
54
  class Sample(sampleId: String) extends super.Sample(sampleId) {
Peter van 't Hof's avatar
Peter van 't Hof committed
55
    /** Method to make a library */
56
    override def makeLibrary(id: String) = new this.Library(id)
Peter van 't Hof's avatar
Peter van 't Hof committed
57

58
59
60
    /** Sample specific settings */
    override def summarySettings = Map("single_sample_variantcalling" -> variantcalling.isDefined)

Peter van 't Hof's avatar
Peter van 't Hof committed
61
    /** Class to generate jobs for a library */
62
    class Library(libId: String) extends super.Library(libId) {
63
64
65
      /** Library specific settings */
      override def summarySettings = Map("library_variantcalling" -> variantcalling.isDefined)

66
      lazy val variantcalling = if (config("library_variantcalling", default = false).asBoolean &&
Peter van 't Hof's avatar
Peter van 't Hof committed
67
68
69
70
        (bamFile.isDefined || preProcessBam.isDefined)) {
        Some(makeVariantcalling(multisample = false))
      } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
71
      /** This will add jobs for this library */
72
73
      override def addJobs = {
        super.addJobs()
Peter van 't Hof's avatar
Peter van 't Hof committed
74

Peter van 't Hof's avatar
Peter van 't Hof committed
75
        variantcalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
76
77
          vc.sampleId = Some(sampleId)
          vc.libId = Some(libId)
Peter van 't Hof's avatar
Peter van 't Hof committed
78
          vc.outputDir = new File(libDir, "variantcalling")
79
80
          if (preProcessBam.isDefined) vc.inputBams = Map(sampleId -> preProcessBam.get)
          else vc.inputBams = Map(sampleId -> bamFile.get)
Peter van 't Hof's avatar
Peter van 't Hof committed
81
82
          vc.init()
          vc.biopetScript()
Peter van 't Hof's avatar
Peter van 't Hof committed
83
          addAll(vc.functions)
84
          addSummaryQScript(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
85
        })
Peter van 't Hof's avatar
Peter van 't Hof committed
86
87
88
      }
    }

Peter van 't Hof's avatar
fix bug    
Peter van 't Hof committed
89
    lazy val variantcalling = if (config("single_sample_variantcalling", default = false).asBoolean) {
Peter van 't Hof's avatar
Peter van 't Hof committed
90
      Some(makeVariantcalling(multisample = false))
Peter van 't Hof's avatar
Peter van 't Hof committed
91
92
    } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
93
    /** This will add sample jobs */
94
95
    override def addJobs(): Unit = {
      super.addJobs()
Peter van 't Hof's avatar
Peter van 't Hof committed
96

97
      preProcessBam.foreach { bam =>
Peter van 't Hof's avatar
Peter van 't Hof committed
98
        variantcalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
99
100
          vc.sampleId = Some(sampleId)
          vc.outputDir = new File(sampleDir, "variantcalling")
101
          vc.inputBams = Map(sampleId -> bam)
Peter van 't Hof's avatar
Peter van 't Hof committed
102
103
          vc.init()
          vc.biopetScript()
Peter van 't Hof's avatar
Peter van 't Hof committed
104
105
          addAll(vc.functions)
          addSummaryQScript(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
106
        })
Peter van 't Hof's avatar
Peter van 't Hof committed
107
      }
Peter van 't Hof's avatar
Peter van 't Hof committed
108
109
110
    }
  }

111
  lazy val multisampleVariantCalling = if (config("multisample_variantcalling", default = true).asBoolean) {
Peter van 't Hof's avatar
Peter van 't Hof committed
112
113
114
    Some(makeVariantcalling(multisample = true))
  } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
115
  lazy val svCalling = if (config("sv_calling", default = false).asBoolean) {
Peter van 't Hof's avatar
Peter van 't Hof committed
116
    Some(new ShivaSvCalling(this))
Peter van 't Hof's avatar
Peter van 't Hof committed
117
118
  } else None

119
120
121
122
123
  lazy val annotation = if (multisampleVariantCalling.isDefined &&
    config("annotation", default = false).asBoolean) {
    Some(new Toucan(this))
  } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
124
  /** This will add the mutisample variantcalling */
125
126
127
  override def addMultiSampleJobs = {
    super.addMultiSampleJobs()

128
    multisampleVariantCalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
129
      vc.outputDir = new File(outputDir, "variantcalling")
130
      vc.inputBams = samples.flatMap { case (sampleId, sample) => sample.preProcessBam.map(sampleId -> _) }
Peter van 't Hof's avatar
Peter van 't Hof committed
131
132
      vc.init()
      vc.biopetScript()
Peter van 't Hof's avatar
Peter van 't Hof committed
133
      addAll(vc.functions)
134
      addSummaryQScript(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
135

136
      annotation.foreach { toucan =>
Peter van 't Hof's avatar
Peter van 't Hof committed
137
138
139
140
141
142
143
        toucan.outputDir = new File(outputDir, "annotation")
        toucan.inputVCF = vc.finalFile
        toucan.init()
        toucan.biopetScript()
        addAll(toucan.functions)
        addSummaryQScript(toucan)
      }
Peter van 't Hof's avatar
Peter van 't Hof committed
144
    })
Peter van 't Hof's avatar
Peter van 't Hof committed
145
146

    svCalling.foreach(sv => {
Peter van 't Hof's avatar
Peter van 't Hof committed
147
      sv.outputDir = new File(outputDir, "sv_calling")
148
      sv.inputBams = samples.flatMap { case (sampleId, sample) => sample.preProcessBam.map(sampleId -> _) }
Peter van 't Hof's avatar
Peter van 't Hof committed
149
150
151
152
153
      sv.init()
      sv.biopetScript()
      addAll(sv.functions)
      addSummaryQScript(sv)
    })
Peter van 't Hof's avatar
Peter van 't Hof committed
154
155
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
156
  /** Location of summary file */
Peter van 't Hof's avatar
Peter van 't Hof committed
157
  def summaryFile = new File(outputDir, "Shiva.summary.json")
Peter van 't Hof's avatar
Peter van 't Hof committed
158

Peter van 't Hof's avatar
Peter van 't Hof committed
159
  /** Settings of pipeline for summary */
160
  override def summarySettings = super.summarySettings ++ Map(
161
162
163
164
165
166
    "annotation" -> annotation.isDefined,
    "multisample_variantcalling" -> multisampleVariantCalling.isDefined,
    "sv_calling" -> svCalling.isDefined,
    "regions_of_interest" -> roiBedFiles.map(_.getName.stripSuffix(".bed")),
    "amplicon_bed" -> ampliconBedFile.map(_.getName.stripSuffix(".bed"))
  )
Peter van 't Hof's avatar
Peter van 't Hof committed
167
}