Package htsjdk.variant.variantcontext.writer

# 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 enum`
`VariantContextWriterBuilder.OutputType`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final EnumSet<Options>`
`DEFAULT_OPTIONS`
`static final EnumSet<VariantContextWriterBuilder.OutputType>`
`FILE_TYPES`
`static final EnumSet<Options>`
`NO_OPTIONS`
`protected EnumSet<Options>`
`options`
`static final EnumSet<VariantContextWriterBuilder.OutputType>`
`STREAM_TYPES`

## Constructor Summary

Constructors
Constructor
Description
`VariantContextWriterBuilder()`
Default constructor.

## Method Summary

Modifier and Type
Method
Description
`VariantContextWriter`
`build()`
Validate and build the `VariantContextWriter`.
`VariantContextWriter`
`build(OpenOption... openOptions)`
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`.
`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 given
`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(EnumSet<Options> options)`
Replace the set of `Options` for the `VariantContextWriterBuilder` with a new set.
`VariantContextWriterBuilder`
`setOutputBCFStream(OutputStream outStream)`
Set the output BCF stream for the next `VariantContextWriter` created by this builder.
`VariantContextWriterBuilder`
`setOutputFile(File outFile)`
Set the output file for the next `VariantContextWriter` created by this builder.
`VariantContextWriterBuilder`
`setOutputFile(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`
`setOutputPath(Path outPath)`
Set the output file for the next `VariantContextWriter` created by this builder.
`VariantContextWriterBuilder`
`setOutputStream(OutputStream outStream)`
Set the output stream (VCF, by default) for the next `VariantContextWriter` created by this builder.
`VariantContextWriterBuilder`
`setOutputVCFStream(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 `VariantContextWriter`s 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_OPTIONS

public static final EnumSet<Options> DEFAULT_OPTIONS

### NO_OPTIONS

public static final EnumSet<Options> NO_OPTIONS

### FILE_TYPES

public static final EnumSet<VariantContextWriterBuilder.OutputType> FILE_TYPES

### STREAM_TYPES

public static final EnumSet<VariantContextWriterBuilder.OutputType> STREAM_TYPES

### options

protected EnumSet<Options> options

## Constructor Details

### VariantContextWriterBuilder

public VariantContextWriterBuilder()
Default constructor. Adds `USE_ASYNC_IO` to the Options if it is present in Defaults.

## Method Details

### setReferenceDictionary

public VariantContextWriterBuilder setReferenceDictionary(SAMSequenceDictionary refDict)
Set the reference dictionary to be used by `VariantContextWriter`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 next `VariantContextWriter` created by this builder. Determines file type implicitly from the filename.

Parameters:
  `outFile` - the file the `VariantContextWriter` will write to
Returns:
  this `VariantContextWriterBuilder`

### setOutputPath

public VariantContextWriterBuilder setOutputPath(Path outPath)
Set the output file for the next `VariantContextWriter` created by this builder. Determines file type implicitly from the filename.

Parameters:
  `outPath` - the file the `VariantContextWriter` will write to
Returns:
  this `VariantContextWriterBuilder`

### setOutputFile

public VariantContextWriterBuilder setOutputFile(String outFile)
Set the output file for the next `VariantContextWriter` created by this builder. Determines file type implicitly from the filename.

Parameters:
  `outFile` - the file the `VariantContextWriter` will write to
Returns:
  this `VariantContextWriterBuilder`

### setOutputFileType

public VariantContextWriterBuilder setOutputFileType(VariantContextWriterBuilder.OutputType outType)
Set the output file type for the next `VariantContextWriter` created by this builder.

Parameters:
  `outType` - the type of file the `VariantContextWriter` will write to
Returns:
  this `VariantContextWriterBuilder`

### setOutputVCFStream

public VariantContextWriterBuilder setOutputVCFStream(OutputStream outStream)
Set the output VCF stream for the next `VariantContextWriter` created by this builder. If buffered writing is desired, caller must provide some kind of buffered `OutputStream`.

Parameters:
  `outStream` - the output stream to write to
Returns:
  this `VariantContextWriterBuilder`

### setOutputBCFStream

public VariantContextWriterBuilder setOutputBCFStream(OutputStream outStream)
Set the output BCF stream for the next `VariantContextWriter` created by this builder. If buffered writing is desired, caller must provide some kind of buffered `OutputStream`.

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 next `VariantContextWriter` created by this builder. If buffered writing is desired, caller must provide some kind of buffered `OutputStream`.

Parameters:
  `outStream` - the output stream to write to
Returns:
  this VariantContextWriterBuilder

### setIndexCreator

public VariantContextWriterBuilder setIndexCreator(IndexCreator idxCreator)
Set an IndexCreator for the next `VariantContextWriter` created by this builder.

Parameters:
  `idxCreator` - the `IndexCreator` to use
Returns:
  this `VariantContextWriterBuilder`

### clearIndexCreator

public VariantContextWriterBuilder clearIndexCreator()
Do not pass an `IndexCreator` to the next `VariantContextWriter` 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 next `VariantContextWriter` created by this builder. Set to 0 for no buffering. Does not affect OutputStreams passed directly to `VariantContextWriterBuilder`.

Parameters:
  `bufferSize` - the buffer size to use
Returns:
  this `VariantContextWriterBuilder`

### unsetBuffering

public VariantContextWriterBuilder unsetBuffering()
Do not use buffering in the next `VariantContextWriter` created by this builder. Does not affect `OutputStream`s passed directly to `VariantContextWriterBuilder`.

Returns:
  this `VariantContextWriterBuilder`

### setCreateMD5

public VariantContextWriterBuilder setCreateMD5(boolean createMD5)
Choose whether to also create an MD5 digest file for the next `VariantContextWriter` 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 next `VariantContextWriter` created by this builder.

Returns:
  this `VariantContextWriterBuilder`

### unsetCreateMD5

public VariantContextWriterBuilder unsetCreateMD5()
Don't create an MD5 digest file for the next `VariantContextWriter` created by this builder.

Returns:
  this `VariantContextWriterBuilder`

### setOptions

public VariantContextWriterBuilder setOptions(EnumSet<Options> options)
Replace the set of `Options` for the `VariantContextWriterBuilder` 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 of `Options` for the `VariantContextWriterBuilder`, 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 of `Options` for the `VariantContextWriterBuilder`, 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 modify
  `setIt` - 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 default `Options` 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 default `Options` 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 of `Options` for the `VariantContextWriterBuilder`.

Returns:
  this VariantContextWriterBuilder

### build

public VariantContextWriter build()
Validate and build the `VariantContextWriter`.

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` - if `Options.INDEX_ON_THE_FLY` is specified and no reference dictionary is provided.
  `IllegalArgumentException` - if `Options.INDEX_ON_THE_FLY` is specified and a stream output is specified.

### build

public VariantContextWriter build(OpenOption... openOptions)
Validate and build the `VariantContextWriter`.

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` - if `Options.INDEX_ON_THE_FLY` is specified and no reference dictionary is provided.
  `IllegalArgumentException` - if `Options.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 whose `VariantContextWriterBuilder.OutputType` we want to infer
Returns:
  The file's `VariantContextWriterBuilder.OutputType`. Never `null`.

### 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 whose `VariantContextWriterBuilder.OutputType` we want to infer
Returns:
  The file's `VariantContextWriterBuilder.OutputType`. Never `null`.