ShivaTrait.scala 5.48 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 */
Peter van 't Hof's avatar
Peter van 't Hof committed
39
  def makeVariantcalling(multisample: Boolean = false): ShivaVariantcallingTrait with QScript = {
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
      override def configName: String = "shivavariantcalling"
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
45
46
47
48
49
      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 */
Peter van 't Hof's avatar
Peter van 't Hof committed
72
      override def addJobs() = {
73
        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
          add(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
82
        })
Peter van 't Hof's avatar
Peter van 't Hof committed
83
84
85
      }
    }

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

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

94
      preProcessBam.foreach { bam =>
Peter van 't Hof's avatar
Peter van 't Hof committed
95
        variantcalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
96
97
          vc.sampleId = Some(sampleId)
          vc.outputDir = new File(sampleDir, "variantcalling")
98
          vc.inputBams = Map(sampleId -> bam)
Peter van 't Hof's avatar
Peter van 't Hof committed
99
          add(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
100
        })
Peter van 't Hof's avatar
Peter van 't Hof committed
101
      }
Peter van 't Hof's avatar
Peter van 't Hof committed
102
103
104
    }
  }

105
  lazy val multisampleVariantCalling = if (config("multisample_variantcalling", default = true).asBoolean) {
Peter van 't Hof's avatar
Peter van 't Hof committed
106
107
108
    Some(makeVariantcalling(multisample = true))
  } else None

Peter van 't Hof's avatar
Peter van 't Hof committed
109
  lazy val svCalling = if (config("sv_calling", default = false).asBoolean) {
Peter van 't Hof's avatar
Peter van 't Hof committed
110
    Some(new ShivaSvCalling(this))
Peter van 't Hof's avatar
Peter van 't Hof committed
111
112
  } else None

113
114
115
116
117
  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
118
  /** This will add the mutisample variantcalling */
Peter van 't Hof's avatar
Peter van 't Hof committed
119
  override def addMultiSampleJobs() = {
120
121
    super.addMultiSampleJobs()

122
    multisampleVariantCalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
123
      vc.outputDir = new File(outputDir, "variantcalling")
124
      vc.inputBams = samples.flatMap { case (sampleId, sample) => sample.preProcessBam.map(sampleId -> _) }
Peter van 't Hof's avatar
Peter van 't Hof committed
125
      add(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
126

127
      annotation.foreach { toucan =>
Peter van 't Hof's avatar
Peter van 't Hof committed
128
129
        toucan.outputDir = new File(outputDir, "annotation")
        toucan.inputVCF = vc.finalFile
Peter van 't Hof's avatar
Peter van 't Hof committed
130
        add(toucan)
Peter van 't Hof's avatar
Peter van 't Hof committed
131
      }
Peter van 't Hof's avatar
Peter van 't Hof committed
132
    })
Peter van 't Hof's avatar
Peter van 't Hof committed
133
134

    svCalling.foreach(sv => {
Peter van 't Hof's avatar
Peter van 't Hof committed
135
      sv.outputDir = new File(outputDir, "sv_calling")
136
      sv.inputBams = samples.flatMap { case (sampleId, sample) => sample.preProcessBam.map(sampleId -> _) }
Peter van 't Hof's avatar
Peter van 't Hof committed
137
      add(sv)
Peter van 't Hof's avatar
Peter van 't Hof committed
138
    })
Peter van 't Hof's avatar
Peter van 't Hof committed
139
140
  }

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

Peter van 't Hof's avatar
Peter van 't Hof committed
144
  /** Settings of pipeline for summary */
145
  override def summarySettings = super.summarySettings ++ Map(
146
147
148
149
150
151
    "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
152
}