From 4fbe0d0d2b58986dbbba33161eda0d6fb6ec3547 Mon Sep 17 00:00:00 2001
From: Sander Bollen <a.h.b.bollen@lumc.nl>
Date: Thu, 9 Apr 2015 11:46:17 +0200
Subject: [PATCH] setting reference dictionaries

---
 .../nl/lumc/sasc/biopet/tools/AnnotateVcfWithBed.scala   | 6 +++++-
 .../nl/lumc/sasc/biopet/tools/CheckAllelesVcfInBam.scala | 3 ++-
 .../scala/nl/lumc/sasc/biopet/tools/MergeAlleles.scala   | 5 ++++-
 .../scala/nl/lumc/sasc/biopet/tools/VcfWithVcf.scala     | 9 ++++++---
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/AnnotateVcfWithBed.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/AnnotateVcfWithBed.scala
index d6fcedf42..da0ae72f8 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/AnnotateVcfWithBed.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/AnnotateVcfWithBed.scala
@@ -106,7 +106,11 @@ object AnnotateVcfWithBed extends ToolCommand {
     val reader = new VCFFileReader(commandArgs.inputFile, false)
     val header = reader.getFileHeader
 
-    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputFile).build)
+    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().
+      setOutputFile(commandArgs.outputFile).
+      setReferenceDictionary(header.getSequenceDictionary).
+      build)
+
     val fieldType = commandArgs.fieldType match {
       case "Integer"   => VCFHeaderLineType.Integer
       case "Flag"      => VCFHeaderLineType.Flag
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/CheckAllelesVcfInBam.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/CheckAllelesVcfInBam.scala
index 25eca44c4..23fa77437 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/CheckAllelesVcfInBam.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/CheckAllelesVcfInBam.scala
@@ -87,7 +87,8 @@ object CheckAllelesVcfInBam extends ToolCommand {
     val bamHeaders = bamReaders.map(x => (x._1, x._2.getFileHeader))
 
     val reader = new VCFFileReader(commandArgs.inputFile, false)
-    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputFile).build)
+    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputFile).
+      setReferenceDictionary(reader.getFileHeader.getSequenceDictionary).build)
 
     val header = reader.getFileHeader
     for ((sample, _) <- bamReaders) {
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/MergeAlleles.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/MergeAlleles.scala
index 8d3b6358f..72abb6cea 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/MergeAlleles.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/MergeAlleles.scala
@@ -93,7 +93,10 @@ object MergeAlleles extends ToolCommand {
 
     val readers = commandArgs.inputFiles.map(new VCFFileReader(_, true))
     val referenceFile = new FastaSequenceFile(commandArgs.reference, true)
-    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputFile).build)
+    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().
+      setReferenceDictionary(referenceFile.getSequenceDictionary).
+      setOutputFile(commandArgs.outputFile).
+      build)
     val header = new VCFHeader
     val referenceDict = referenceFile.getSequenceDictionary
     header.setSequenceDictionary(referenceDict)
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/VcfWithVcf.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/VcfWithVcf.scala
index 8ae73a317..e86d146fb 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/VcfWithVcf.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/VcfWithVcf.scala
@@ -51,6 +51,11 @@ object VcfWithVcf extends ToolCommand {
 
     val header = reader.getFileHeader
     val secondHeader = secondaryReader.getFileHeader
+    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().
+      setOutputFile(commandArgs.outputFile).
+      setReferenceDictionary(header.getSequenceDictionary).
+      build)
+    writer.writeHeader(header)
 
     for (x <- commandArgs.fields) {
       if (header.hasInfoLine(x.outputField))
@@ -65,9 +70,7 @@ object VcfWithVcf extends ToolCommand {
       header.addMetaDataLine(newHeaderLine)
     }
 
-    val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().
-      setOutputFile(commandArgs.outputFile).build())
-    writer.writeHeader(header)
+
     var idx = 0
 
     for (record <- reader) {
-- 
GitLab