VarscanCnsSingleSample.scala 2.68 KB
Newer Older
1
2
3
4
package nl.lumc.sasc.biopet.pipelines.shiva.variantcallers

import java.io.PrintWriter

5
6
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.extensions.PythonCommandLineFunction
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import nl.lumc.sasc.biopet.extensions.gatk.CombineVariants
import nl.lumc.sasc.biopet.extensions.{ Ln, Tabix, Bgzip }
import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsMpileup
import nl.lumc.sasc.biopet.extensions.varscan.VarscanMpileup2cns
import nl.lumc.sasc.biopet.utils.config.Configurable

/**
 * Created by sajvanderzeeuw on 15-1-16.
 */
class VarscanCnsSingleSample(val root: Configurable) extends Variantcaller {
  val name = "varscan_cns_singlesample"
  protected def defaultPrio = 25

  override def defaults = Map(
    "samtoolsmpileup" -> Map(
      "disable_baq" -> true,
      "depth" -> 1000000
    ),
25
    "varscanmpileup2cns" -> Map("strand_filter" -> 0)
26
27
28
29
  )

  override def fixedValues = Map(
    "samtoolsmpileup" -> Map("output_mapping_quality" -> true),
30
    "varscanmpileup2cns" -> Map("output_vcf" -> 1)
31
32
33
34
35
36
37
38
39
40
  )

  def biopetScript: Unit = {
    val sampleVcfs = for ((sample, inputBam) <- inputBams.toList) yield {
      val mpileup = new SamtoolsMpileup(this)
      mpileup.input = List(inputBam)

      val sampleVcf = new File(outputDir, s"${name}_$sample.vcf.gz")

      val sampleFile = new File(outputDir, s"$sample.name.txt")
41
      sampleFile.getParentFile.mkdirs()
42
43
44
45
46
      sampleFile.deleteOnExit()
      val writer = new PrintWriter(sampleFile)
      writer.println(sample)
      writer.close()

47
48
49
50
51
52
53
54
55
56
57
58
59
60
      val fixMpileup = new PythonCommandLineFunction {
        setPythonScript("fix_mpileup.py", "/nl/lumc/sasc/biopet/pipelines/shiva/scripts/")
        override val root: Configurable = this.root
        override def configName = "fix_mpileup"
        def cmdLine = getPythonCommand
      }

      def removeEmptyPile() = new BiopetCommandLineFunction {
        override val root: Configurable = this.root
        override def configName = "remove_empty_pile"
        executable = config("exe", default = "grep", freeVar = false)
        override def cmdLine: String = required(executable) + required("-vP") + required("""\t\t""")
      }

61
62
63
      val varscan = new VarscanMpileup2cns(this)
      varscan.vcfSampleList = Some(sampleVcf)

64
      add(mpileup | fixMpileup | removeEmptyPile() | varscan | new Bgzip(this) > sampleVcf)
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      add(Tabix(this, sampleVcf))

      sampleVcf
    }

    if (sampleVcfs.size > 1) {
      val cv = new CombineVariants(this)
      cv.inputFiles = sampleVcfs
      cv.outputFile = outputFile
      cv.setKey = "null"
      cv.excludeNonVariants = true
      add(cv)
    } else add(Ln.apply(this, sampleVcfs.head, outputFile))
    add(Tabix(this, outputFile))
  }
}