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 aSamReader.PrimitiveSamReaderthat expands its functionality into aSamReader, given the backingSamInputResource. Wraps theSamReader.Indexinginterface as well, which was originally separate fromSamReaderbut 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()BrowseableBAMIndexgetBrowseableIndex()Gets an index tagged with the BrowseableBAMIndex interface.SAMFileHeadergetFileHeader()SAMFileSpangetFilePointerSpanningReads()Gets a pointer spanning all reads in the BAM file.BAMIndexgetIndex()Retrieves the index for the given file type.StringgetResourceDescription()booleanhasBrowseableIndex()Returns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.booleanhasIndex()SamReader.Indexingindexing()Exposes theSamReader.Indexingfacet of thisSamReader.SAMRecordIteratoriterator()Iterate through file in order.SAMRecordIteratoriterator(SAMFileSpan chunks)Iterate through the given chunks in the file.SAMRecordIteratorquery(QueryInterval[] intervals, boolean contained)Iterate over records that match one of the given intervals.SAMRecordIteratorquery(String sequence, int start, int end, boolean contained)Iterate over records that match the given interval.SAMRecordIteratorqueryAlignmentStart(String sequence, int start)Iterate over records that map to the given sequence and start at the given position.SAMRecordIteratorqueryContained(QueryInterval[] intervals)Iterate over records that are contained in the given interval.SAMRecordIteratorqueryContained(String sequence, int start, int end)Iterate over records that are contained in the given interval.SAMRecordqueryMate(SAMRecord rec)Wraps the boilerplate code for querying a record's mate, which is common across many implementations.SAMRecordIteratorqueryOverlapping(QueryInterval[] intervals)Iterate over records that overlap any of the given intervals.SAMRecordIteratorqueryOverlapping(String sequence, int start, int end)Iterate over records that overlap the given interval.SAMRecordIteratorqueryUnmapped()SamReader.Typetype()SamReader.PrimitiveSamReaderunderlyingReader()Access the underlyingSamReader.PrimitiveSamReaderused 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 Detail
-
PrimitiveSamReaderToSamReaderAdapter
public PrimitiveSamReaderToSamReaderAdapter(SamReader.PrimitiveSamReader p, SamInputResource resource)
-
-
Method Detail
-
underlyingReader
public SamReader.PrimitiveSamReader underlyingReader()
Access the underlyingSamReader.PrimitiveSamReaderused by this adapter.- Returns:
- the
SamReader.PrimitiveSamReaderused by this adapter.
-
queryOverlapping
public SAMRecordIterator queryOverlapping(String sequence, int start, int end)
Description copied from interface:SamReaderIterate 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:
queryOverlappingin 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
public SAMRecordIterator queryOverlapping(QueryInterval[] intervals)
Description copied from interface:SamReaderIterate 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:
queryOverlappingin 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
public SAMRecordIterator queryContained(String sequence, int start, int end)
Description copied from interface:SamReaderIterate 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:
queryContainedin 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
public SAMRecordIterator queryContained(QueryInterval[] intervals)
Description copied from interface:SamReaderIterate 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:
queryContainedin 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
public SAMRecord queryMate(SAMRecord rec)
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.IndexingReturns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.- Specified by:
hasBrowseableIndexin interfaceSamReader.Indexing- Returns:
- True if the index supports the BrowseableBAMIndex interface. False otherwise.
-
getBrowseableIndex
public BrowseableBAMIndex getBrowseableIndex()
Description copied from interface:SamReader.IndexingGets an index tagged with the BrowseableBAMIndex interface. Throws an exception if no such index is available.- Specified by:
getBrowseableIndexin interfaceSamReader.Indexing- Returns:
- An index with a browseable interface, if possible.
-
iterator
public SAMRecordIterator iterator()
Description copied from interface:SamReaderIterate 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
public SAMRecordIterator iterator(SAMFileSpan chunks)
Description copied from interface:SamReader.IndexingIterate through the given chunks in the file.- Specified by:
iteratorin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getFilePointerSpanningReads
public SAMFileSpan getFilePointerSpanningReads()
Description copied from interface:SamReader.IndexingGets a pointer spanning all reads in the BAM file.- Specified by:
getFilePointerSpanningReadsin interfaceSamReader.Indexing- Returns:
- Unbounded pointer to the first record, in chunk format.
-
getFileHeader
public SAMFileHeader getFileHeader()
- Specified by:
getFileHeaderin interfaceSamReader
-
type
public SamReader.Type type()
- Specified by:
typein interfaceSamReader- Returns:
- the
SamReader.Typeof thisSamReader
-
getResourceDescription
public String getResourceDescription()
- Specified by:
getResourceDescriptionin interfaceSamReader- Returns:
- a human readable description of the resource backing this sam reader
-
hasIndex
public boolean hasIndex()
-
indexing
public SamReader.Indexing indexing()
Description copied from interface:SamReaderExposes theSamReader.Indexingfacet of thisSamReader.
-
getIndex
public BAMIndex getIndex()
Description copied from interface:SamReader.IndexingRetrieves the index for the given file type. Ensure that the index is of the specified type.- Specified by:
getIndexin interfaceSamReader.Indexing- Returns:
- An index of the given type.
-
query
public SAMRecordIterator query(QueryInterval[] intervals, boolean contained)
Description copied from interface:SamReaderIterate 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:
queryin 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
public SAMRecordIterator query(String sequence, int start, int end, boolean contained)
Description copied from interface:SamReaderIterate 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:
queryin 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
public SAMRecordIterator queryUnmapped()
- Specified by:
queryUnmappedin interfaceSamReader
-
queryAlignmentStart
public SAMRecordIterator queryAlignmentStart(String sequence, int start)
Description copied from interface:SamReaderIterate 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:
queryAlignmentStartin interfaceSamReader- Parameters:
sequence- Reference sequence of interest.start- Alignment start of interest.- Returns:
- Iterator over the SAMRecords with the given alignment start.
-
-