# Class FASTACodecV1_0

java.lang.Object
htsjdk.beta.codecs.hapref.fasta.FASTACodecV1_0

All Implemented Interfaces:
  `HaploidReferenceCodec, HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>, Upgradeable`

public class FASTACodecV1_0 extends Object implements HaploidReferenceCodec
The v1.0 FASTA codec.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final HtsVersion`
`VERSION_1`

## Constructor Summary

Constructors
Constructor
Description
`FASTACodecV1_0()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`canDecodeSignature(SignatureStream signatureStream, String sourceName)`
Determine if the codec can decode an input stream by inspecting a signature embedded within the stream.
`boolean`
`canDecodeURI(IOPath ioPath)`
Determine if the URI for `ioPath` (obtained via `IOPath.getURI()`) conforms to the expected URI format this codec's file format.
`HaploidReferenceDecoder`
`getDecoder(Bundle inputBundle, HaploidReferenceDecoderOptions options)`
Get an `HtsDecoder` to decode the provided inputs.
`HaploidReferenceEncoder`
`getEncoder(Bundle outputBundle, HaploidReferenceEncoderOptions options)`
Get an `HtsEncoder` to encode to the provided outputs.
`String`
`getFileFormat()`
Get the name of the file format supported by this codec.
`int`
`getSignatureLength()`
Get the number of bytes in the format and version signature used by the file format supported by this codec.
`HtsVersion`
`getVersion()`
Get the version of the file format returned by `HtsCodec.getFileFormat()` that is supported by this codec.
`boolean`
`runVersionUpgrade(HtsVersion sourceCodecVersion, HtsVersion targetCodecVersion)`

### Methods inherited from class Object

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

### Methods inherited from interface HaploidReferenceCodec

`getContentType`

### Methods inherited from interface HtsCodec

`getDisplayName, getSignatureProbeLength, ownsURI`

## Field Details

### VERSION_1

public static final HtsVersion VERSION_1

## Constructor Details

### FASTACodecV1_0

public FASTACodecV1_0()

## Method Details

### getVersion

public HtsVersion getVersion()
Description copied from interface: `HtsCodec`
Get the version of the file format returned by `HtsCodec.getFileFormat()` that is supported by this codec.

Specified by:
  `getVersion` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Returns:
  the file format version (`HtsVersion`) supported by this codec

### getFileFormat

public String getFileFormat()
Description copied from interface: `HtsCodec`
Get the name of the file format supported by this codec. The format name defines the underlying format handled by this codec, and also corresponds to the format of the primary bundle resource that is required when decoding or encoding (see `BundleResourceType` and `BundleResource.getFileFormat()`).

Specified by:
  `getFileFormat` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Returns:
  the name of the underlying file format handled by this codec

### getSignatureLength

public int getSignatureLength()
Description copied from interface: `HtsCodec`
Get the number of bytes in the format and version signature used by the file format supported by this codec.

Specified by:
  `getSignatureLength` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Returns:
  if the file format supported by this codecs is not remote, and is accessible via a local file or stream, the size of the unique signature/version for this file format. otherwise 0. Note: Codecs that are custom URI handlers (those that return true for `HtsCodec.ownsURI(IOPath)`), should always return 0 from this method. Since this method is used during codec resolution, implementations should avoid calling methods that may throw exceptions.

### canDecodeSignature

public boolean canDecodeSignature(SignatureStream signatureStream, String sourceName)
Description copied from interface: `HtsCodec`
Determine if the codec can decode an input stream by inspecting a signature embedded within the stream. The probingInputStream stream will contain only a fragment of the actual input stream, taken from the start of the stream, the size of which will be the lesser of:

1. the number of bytes returned by `HtsCodec.getSignatureProbeLength()`
2. the entire input stream, for streams that are smaller than `HtsCodec.getSignatureProbeLength()`

Codecs that handle custom URIs that reference remote resources (those that return true for `HtsCodec.ownsURI(IOPath)`) should generally not inspect the stream, and should return false from this method, since the method will never be called with any resource for which `HtsCodec.ownsURI(IOPath)` returned true. Since this method is used during codec resolution, implementations should avoid calling methods that may throw exceptions.

Specified by:
  `canDecodeSignature` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Parameters:
  `signatureStream` - the stream to be inspect for the resource's embedded signature and version
  `sourceName` - a display name describing the source of the input stream, for use in error messages
Returns:
  true if this codec recognizes the stream by it's signature, and can provide a decoder to decode the stream, otherwise false

### canDecodeURI

public boolean canDecodeURI(IOPath ioPath)
Description copied from interface: `HtsCodec`
Determine if the URI for `ioPath` (obtained via `IOPath.getURI()`) conforms to the expected URI format this codec's file format. Most implementations only look at the file extension (see `IOPath.hasExtension(String)`). For codecs that implement formats that use specific, well known file extensions, the codec should reject inputs that do not conform to any of the accepted extensions. If the format does not use a specific extension, or if the codec cannot determine if it can decode the underlying resource without inspecting the underlying stream, it is safe to return true, after which the framework will subsequently call this codec's `HtsCodec.canDecodeSignature(SignatureStream, String)` method, at which time the codec can inspect the actual underlying stream via the `SignatureStream`.

Implementations should generally not inspect the URI's protocol scheme unless the file format supported by the codec requires the use a specific protocol scheme. For codecs that do own a specific scheme or URI format, the return values for `HtsCodec.ownsURI(IOPath)` and `HtsCodec.canDecodeURI(IOPath)` must always be the same (both true or both false) for a given IOPath. For codecs that do not use a custom URI (and rely on NIO access), @link #ownsURI(IOPath)} should always return false, with only the value returned from `HtsCodec.canDecodeURI(IOPath)` varying based on features such as file extension probes.

It is never safe to attempt to directly inspect the underlying stream for `ioPath` in this method. If the stream needs to be inspected, it should be done using the signature stream when the `HtsCodec.canDecodeSignature(SignatureStream, String)` method is called.

For custom URI handlers (see `HtsCodec.ownsURI(IOPath)`, codecs should avoid making remote calls to determine the suitability of the input resource; the return value for this method should be based only on the format of the URI that is presented. Since this method is used during codec resolution, implementations should avoid calling methods that may throw exceptions.

Specified by:
  `canDecodeURI` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Parameters:
  `ioPath` - to be decoded
Returns:
  true if the codec can provide a decoder to provide this URI

### getDecoder

public HaploidReferenceDecoder getDecoder(Bundle inputBundle, HaploidReferenceDecoderOptions options)
Description copied from interface: `HtsCodec`
Get an `HtsDecoder` to decode the provided inputs. The input bundle must contain resources of the type required by this codec. To find a codec appropriate for decoding a given resource, use an `HtsCodecResolver` obtained from an `HtsCodecRegistry`.

The framework will never call thi* method unless either `HtsCodec.ownsURI(IOPath)`, or `HtsCodec.canDecodeURI(IOPath)` and `HtsCodec.canDecodeSignature(SignatureStream, String)` (IOPath)} return true for `inputBundle`.

Specified by:
  `getDecoder` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Parameters:
  `inputBundle` - input to be decoded. To get a decoder for use with index queries that use `HtsQuery` methods, the bundle must contain an index resource.
  `options` - options for the decoder to use
Returns:
  an `HtsDecoder` that can decode the provided inputs

### getEncoder

public HaploidReferenceEncoder getEncoder(Bundle outputBundle, HaploidReferenceEncoderOptions options)
Description copied from interface: `HtsCodec`
Get an `HtsEncoder` to encode to the provided outputs. The output bundle must contain resources of the type required by this codec. To find a codec appropriate for encoding a given resource, use an `HtsCodecResolver` obtained from an `HtsCodecRegistry`. The framework will never call this method unless either `HtsCodec.ownsURI(IOPath)`, or `HtsCodec.canDecodeURI(IOPath)` returned true for `outputBundle`.

Specified by:
  `getEncoder` in interface `HtsCodec<HaploidReferenceDecoderOptions, HaploidReferenceEncoderOptions>`
Parameters:
  `outputBundle` - target output for the encoder
  `options` - encoder options to use
Returns:
  an `HtsEncoder` suitable for writing to the provided outputs

### runVersionUpgrade

public boolean runVersionUpgrade(HtsVersion sourceCodecVersion, HtsVersion targetCodecVersion)

Specified by:
  `runVersionUpgrade` in interface `Upgradeable`