Delly.scala 3.52 KB
Newer Older
1
package nl.lumc.sasc.biopet.extensions.delly
2
3
4

import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
5
import nl.lumc.sasc.biopet.core.{ BiopetQScript, PipelineCommand }
6
7
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.extensions.Ln
Peter van 't Hof's avatar
Peter van 't Hof committed
8
9
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.queue.extensions.gatk.CatVariants
10
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

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

  @Input(doc = "Input file (bam)")
  var input: File = _

  @Argument(doc = "Work directory")
  var workdir: String = _

  @Output(doc = "Delly result VCF")
  var outputvcf: File = _

  var outputBaseName: String = _

  // select the analysis types DEL,DUP,INV,TRA
  var del: Boolean = config("DEL", default = false)
  var dup: Boolean = config("DUP", default = false)
  var inv: Boolean = config("INV", default = false)
  var tra: Boolean = config("TRA", default = false)

  override def init() {
  }

  def biopetScript() {
    // write the pipeline here
    logger.info("Configuring Delly pipeline")
    var outputFiles: Map[String, File] = Map()
    var vcfFiles: Map[String, File] = Map()

    this.outputBaseName = workdir + input.getName.substring(0, input.getName.lastIndexOf(".bam"))
    this.outputvcf = outputBaseName + ".delly.vcf"

    /// start delly and then copy the vcf into the root directory "<sample>.delly/"
    if (del) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "DEL"
      delly.outputvcf = outputBaseName + ".delly.del.vcf"
      add(delly)
      vcfFiles += ("DEL" -> delly.outputvcf)
    }
    if (dup) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "DUP"
      delly.outputvcf = outputBaseName + ".delly.dup.vcf"
      add(delly)
      vcfFiles += ("DUP" -> delly.outputvcf)
    }
    if (inv) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "INV"
      delly.outputvcf = outputBaseName + ".delly.inv.vcf"
      add(delly)
      vcfFiles += ("INV" -> delly.outputvcf)
    }
    if (tra) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "TRA"
      delly.outputvcf = outputBaseName + ".delly.tra.vcf"
      //      vcfFiles += ("TRA" -> delly.outputvcf)
      add(delly)
    }
    // we need to merge the vcf's
    var finalVCF = if (vcfFiles.size > 1) {
      // do merging
      // CatVariants is a $org.broadinstitute.gatk.utils.commandline.CommandLineProgram$;
      val variants = new CatVariants()
      variants.jobResourceRequests :+= "h_vmem=4G"
      variants.nCoresRequest = 1
      variants.memoryLimit = Option(2.0)
      variants.variant = vcfFiles.values.toList
      variants.reference = config("reference")
      variants.outputFile = this.outputvcf
      // add the job
      add(variants)
89
      this.outputvcf
90
91
92
93
    } else {
      // TODO: pretify this
      val ln = Ln(this, vcfFiles.head._2, this.outputvcf, relative = true)
      add(ln)
94
      ln.output
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    }

    outputFiles += ("vcf" -> this.outputvcf)
  }

  private def swapExtension(inputFile: String) = inputFile.substring(0, inputFile.lastIndexOf(".bam")) + ".delly.vcf"
}

object Delly extends PipelineCommand {
  override val pipeline = "/nl/lumc/sasc/biopet/extensions/svcallers/Delly/Delly.class"

  def apply(root: Configurable, input: File, runDir: String): Delly = {
    val dellypipeline = new Delly(root)
    dellypipeline.input = input
    dellypipeline.workdir = runDir
Peter van 't Hof's avatar
Peter van 't Hof committed
110
111
112
    dellypipeline.init()
    dellypipeline.biopetScript()
    dellypipeline
113
114
115
  }

}