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
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Gets an index tagged with the BrowseableBAMIndex interface.Gets a pointer spanning all reads in the BAM file.getIndex()
Retrieves the index for the given file type.boolean
Returns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.boolean
hasIndex()
indexing()
Exposes theSamReader.Indexing
facet of thisSamReader
.boolean
iterator()
Iterate through file in order.iterator
(SAMFileSpan chunks) Iterate through the given chunks in the file.query
(QueryInterval[] intervals, boolean contained) Iterate over records that match one of the given intervals.Iterate over records that match the given interval.queryAlignmentStart
(String sequence, int start) Iterate over records that map to the given sequence and start at the given position.queryContained
(QueryInterval[] intervals) Iterate over records that are contained in the given interval.queryContained
(String sequence, int start, int end) Iterate over records that are contained in the given interval.Wraps the boilerplate code for querying a record's mate, which is common across many implementations.queryOverlapping
(QueryInterval[] intervals) Iterate over records that overlap any of the given intervals.queryOverlapping
(String sequence, int start, int end) Iterate over records that overlap the given interval.type()
Access the underlyingSamReader.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
Access the underlyingSamReader.PrimitiveSamReader
used by this adapter.- Returns:
- the
SamReader.PrimitiveSamReader
used by this adapter.
-
queryOverlapping
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 interfaceSamReader
- 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
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 interfaceSamReader
- 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 withQueryInterval.optimizeIntervals(htsjdk.samtools.QueryInterval[])
-
queryContained
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 interfaceSamReader
- 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
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 interfaceSamReader
- 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 withQueryInterval.optimizeIntervals(htsjdk.samtools.QueryInterval[])
- Returns:
- Iterator over the SAMRecords contained in any of the intervals.
-
queryMate
Wraps the boilerplate code for querying a record's mate, which is common across many implementations. -
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 interfaceSamReader.Indexing
- Returns:
- True if the index supports the BrowseableBAMIndex interface. False otherwise.
-
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 interfaceSamReader.Indexing
- Returns:
- An index with a browseable interface, if possible.
-
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. -
iterator
Description copied from interface:SamReader.Indexing
Iterate through the given chunks in the file.- Specified by:
iterator
in interfaceSamReader.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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getFilePointerSpanningReads
Description copied from interface:SamReader.Indexing
Gets a pointer spanning all reads in the BAM file.- Specified by:
getFilePointerSpanningReads
in interfaceSamReader.Indexing
- Returns:
- Unbounded pointer to the first record, in chunk format.
-
getFileHeader
- Specified by:
getFileHeader
in interfaceSamReader
-
type
- Specified by:
type
in interfaceSamReader
- Returns:
- the
SamReader.Type
of thisSamReader
-
getResourceDescription
- Specified by:
getResourceDescription
in interfaceSamReader
- Returns:
- a human readable description of the resource backing this sam reader
-
isQueryable
public boolean isQueryable()- Specified by:
isQueryable
in interfaceSamReader
- Returns:
- true if this source can be queried by interval, regardless of whether it has an index
-
hasIndex
public boolean hasIndex() -
indexing
Description copied from interface:SamReader
Exposes theSamReader.Indexing
facet of thisSamReader
. -
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 interfaceSamReader.Indexing
- Returns:
- An index of the given type.
-
query
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 interfaceSamReader
- 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 withQueryInterval.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
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 interfaceSamReader
- 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
- Specified by:
queryUnmapped
in interfaceSamReader
-
queryAlignmentStart
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 interfaceSamReader
- Parameters:
sequence
- Reference sequence of interest.start
- Alignment start of interest.- Returns:
- Iterator over the SAMRecords with the given alignment start.
-