BamStats.scala 2.15 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
9
10
11
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.Input

/**
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
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
39
  def bamstatsSummary: File = new File(outputDir, "bamstats.summary.json")
40
41
42
43
  def flagstatSummaryFile(contig: Option[String] = None): File = getOutputFile("flagstats.summary.json", contig)
  def mappingQualityFile(contig: Option[String] = None): File = getOutputFile("mapping_quality.tsv", contig)
  def clipingFile(contig: Option[String] = None): File = getOutputFile("clipping.tsv", contig)

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 :+= bamFile.getAbsolutePath.replaceAll(".bam$", ".bai")
Peter van 't Hof's avatar
Peter van 't Hof committed
47
    jobOutputFile = new File(outputDir, ".bamstats.out")
Peter van 't Hof's avatar
Peter van 't Hof committed
48
    if (reference == null) reference = referenceFasta()
Peter van 't Hof's avatar
Peter van 't Hof committed
49
50
  }

51
52
53
54
55
  /** 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
56
    optional("--binSize", binSize) +
57
58
    optional("--threadBinSize", threadBinSize)

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

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