CustomVarScan.scala 3.9 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.
 */
16
17
18
19
package nl.lumc.sasc.biopet.pipelines.gentrap.extensions

import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.core.{ Reference, BiopetCommandLineFunction }
21
import nl.lumc.sasc.biopet.core.extensions.PythonCommandLineFunction
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.utils.config.Configurable
23
import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsMpileup
24
import nl.lumc.sasc.biopet.extensions.varscan.VarscanMpileup2cns
25
import nl.lumc.sasc.biopet.extensions.{ Bgzip, Tabix }
Peter van 't Hof's avatar
Peter van 't Hof committed
26
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
27
28
29
30

/** Ad-hoc extension for VarScan variant calling that involves 6-command pipe */
// FIXME: generalize piping instead of building something by hand like this!
// Better to do everything quick and dirty here rather than something half-implemented with the objects
Peter van 't Hof's avatar
Peter van 't Hof committed
31
class CustomVarScan(val root: Configurable) extends BiopetCommandLineFunction with Reference { wrapper =>
32

33
34
  override def configName = "customvarscan"

35
36
37
38
39
40
  @Input(doc = "Input BAM file", required = true)
  var input: File = null

  @Output(doc = "Output VCF file", required = true)
  var output: File = null

bow's avatar
bow committed
41
42
43
  @Output(doc = "Output VCF file index", required = true)
  lazy val outputIndex: File = new File(output.toString + ".tbi")

44
45
  // mpileup, varscan, fix_mpileup.py, binom_test.py, bgzip, tabix
  private def mpileup = new SamtoolsMpileup(wrapper.root) {
bow's avatar
bow committed
46
    this.input = List(wrapper.input)
47
    override def configName = wrapper.configName
48
49
50
    disableBaq = true
    depth = Option(1000000)
    outputMappingQuality = true
51

52
53
54
55
56
  }

  private def fixMpileup = new PythonCommandLineFunction {
    setPythonScript("fix_mpileup.py", "/nl/lumc/sasc/biopet/pipelines/gentrap/scripts/")
    override val root: Configurable = wrapper.root
57
    override def configName = wrapper.configName
58
59
60
    def cmdLine = getPythonCommand
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
61
  private def removeEmptyPile() = new BiopetCommandLineFunction {
62
    override val root: Configurable = wrapper.root
63
    override def configName = wrapper.configName
64
    executable = config("exe", default = "grep", freeVar = false)
65
66
67
    override def cmdLine: String = required(executable) + required("-vP") + required("""\t\t""")
  }

68
  private val varscan = new VarscanMpileup2cns(wrapper.root) {
69
    override def configName = wrapper.configName
70
71
72
73
    strandFilter = Option(0)
    outputVcf = Option(1)
  }

74
  private val compress = new Bgzip(wrapper.root)
75

76
  private val index = new Tabix(wrapper.root) {
77
    override def configName = wrapper.configName
bow's avatar
bow committed
78
79
80
    p = Option("vcf")
  }

81
82
83
84
  override def freezeFieldValues(): Unit = {
    varscan.output = Option(new File(wrapper.output.toString.stripSuffix(".gz")))
    compress.input = List(varscan.output.get)
    compress.output = this.output
85
    index.input = compress.output
86
87
88
89
90
    super.freezeFieldValues()
    varscan.qSettings = this.qSettings
    varscan.freezeFieldValues()
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
91
  override def beforeGraph(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
92
    super.beforeGraph()
93
    require(output.toString.endsWith(".gz"), "Output must have a .gz file extension")
94
    deps :+= referenceFasta()
95
96
  }

97
98
99
  def cmdLine: String = {
    // FIXME: manual trigger of commandLine for version retrieval
    mpileup.commandLine
100
    (mpileup | fixMpileup | removeEmptyPile() | varscan).commandLine + " && " + compress.commandLine + " && " + index.commandLine
101
  }
102
}