Bam2Wig.scala 2.44 KB
Newer Older
bow's avatar
bow committed
1
/**
2 3 4 5 6 7 8 9 10 11 12 13 14
  * 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 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.
  */
Peter van 't Hof's avatar
Peter van 't Hof committed
15 16
package nl.lumc.sasc.biopet.pipelines.bamtobigwig

Peter van 't Hof's avatar
Peter van 't Hof committed
17 18
import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.utils.config.Configurable
20
import nl.lumc.sasc.biopet.core.{BiopetQScript, PipelineCommand}
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.extensions.WigToBigWig
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.extensions.igvtools.IGVToolsCount
Peter van 't Hof's avatar
Peter van 't Hof committed
23 24 25
import org.broadinstitute.gatk.queue.QScript

/**
26 27 28 29
  * Pipeline to create BigWigle files from a bam file
  *
  * Created by pjvan_thof on 1/29/15.
  */
Peter van 't Hof's avatar
Peter van 't Hof committed
30
class Bam2Wig(val parent: Configurable) extends QScript with BiopetQScript {
Peter van 't Hof's avatar
Peter van 't Hof committed
31 32
  def this() = this(null)

Peter van 't Hof's avatar
Peter van 't Hof committed
33
  @Input(doc = "Input bam file", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
34
  var bamFile: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
35 36

  def init(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
37
    inputFiles :+= new InputFile(bamFile)
Peter van 't Hof's avatar
Peter van 't Hof committed
38 39
  }

40 41 42 43
  def outputWigleFile = new File(outputDir, bamFile.getName + ".wig")
  def outputTdfFile = new File(outputDir, bamFile.getName + ".tdf")
  def outputBwFile = new File(outputDir, bamFile.getName + ".bw")

Peter van 't Hof's avatar
Peter van 't Hof committed
44 45 46
  def biopetScript(): Unit = {
    val bs = new BamToChromSizes(this)
    bs.bamFile = bamFile
Peter van 't Hof's avatar
Peter van 't Hof committed
47
    bs.chromSizesFile = bamFile.getAbsoluteFile + ".chrom.sizes"
Peter van 't Hof's avatar
Peter van 't Hof committed
48 49 50
    bs.isIntermediate = true
    add(bs)

Peter van 't Hof's avatar
Peter van 't Hof committed
51 52 53
    val igvCount = new IGVToolsCount(this)
    igvCount.input = bamFile
    igvCount.genomeChromSizes = bs.chromSizesFile
54 55
    igvCount.wig = Some(outputWigleFile)
    igvCount.tdf = Some(outputTdfFile)
56
    add(igvCount)
Peter van 't Hof's avatar
Peter van 't Hof committed
57

Peter van 't Hof's avatar
Peter van 't Hof committed
58
    val wigToBigWig = new WigToBigWig(this)
Peter van 't Hof's avatar
Peter van 't Hof committed
59
    wigToBigWig.inputWigFile = igvCount.wig.get
Peter van 't Hof's avatar
Peter van 't Hof committed
60
    wigToBigWig.inputChromSizesFile = bs.chromSizesFile
61
    wigToBigWig.outputBigWig = outputBwFile
Peter van 't Hof's avatar
Peter van 't Hof committed
62 63 64 65
    add(wigToBigWig)
  }
}

Peter van 't Hof's avatar
Peter van 't Hof committed
66 67 68
object Bam2Wig extends PipelineCommand {
  def apply(root: Configurable, bamFile: File): Bam2Wig = {
    val bamToBigWig = new Bam2Wig(root)
Peter van 't Hof's avatar
Peter van 't Hof committed
69
    bamToBigWig.outputDir = bamFile.getParentFile
Peter van 't Hof's avatar
Peter van 't Hof committed
70 71 72
    bamToBigWig.bamFile = bamFile
    bamToBigWig
  }
73
}