CollectGcBiasMetrics.scala 3.78 KB
Newer Older
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
package nl.lumc.sasc.biopet.extensions.picard
16
17

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
24
/** Extension for picard CollectGcBiasMetrics */
25
26
27
28
class CollectGcBiasMetrics(val parent: Configurable)
    extends Picard
    with Summarizable
    with Reference {
29

30
31
  @Input(doc = "The input SAM or BAM files to analyze.  Must be coordinate sorted.",
         required = true)
32
33
  var input: Seq[File] = Nil

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

  @Output(doc = "Output chart", required = false)
38
  var outputChart: File = _
bow's avatar
bow committed
39

40
  @Output(doc = "Output summary", required = true)
41
42
  var outputSummary: File = _

43
  @Input(doc = "Reference file", required = false)
44
  var reference: File = _
bow's avatar
bow committed
45
46

  @Argument(doc = "Window size", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
47
  var windowSize: Option[Int] = config("windowsize")
bow's avatar
bow committed
48
49

  @Argument(doc = "MINIMUM_GENOME_FRACTION", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
50
  var minGenomeFraction: Option[Double] = config("mingenomefraction")
bow's avatar
bow committed
51
52
53
54
55

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

  @Argument(doc = "IS_BISULFITE_SEQUENCED", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
56
  var isBisulfiteSequinced: Option[Boolean] = config("isbisulfitesequinced")
bow's avatar
bow committed
57

Peter van 't Hof's avatar
Peter van 't Hof committed
58
  override def defaultCoreMemory = 8.0
Peter van 't Hof's avatar
Peter van 't Hof committed
59

Peter van 't Hof's avatar
Peter van 't Hof committed
60
61
  override def beforeGraph() {
    super.beforeGraph()
62
    if (outputChart == null) outputChart = 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: String =
68
69
70
71
72
73
74
75
76
77
    super.cmdLine +
      repeat("INPUT=", input, spaceSeparated = false) +
      required("OUTPUT=", output, spaceSeparated = false) +
      optional("CHART_OUTPUT=", outputChart, spaceSeparated = false) +
      required("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
      required("SUMMARY_OUTPUT=", outputSummary, spaceSeparated = false) +
      optional("WINDOW_SIZE=", windowSize, spaceSeparated = false) +
      optional("MINIMUM_GENOME_FRACTION=", minGenomeFraction, spaceSeparated = false) +
      conditional(assumeSorted, "ASSUME_SORTED=TRUE") +
      conditional(isBisulfiteSequinced.getOrElse(false), "IS_BISULFITE_SEQUENCED=TRUE")
78
79
80
81
82

  /** Returns files for summary */
  def summaryFiles: Map[String, File] = Map()

  /** Returns stats for summary */
Peter van 't Hof's avatar
Peter van 't Hof committed
83
84
  def summaryStats: Option[Map[String, List[Option[Any]]]] =
    Picard.getHistogram(output, tag = "METRICS CLASS")
85
86
87
}

object CollectGcBiasMetrics {
88

Peter van 't Hof's avatar
Peter van 't Hof committed
89
  /** Returns default CollectGcBiasMetrics */
Peter van 't Hof's avatar
Peter van 't Hof committed
90
  def apply(root: Configurable, input: File, outputDir: File): CollectGcBiasMetrics = {
91
92
    val collectGcBiasMetrics = new CollectGcBiasMetrics(root)
    collectGcBiasMetrics.input :+= input
93
94
95
96
    collectGcBiasMetrics.output =
      new File(outputDir, input.getName.stripSuffix(".bam") + ".gcbiasmetrics")
    collectGcBiasMetrics.outputSummary =
      new File(outputDir, input.getName.stripSuffix(".bam") + ".gcbiasmetrics.summary")
Peter van 't Hof's avatar
Peter van 't Hof committed
97
    collectGcBiasMetrics
98
99
  }
}