Delly.scala 3.35 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

  @Output(doc = "Delly result VCF")
Peter van 't Hof's avatar
Peter van 't Hof committed
20
  var outputVcf: File = _
21

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

  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()

Peter van 't Hof's avatar
Peter van 't Hof committed
39
40
    this.outputBaseName = workDir + input.getName.substring(0, input.getName.lastIndexOf(".bam"))
    this.outputVcf = outputBaseName + ".delly.vcf"
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

    /// 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
76
    val finalVCF = if (vcfFiles.size > 1) {
77
78
      // 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
      val variants = new CatVariants()
      variants.variant = vcfFiles.values.toList
Peter van 't Hof's avatar
Peter van 't Hof committed
82
      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)
Peter van 't Hof's avatar
Peter van 't Hof committed
86
      Some(outputVcf)
87
    } else if (vcfFiles.size == 1) {
88
      // TODO: pretify this
Peter van 't Hof's avatar
Peter van 't Hof committed
89
      val ln = Ln(this, vcfFiles.head._2, this.outputVcf, relative = true)
90
      add(ln)
91
92
      Some(ln.output)
    } else None
93

94
    finalVCF.foreach(file => outputFiles += ("vcf" -> file))
95
96
97
98
99
100
  }
}

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
101
  def apply(root: Configurable, input: File, runDir: File): Delly = {
102
103
    val dellyPipeline = new Delly(root)
    dellyPipeline.input = input
Peter van 't Hof's avatar
Peter van 't Hof committed
104
    dellyPipeline.workDir = runDir
105
106
107
    dellyPipeline.init()
    dellyPipeline.biopetScript()
    dellyPipeline
108
109
110
  }

}