# Class CRAMDecoder

java.lang.Object
htsjdk.beta.codecs.reads.cram.CRAMDecoder

All Implemented Interfaces:
  `HtsDecoder<SAMFileHeader, SAMRecord>, HtsQuery<SAMRecord>, ReadsDecoder, ReadsQuery<SAMRecord>, Closeable, AutoCloseable, Iterable<SAMRecord>`

Direct Known Subclasses:
  `CRAMDecoderV2_1, CRAMDecoderV3_0, CRAMDecoderV3_1`

@InternalAPI public abstract class CRAMDecoder extends Object implements ReadsDecoder
InternalAPI Base class for `BundleResourceType.FMT_READS_CRAM` decoders.

## Constructor Summary

Constructors
Constructor
Description
`CRAMDecoder(Bundle inputBundle, ReadsDecoderOptions readsDecoderOptions)`
InternalAPI Common constructor for CRAM decoders.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close any resources associated with this decoder.
`static CRAMReferenceSource`
`getCRAMReferenceSource(CRAMDecoderOptions cramDecoderOptions)`
`final String`
`getDisplayName()`
Get a user-friendly display name for this decoder.
`final String`
`getFileFormat()`
Get the name of the file format supported by this decoder.The format name defines the underlying format handled by this decoder, and also corresponds to the format of the primary bundle resource that is required when decoding (see `BundleResourceType` and `BundleResource.getFileFormat()`).
`SAMFileHeader`
`getHeader()`
Get the file header for this decoder.
`Bundle`
`getInputBundle()`
Get the input `Bundle` for this decoder.
`ReadsDecoderOptions`
`getReadsDecoderOptions()`
Get the `ReadsDecoderOptions` for this decoder.
`boolean`
`hasIndex()`
Return true if the underlying resource has an index.
`boolean`
`isQueryable()`
Gte true if the underlying resource is queryable.
`CloseableIterator<SAMRecord>`
`iterator()`
Get an iterator of all records in the underlying resource.
`CloseableIterator<SAMRecord>`
`query(List<HtsInterval> intervals, HtsQueryRule queryRule)`
Get an iterator over all records from the underlying resource that match the query arguments.
`Optional<SAMRecord>`
`queryMate(SAMRecord rec)`
Fetch the mate for the given read.
`CloseableIterator<SAMRecord>`
`queryStart(String queryName, long start)`
Get an iterator over all records from the underlying resource that overlap the start position
`CloseableIterator<SAMRecord>`
`queryUnmapped()`
Get an iterator of unmapped reads.

### Methods inherited from class Object

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

### Methods inherited from interface HtsDecoder

`getVersion`

### Methods inherited from interface HtsQuery

`query, query, query, queryContained, queryContained, queryContained, queryOverlapping, queryOverlapping, queryOverlapping`

### Methods inherited from interface Iterable

`forEach, spliterator`

## Constructor Details

### CRAMDecoder

@InternalAPI public CRAMDecoder(Bundle inputBundle, ReadsDecoderOptions readsDecoderOptions)
InternalAPI Common constructor for CRAM decoders.

Parameters:
  `inputBundle` - an `Bundle` containing cram resource
  `readsDecoderOptions` - `ReadsDecoderOptions` to use.

## Method Details

### getFileFormat

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

Specified by:
  `getFileFormat` in interface `HtsDecoder<SAMFileHeader, SAMRecord>`
Returns:
  the name of the underlying file format handled by this decoder

### getDisplayName

public final String getDisplayName()
Description copied from interface: `HtsDecoder`
Get a user-friendly display name for this decoder.

Specified by:
  `getDisplayName` in interface `HtsDecoder<SAMFileHeader, SAMRecord>`
Returns:
  a user-friendly display name for this decoder for use in error and warning messages

### getHeader

public SAMFileHeader getHeader()
Description copied from interface: `HtsDecoder`
Get the file header for this decoder.

Specified by:
  `getHeader` in interface `HtsDecoder<SAMFileHeader, SAMRecord>`
Returns:
  the file header for this decoder, of type `H`

### close

public void close()
Description copied from interface: `HtsDecoder`
Close any resources associated with this decoder.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `HtsDecoder<SAMFileHeader, SAMRecord>`

### iterator

public CloseableIterator<SAMRecord> iterator()
Description copied from interface: `HtsQuery`
Get an iterator of all records in the underlying resource.

Specified by:
  `iterator` in interface `HtsQuery<SAMRecord>`
Specified by:
  `iterator` in interface `Iterable<SAMRecord>`
Returns:
  an iterator of all records in the underlying resource

### isQueryable

public boolean isQueryable()
Description copied from interface: `HtsQuery`
Gte true if the underlying resource is queryable.

Specified by:
  `isQueryable` in interface `HtsQuery<SAMRecord>`
Returns:
  true if the underlying resource is queryable. this may be true even if the underlying resource returns false for `HtsQuery.hasIndex()`

### hasIndex

public boolean hasIndex()
Description copied from interface: `HtsQuery`
Return true if the underlying resource has an index.

Specified by:
  `hasIndex` in interface `HtsQuery<SAMRecord>`
Returns:
  true if the underlying resource has an index

### query

public CloseableIterator<SAMRecord> query(List<HtsInterval> intervals, HtsQueryRule queryRule)
Description copied from interface: `HtsQuery`
Get an iterator over all records from the underlying resource that match the query arguments. Callers much ensure that the intervals are in increasing order and do not overlap or abut.

Specified by:
  `query` in interface `HtsQuery<SAMRecord>`
Parameters:
  `intervals` - list of intervals to match
  `queryRule` - query rule to use, from `HtsQueryRule`
Returns:
  an iterator over all records from the underlying resource that match the query arguments

### queryStart

public CloseableIterator<SAMRecord> queryStart(String queryName, long start)
Description copied from interface: `HtsQuery`
Get an iterator over all records from the underlying resource that overlap the start position

Specified by:
  `queryStart` in interface `HtsQuery<SAMRecord>`
Parameters:
  `queryName` - name to match
  `start` - start position to overlap
Returns:
  an iterator over all records from the underlying resource that overlap the start position

### queryUnmapped

public CloseableIterator<SAMRecord> queryUnmapped()
Description copied from interface: `ReadsDecoder`
Get an iterator of unmapped reads. Requires an index resource to be included in the input `Bundle`.

Specified by:
  `queryUnmapped` in interface `ReadsDecoder`
Specified by:
  `queryUnmapped` in interface `ReadsQuery<SAMRecord>`

### queryMate

public Optional<SAMRecord> queryMate(SAMRecord rec)
Description copied from interface: `ReadsDecoder`
Fetch the mate for the given read. Requires an index resource to be included in the input `Bundle`.

Specified by:
  `queryMate` in interface `ReadsDecoder`
Specified by:
  `queryMate` in interface `ReadsQuery<SAMRecord>`
Parameters:
  `rec` - the source record
Returns:
  the source record's mate, or Optional.empty() if the source record has no mate

### getInputBundle

public Bundle getInputBundle()
Get the input `Bundle` for this decoder.

Returns:
  the input `Bundle` for this decoder

### getReadsDecoderOptions

public ReadsDecoderOptions getReadsDecoderOptions()
Get the `ReadsDecoderOptions` for this decoder.

Returns:
  the `ReadsDecoderOptions` for this decoder.

### getCRAMReferenceSource

@InternalAPI public static CRAMReferenceSource getCRAMReferenceSource(CRAMDecoderOptions cramDecoderOptions)