Stats.scala 3.86 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
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
16
package nl.lumc.sasc.biopet.tools.bamstats

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
20
import nl.lumc.sasc.biopet.tools.flagstat.FlagstatCollector

21
22
23
/**
 * Created by pjvanthof on 05/07/16.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
24
case class Stats(flagstat: FlagstatCollector = new FlagstatCollector(),
Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
27
28
29
30
31
                 mappingQualityHistogram: Histogram[Int] = new Histogram[Int](),
                 insertSizeHistogram: Histogram[Int] = new Histogram[Int](),
                 clippingHistogram: Histogram[Int] = new Histogram[Int](),
                 leftClippingHistogram: Histogram[Int] = new Histogram[Int](),
                 rightClippingHistogram: Histogram[Int] = new Histogram[Int](),
                 _5_ClippingHistogram: Histogram[Int] = new Histogram[Int](),
                 _3_ClippingHistogram: Histogram[Int] = new Histogram[Int]()) {
32

Peter van 't Hof's avatar
Peter van 't Hof committed
33
  flagstat.loadDefaultFunctions()
34
  flagstat.loadQualityFunctions()
Peter van 't Hof's avatar
Peter van 't Hof committed
35
  flagstat.loadOrientationFunctions
Peter van 't Hof's avatar
Peter van 't Hof committed
36

Peter van 't Hof's avatar
Peter van 't Hof committed
37
  /** This will add an other [[Stats]] inside `this` */
Peter van 't Hof's avatar
Peter van 't Hof committed
38
  def +=(other: Stats): Stats = {
Peter van 't Hof's avatar
Peter van 't Hof committed
39
    this.flagstat += other.flagstat
Peter van 't Hof's avatar
Peter van 't Hof committed
40
41
    this.mappingQualityHistogram += other.mappingQualityHistogram
    this.insertSizeHistogram += other.insertSizeHistogram
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
44
45
46
    this.clippingHistogram += other.clippingHistogram
    this.leftClippingHistogram += other.leftClippingHistogram
    this.rightClippingHistogram += other.rightClippingHistogram
    this._5_ClippingHistogram += other._5_ClippingHistogram
    this._3_ClippingHistogram += other._3_ClippingHistogram
47
48
    this
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
49
50

  def writeStatsToFiles(outputDir: File): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
51
52
    this.flagstat.writeReportToFile(new File(outputDir, "flagstats"))
    this.flagstat.writeSummaryTofile(new File(outputDir, "flagstats.summary.json"))
Peter van 't Hof's avatar
Peter van 't Hof committed
53
54
55
56
57
58
59
60
    this.mappingQualityHistogram.writeToTsv(new File(outputDir, "mapping_quality.tsv"))
    this.insertSizeHistogram.writeToTsv(new File(outputDir, "insert_size.tsv"))
    this.clippingHistogram.writeToTsv(new File(outputDir, "clipping.tsv"))
    this.leftClippingHistogram.writeToTsv(new File(outputDir, "left_clipping.tsv"))
    this.rightClippingHistogram.writeToTsv(new File(outputDir, "right_clipping.tsv"))
    this._5_ClippingHistogram.writeToTsv(new File(outputDir, "5_prime_clipping.tsv"))
    this._3_ClippingHistogram.writeToTsv(new File(outputDir, "3_prime_clipping.tsv"))
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
61
62
63
64

  def toSummaryMap = {
    Map(
      "flagstats" -> flagstat.toSummaryMap,
Peter van 't Hof's avatar
Peter van 't Hof committed
65
66
67
68
69
70
71
      "mapping_quality" -> Map("histogram" -> mappingQualityHistogram.toSummaryMap, "general" -> mappingQualityHistogram.aggregateStats),
      "insert_size" -> Map("histogram" -> insertSizeHistogram.toSummaryMap, "general" -> insertSizeHistogram.aggregateStats),
      "clipping" -> Map("histogram" -> clippingHistogram.toSummaryMap, "general" -> clippingHistogram.aggregateStats),
      "left_clipping" -> Map("histogram" -> leftClippingHistogram.toSummaryMap, "general" -> leftClippingHistogram.aggregateStats),
      "right_clipping" -> Map("histogram" -> rightClippingHistogram.toSummaryMap, "general" -> rightClippingHistogram.aggregateStats),
      "5_prime_clipping" -> Map("histogram" -> _5_ClippingHistogram.toSummaryMap, "general" -> _5_ClippingHistogram.aggregateStats),
      "3_prime_clipping" -> Map("histogram" -> _3_ClippingHistogram.toSummaryMap, "general" -> _3_ClippingHistogram.aggregateStats)
Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
    )
  }
74
}