BamStats.scala 2.7 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
/**
 * 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.
 */
15 16 17 18
package nl.lumc.sasc.biopet.extensions.tools

import java.io.File

19
import nl.lumc.sasc.biopet.core.summary.Summarizable
Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.core.{ Reference, ToolCommandFunction }
21
import nl.lumc.sasc.biopet.utils.ConfigUtils
22
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
23
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
24 25

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
26 27
 * Created by pjvanthof on 18/11/2016.
 */
28
class BamStats(val root: Configurable) extends ToolCommandFunction with Reference with Summarizable {
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  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
44
  override def dictRequired = true
45

46
  def getOutputFile(name: String, contig: Option[String] = None): File = {
47
    contig match {
48
      case Some(contig) => new File(outputDir, "contigs" + File.separator + contig + File.separator + name)
Peter van 't Hof's avatar
Peter van 't Hof committed
49
      case _            => new File(outputDir, name)
50 51 52
    }
  }

53 54 55
  @Output
  private var outputFiles: List[File] = Nil

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

Peter van 't Hof's avatar
Peter van 't Hof committed
58 59
  override def beforeGraph() {
    super.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
60
    deps :+= new File(bamFile.getAbsolutePath.replaceAll(".bam$", ".bai"))
61
    outputFiles :+= bamstatsSummary
Peter van 't Hof's avatar
Peter van 't Hof committed
62
    jobOutputFile = new File(outputDir, ".bamstats.out")
Peter van 't Hof's avatar
Peter van 't Hof committed
63
    if (reference == null) reference = referenceFasta()
Peter van 't Hof's avatar
Peter van 't Hof committed
64 65
  }

66 67 68 69 70
  /** 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
71
    optional("--binSize", binSize) +
72 73
    optional("--threadBinSize", threadBinSize)

74 75
  def summaryFiles: Map[String, File] = Map()

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

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