BamStats.scala 2.03 KB
Newer Older
1 2 3 4
package nl.lumc.sasc.biopet.extensions.tools

import java.io.File

5
import nl.lumc.sasc.biopet.core.summary.Summarizable
Peter van 't Hof's avatar
Peter van 't Hof committed
6
import nl.lumc.sasc.biopet.core.{ Reference, ToolCommandFunction }
7
import nl.lumc.sasc.biopet.utils.ConfigUtils
8
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
9
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
10 11

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
12 13
 * Created by pjvanthof on 18/11/2016.
 */
14
class BamStats(val root: Configurable) extends ToolCommandFunction with Reference with Summarizable {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  def toolObject = nl.lumc.sasc.biopet.tools.bamstats.BamStats

  @Input(required = true)
  var reference: File = _

  @Input(required = true)
  var bamFile: File = _

  var outputDir: File = _

  var binSize: Option[Int] = config("bin_size")
  var threadBinSize: Option[Int] = config("thread_bin_size")

  override def defaultThreads = 3
  override def defaultCoreMemory = 5.0
Peter van 't Hof's avatar
Peter van 't Hof committed
30
  override def dictRequired = true
31

32
  def getOutputFile(name: String, contig: Option[String] = None): File = {
33
    contig match {
34
      case Some(contig) => new File(outputDir, "contigs" + File.separator + contig + File.separator + name)
Peter van 't Hof's avatar
Peter van 't Hof committed
35
      case _            => new File(outputDir, name)
36 37 38
    }
  }

39 40 41
  @Output
  private var outputFiles: List[File] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
42
  def bamstatsSummary: File = new File(outputDir, "bamstats.summary.json")
43

Peter van 't Hof's avatar
Peter van 't Hof committed
44 45
  override def beforeGraph() {
    super.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
46
    deps :+= new File(bamFile.getAbsolutePath.replaceAll(".bam$", ".bai"))
47
    outputFiles :+= bamstatsSummary
Peter van 't Hof's avatar
Peter van 't Hof committed
48
    jobOutputFile = new File(outputDir, ".bamstats.out")
Peter van 't Hof's avatar
Peter van 't Hof committed
49
    if (reference == null) reference = referenceFasta()
Peter van 't Hof's avatar
Peter van 't Hof committed
50 51
  }

52 53 54 55 56
  /** Creates command to execute extension */
  override def cmdLine = super.cmdLine +
    required("-b", bamFile) +
    required("-o", outputDir) +
    required("-R", reference) +
Peter van 't Hof's avatar
Peter van 't Hof committed
57
    optional("--binSize", binSize) +
58 59
    optional("--threadBinSize", threadBinSize)

60 61
  def summaryFiles: Map[String, File] = Map()

Peter van 't Hof's avatar
Peter van 't Hof committed
62
  def summaryStats: Map[String, Any] = ConfigUtils.fileToConfigMap(bamstatsSummary)
63 64

  override def summaryDeps: List[File] = bamstatsSummary :: super.summaryDeps
65
}