CollectAlignmentSummaryMetrics.scala 3.62 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
Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
19

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

Peter van 't Hof's avatar
Peter van 't Hof committed
23
/** Extension for picard CollectAlignmentSummaryMetrics */
24
class CollectAlignmentSummaryMetrics(val root: Configurable) extends Picard with Summarizable {
25
  javaMainClass = new picard.analysis.CollectAlignmentSummaryMetrics().getClass.getName
bow's avatar
bow committed
26
27

  @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
28
  var input: File = _
bow's avatar
bow committed
29
30

  @Argument(doc = "MAX_INSERT_SIZE", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
31
  var maxInstertSize: Option[Int] = config("maxInstertSize")
bow's avatar
bow committed
32
33

  @Argument(doc = "ADAPTER_SEQUENCE", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
34
  var adapterSequence: List[String] = config("adapterSequence", default = Nil)
bow's avatar
bow committed
35
36

  @Argument(doc = "IS_BISULFITE_SEQUENCED", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
37
  var isBisulfiteSequenced: Option[Boolean] = config("isBisulfiteSequenced")
bow's avatar
bow committed
38
39

  @Output(doc = "The output file to write statistics to", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
40
  var output: File = _
bow's avatar
bow committed
41
42

  @Argument(doc = "Reference file", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
43
  var reference: File = config("reference")
bow's avatar
bow committed
44
45
46
47
48

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

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
54
  /** Returns command to execute */
Peter van 't Hof's avatar
Peter van 't Hof committed
55
  override def commandLine = super.commandLine +
bow's avatar
bow committed
56
57
58
59
60
61
62
63
64
    required("INPUT=", input, spaceSeparated = false) +
    required("OUTPUT=", output, spaceSeparated = false) +
    optional("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
    repeat("METRIC_ACCUMULATION_LEVEL=", metricAccumulationLevel, spaceSeparated = false) +
    optional("MAX_INSERT_SIZE=", maxInstertSize, spaceSeparated = false) +
    optional("IS_BISULFITE_SEQUENCED=", isBisulfiteSequenced, spaceSeparated = false) +
    optional("ASSUME_SORTED=", assumeSorted, spaceSeparated = false) +
    optional("STOP_AFTER=", stopAfter, spaceSeparated = false) +
    repeat("ADAPTER_SEQUENCE=", adapterSequence, spaceSeparated = false)
65
66
67

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

Peter van 't Hof's avatar
Peter van 't Hof committed
68
  /** Returns stats for summary */
Peter van 't Hof's avatar
Peter van 't Hof committed
69
  def summaryStats = Picard.getMetrics(output).getOrElse(Map())
Peter van 't Hof's avatar
Peter van 't Hof committed
70
71
72
}

object CollectAlignmentSummaryMetrics {
Peter van 't Hof's avatar
Peter van 't Hof committed
73
  /** Returns default CollectAlignmentSummaryMetrics */
Peter van 't Hof's avatar
Peter van 't Hof committed
74
  def apply(root: Configurable, input: File, outputDir: File): CollectAlignmentSummaryMetrics = {
Peter van 't Hof's avatar
Peter van 't Hof committed
75
76
77
78
79
80
    val collectAlignmentSummaryMetrics = new CollectAlignmentSummaryMetrics(root)
    collectAlignmentSummaryMetrics.input = input
    collectAlignmentSummaryMetrics.output = new File(outputDir, input.getName.stripSuffix(".bam") + ".alignmentMetrics")
    return collectAlignmentSummaryMetrics
  }
}