From 1579a88b32b33a12ed391384c55bb3bfe036d7a9 Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Thu, 21 Jul 2016 19:35:31 +0200
Subject: [PATCH] Split methods

---
 .../lumc/sasc/biopet/tools/bamstats/BamStats.scala |  2 +-
 .../nl/lumc/sasc/biopet/tools/bamstats/Stats.scala |  3 ++-
 .../biopet/tools/flagstat/BiopetFlagstat.scala     |  2 +-
 .../biopet/tools/flagstat/FlagstatCollector.scala  | 14 +++++++++++++-
 4 files changed, 17 insertions(+), 4 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 4b39411da..6509e9cdb 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
@@ -77,7 +77,7 @@ object BamStats extends ToolCommand {
   }
 
   /**
-   * This is the main running function of [[BamStats]]. This will start the thereads and collect and write the results.
+   * This is the main running function of [[BamStats]]. This will start the threads and collect and write the results.
    *
    * @param outputDir All output files will be placed here
    * @param bamFile Input bam file
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 394ccb8dd..6f6aa43c4 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
@@ -17,7 +17,8 @@ case class Stats(flagstat: FlagstatCollector = new FlagstatCollector(),
                  _3_ClippingHistogram: Histogram[Int] = new Histogram[Int]()) {
 
   flagstat.loadDefaultFunctions()
-  flagstat.loadAditionalFunctions(1, 0)
+  flagstat.loadQualityFunctions(1, 0)
+  flagstat.loadOrientationFunctions
 
   /** This will add an other [[Stats]] inside `this` */
   def +=(other: Stats): Stats = {
diff --git a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/BiopetFlagstat.scala b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/BiopetFlagstat.scala
index 193d6ce80..9ba72c3ff 100644
--- a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/BiopetFlagstat.scala
+++ b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/BiopetFlagstat.scala
@@ -62,7 +62,7 @@ object BiopetFlagstat extends ToolCommand {
 
     val flagstatCollector = new FlagstatCollector
     flagstatCollector.loadDefaultFunctions()
-    flagstatCollector.loadAditionalFunctions()
+    flagstatCollector.loadQualityFunctions()
 
     logger.info("Start reading file: " + commandArgs.inputFile)
     for (record <- iterSam) {
diff --git a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/FlagstatCollector.scala b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/FlagstatCollector.scala
index 693bf849a..f24d04e38 100644
--- a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/FlagstatCollector.scala
+++ b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/flagstat/FlagstatCollector.scala
@@ -40,9 +40,21 @@ class FlagstatCollector {
     addFunction("SecondaryOrSupplementary", record => record.isSecondaryOrSupplementary)
   }
 
-  def loadAditionalFunctions(m: Int = 10, max: Int = 60): Unit = {
+  /**
+    * The method will aditional checks based on  mapping quality of the sam records.
+    *
+    * @param m steps of qaulity
+    * @param max maximum quality
+    */
+  def loadQualityFunctions(m: Int = 10, max: Int = 60): Unit = {
     for (t <- 0 to (max / m))
       this.addFunction("MAPQ>" + (t * m), record => record.getMappingQuality > (t * m))
+  }
+
+  /**
+    * This method will add functions to check orientation, for this a combination of flags and read positions are used.
+    */
+  def loadOrientationFunctions = {
     this.addFunction("First normal, second read inverted (paired end orientation)", record => {
       if (record.getReadPairedFlag &&
         record.getReferenceIndex == record.getMateReferenceIndex && record.getReadNegativeStrandFlag != record.getMateNegativeStrandFlag &&
-- 
GitLab