From 2af46d82e538afe56b5e2415ff9ab7abd6032b8a Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Tue, 5 Apr 2016 12:57:21 +0200
Subject: [PATCH] Refactor Reference so dict and fai file becomes accessable as
 a method

---
 .../core/BiopetCommandLineFunction.scala      |  9 +++++++
 .../nl/lumc/sasc/biopet/core/Reference.scala  | 26 +++++++++----------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
index a413c8bad..23122f1e3 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
@@ -73,6 +73,15 @@ trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction =>
   def beforeGraph() {}
 
   override def freezeFieldValues() {
+
+    this match {
+      case r:Reference =>
+        if (r.dictRequired) deps :+= r.referenceDict
+        if (r.faiRequired) deps :+= r.referenceFai
+        deps = deps.distinct
+      case _ =>
+    }
+
     preProcessExecutable()
     beforeGraph()
     internalBeforeGraph()
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
index 6a39ca3eb..f00de9e17 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
@@ -61,25 +61,25 @@ trait Reference extends Configurable {
   }
 
   /** When set override this on true the pipeline with raise an exception when fai index is not found */
-  protected def faiRequired = false
+  def faiRequired = false
 
   /** When set override this on true the pipeline with raise an exception when dict index is not found */
-  protected def dictRequired = this.isInstanceOf[Summarizable] || this.isInstanceOf[SummaryQScript]
+  def dictRequired = this.isInstanceOf[Summarizable] || this.isInstanceOf[SummaryQScript]
+
+  /** Returns the dict file belonging to the fasta file */
+  def referenceDict = new File(referenceFasta().getAbsolutePath
+    .stripSuffix(".fa")
+    .stripSuffix(".fasta")
+    .stripSuffix(".fna") + ".dict")
+
+  /** Returns the fai file belonging to the fasta file */
+  def referenceFai = new File(referenceFasta().getAbsolutePath + ".fai")
 
   /** Returns the fasta file */
   def referenceFasta(): File = {
     val file: File = config("reference_fasta")
-    if (config.contains("reference_fasta")) {
-      checkFasta(file)
-
-      val dict = new File(file.getAbsolutePath.stripSuffix(".fa").stripSuffix(".fasta").stripSuffix(".fna") + ".dict")
-      val fai = new File(file.getAbsolutePath + ".fai")
-
-      this match {
-        case c: BiopetCommandLineFunction => c.deps :::= dict :: fai :: Nil
-        case _                            =>
-      }
-    } else {
+    if (config.contains("reference_fasta")) checkFasta(file)
+    else {
       val defaults = ConfigUtils.mergeMaps(this.defaults, this.internalDefaults)
 
       def getReferences(map: Map[String, Any]): Set[(String, String)] = (for (
-- 
GitLab