From 1caad8532e91460b82138cabd5c8ed764e0b8e19 Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Tue, 20 Sep 2016 16:30:39 +0200
Subject: [PATCH] Add a split to unique reports

---
 .../centrifuge/CentrifugeKreport.scala        | 13 +++++++++++-
 .../pipelines/gears/GearsCentrifuge.scala     | 20 +++++++++++++------
 .../biopet/pipelines/gears/GearsReport.scala  |  7 +++++--
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/centrifuge/CentrifugeKreport.scala b/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/centrifuge/CentrifugeKreport.scala
index 24cd283c3..386a372b3 100644
--- a/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/centrifuge/CentrifugeKreport.scala
+++ b/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/centrifuge/CentrifugeKreport.scala
@@ -19,10 +19,21 @@ class CentrifugeKreport(val root: Configurable) extends BiopetCommandLineFunctio
   @Input(doc = "Centrifuge index prefix", required = true)
   var index: File = config("centrifuge_index", namespace = "centrifuge")
 
+  var onlyUnique: Boolean = config ("only_unique", default = false)
+  var showZeros: Boolean = config ("show_zeros", default = false)
+  var isCounts: Boolean = config ("is_counts", default = false)
+
+  var minScore: Option[Double] = config("min_score")
+  var minLength: Option[Int] = config("min_length")
+
   executable = config("exe", default = "centrifuge-kreport", freeVar = false)
 
   def cmdLine = executable +
-    //TODO: Options
+    conditional(onlyUnique, "--only-unique") +
+    conditional(showZeros, "--show-zeros") +
+    conditional(showZeros, "--is-counts") +
+    optional("--min-score=", minScore, spaceSeparated = false) +
+    optional("--min-length=", minLength, spaceSeparated = false) +
     required("-x", index) +
     repeat(centrifugeOutputFiles) +
     " > " + required(output)
diff --git a/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsCentrifuge.scala b/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsCentrifuge.scala
index 45ecf3e60..210c53182 100644
--- a/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsCentrifuge.scala
+++ b/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsCentrifuge.scala
@@ -18,6 +18,8 @@ class GearsCentrifuge(val root: Configurable) extends QScript with SummaryQScrip
 
   var outputName: String = _
 
+  override def fixedValues = Map("centrifugekreport" -> Map("only_unique" -> false))
+
   def init(): Unit = {
     require(fastqR1 != null)
     if (outputName == null) outputName = fastqR1.getName
@@ -34,19 +36,25 @@ class GearsCentrifuge(val root: Configurable) extends QScript with SummaryQScrip
     centrifuge.report = Some(new File(outputDir, s"$outputName.centrifuge.report"))
     add(centrifuge)
 
+    makeKreport(List(centrifuge.output), "centrifuge", unique = false)
+    makeKreport(List(centrifuge.output), "centrifuge_unique", unique = true)
+
+    addSummaryJobs()
+  }
+
+  protected def makeKreport(inputFiles: List[File], name: String, unique: Boolean): Unit = {
     val centrifugeKreport = new CentrifugeKreport(this)
-    centrifugeKreport.centrifugeOutputFiles :+= centrifuge.output
-    centrifugeKreport.output = new File(outputDir, s"$outputName.centrifuge.kreport")
+    centrifugeKreport.centrifugeOutputFiles = inputFiles
+    centrifugeKreport.output = new File(outputDir, s"$outputName.$name.kreport")
+    centrifugeKreport.onlyUnique = unique
     add(centrifugeKreport)
 
     val krakenReportJSON = new KrakenReportToJson(this)
     krakenReportJSON.inputReport = centrifugeKreport.output
-    krakenReportJSON.output = new File(outputDir, s"$outputName.krkn.json")
+    krakenReportJSON.output = new File(outputDir, s"$outputName.$name.krkn.json")
     krakenReportJSON.skipNames = config("skipNames", default = false)
     add(krakenReportJSON)
-    addSummarizable(krakenReportJSON, "centrifuge_report")
-
-    addSummaryJobs()
+    addSummarizable(krakenReportJSON, s"${name}_report")
   }
 
   /** Location of summary file */
diff --git a/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsReport.scala b/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsReport.scala
index bc38c3f32..69e005f26 100644
--- a/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsReport.scala
+++ b/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsReport.scala
@@ -46,8 +46,11 @@ object GearsReport extends MultisampleReportBuilder {
 
     ReportPage(
       (if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List(), List(
-        "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
-        )), Map("summaryStatsTag" -> "centrifuge_report", "summaryModuleTag" -> "gearscentrifuge")))
+        "Unique Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
+          Map("summaryStatsTag" -> "centrifuge_unique_report")
+        ), "All Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
+          Map("summaryStatsTag" -> "centrifuge_report")
+        )), Map("summaryModuleTag" -> "gearscentrifuge")))
       else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List(
         "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
         )), Map()))
-- 
GitLab