ShivaTrait.scala 5.56 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
import nl.lumc.sasc.biopet.core.Reference
Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.core.report.ReportBuilderExtension
20
import nl.lumc.sasc.biopet.pipelines.bammetrics.TargetRegions
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.pipelines.mapping.MultisampleMappingTrait
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.pipelines.toucan.Toucan
23
import org.broadinstitute.gatk.queue.QScript
Peter van 't Hof's avatar
Peter van 't Hof committed
24

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

Peter van 't Hof's avatar
Peter van 't Hof committed
32
  override def reportClass: Option[ReportBuilderExtension] = {
33
34
35
36
37
38
    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
39
  /** Method to make the variantcalling submodule of shiva */
Peter van 't Hof's avatar
Peter van 't Hof committed
40
  def makeVariantcalling(multisample: Boolean = false): ShivaVariantcallingTrait with QScript = {
Peter van 't Hof's avatar
Peter van 't Hof committed
41
    if (multisample) new ShivaVariantcalling(qscript) {
Peter van 't Hof's avatar
Peter van 't Hof committed
42
      override def namePrefix = "multisample"
Peter van 't Hof's avatar
Peter van 't Hof committed
43
      override def configName: String = "shivavariantcalling"
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46
47
48
49
50
      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
51
  /** Method to make a sample */
52
  override def makeSample(id: String) = new this.Sample(id)
53

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

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

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

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
76
        variantcalling.foreach(vc => {
Peter van 't Hof's avatar
Peter van 't Hof committed
77
78
          vc.sampleId = Some(sampleId)
          vc.libId = Some(libId)
Peter van 't Hof's avatar
Peter van 't Hof committed
79
          vc.outputDir = new File(libDir, "variantcalling")
80
81
          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
82
          add(vc)
Peter van 't Hof's avatar
Peter van 't Hof committed
83
        })
Peter van 't Hof's avatar
Peter van 't Hof committed
84
85
86
      }
    }

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

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

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

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

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

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

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

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

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

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

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