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

22
  var outputName: String = _
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
  override def init(): Unit = {
    if (outputName == null) outputName = input.getName.stripSuffix(".bam")
    if (outputVcf == null) outputVcf = new File(workDir, outputName + ".delly.vcf")
33 34 35 36 37 38 39 40 41 42 43 44 45
  }

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

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

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

100
  def apply(root: Configurable, input: File, workDir: File): Delly = {
101 102
    val dellyPipeline = new Delly(root)
    dellyPipeline.input = input
103
    dellyPipeline.workDir = workDir
104 105 106
    dellyPipeline.init()
    dellyPipeline.biopetScript()
    dellyPipeline
107 108 109
  }

}