diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/BCF2Writer.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/BCF2Writer.java index 6b887aa15..bd3f0bb76 100644 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/BCF2Writer.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/BCF2Writer.java @@ -62,8 +62,6 @@ class BCF2Writer extends IndexingVariantContextWriter { @Override public void writeHeader(final VCFHeader header) { - this.header = header; - // create the config offsets map for ( final VCFContigHeaderLine contig : header.getContigLines()) contigDictionary.put(contig.getID(), contig.getContigIndex()); @@ -78,7 +76,7 @@ class BCF2Writer extends IndexingVariantContextWriter { // write out the header into a byte stream, get it's length, and write everything to the file final ByteArrayOutputStream capture = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(capture); - VCFWriter.writeHeader(header, writer, doNotWriteGenotypes, VCFWriter.getVersionLine(), "BCF2 stream"); + this.header = VCFWriter.writeHeader(header, writer, doNotWriteGenotypes, VCFWriter.getVersionLine(), "BCF2 stream"); writer.append('\0'); // the header is null terminated by a byte writer.close(); diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/VCFWriter.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/VCFWriter.java index 24f1921a8..d080d1754 100755 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/VCFWriter.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/writer/VCFWriter.java @@ -90,8 +90,9 @@ class VCFWriter extends IndexingVariantContextWriter { @Override public void writeHeader(VCFHeader header) { - mHeader = header; - writeHeader(mHeader, mWriter, doNotWriteGenotypes, getVersionLine(), getStreamName()); + // note we need to update the mHeader object after this call because they header + // may have genotypes trimmed out of it, if doNotWriteGenotypes is true + mHeader = writeHeader(header, mWriter, doNotWriteGenotypes, getVersionLine(), getStreamName()); // determine if we use filters, so we should FORCE pass the records // TODO -- this might not be necessary any longer as we have unfiltered, filtered, and PASS VCs @@ -105,11 +106,11 @@ class VCFWriter extends IndexingVariantContextWriter { return VERSION_LINE; } - public static void writeHeader(VCFHeader header, - final Writer writer, - final boolean doNotWriteGenotypes, - final String versionLine, - final String streamNameForError) { + public static VCFHeader writeHeader(VCFHeader header, + final Writer writer, + final boolean doNotWriteGenotypes, + final String versionLine, + final String streamNameForError) { header = doNotWriteGenotypes ? new VCFHeader(header.getMetaData()) : header; try { @@ -151,6 +152,8 @@ class VCFWriter extends IndexingVariantContextWriter { catch (IOException e) { throw new ReviewedStingException("IOException writing the VCF header to " + streamNameForError, e); } + + return header; } /**