/** * Set the output stream (VCF, by default) for the next <code>VariantContextWriter</code> created by this builder. * If buffered writing is desired, caller must provide some kind of buffered <code>OutputStream</code>. * * @param outStream the output stream to write to * @return this VariantContextWriterBuilder */ public VariantContextWriterBuilder setOutputStream(final OutputStream outStream) { return setOutputVCFStream(outStream); }
/** * Set the output stream (VCF, by default) for the next VariantContextWriter created by this builder * If buffered writing is desired, caller must provide some kind of buffered OutputStream. * * @param outStream the output stream to write to * @return this VariantContextWriterBuilder */ public VariantContextWriterBuilder setOutputStream(final OutputStream outStream) { return setOutputVCFStream(outStream); }
/** * Set the output stream (VCF, by default) for the next <code>VariantContextWriter</code> created by this builder. * If buffered writing is desired, caller must provide some kind of buffered <code>OutputStream</code>. * * @param outStream the output stream to write to * @return this VariantContextWriterBuilder */ public VariantContextWriterBuilder setOutputStream(final OutputStream outStream) { return setOutputVCFStream(outStream); }
.setOutputVCFStream(headerOut).build(); writer.writeHeader(header); headerOut.flush();
.setOutputVCFStream(headerOut).build(); writer.writeHeader(header); headerOut.flush();
.setOutputVCFStream(headerOut).build(); writer.writeHeader(header); headerOut.flush();
@Test public void testSetOutputStream() { final OutputStream stream = new ByteArrayOutputStream(); final VariantContextWriterBuilder builder = new VariantContextWriterBuilder() .setReferenceDictionary(dictionary) .unsetOption(Options.INDEX_ON_THE_FLY) .setOutputStream(stream); VariantContextWriter writer = builder.build(); Assert.assertTrue(writer instanceof VCFWriter, "testSetOutputStream default"); writer = builder.setOption(Options.FORCE_BCF).build(); Assert.assertTrue(writer instanceof BCF2Writer, "testSetOutputStream FORCE_BCF set -> expected BCF stream, was VCF stream"); // test that FORCE_BCF remains in effect, overriding the explicit setting of VCF writer = builder.setOutputVCFStream(stream).build(); Assert.assertTrue(writer instanceof BCF2Writer, "testSetOutputStream FORCE_BCF set 2 -> expected BCF stream, was VCF stream"); writer = builder.unsetOption(Options.FORCE_BCF).build(); Assert.assertTrue(writer instanceof VCFWriter, "testSetOutputStream FORCE_BCF unset -> expected VCF stream, was BCF stream"); writer = builder.setOutputBCFStream(stream).build(); Assert.assertTrue(writer instanceof BCF2Writer, "testSetOutputStream BCF"); writer = builder.setOutputVCFStream(stream).build(); Assert.assertTrue(writer instanceof VCFWriter, "testSetOutputStream VCF"); }
/** * Converts a list of variants into a VCF file, given a {@link VCFHeader} * and an {@link OutputStream}. * <p> This function uses HTSJDK to create {@link VariantCall} objects then * writes them to the given output stream. Note that this implementation depends * heavily on HTSJDK and makes the same assumptions as HTSJDK (e.g. integer values GQ). * * @param header The header to use to generate the output VCF * @param variants A list of variants to encode in the output VCF * @param os The output stream to which to write the generated VCF */ public static void convertVariantToVcf(VCFHeader header, List<Variant> variants, OutputStream os, boolean writeHeader) { if (vcfWriter == null) { vcfWriter = new VariantContextWriterBuilder().clearOptions() .setOutputVCFStream(os).build(); } if (writeHeader) { vcfWriter.writeHeader(header); } for (Variant currVariant : variants) { vcfWriter.add(getContextFromVariant(header, currVariant)); } } }
case VCF_STREAM: mVCWriter = new VariantContextWriterBuilder() .setOutputVCFStream(mStream) .unsetOption(Options.INDEX_ON_THE_FLY).build(); break;
/** * Constructs an object which will write directly into the output file provided by the stub. * Intentionally delaying the writing of the header -- this should be filled in by the walker. * * Respecs the isCompressed() request in stub, so if isCompressed() is true then this * will create a storage output that dumps output to a BlockCompressedOutputStream. * * @param stub Stub to use when constructing the output file. */ public VariantContextWriterStorage(VariantContextWriterStub stub) { if ( stub.getOutputFile() != null ) { this.file = stub.getOutputFile(); writer = vcfWriterToFile(stub,stub.getOutputFile(),true,true); } else if ( stub.getOutputStream() != null ) { this.file = null; this.stream = stub.getOutputStream(); writer = new VariantContextWriterBuilder() .setOutputVCFStream(stream) .setReferenceDictionary(stub.getMasterSequenceDictionary()) .setOptions(stub.getWriterOptions(false)) .build(); } else throw new ReviewedGATKException("Unable to create target to which to write; storage was provided with neither a file nor a stream."); }