CollectInsertSizeMetrics.scala 3.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * 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 that are
 * not part of GATK Queue 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.
 */
16
package nl.lumc.sasc.biopet.extensions.picard
17
18

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
import scala.collection.immutable.Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
27
/** Extension for picard CollectInsertSizeMetrics */
28
class CollectInsertSizeMetrics(val root: Configurable) extends Picard with Summarizable with Reference {
29
  javaMainClass = new picard.analysis.CollectInsertSizeMetrics().getClass.getName
30

bow's avatar
bow committed
31
  @Input(doc = "The input SAM or BAM files to analyze.  Must be coordinate sorted.", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
32
  var input: File = null
33

bow's avatar
bow committed
34
  @Output(doc = "The output file to write statistics to", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
35
  var output: File = null
bow's avatar
bow committed
36
37

  @Output(doc = "Output histogram", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
38
  protected var outputHistogram: File = null
bow's avatar
bow committed
39
40

  @Argument(doc = "Reference file", required = false)
41
  var reference: File = _
bow's avatar
bow committed
42
43

  @Argument(doc = "DEVIATIONS", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
44
  var deviations: Option[Double] = config("deviations")
bow's avatar
bow committed
45
46

  @Argument(doc = "MINIMUM_PCT", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
47
  var minPct: Option[Double] = config("minpct")
bow's avatar
bow committed
48
49
50
51
52

  @Argument(doc = "ASSUME_SORTED", required = false)
  var assumeSorted: Boolean = config("assumesorted", default = true)

  @Argument(doc = "STOP_AFTER", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
53
  var stopAfter: Option[Long] = config("stopAfter")
bow's avatar
bow committed
54
55

  @Argument(doc = "METRIC_ACCUMULATION_LEVEL", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
56
  var metricAccumulationLevel: List[String] = config("metricaccumulationlevel", default = Nil)
bow's avatar
bow committed
57
58

  @Argument(doc = "HISTOGRAM_WIDTH", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
59
  var histogramWidth: Option[Int] = config("histogramWidth")
bow's avatar
bow committed
60

Peter van 't Hof's avatar
Peter van 't Hof committed
61
  override def beforeGraph() {
Peter van 't Hof's avatar
Peter van 't Hof committed
62
    outputHistogram = new File(output + ".pdf")
63
    if (reference == null) reference = referenceFasta()
64
  }
bow's avatar
bow committed
65

Peter van 't Hof's avatar
Peter van 't Hof committed
66
  /** Returns command to execute */
67
  override def cmdLine = super.cmdLine +
bow's avatar
bow committed
68
69
70
71
72
73
74
75
    required("INPUT=", input, spaceSeparated = false) +
    required("OUTPUT=", output, spaceSeparated = false) +
    optional("HISTOGRAM_FILE=", outputHistogram, spaceSeparated = false) +
    required("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
    optional("DEVIATIONS=", deviations, spaceSeparated = false) +
    repeat("METRIC_ACCUMULATION_LEVEL=", metricAccumulationLevel, spaceSeparated = false) +
    optional("STOP_AFTER=", stopAfter, spaceSeparated = false) +
    optional("HISTOGRAM_WIDTH=", histogramWidth, spaceSeparated = false) +
76
    conditional(assumeSorted, "ASSUME_SORTED=TRUE")
77

Peter van 't Hof's avatar
Peter van 't Hof committed
78
  /** Returns files for summary */
79
80
  def summaryFiles: Map[String, File] = Map("output_histogram" -> outputHistogram)

Peter van 't Hof's avatar
Peter van 't Hof committed
81
  def summaryStats = Picard.getMetrics(output).getOrElse(Map())
82
83
84
}

object CollectInsertSizeMetrics {
Peter van 't Hof's avatar
Peter van 't Hof committed
85
  /** Returns default CollectInsertSizeMetrics */
Peter van 't Hof's avatar
Peter van 't Hof committed
86
  def apply(root: Configurable, input: File, outputDir: File): CollectInsertSizeMetrics = {
87
88
89
    val collectInsertSizeMetrics = new CollectInsertSizeMetrics(root)
    collectInsertSizeMetrics.input = input
    collectInsertSizeMetrics.output = new File(outputDir, input.getName.stripSuffix(".bam") + ".insertsizemetrics")
90
    collectInsertSizeMetrics
91
92
  }
}