CollectMultipleMetrics.scala 4.39 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
package nl.lumc.sasc.biopet.extensions.picard

import java.io.File

import nl.lumc.sasc.biopet.core.BiopetQScript
import nl.lumc.sasc.biopet.core.config.Configurable
7
import nl.lumc.sasc.biopet.core.summary.{ Summarizable, SummaryQScript }
Peter van 't Hof's avatar
Peter van 't Hof committed
8
9
10
11
12
import org.broadinstitute.gatk.utils.commandline.{ Output, Argument, Input }

/**
 * Created by pjvan_thof on 4/16/15.
 */
13
class CollectMultipleMetrics(val root: Configurable) extends Picard with Summarizable {
Peter van 't Hof's avatar
Peter van 't Hof committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  import CollectMultipleMetrics._

  javaMainClass = new picard.analysis.CollectMultipleMetrics().getClass.getName

  @Input(doc = "The input SAM or BAM files to analyze", required = true)
  var input: File = null

  @Output(doc = "Base name of output files", required = true)
  var outputName: File = null

  @Argument(doc = "Base name of output files", required = true)
  var program: List[String] = config("metrics_programs",
    default = Programs.values.iterator.toList.map(_.toString))

  @Argument(doc = "Assume alignment file is sorted by position", required = false)
  var assumeSorted: Boolean = config("assume_sorted", default = false)

  @Argument(doc = "Stop after processing N reads", required = false)
  var stopAfter: Option[Long] = config("stop_after")

  @Output
  protected var outputFiles: List[File] = Nil

  override def beforeGraph: Unit = {
    program.foreach(p => p match {
      case _ if p == Programs.CollectAlignmentSummaryMetrics.toString => {
        outputFiles :+= new File(outputName + ".alignment_summary_metrics")
      }
      case _ if p == Programs.CollectInsertSizeMetrics.toString => {
        outputFiles :+= new File(outputName + ".insert_size_metrics")
        outputFiles :+= new File(outputName + ".insert_size_Histogram.pdf")
      }
      case _ if p == Programs.QualityScoreDistribution.toString => {
        outputFiles :+= new File(outputName + ".quality_distribution_metrics")
        outputFiles :+= new File(outputName + ".test.quality_distribution.pdf")
      }
      case _ if p == Programs.MeanQualityByCycle.toString => {
        outputFiles :+= new File(outputName + ".quality_by_cycle_metrics")
        outputFiles :+= new File(outputName + ".quality_by_cycle.pdf")
      }
      case _ if p == Programs.CollectBaseDistributionByCycle.toString => {
        outputFiles :+= new File(outputName + ".base_distribution_by_cycle_metrics")
        outputFiles :+= new File(outputName + ".base_distribution_by_cycle.pdf")
      }
      case _ => BiopetQScript.addError("Program '" + p + "' does not exist for 'CollectMultipleMetrics'")
    })
  }

  override def commandLine = super.commandLine +
    required("INPUT=", input, spaceSeparated = false) +
    required("OUTPUT=", outputName, spaceSeparated = false) +
Peter van 't Hof's avatar
Peter van 't Hof committed
65
66
    conditional(assumeSorted, "ASSUME_SORTED=true") +
    optional("STOP_AFTER=", stopAfter, spaceSeparated = false) +
Peter van 't Hof's avatar
Peter van 't Hof committed
67
    repeat("PROGRAM=", program, spaceSeparated = false)
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

  override def addToQscriptSummary(qscript: SummaryQScript, name: String): Unit = {
    program.foreach(p => {
      val stats: Map[String, Any] = p match {
        case _ if p == Programs.CollectAlignmentSummaryMetrics.toString =>
          Picard.getMetrics(new File(outputName + ".alignment_summary_metrics")).getOrElse(Map())
        case _ if p == Programs.CollectInsertSizeMetrics.toString =>
          Map()
          Picard.getMetrics(new File(outputName + ".insert_size_metrics")).getOrElse(Map())
        case _ if p == Programs.QualityScoreDistribution.toString =>
          Map()
          Picard.getMetrics(new File(outputName + ".quality_distribution_metrics")).getOrElse(Map())
        case _ if p == Programs.MeanQualityByCycle.toString =>
          Map()
          Picard.getMetrics(new File(outputName + ".quality_by_cycle_metrics")).getOrElse(Map())
        case _ if p == Programs.CollectBaseDistributionByCycle.toString =>
          Map()
          Picard.getMetrics(new File(outputName + ".base_distribution_by_cycle_metrics")).getOrElse(Map())
        case _ => Map()
      }
      val sum = new Summarizable {
        override def summaryFiles: Map[String, File] = Map()
        override def summaryStats: Map[String, Any] = stats
      }
      qscript.addSummarizable(sum, p)
    })

  }

  def summaryFiles = Map()

  def summaryStats = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
100
101
102
103
104
105
106
}

object CollectMultipleMetrics {
  object Programs extends Enumeration {
    val CollectAlignmentSummaryMetrics, CollectInsertSizeMetrics, QualityScoreDistribution, MeanQualityByCycle, CollectBaseDistributionByCycle = Value
  }
}