Delly.scala 3.41 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.{ Reference, 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

Peter van 't Hof's avatar
Peter van 't Hof committed
11
class Delly(val root: Configurable) extends QScript with BiopetQScript with Reference {
12
13
14
15
16
  def this() = this(null)

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

Peter van 't Hof's avatar
Peter van 't Hof committed
17
  var workdir: File = _
18
19
20
21

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

Peter van 't Hof's avatar
Peter van 't Hof committed
22
  var outputBaseName: File = _
23
24

  // select the analysis types DEL,DUP,INV,TRA
Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
27
28
  var del: Boolean = config("DEL", default = true)
  var dup: Boolean = config("DUP", default = true)
  var inv: Boolean = config("INV", default = true)
  var tra: Boolean = config("TRA", default = true)
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

  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$;
Peter van 't Hof's avatar
Peter van 't Hof committed
79
      //TODO: convert to biopet extension
80
81
82
      val variants = new CatVariants()
      variants.variant = vcfFiles.values.toList
      variants.outputFile = this.outputvcf
Peter van 't Hof's avatar
Peter van 't Hof committed
83
      variants.reference = referenceFasta()
84
85
      // add the job
      add(variants)
86
      this.outputvcf
87
88
89
90
    } else {
      // TODO: pretify this
      val ln = Ln(this, vcfFiles.head._2, this.outputvcf, relative = true)
      add(ln)
91
      ln.output
92
93
94
95
96
97
98
99
100
101
102
    }

    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"

Peter van 't Hof's avatar
Peter van 't Hof committed
103
  def apply(root: Configurable, input: File, runDir: File): Delly = {
104
105
106
    val dellypipeline = new Delly(root)
    dellypipeline.input = input
    dellypipeline.workdir = runDir
Peter van 't Hof's avatar
Peter van 't Hof committed
107
108
109
    dellypipeline.init()
    dellypipeline.biopetScript()
    dellypipeline
110
111
112
  }

}