Package htsjdk.samtools

# Class SamReader.PrimitiveSamReaderToSamReaderAdapter

java.lang.Object
htsjdk.samtools.SamReader.PrimitiveSamReaderToSamReaderAdapter

All Implemented Interfaces:
  `SamReader`, `SamReader.Indexing`, `Closeable`, `AutoCloseable`, `Iterable<SAMRecord>`

Enclosing interface:
  `SamReader`

public static class SamReader.PrimitiveSamReaderToSamReaderAdapter extends Object implements SamReader, SamReader.Indexing
Decorator for a `SamReader.PrimitiveSamReader` that expands its functionality into a `SamReader`, given the backing `SamInputResource`. Wraps the `SamReader.Indexing` interface as well, which was originally separate from `SamReader` but in practice the two are always implemented by the same class.

## Nested Class Summary

## Nested classes/interfaces inherited from interface htsjdk.samtools.SamReader

`SamReader.AssertingIterator, SamReader.Indexing, SamReader.PrimitiveSamReader, SamReader.PrimitiveSamReaderToSamReaderAdapter, SamReader.ReaderImplementation, SamReader.Type`

## Constructor Summary

Constructors
Constructor
Description
`PrimitiveSamReaderToSamReaderAdapter(SamReader.PrimitiveSamReader p, SamInputResource resource)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`BrowseableBAMIndex`
`getBrowseableIndex()`
Gets an index tagged with the BrowseableBAMIndex interface.
`SAMFileHeader`
`getFileHeader()`
`SAMFileSpan`
`getFilePointerSpanningReads()`
Gets a pointer spanning all reads in the BAM file.
`BAMIndex`
`getIndex()`
Retrieves the index for the given file type.
`String`
`getResourceDescription()`
`boolean`
`hasBrowseableIndex()`
Returns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.
`boolean`
`hasIndex()`
`SamReader.Indexing`
`indexing()`
Exposes the `SamReader.Indexing` facet of this `SamReader`.
`boolean`
`isQueryable()`
`SAMRecordIterator`
`iterator()`
Iterate through file in order.
`SAMRecordIterator`
`iterator(SAMFileSpan chunks)`
Iterate through the given chunks in the file.
`SAMRecordIterator`
`query(QueryInterval[] intervals, boolean contained)`
Iterate over records that match one of the given intervals.
`SAMRecordIterator`
`query(String sequence, int start, int end, boolean contained)`
Iterate over records that match the given interval.
`SAMRecordIterator`
`queryAlignmentStart(String sequence, int start)`
Iterate over records that map to the given sequence and start at the given position.
`SAMRecordIterator`
`queryContained(QueryInterval[] intervals)`
Iterate over records that are contained in the given interval.
`SAMRecordIterator`
`queryContained(String sequence, int start, int end)`
Iterate over records that are contained in the given interval.
`SAMRecord`
`queryMate(SAMRecord rec)`
Wraps the boilerplate code for querying a record's mate, which is common across many implementations.
`SAMRecordIterator`
`queryOverlapping(QueryInterval[] intervals)`
Iterate over records that overlap any of the given intervals.
`SAMRecordIterator`
`queryOverlapping(String sequence, int start, int end)`
Iterate over records that overlap the given interval.
`SAMRecordIterator`
`queryUnmapped()`
`SamReader.Type`
`type()`
`SamReader.PrimitiveSamReader`
`underlyingReader()`
Access the underlying `SamReader.PrimitiveSamReader` used by this adapter.

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

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Constructor Details

### PrimitiveSamReaderToSamReaderAdapter

public PrimitiveSamReaderToSamReaderAdapter(SamReader.PrimitiveSamReader p, SamInputResource resource)

## Method Details

### underlyingReader

public SamReader.PrimitiveSamReader underlyingReader()
Access the underlying `SamReader.PrimitiveSamReader` used by this adapter.

Returns:
  the `SamReader.PrimitiveSamReader` used by this adapter.

### queryOverlapping

public SAMRecordIterator queryOverlapping(String sequence, int start, int end)
Description copied from interface: `SamReader`
Iterate over records that overlap the given interval. Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `queryOverlapping` in interface `SamReader`
Parameters:
  `sequence` - Reference sequence of interest.
  `start` - 1-based, inclusive start of interval of interest. Zero implies start of the reference sequence.
  `end` - 1-based, inclusive end of interval of interest. Zero implies end of the reference sequence.
Returns:
  Iterator over the SAMRecords overlapping the interval.

### queryOverlapping

public SAMRecordIterator queryOverlapping(QueryInterval[] intervals)
Description copied from interface: `SamReader`
Iterate over records that overlap any of the given intervals. This may be more efficient than querying each interval separately, because multiple reads of the same SAMRecords is avoided.

Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `queryOverlapping` in interface `SamReader`
Parameters:
  `intervals` - Intervals to be queried. The intervals must be optimized, i.e. in order, with overlapping and abutting intervals merged. This can be done with `QueryInterval.optimizeIntervals(htsjdk.samtools.QueryInterval[])`

### queryContained

public SAMRecordIterator queryContained(String sequence, int start, int end)
Description copied from interface: `SamReader`
Iterate over records that are contained in the given interval. Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `queryContained` in interface `SamReader`
Parameters:
  `sequence` - Reference sequence of interest.
  `start` - 1-based, inclusive start of interval of interest. Zero implies start of the reference sequence.
  `end` - 1-based, inclusive end of interval of interest. Zero implies end of the reference sequence.
Returns:
  Iterator over the SAMRecords contained in the interval.

### queryContained

public SAMRecordIterator queryContained(QueryInterval[] intervals)
Description copied from interface: `SamReader`
Iterate over records that are contained in the given interval. This may be more efficient than querying each interval separately, because multiple reads of the same SAMRecords is avoided.

Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `queryContained` in interface `SamReader`
Parameters:
  `intervals` - Intervals to be queried. The intervals must be optimized, i.e. in order, with overlapping and abutting intervals merged. This can be done with `QueryInterval.optimizeIntervals(htsjdk.samtools.QueryInterval[])`
Returns:
  Iterator over the SAMRecords contained in any of the intervals.

### queryMate

public SAMRecord queryMate(SAMRecord rec)
Wraps the boilerplate code for querying a record's mate, which is common across many implementations.

Specified by:
  `queryMate` in interface `SamReader`
Parameters:
  `rec` - Record for which mate is sought. Must be a paired read.
Returns:

### hasBrowseableIndex

public boolean hasBrowseableIndex()
Description copied from interface: `SamReader.Indexing`
Returns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.

Specified by:
  `hasBrowseableIndex` in interface `SamReader.Indexing`
Returns:
  True if the index supports the BrowseableBAMIndex interface. False otherwise.

### getBrowseableIndex

public BrowseableBAMIndex getBrowseableIndex()
Description copied from interface: `SamReader.Indexing`
Gets an index tagged with the BrowseableBAMIndex interface. Throws an exception if no such index is available.

Specified by:
  `getBrowseableIndex` in interface `SamReader.Indexing`
Returns:
  An index with a browseable interface, if possible.

### iterator

public SAMRecordIterator iterator()
Description copied from interface: `SamReader`
Iterate through file in order. For a SamReader constructed from an InputStream, and for any SAM file, a 2nd iteration starts where the 1st one left off. For a BAM constructed from a SeekableStream or File, each new iteration starts at the first record.

Only a single open iterator on a SAM or BAM file may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Specified by:
  `iterator` in interface `Iterable<SAMRecord>`
Specified by:
  `iterator` in interface `SamReader`

### iterator

public SAMRecordIterator iterator(SAMFileSpan chunks)
Description copied from interface: `SamReader.Indexing`
Iterate through the given chunks in the file.

Specified by:
  `iterator` in interface `SamReader.Indexing`
Parameters:
  `chunks` - List of chunks for which to retrieve data.
Returns:
  An iterator over the given chunks.

### close

public void close()

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

### getFilePointerSpanningReads

public SAMFileSpan getFilePointerSpanningReads()
Description copied from interface: `SamReader.Indexing`
Gets a pointer spanning all reads in the BAM file.

Specified by:
  `getFilePointerSpanningReads` in interface `SamReader.Indexing`
Returns:
  Unbounded pointer to the first record, in chunk format.

### getFileHeader

public SAMFileHeader getFileHeader()

Specified by:
  `getFileHeader` in interface `SamReader`

### type

public SamReader.Type type()

Specified by:
  `type` in interface `SamReader`
Returns:
  the `SamReader.Type` of this `SamReader`

### getResourceDescription

public String getResourceDescription()

Specified by:
  `getResourceDescription` in interface `SamReader`
Returns:
  a human readable description of the resource backing this sam reader

### isQueryable

public boolean isQueryable()

Specified by:
  `isQueryable` in interface `SamReader`
Returns:
  true if this source can be queried by interval, regardless of whether it has an index

### hasIndex

public boolean hasIndex()

Specified by:
  `hasIndex` in interface `SamReader`
Returns:
  true if ths is a BAM file, and has an index

### indexing

public SamReader.Indexing indexing()
Description copied from interface: `SamReader`
Exposes the `SamReader.Indexing` facet of this `SamReader`.

Specified by:
  `indexing` in interface `SamReader`

### getIndex

public BAMIndex getIndex()
Description copied from interface: `SamReader.Indexing`
Retrieves the index for the given file type. Ensure that the index is of the specified type.

Specified by:
  `getIndex` in interface `SamReader.Indexing`
Returns:
  An index of the given type.

### query

public SAMRecordIterator query(QueryInterval[] intervals, boolean contained)
Description copied from interface: `SamReader`
Iterate over records that match one of the given intervals. This may be more efficient than querying each interval separately, because multiple reads of the same SAMRecords is avoided.

Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first. You can use a second SamReader to iterate in parallel over the same underlying file.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match an interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `query` in interface `SamReader`
Parameters:
  `intervals` - Intervals to be queried. The intervals must be optimized, i.e. in order, with overlapping and abutting intervals merged. This can be done with `QueryInterval.optimizeIntervals(htsjdk.samtools.QueryInterval[])`
  `contained` - If true, each SAMRecord returned is will have its alignment completely contained in one of the intervals of interest. If false, the alignment of the returned SAMRecords need only overlap one of the intervals of interest.
Returns:
  Iterator over the SAMRecords matching the interval.

### query

public SAMRecordIterator query(String sequence, int start, int end, boolean contained)
Description copied from interface: `SamReader`
Iterate over records that match the given interval. Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first. You can use a second SamReader to iterate in parallel over the same underlying file.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that is in the query region.

Specified by:
  `query` in interface `SamReader`
Parameters:
  `sequence` - Reference sequence of interest.
  `start` - 1-based, inclusive start of interval of interest. Zero implies start of the reference sequence.
  `end` - 1-based, inclusive end of interval of interest. Zero implies end of the reference sequence.
  `contained` - If true, each SAMRecord returned will have its alignment completely contained in the interval of interest. If false, the alignment of the returned SAMRecords need only overlap the interval of interest.
Returns:
  Iterator over the SAMRecords matching the interval.

### queryUnmapped

public SAMRecordIterator queryUnmapped()

Specified by:
  `queryUnmapped` in interface `SamReader`

### queryAlignmentStart

public SAMRecordIterator queryAlignmentStart(String sequence, int start)
Description copied from interface: `SamReader`
Iterate over records that map to the given sequence and start at the given position. Only valid to call this if hasIndex() == true.

Only a single open iterator on a given SamReader may be extant at any one time. If you want to start a second iteration, the first one must be closed first.

Note that indexed lookup is not perfectly efficient in terms of disk I/O. I.e. some SAMRecords may be read and then discarded because they do not match the interval of interest.

Note that an unmapped read will be returned by this call if it has a coordinate for the purpose of sorting that matches the arguments.

Specified by:
  `queryAlignmentStart` in interface `SamReader`
Parameters:
  `sequence` - Reference sequence of interest.
  `start` - Alignment start of interest.
Returns:
  Iterator over the SAMRecords with the given alignment start.