Class ShardingVCFWriter
java.lang.Object
org.broadinstitute.hellbender.utils.variant.writers.ShardingVCFWriter
- All Implemented Interfaces:
htsjdk.variant.variantcontext.writer.VariantContextWriter
,Closeable
,AutoCloseable
public class ShardingVCFWriter
extends Object
implements htsjdk.variant.variantcontext.writer.VariantContextWriter
Variant writer tha splits output to multiple VCFs given the maximum records per file. Before using
add(htsjdk.variant.variantcontext.VariantContext)
,
the header should be set using either setHeader(htsjdk.variant.vcf.VCFHeader)
or writeHeader(htsjdk.variant.vcf.VCFHeader)
, which may only be called once
and will determine whether headers are written to all shards.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionShardingVCFWriter
(Path basePath, int maxVariantsPerShard, htsjdk.samtools.SAMSequenceDictionary dictionary, boolean createMD5, htsjdk.variant.variantcontext.writer.Options... options) Create a new sharding VCF writer -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(htsjdk.variant.variantcontext.VariantContext vc) Adds variant to writer.boolean
void
close()
protected htsjdk.variant.variantcontext.writer.VariantContextWriter
Creates a writer for a new shardprotected void
Initializes a new sharded file.static String
getShardFilename
(Path basePath, int shardIndex) Gets filepath for the given shard and base pathprotected void
Initializes shard header depending on which header function (set or write) was usedvoid
setHeader
(htsjdk.variant.vcf.VCFHeader header) Defines header for the writer.void
writeHeader
(htsjdk.variant.vcf.VCFHeader header) Defines header for the writer that will be written to all shards.
-
Field Details
-
SHARD_INDEX_PREFIX
- See Also:
-
SHARD_INDEX_SUFFIX
- See Also:
-
-
Constructor Details
-
ShardingVCFWriter
public ShardingVCFWriter(Path basePath, int maxVariantsPerShard, htsjdk.samtools.SAMSequenceDictionary dictionary, boolean createMD5, htsjdk.variant.variantcontext.writer.Options... options) Create a new sharding VCF writer- Parameters:
basePath
- base path of the output VCFs. The shard designation and file extension will be added.maxVariantsPerShard
- max number of records per file (last shard may have less)dictionary
- sequence dictionary for this writercreateMD5
- enable MD5 file creationoptions
- vcf writer options
-
-
Method Details
-
createNextShard
protected void createNextShard()Initializes a new sharded file. -
initializeShardHeader
protected void initializeShardHeader()Initializes shard header depending on which header function (set or write) was used -
createNewWriter
protected htsjdk.variant.variantcontext.writer.VariantContextWriter createNewWriter()Creates a writer for a new shard- Returns:
- the new writer
-
getShardFilename
Gets filepath for the given shard and base path- Parameters:
basePath
- path without extensionshardIndex
-- Returns:
- path as String
-
setHeader
public void setHeader(htsjdk.variant.vcf.VCFHeader header) Defines header for the writer. The header will not be written to any shards. May only be called once and only ifwriteHeader(htsjdk.variant.vcf.VCFHeader)
has not been called.- Specified by:
setHeader
in interfacehtsjdk.variant.variantcontext.writer.VariantContextWriter
- Parameters:
header
- header to use
-
writeHeader
public void writeHeader(htsjdk.variant.vcf.VCFHeader header) Defines header for the writer that will be written to all shards. May only be called once and only ifsetHeader(htsjdk.variant.vcf.VCFHeader)
has not been called.- Specified by:
writeHeader
in interfacehtsjdk.variant.variantcontext.writer.VariantContextWriter
- Parameters:
header
- header to use
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacehtsjdk.variant.variantcontext.writer.VariantContextWriter
-
checkError
public boolean checkError()- Specified by:
checkError
in interfacehtsjdk.variant.variantcontext.writer.VariantContextWriter
-
add
public void add(htsjdk.variant.variantcontext.VariantContext vc) Adds variant to writer. Note that a header must be assigned first.- Specified by:
add
in interfacehtsjdk.variant.variantcontext.writer.VariantContextWriter
- Parameters:
vc
- variant to write
-