Delly.scala 4.14 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof 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
package nl.lumc.sasc.biopet.extensions.delly
17
18
19

import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.core.{ Reference, BiopetQScript, PipelineCommand }
21
22
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
23
24
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.queue.extensions.gatk.CatVariants
25

Peter van 't Hof's avatar
Peter van 't Hof committed
26
class Delly(val root: Configurable) extends QScript with BiopetQScript with Reference {
27
28
29
30
31
  def this() = this(null)

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

Peter van 't Hof's avatar
Peter van 't Hof committed
32
  var workDir: File = _
33
34

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

37
  var outputName: String = _
38
39

  // select the analysis types DEL,DUP,INV,TRA
Peter van 't Hof's avatar
Peter van 't Hof committed
40
41
42
43
  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)
44

45
46
47
  override def init(): Unit = {
    if (outputName == null) outputName = input.getName.stripSuffix(".bam")
    if (outputVcf == null) outputVcf = new File(workDir, outputName + ".delly.vcf")
48
49
50
51
52
53
54
55
56
57
58
59
60
  }

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

    /// 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"
61
      delly.outputvcf = new File(workDir, outputName + ".delly.del.vcf")
62
63
64
65
66
67
68
      add(delly)
      vcfFiles += ("DEL" -> delly.outputvcf)
    }
    if (dup) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "DUP"
69
      delly.outputvcf = new File(workDir, outputName + ".delly.dup.vcf")
70
71
72
73
74
75
76
      add(delly)
      vcfFiles += ("DUP" -> delly.outputvcf)
    }
    if (inv) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "INV"
77
      delly.outputvcf = new File(workDir, outputName + ".delly.inv.vcf")
78
79
80
81
82
83
84
      add(delly)
      vcfFiles += ("INV" -> delly.outputvcf)
    }
    if (tra) {
      val delly = new DellyCaller(this)
      delly.input = input
      delly.analysistype = "TRA"
85
      delly.outputvcf = new File(workDir, outputName + ".delly.tra.vcf")
86
87
88
89
      //      vcfFiles += ("TRA" -> delly.outputvcf)
      add(delly)
    }
    // we need to merge the vcf's
90
    val finalVCF = if (vcfFiles.size > 1) {
91
92
      // do merging
      // CatVariants is a $org.broadinstitute.gatk.utils.commandline.CommandLineProgram$;
Peter van 't Hof's avatar
Peter van 't Hof committed
93
      //TODO: convert to biopet extension
94
95
      val variants = new CatVariants()
      variants.variant = vcfFiles.values.toList
Peter van 't Hof's avatar
Peter van 't Hof committed
96
      variants.outputFile = this.outputVcf
Peter van 't Hof's avatar
Peter van 't Hof committed
97
      variants.reference = referenceFasta()
98
      // add the job
Peter van 't Hof's avatar
Peter van 't Hof committed
99
      //add(variants)
Peter van 't Hof's avatar
Peter van 't Hof committed
100
      Some(outputVcf)
101
    } else if (vcfFiles.size == 1) {
102
      // TODO: pretify this
Peter van 't Hof's avatar
Peter van 't Hof committed
103
      val ln = Ln(this, vcfFiles.head._2, this.outputVcf, relative = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
104
      //add(ln)
105
106
      Some(ln.output)
    } else None
107

108
    finalVCF.foreach(file => outputFiles += ("vcf" -> file))
109
110
111
112
113
114
  }
}

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

115
  def apply(root: Configurable, input: File, workDir: File): Delly = {
116
117
    val dellyPipeline = new Delly(root)
    dellyPipeline.input = input
118
    dellyPipeline.workDir = workDir
119
120
121
    dellyPipeline.init()
    dellyPipeline.biopetScript()
    dellyPipeline
122
123
124
  }

}