Class VariantContextWriterBuilder
- java.lang.Object
-
- htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder
-
public class VariantContextWriterBuilder extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VariantContextWriterBuilder.OutputType
-
Field Summary
Fields Modifier and Type Field Description static EnumSet<Options>
DEFAULT_OPTIONS
static EnumSet<VariantContextWriterBuilder.OutputType>
FILE_TYPES
static EnumSet<Options>
NO_OPTIONS
protected EnumSet<Options>
options
static EnumSet<VariantContextWriterBuilder.OutputType>
STREAM_TYPES
-
Constructor Summary
Constructors Constructor Description VariantContextWriterBuilder()
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description VariantContextWriter
build()
Validate and build theVariantContextWriter
.VariantContextWriter
build(OpenOption... openOptions)
Validate and build theVariantContextWriter
.VariantContextWriterBuilder
clearIndexCreator()
Do not pass anIndexCreator
to the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
clearOptions()
Remove all options from the set ofOptions
for theVariantContextWriterBuilder
.static VariantContextWriterBuilder.OutputType
determineOutputTypeFromFile(File file)
Attempts to determine the type of file/data to write based on the File path being written to.static VariantContextWriterBuilder.OutputType
determineOutputTypeFromFile(Path path)
Attempts to determine the type of file/data to write based on the File path being written to.VariantContextWriterBuilder
modifyOption(Options option, boolean setIt)
Set or unset option depending on the boolean givenVariantContextWriterBuilder
setBuffer(int bufferSize)
Set a buffer size for the file output stream passed to the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setCreateMD5()
Create an MD5 digest file for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setCreateMD5(boolean createMD5)
Choose whether to also create an MD5 digest file for the nextVariantContextWriter
created by this builder.static void
setDefaultOption(Options option)
Add one option to the set of defaultOptions
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 nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOption(Options option)
Add one option to the set ofOptions
for theVariantContextWriterBuilder
, if it's not already present.VariantContextWriterBuilder
setOptions(EnumSet<Options> options)
Replace the set ofOptions
for theVariantContextWriterBuilder
with a new set.VariantContextWriterBuilder
setOutputBCFStream(OutputStream outStream)
Set the output BCF stream for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputFile(File outFile)
Set the output file for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputFile(String outFile)
Set the output file for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputFileType(VariantContextWriterBuilder.OutputType outType)
Set the output file type for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputPath(Path outPath)
Set the output file for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputStream(OutputStream outStream)
Set the output stream (VCF, by default) for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setOutputVCFStream(OutputStream outStream)
Set the output VCF stream for the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
setReferenceDictionary(SAMSequenceDictionary refDict)
Set the reference dictionary to be used byVariantContextWriter
s created by this builder.VariantContextWriterBuilder
unsetBuffering()
Do not use buffering in the nextVariantContextWriter
created by this builder.VariantContextWriterBuilder
unsetCreateMD5()
Don't create an MD5 digest file for the nextVariantContextWriter
created by this builder.static void
unsetDefaultOption(Options option)
Remove an option from the set of defaultOptions
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 ofOptions
for theVariantContextWriterBuilder
, if it's present.
-
-
-
Field Detail
-
FILE_TYPES
public static final EnumSet<VariantContextWriterBuilder.OutputType> FILE_TYPES
-
STREAM_TYPES
public static final EnumSet<VariantContextWriterBuilder.OutputType> STREAM_TYPES
-
-
Method Detail
-
setReferenceDictionary
public VariantContextWriterBuilder setReferenceDictionary(SAMSequenceDictionary refDict)
Set the reference dictionary to be used byVariantContextWriter
s created by this builder.- Parameters:
refDict
- the reference dictionary- Returns:
- this
VariantContextWriterBuilder
-
setOutputFile
public VariantContextWriterBuilder setOutputFile(File outFile)
Set the output file for the nextVariantContextWriter
created by this builder. Determines file type implicitly from the filename.- Parameters:
outFile
- the file theVariantContextWriter
will write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputPath
public VariantContextWriterBuilder setOutputPath(Path outPath)
Set the output file for the nextVariantContextWriter
created by this builder. Determines file type implicitly from the filename.- Parameters:
outPath
- the file theVariantContextWriter
will write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputFile
public VariantContextWriterBuilder setOutputFile(String outFile)
Set the output file for the nextVariantContextWriter
created by this builder. Determines file type implicitly from the filename.- Parameters:
outFile
- the file theVariantContextWriter
will write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputFileType
public VariantContextWriterBuilder setOutputFileType(VariantContextWriterBuilder.OutputType outType)
Set the output file type for the nextVariantContextWriter
created by this builder.- Parameters:
outType
- the type of file theVariantContextWriter
will write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputVCFStream
public VariantContextWriterBuilder setOutputVCFStream(OutputStream outStream)
Set the output VCF stream for the nextVariantContextWriter
created by this builder. If buffered writing is desired, caller must provide some kind of bufferedOutputStream
.- Parameters:
outStream
- the output stream to write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputBCFStream
public VariantContextWriterBuilder setOutputBCFStream(OutputStream outStream)
Set the output BCF stream for the nextVariantContextWriter
created by this builder. If buffered writing is desired, caller must provide some kind of bufferedOutputStream
.- Parameters:
outStream
- the output stream to write to- Returns:
- this
VariantContextWriterBuilder
-
setOutputStream
public VariantContextWriterBuilder setOutputStream(OutputStream outStream)
Set the output stream (VCF, by default) for the nextVariantContextWriter
created by this builder. If buffered writing is desired, caller must provide some kind of bufferedOutputStream
.- Parameters:
outStream
- the output stream to write to- Returns:
- this VariantContextWriterBuilder
-
setIndexCreator
public VariantContextWriterBuilder setIndexCreator(IndexCreator idxCreator)
Set an IndexCreator for the nextVariantContextWriter
created by this builder.- Parameters:
idxCreator
- theIndexCreator
to use- Returns:
- this
VariantContextWriterBuilder
-
clearIndexCreator
public VariantContextWriterBuilder clearIndexCreator()
Do not pass anIndexCreator
to the nextVariantContextWriter
created by this builder.- Returns:
- this
VariantContextWriterBuilder
-
setBuffer
public VariantContextWriterBuilder setBuffer(int bufferSize)
Set a buffer size for the file output stream passed to the nextVariantContextWriter
created by this builder. Set to 0 for no buffering. Does not affect OutputStreams passed directly toVariantContextWriterBuilder
.- Parameters:
bufferSize
- the buffer size to use- Returns:
- this
VariantContextWriterBuilder
-
unsetBuffering
public VariantContextWriterBuilder unsetBuffering()
Do not use buffering in the nextVariantContextWriter
created by this builder. Does not affectOutputStream
s passed directly toVariantContextWriterBuilder
.- Returns:
- this
VariantContextWriterBuilder
-
setCreateMD5
public VariantContextWriterBuilder setCreateMD5(boolean createMD5)
Choose whether to also create an MD5 digest file for the nextVariantContextWriter
created by this builder.- Parameters:
createMD5
- boolean,true
to create an MD5 digest- Returns:
- this
VariantContextWriterBuilder
-
setCreateMD5
public VariantContextWriterBuilder setCreateMD5()
Create an MD5 digest file for the nextVariantContextWriter
created by this builder.- Returns:
- this
VariantContextWriterBuilder
-
unsetCreateMD5
public VariantContextWriterBuilder unsetCreateMD5()
Don't create an MD5 digest file for the nextVariantContextWriter
created by this builder.- Returns:
- this
VariantContextWriterBuilder
-
setOptions
public VariantContextWriterBuilder setOptions(EnumSet<Options> options)
Replace the set ofOptions
for theVariantContextWriterBuilder
with a new set.- Parameters:
options
- the complete set of options to use- Returns:
- this
VariantContextWriterBuilder
-
setOption
public VariantContextWriterBuilder setOption(Options option)
Add one option to the set ofOptions
for theVariantContextWriterBuilder
, if it's not already present.- Parameters:
option
- the option to set- Returns:
- this
VariantContextWriterBuilder
-
unsetOption
public VariantContextWriterBuilder unsetOption(Options option)
Remove one option from the set ofOptions
for theVariantContextWriterBuilder
, if it's present.- Parameters:
option
- the option to unset- Returns:
- this
VariantContextWriterBuilder
-
modifyOption
public VariantContextWriterBuilder modifyOption(Options option, boolean setIt)
Set or unset option depending on the boolean given- Parameters:
option
- the option to modifysetIt
- true to set the option, false to unset it.- Returns:
- this
VariantContextWriterBuilder
-
setDefaultOption
public static void setDefaultOption(Options option)
Add one option to the set of defaultOptions
that will be used as the initial set of options for all VariantContextWriterBuilders created after this call.- Parameters:
option
- the option to set
-
unsetDefaultOption
public static void unsetDefaultOption(Options option)
Remove an option from the set of defaultOptions
that will be used as the initial set of options for all VariantContextWriterBuilders created after this call.- Parameters:
option
- the option to unset
-
clearOptions
public VariantContextWriterBuilder clearOptions()
Remove all options from the set ofOptions
for theVariantContextWriterBuilder
.- Returns:
- this VariantContextWriterBuilder
-
build
public VariantContextWriter build()
Validate and build theVariantContextWriter
.- Returns:
- the
VariantContextWriter
as specified by previous method calls. - Throws:
RuntimeIOException
- if the writer is configured to write to a file, and the corresponding path does not exist.IllegalArgumentException
- if no output file or stream is specified.IllegalArgumentException
- ifOptions.INDEX_ON_THE_FLY
is specified and no reference dictionary is provided.IllegalArgumentException
- ifOptions.INDEX_ON_THE_FLY
is specified and a stream output is specified.
-
build
public VariantContextWriter build(OpenOption... openOptions)
Validate and build theVariantContextWriter
.- Parameters:
openOptions
- options to use when opening the underlying output stream.- Returns:
- the
VariantContextWriter
as specified by previous method calls, optionally applying the specified OpenOptions. - Throws:
RuntimeIOException
- if the writer is configured to write to a file, and the corresponding path does not exist.IllegalArgumentException
- if no output file or stream is specified.IllegalArgumentException
- ifOptions.INDEX_ON_THE_FLY
is specified and no reference dictionary is provided.IllegalArgumentException
- ifOptions.INDEX_ON_THE_FLY
is specified and a stream output is specified.
-
determineOutputTypeFromFile
public static VariantContextWriterBuilder.OutputType determineOutputTypeFromFile(File file)
Attempts to determine the type of file/data to write based on the File path being written to. Will attempt to determine using the logical filename; if that fails it will attempt to resolve any symlinks and try again. If that fails, and the output file exists but is neither a file or directory then VCF_STREAM is returned.- Parameters:
file
- A file whoseVariantContextWriterBuilder.OutputType
we want to infer- Returns:
- The file's
VariantContextWriterBuilder.OutputType
. Nevernull
.
-
determineOutputTypeFromFile
public static VariantContextWriterBuilder.OutputType determineOutputTypeFromFile(Path path)
Attempts to determine the type of file/data to write based on the File path being written to. Will attempt to determine using the logical filename; if that fails it will attempt to resolve any symlinks and try again. If that fails, and the output file exists but is neither a file or directory then VCF_STREAM is returned.- Parameters:
path
- A file whoseVariantContextWriterBuilder.OutputType
we want to infer- Returns:
- The file's
VariantContextWriterBuilder.OutputType
. Nevernull
.
-
-