GatkGenotyping.scala 2.33 KB
Newer Older
1
2
3
4
5
/**
 * Due to the license issue with GATK, this part of Biopet can only be used inside the
 * LUMC. Please refer to https://git.lumc.nl/biopet/biopet/wikis/home for instructions
 * on how to use this protected part of biopet or contact us at sasc@lumc.nl
 */
6
7
8
9
package nl.lumc.sasc.biopet.pipelines.gatk

import nl.lumc.sasc.biopet.core.{ BiopetQScript, PipelineCommand }
import nl.lumc.sasc.biopet.core.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
10
import nl.lumc.sasc.biopet.extensions.gatk.broad.{ SelectVariants, GenotypeGVCFs }
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.utils.commandline.{ Input, Output, Argument }

class GatkGenotyping(val root: Configurable) extends QScript with BiopetQScript {
  def this() = this(null)

  @Input(doc = "Gvcf files", shortName = "I")
  var inputGvcfs: List[File] = Nil

  @Argument(doc = "Reference", shortName = "R", required = false)
  var reference: File = config("reference")

  @Argument(doc = "Dbsnp", shortName = "dbsnp", required = false)
  var dbsnp: File = config("dbsnp")

  @Argument(doc = "OutputName", required = false)
  var outputName: String = "genotype"

  @Output(doc = "OutputFile", shortName = "O", required = false)
  var outputFile: File = _

  @Argument(doc = "Samples", shortName = "sample", required = false)
  var samples: List[String] = Nil

  def init() {
Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
    require(outputName != null, "Outputname is null")
    if (outputFile == null) outputFile = new File(outputDir, outputName + ".vcf.gz")
38
39
40
41
42
  }

  def biopetScript() {
    addGenotypeGVCFs(inputGvcfs, outputFile)
    if (!samples.isEmpty) {
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
      if (samples.size > 1) addSelectVariants(outputFile, samples, new File(outputDir, "samples/"), "all")
      for (sample <- samples) addSelectVariants(outputFile, List(sample), new File(outputDir, "samples/"), sample)
45
46
47
48
49
50
51
52
53
    }
  }

  def addGenotypeGVCFs(gvcfFiles: List[File], outputFile: File): File = {
    val genotypeGVCFs = GenotypeGVCFs(this, gvcfFiles, outputFile)
    add(genotypeGVCFs)
    return genotypeGVCFs.out
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
  def addSelectVariants(inputFile: File, samples: List[String], outputDir: File, name: String) {
    val selectVariants = SelectVariants(this, inputFile, new File(outputDir, name + ".vcf.gz"))
56
57
58
59
60
61
62
    selectVariants.excludeNonVariants = true
    for (sample <- samples) selectVariants.sample_name :+= sample
    add(selectVariants)
  }
}

object GatkGenotyping extends PipelineCommand