Class VariantContextWriterBuilder

java.lang.Object
htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder

public class VariantContextWriterBuilder extends Object
  • Field Details

  • 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 VariantContextWriters 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

      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 OutputStreams 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.