Package htsjdk.variant.bcf2

# Class BCF2Codec

java.lang.Object
htsjdk.tribble.BinaryFeatureCodec<VariantContext>
htsjdk.variant.bcf2.BCF2Codec

All Implemented Interfaces:
  `FeatureCodec<VariantContext,PositionalBufferedStream>`

public class BCF2Codec extends BinaryFeatureCodec<VariantContext>
Decode BCF2 files

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`BCF2Codec.LazyData`
`protected static final class`
`BCF2Codec.SitesInfoForDecoding`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final BCFVersion`
`ALLOWED_BCF_VERSION`
`protected static final int`
`ALLOWED_MAJOR_VERSION`
`protected static final int`
`ALLOWED_MINOR_VERSION`
`static final int`
`SIZEOF_BCF_HEADER`
sizeof a BCF header (+ min/max version).

## Constructor Summary

Constructors
Constructor
Description
`BCF2Codec()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`canDecode(String path)`
This function returns true iff the File potentialInput can be parsed by this codec.
`VariantContext`
`decode(PositionalBufferedStream inputStream)`
Decode a single `Feature` from the `FeatureCodec`, reading no further in the underlying source than beyond that feature.
`Feature`
`decodeLoc(PositionalBufferedStream inputStream)`
Decode a line to obtain just its FeatureLoc for indexing -- contig, start, and stop.
`protected void`
`error(String message)`
`protected final String`
`getDictionaryString(int offset)`
`Class<VariantContext>`
`getFeatureType()`
This function returns the object the codec generates.
`protected BCF2GenotypeFieldDecoders.Decoder`
`getGenotypeFieldDecoder(String field)`
`protected VCFHeader`
`getHeader()`
`FeatureCodecHeader`
`readHeader(PositionalBufferedStream inputStream)`
Read and return the header, or null if there is no header.
`static BCFVersion`
`tryReadBCFVersion(BufferedInputStream uncompressedBufferedInput)`
try to read a BCFVersion from an uncompressed BufferedInputStream.
`protected void`
`validateVersionCompatibility(BCFVersion supportedVersion, BCFVersion actualVersion)`
Validate the actual version against the supported version to determine compatibility.

### Methods inherited from class htsjdk.tribble.BinaryFeatureCodec

`close, getTabixFormat, isDone, makeIndexableSourceFromStream, makeSourceFromStream`

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

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

### Methods inherited from interface htsjdk.tribble.FeatureCodec

`getPathToDataFile`

## Field Details

### ALLOWED_MAJOR_VERSION

protected static final int ALLOWED_MAJOR_VERSION

See Also:
  - Constant Field Values

### ALLOWED_MINOR_VERSION

protected static final int ALLOWED_MINOR_VERSION

See Also:
  - Constant Field Values

### ALLOWED_BCF_VERSION

public static final BCFVersion ALLOWED_BCF_VERSION

### SIZEOF_BCF_HEADER

public static final int SIZEOF_BCF_HEADER
sizeof a BCF header (+ min/max version). Used when trying to detect when a streams starts with a bcf header

## Constructor Details

### BCF2Codec

public BCF2Codec()

## Method Details

### decodeLoc

public Feature decodeLoc(PositionalBufferedStream inputStream)
Description copied from interface: `FeatureCodec`
Decode a line to obtain just its FeatureLoc for indexing -- contig, start, and stop.

Parameters:
  `inputStream` - the input stream from which to decode the next record
Returns:
  Return the FeatureLoc encoded by the line, or null if the line does not represent a feature (e.g. is a comment)

### decode

public VariantContext decode(PositionalBufferedStream inputStream)
Description copied from interface: `FeatureCodec`
Decode a single `Feature` from the `FeatureCodec`, reading no further in the underlying source than beyond that feature.

Parameters:
  `inputStream` - the input stream from which to decode the next record
Returns:
  Return the Feature encoded by the line, or null if the line does not represent a feature (e.g. is a comment)

### getFeatureType

public Class<VariantContext> getFeatureType()
Description copied from interface: `FeatureCodec`

This function returns the object the codec generates. This is allowed to be Feature in the case where conditionally different types are generated. Be as specific as you can though.

This function is used by reflections based tools, so we can know the underlying type

Returns:
  the feature type this codec generates.

### validateVersionCompatibility

protected void validateVersionCompatibility(BCFVersion supportedVersion, BCFVersion actualVersion)
Validate the actual version against the supported version to determine compatibility. Throws a TribbleException if the actualVersion is not compatible with the supportedVersion. Subclasses can override this to provide a custom version compatibility policy, but allowing something other than the supported version is dangerous and should be done with great care. The default policy is to require an exact version match.

Parameters:
  `supportedVersion` - the current BCF implementation version
  `actualVersion` - the actual version

### readHeader

public FeatureCodecHeader readHeader(PositionalBufferedStream inputStream)
Description copied from interface: `FeatureCodec`
Read and return the header, or null if there is no header. Note: Implementers of this method must be careful to read exactly as much from `FeatureCodec` as needed to parse the header, and no more. Otherwise, data that might otherwise be fed into parsing a `Feature` may be lost.

Parameters:
  `inputStream` - the source from which to decode the header
Returns:
  header object

### canDecode

public boolean canDecode(String path)
Description copied from interface: `FeatureCodec`

This function returns true iff the File potentialInput can be parsed by this codec. Note that checking the file's extension is a perfectly acceptable implementation of this method and file contents only rarely need to be checked.

There is an assumption that there's never a situation where two different Codecs return true for the same file. If this occurs, the recommendation would be to error out.

Note this function must never throw an error. All errors should be trapped and false returned.

Parameters:
  `path` - the file to test for parsability with this codec
Returns:
  true if potentialInput can be parsed, false otherwise

### getDictionaryString

protected final String getDictionaryString(int offset)

### getHeader

protected VCFHeader getHeader()

Returns:
  the VCFHeader we found in this BCF2 file

### getGenotypeFieldDecoder

protected BCF2GenotypeFieldDecoders.Decoder getGenotypeFieldDecoder(String field)

### error

protected void error(String message) throws RuntimeException

Throws:
  `RuntimeException`

### tryReadBCFVersion

public static BCFVersion tryReadBCFVersion(BufferedInputStream uncompressedBufferedInput) throws IOException
try to read a BCFVersion from an uncompressed BufferedInputStream. The buffer must be large enough to contain `SIZEOF_BCF_HEADER`

Parameters:
  `uncompressedBufferedInput` - the uncompressed input stream
Returns:
  the BCFVersion if it can be decoded, or null if not found.
Throws:
  `IOException`