From f1599432771af45d80bbbbfbb99fd5b5890d043e Mon Sep 17 00:00:00 2001
From: sajvanderzeeuw <s.a.j.van_der_zeeuw@lumc.nl>
Date: Fri, 16 Oct 2015 11:23:24 +0200
Subject: [PATCH] added tabix to bcftools output

---
 .../lumc/sasc/biopet/extensions/Tabix.scala   | 26 +++++++++++++++----
 .../shiva/ShivaVariantcallingTrait.scala      |  3 ++-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
index 4a80600c5..d8f36a194 100644
--- a/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
@@ -35,10 +35,9 @@ class Tabix(val root: Configurable) extends BiopetCommandLineFunction {
   @Output(doc = "Output (for region query)", required = false)
   var outputQuery: File = null
 
-  @Output(doc = "Output (for indexing)", required = false) // NOTE: it's a def since we can't change the index name ~ it's always input_name + .tbi
-  lazy val outputIndex: File = {
-    require(input != null, "Input must be defined")
-    new File(input.toString + ".tbi")
+  def outputIndex: File = {
+    require(input != null, "Input should be defined")
+    new File(input.getAbsolutePath + ".tbi")
   }
 
   @Argument(doc = "Regions to query", required = false)
@@ -70,7 +69,8 @@ class Tabix(val root: Configurable) extends BiopetCommandLineFunction {
     p match {
       case Some(fmt) =>
         require(validFormats.contains(fmt), "-p flag must be one of " + validFormats.mkString(", "))
-      case None => ;
+        outputFiles :+= outputIndex
+      case None =>
     }
   }
 
@@ -96,3 +96,19 @@ class Tabix(val root: Configurable) extends BiopetCommandLineFunction {
     else baseCommand
   }
 }
+
+object Tabix {
+  def apply(root: Configurable, input: File) = {
+    val tabix = new Tabix(root)
+    tabix.input = input
+    tabix.p = tabix.input.getName match {
+      case s if s.endsWith(".vcf.gz")    => Some("vcf")
+      case s if s.endsWith(".bed.gz")    => Some("bed")
+      case s if s.endsWith(".sam.gz")    => Some("sam")
+      case s if s.endsWith(".gff.gz")    => Some("gff")
+      case s if s.endsWith(".psltbl.gz") => Some("psltbl")
+      case _                             => throw new IllegalArgumentException("Unknown file type")
+    }
+    tabix
+  }
+}
\ No newline at end of file
diff --git a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTrait.scala b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTrait.scala
index 985d75879..365d4e638 100644
--- a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTrait.scala
+++ b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTrait.scala
@@ -163,7 +163,6 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag with
       val mp = new SamtoolsMpileup(qscript)
       mp.input = inputBams
       mp.u = true
-      //TODO: proper piping should be implemented
       mp.reference = referenceFasta()
 
       val bt = new BcftoolsCall(qscript)
@@ -172,6 +171,7 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag with
       bt.c = true
 
       add(mp | bt > outputFile)
+      add(Tabix(qscript, outputFile))
     }
   }
 
@@ -197,6 +197,7 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag with
         bt.output = new File(outputDir, inputBam.getName + ".vcf.gz")
 
         add(mp | bt)
+        add(Tabix(qscript, bt.output))
         bt.output
       }
 
-- 
GitLab