public class VariantContextWriterBuilder
extends java.lang.Object
Provides methods for creating VariantContextWriters using the Builder pattern.
Replaces VariantContextWriterFactory.
The caller must choose an output file or an output stream for the VariantContextWriter to write to.
When a file is chosen, the output stream is created implicitly based on Defaults and options passed to the builder.
When a stream is chosen, it is passed unchanged to the VariantContextWriter.
Example: Create a series of files with buffering and indexing on the fly. Determine the appropriate file type based on filename.
VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
.setReferenceDictionary(refDict)
.setOption(Options.INDEX_ON_THE_FLY)
.setBuffer(8192);
VariantContextWriter sample1_writer = builder
.setOutputFile("sample1.vcf")
.build();
VariantContextWriter sample2_writer = builder
.setOutputFile("sample2.bcf")
.build();
VariantContextWriter sample3_writer = builder
.setOutputFile("sample3.vcf.bgzf")
.build();
Example: Explicitly turn off buffering and explicitly set the file type
VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
.setReferenceDictionary(refDict)
.setOption(Options.INDEX_ON_THE_FLY)
.unsetBuffering();
VariantContextWriter sample1_writer = builder
.setOutputFile("sample1.custom_extension")
.setOutputFileType(OutputType.VCF)
.build();
VariantContextWriter sample2_writer = builder
.setOutputFile("sample2.custom_extension")
.setOutputFileType(OutputType.BLOCK_COMPRESSED_VCF)
.build();
| Modifier and Type | Class and Description |
|---|---|
static class |
VariantContextWriterBuilder.OutputType |
| Modifier and Type | Field and Description |
|---|---|
static java.util.EnumSet<Options> |
DEFAULT_OPTIONS |
static java.util.EnumSet<VariantContextWriterBuilder.OutputType> |
FILE_TYPES |
static java.util.EnumSet<Options> |
NO_OPTIONS |
protected java.util.EnumSet<Options> |
options |
static java.util.EnumSet<VariantContextWriterBuilder.OutputType> |
STREAM_TYPES |
| Constructor and Description |
|---|
VariantContextWriterBuilder()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
VariantContextWriter |
build()
Validate and build the
VariantContextWriter. |
VariantContextWriterBuilder |
clearIndexCreator()
Do not pass an
IndexCreator to the next VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
clearOptions()
Remove all options from the set of
Options for the VariantContextWriterBuilder. |
VariantContextWriterBuilder |
setBuffer(int bufferSize)
Set a buffer size for the file output stream passed to the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setCreateMD5()
Create an MD5 digest file for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setCreateMD5(boolean createMD5)
Choose whether to also create an MD5 digest file for the next
VariantContextWriter created by this builder. |
static void |
setDefaultOption(Options option)
Add one option to the set of default
Options that will be used as the initial set of options
for all VariantContextWriterBuilders created after this call. |
VariantContextWriterBuilder |
setIndexCreator(IndexCreator idxCreator)
Set an IndexCreator for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOption(Options option)
Add one option to the set of
Options for the VariantContextWriterBuilder, if it's not already present. |
VariantContextWriterBuilder |
setOptions(java.util.EnumSet<Options> options)
Replace the set of
Options for the VariantContextWriterBuilder with a new set. |
VariantContextWriterBuilder |
setOutputBCFStream(java.io.OutputStream outStream)
Set the output BCF stream for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOutputFile(java.io.File outFile)
Set the output file for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOutputFile(java.lang.String outFile)
Set the output file for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOutputFileType(VariantContextWriterBuilder.OutputType outType)
Set the output file type for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOutputStream(java.io.OutputStream outStream)
Set the output stream (VCF, by default) for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setOutputVCFStream(java.io.OutputStream outStream)
Set the output VCF stream for the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
setReferenceDictionary(SAMSequenceDictionary refDict)
Set the reference dictionary to be used by
VariantContextWriters created by this builder. |
VariantContextWriterBuilder |
unsetBuffering()
Do not use buffering in the next
VariantContextWriter created by this builder. |
VariantContextWriterBuilder |
unsetCreateMD5()
Don't create an MD5 digest file for the next
VariantContextWriter created by this builder. |
static void |
unsetDefaultOption(Options option)
Remove an option from the set of default
Options that will be used as the initial set of options
for all VariantContextWriterBuilders created after this call. |
VariantContextWriterBuilder |
unsetOption(Options option)
Remove one option from the set of
Options for the VariantContextWriterBuilder, if it's present. |
public static final java.util.EnumSet<Options> DEFAULT_OPTIONS
public static final java.util.EnumSet<Options> NO_OPTIONS
public static final java.util.EnumSet<VariantContextWriterBuilder.OutputType> FILE_TYPES
public static final java.util.EnumSet<VariantContextWriterBuilder.OutputType> STREAM_TYPES
protected java.util.EnumSet<Options> options
public VariantContextWriterBuilder()
USE_ASYNC_IO to the Options if it is present in Defaults.public VariantContextWriterBuilder setReferenceDictionary(SAMSequenceDictionary refDict)
VariantContextWriters created by this builder.refDict - the reference dictionaryVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputFile(java.io.File outFile)
VariantContextWriter created by this builder.
Determines file type implicitly from the filename.outFile - the file the VariantContextWriter will write toVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputFile(java.lang.String outFile)
VariantContextWriter created by this builder.
Determines file type implicitly from the filename.outFile - the file the VariantContextWriter will write toVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputFileType(VariantContextWriterBuilder.OutputType outType)
VariantContextWriter created by this builder.outType - the type of file the VariantContextWriter will write toVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputVCFStream(java.io.OutputStream outStream)
VariantContextWriter created by this builder.
If buffered writing is desired, caller must provide some kind of buffered OutputStream.outStream - the output stream to write toVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputBCFStream(java.io.OutputStream outStream)
VariantContextWriter created by this builder.
If buffered writing is desired, caller must provide some kind of buffered OutputStream.outStream - the output stream to write toVariantContextWriterBuilderpublic VariantContextWriterBuilder setOutputStream(java.io.OutputStream outStream)
VariantContextWriter created by this builder.
If buffered writing is desired, caller must provide some kind of buffered OutputStream.outStream - the output stream to write topublic VariantContextWriterBuilder setIndexCreator(IndexCreator idxCreator)
VariantContextWriter created by this builder.idxCreator - the IndexCreator to useVariantContextWriterBuilderpublic VariantContextWriterBuilder clearIndexCreator()
IndexCreator to the next VariantContextWriter created by this builder.VariantContextWriterBuilderpublic VariantContextWriterBuilder setBuffer(int bufferSize)
VariantContextWriter created by this builder.
Set to 0 for no buffering.
Does not affect OutputStreams passed directly to VariantContextWriterBuilder.bufferSize - the buffer size to useVariantContextWriterBuilderpublic VariantContextWriterBuilder unsetBuffering()
VariantContextWriter created by this builder.
Does not affect OutputStreams passed directly to VariantContextWriterBuilder.VariantContextWriterBuilderpublic VariantContextWriterBuilder setCreateMD5(boolean createMD5)
VariantContextWriter created by this builder.createMD5 - boolean, true to create an MD5 digestVariantContextWriterBuilderpublic VariantContextWriterBuilder setCreateMD5()
VariantContextWriter created by this builder.VariantContextWriterBuilderpublic VariantContextWriterBuilder unsetCreateMD5()
VariantContextWriter created by this builder.VariantContextWriterBuilderpublic VariantContextWriterBuilder setOptions(java.util.EnumSet<Options> options)
Options for the VariantContextWriterBuilder with a new set.options - the complete set of options to useVariantContextWriterBuilderpublic VariantContextWriterBuilder setOption(Options option)
Options for the VariantContextWriterBuilder, if it's not already present.option - the option to setVariantContextWriterBuilderpublic VariantContextWriterBuilder unsetOption(Options option)
Options for the VariantContextWriterBuilder, if it's present.option - the option to unsetVariantContextWriterBuilderpublic static void setDefaultOption(Options option)
Options that will be used as the initial set of options
for all VariantContextWriterBuilders created after this call.option - the option to setpublic static void unsetDefaultOption(Options option)
Options that will be used as the initial set of options
for all VariantContextWriterBuilders created after this call.option - the option to unsetpublic VariantContextWriterBuilder clearOptions()
Options for the VariantContextWriterBuilder.public VariantContextWriter build()
VariantContextWriter.VariantContextWriter as specified by previous method callsRuntimeIOException - if the writer is configured to write to a file, and the corresponding path does not exist.java.lang.IllegalArgumentException - if no output file or stream is specified.java.lang.IllegalArgumentException - if Options.INDEX_ON_THE_FLY is specified and no reference dictionary is provided.java.lang.IllegalArgumentException - if Options.INDEX_ON_THE_FLY is specified and a stream output is specified.