CollectAlignmentSummaryMetrics.scala 3.6 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

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

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
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input, Output }
Peter van 't Hof's avatar
Peter van 't Hof committed
23

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

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

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

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

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

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

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

  @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
50
  var metricAccumulationLevel: List[String] = config("metricaccumulationlevel", default = Nil)
bow's avatar
bow committed
51
52

  @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

Peter van 't Hof's avatar
Peter van 't Hof committed
55
  /** Returns command to execute */
56
  override def cmdLine = super.cmdLine +
bow's avatar
bow committed
57
58
59
60
61
62
63
64
65
    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)
66
67
68

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

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

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