From 54673e3d23b2d14501525a35c046b1e33cfa3b19 Mon Sep 17 00:00:00 2001
From: Sander Bollen <a.h.b.bollen@lumc.nl>
Date: Thu, 13 Aug 2015 18:30:07 +0200
Subject: [PATCH] basty generate fasta test stub

---
 .../biopet/tools/BastyGenerateFasta.scala     |  9 ++--
 .../biopet/tools/BastyGenerateFastaTest.scala | 41 +++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala

diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFasta.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFasta.scala
index 33c26353d..66f5ba800 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFasta.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFasta.scala
@@ -155,7 +155,7 @@ object BastyGenerateFasta extends ToolCommand {
     }
   }
 
-  protected var cmdArgs: Args = _
+  protected implicit var cmdArgs: Args = _
   private val chunkSize = 100000
 
   /**
@@ -253,7 +253,7 @@ object BastyGenerateFasta extends ToolCommand {
     }
   }
 
-  protected def writeVariantsOnly() {
+  protected[tools] def writeVariantsOnly() {
     val writer = new PrintWriter(cmdArgs.outputVariants)
     writer.println(">" + cmdArgs.outputName)
     val vcfReader = new VCFFileReader(cmdArgs.inputVcf, false)
@@ -265,7 +265,10 @@ object BastyGenerateFasta extends ToolCommand {
     vcfReader.close()
   }
 
-  protected def getMaxAllele(vcfRecord: VariantContext): String = {
+  // TODO: what does this do?
+  // Seems to me it finds the allele in a sample with the highest AD value
+  // if this allele is shorter than the largest allele, it will append '-' to the string
+  protected[tools] def getMaxAllele(vcfRecord: VariantContext)(implicit cmdArgs: Args): String = {
     val maxSize = getLongestAllele(vcfRecord).getBases.length
 
     if (cmdArgs.sampleName == null) return fillAllele(vcfRecord.getReference.getBaseString, maxSize)
diff --git a/public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala b/public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala
new file mode 100644
index 000000000..48ff9cfe2
--- /dev/null
+++ b/public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala
@@ -0,0 +1,41 @@
+package nl.lumc.sasc.biopet.tools
+
+import java.io.File
+import java.nio.file.Paths
+
+import htsjdk.variant.vcf.VCFFileReader
+import org.scalatest.Matchers
+import org.scalatest.testng.TestNGSuite
+import org.testng.annotations.Test
+import org.scalatest.mock.MockitoSugar
+import org.mockito.Mockito._
+
+/**
+ * Created by ahbbollen on 13-8-15.
+ */
+class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers {
+
+  import BastyGenerateFasta._
+  private def resourcePath(p: String): String = {
+    Paths.get(getClass.getResource(p).toURI).toString
+  }
+
+  val vepped_path = resourcePath("/VEP_oneline.vcf")
+  val vepped = new File(vepped_path)
+
+  @Test def testGetMaxAllele = {
+    val reader = new VCFFileReader(vepped, false)
+    val record = reader.iterator().next()
+
+    val child = mock[Args]
+    when(child.sampleName) thenReturn "Child_7006504"
+    val father = mock[Args]
+    when(father.sampleName) thenReturn "Father_7006506"
+
+
+    getMaxAllele(record)(child) shouldBe "C-"
+    getMaxAllele(record)(father) shouldBe "CA"
+
+  }
+
+}
-- 
GitLab