From ed129189e6ac8a3bcc570c25a4ed1fa0cf960605 Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Thu, 21 Jul 2016 14:53:09 +0200
Subject: [PATCH] Remove duplicated stats

---
 .../nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala    | 9 +--------
 .../scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala | 7 +------
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala
index 62f7060fc..e40f3614a 100644
--- a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala
+++ b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala
@@ -94,8 +94,6 @@ object BamStats extends ToolCommand {
 
     val stats = waitOnFutures(unmappedFuture :: contigsFutures.toList)
 
-    logger.info(s"total: ${stats.totalReads},  unmapped: ${stats.unmapped}, secondary: ${stats.secondary}")
-
     stats.writeStatsToFiles(outputDir)
   }
 
@@ -167,10 +165,7 @@ object BamStats extends ToolCommand {
       // Read based stats
       if (samRecord.getAlignmentStart > threadStart && samRecord.getAlignmentStart <= threadEnd) {
         totalStats.flagstat.loadRecord(samRecord)
-        totalStats.totalReads += 1
-        if (samRecord.isSecondaryOrSupplementary) totalStats.secondary += 1
-        if (samRecord.getReadUnmappedFlag) totalStats.unmapped += 1
-        else { // Mapped read
+        if (!samRecord.getReadUnmappedFlag) { // Mapped read
           totalStats.mappingQualityHistogram.add(samRecord.getMappingQuality)
         }
         if (samRecord.getProperPairFlag && samRecord.getFirstOfPairFlag && !samRecord.getSecondOfPairFlag)
@@ -212,8 +207,6 @@ object BamStats extends ToolCommand {
     val samReader = SamReaderFactory.makeDefault().open(bamFile)
     for (samRecord <- samReader.queryUnmapped()) {
       stats.flagstat.loadRecord(samRecord)
-      stats.totalReads += 1
-      stats.unmapped += 1
     }
     samReader.close()
     stats
diff --git a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala
index 1bab56ec2..394ccb8dd 100644
--- a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala
+++ b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/Stats.scala
@@ -7,10 +7,7 @@ import nl.lumc.sasc.biopet.tools.flagstat.FlagstatCollector
 /**
  * Created by pjvanthof on 05/07/16.
  */
-case class Stats(var totalReads: Long = 0L,
-                 var unmapped: Long = 0L,
-                 var secondary: Long = 0L,
-                 flagstat: FlagstatCollector = new FlagstatCollector(),
+case class Stats(flagstat: FlagstatCollector = new FlagstatCollector(),
                  mappingQualityHistogram: Histogram[Int] = new Histogram[Int](),
                  insertSizeHistogram: Histogram[Int] = new Histogram[Int](),
                  clippingHistogram: Histogram[Int] = new Histogram[Int](),
@@ -24,8 +21,6 @@ case class Stats(var totalReads: Long = 0L,
 
   /** This will add an other [[Stats]] inside `this` */
   def +=(other: Stats): Stats = {
-    this.totalReads += other.totalReads
-    this.unmapped += other.unmapped
     this.flagstat += other.flagstat
     this.mappingQualityHistogram += other.mappingQualityHistogram
     this.insertSizeHistogram += other.insertSizeHistogram
-- 
GitLab