Package htsjdk.samtools
Class CRAMFileReader
java.lang.Object
htsjdk.samtools.SamReader.ReaderImplementation
htsjdk.samtools.CRAMFileReader
- All Implemented Interfaces:
SamReader.Indexing
,SamReader.PrimitiveSamReader
,AutoCloseable
public class CRAMFileReader
extends SamReader.ReaderImplementation
implements SamReader.Indexing, AutoCloseable
BAMFileReader
analogue for CRAM files.
Supports random access using BAI index file formats.-
Constructor Summary
ConstructorDescriptionCRAMFileReader
(File cramFile, CRAMReferenceSource referenceSource) Create a CRAMFileReader from a file using the supplied reference source.CRAMFileReader
(File cramFile, File indexFile, CRAMReferenceSource referenceSource) Create a CRAMFileReader from a file and optional index file using the supplied reference source.CRAMFileReader
(File cramFile, File indexFile, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.CRAMFileReader
(File cramFile, InputStream inputStream) Create a CRAMFileReader from either a file or input stream using the reference source returned bygetDefaultCRAMReferenceSource
.CRAMFileReader
(File cramFile, InputStream inputStream, CRAMReferenceSource referenceSource) Create a CRAMFileReader from either a file or input stream using the supplied reference source.CRAMFileReader
(InputStream inputStream, SeekableStream indexInputStream, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) Create a CRAMFileReader from an input stream and optional index stream using the supplied reference source and validation stringency.CRAMFileReader
(InputStream stream, File indexFile, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) Create a CRAMFileReader from an input stream and optional index file using the supplied reference source and validation stringency. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
createIndexIterator
(QueryInterval[] intervals, boolean contained, long[] filePointers) Prepare to iterate through SAMRecords that match the intersection of the given intervals and chunk boundaries.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.getIterator
(SAMFileSpan fileSpan) Note: the resolution of this iterator is the Slice, so the records returned are all of the records in all the slices that overlap these spans.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()
iterator
(SAMFileSpan fileSpan) Iterate through the given chunks in the file.query
(QueryInterval[] intervals, boolean contained) queryAlignmentStart
(String sequence, int start) type()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface htsjdk.samtools.SamReader.PrimitiveSamReader
isQueryable
-
Constructor Details
-
CRAMFileReader
Create a CRAMFileReader from either a file or input stream using the reference source returned bygetDefaultCRAMReferenceSource
.- Parameters:
cramFile
- CRAM file to openinputStream
- CRAM stream to read- Throws:
IllegalArgumentException
- if thecramFile
and theinputStream
are both nullIllegalStateException
- if adefault
reference source cannot be acquired
-
CRAMFileReader
Create a CRAMFileReader from either a file or input stream using the supplied reference source.- Parameters:
cramFile
- CRAM file to readinputStream
- CRAM stream to readreferenceSource
- asource
of reference sequences. May not be null.- Throws:
IllegalArgumentException
- if thecramFile
and theinputStream
are both null or if theCRAMReferenceSource
is null
-
CRAMFileReader
Create a CRAMFileReader from a file and optional index file using the supplied reference source. If index file is supplied then random access will be available.- Parameters:
cramFile
- CRAM file to read. May not be null.indexFile
- index file to be used for random access. May be null.referenceSource
- asource
of reference sequences. May not be null.- Throws:
IllegalArgumentException
- if thecramFile
or theCRAMReferenceSource
is null
-
CRAMFileReader
Create a CRAMFileReader from a file using the supplied reference source.- Parameters:
cramFile
- CRAM file to read. Can not be null.referenceSource
- asource
of reference sequences. May not be null.- Throws:
IllegalArgumentException
- if thecramFile
or theCRAMReferenceSource
is null
-
CRAMFileReader
public CRAMFileReader(InputStream inputStream, SeekableStream indexInputStream, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) throws IOException Create a CRAMFileReader from an input stream and optional index stream using the supplied reference source and validation stringency.- Parameters:
inputStream
- CRAM stream to read. May not be null.indexInputStream
- index stream to be used for random access. May be null.referenceSource
- asource
of reference sequences. May not be null.validationStringency
- Validation stringency to be used when reading- Throws:
IllegalArgumentException
- if theinputStream
or theCRAMReferenceSource
is nullIOException
-
CRAMFileReader
public CRAMFileReader(InputStream stream, File indexFile, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) throws IOException Create a CRAMFileReader from an input stream and optional index file using the supplied reference source and validation stringency.- Parameters:
stream
- CRAM stream to read. May not be null.indexFile
- index file to be used for random access. May be null.referenceSource
- asource
of reference sequences. May not be null.validationStringency
- Validation stringency to be used when reading- Throws:
IllegalArgumentException
- if theinputStream
or theCRAMReferenceSource
is nullIOException
-
CRAMFileReader
public CRAMFileReader(File cramFile, File indexFile, CRAMReferenceSource referenceSource, ValidationStringency validationStringency) throws IOException Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.- Parameters:
cramFile
- CRAM stream to read. May not be null.indexFile
- index file to be used for random access. May be null.referenceSource
- asource
of reference sequences. May not be null.validationStringency
- Validation stringency to be used when reading- Throws:
IllegalArgumentException
- if thecramFile
or theCRAMReferenceSource
is nullIOException
-
-
Method Details
-
hasIndex
public boolean hasIndex()- Specified by:
hasIndex
in interfaceSamReader.PrimitiveSamReader
-
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
- Specified by:
getIndex
in interfaceSamReader.PrimitiveSamReader
- Returns:
- An index of the given type.
-
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.Indexing
Iterate through the given chunks in the file.- Specified by:
iterator
in interfaceSamReader.Indexing
- Parameters:
fileSpan
- List of chunks for which to retrieve data.- Returns:
- An iterator over the given chunks.
-
getFileHeader
- Specified by:
getFileHeader
in interfaceSamReader.PrimitiveSamReader
-
getIterator
- Specified by:
getIterator
in interfaceSamReader.PrimitiveSamReader
-
getIterator
Note: the resolution of this iterator is the Slice, so the records returned are all of the records in all the slices that overlap these spans.- Specified by:
getIterator
in interfaceSamReader.PrimitiveSamReader
-
getFilePointerSpanningReads
Description copied from interface:SamReader.Indexing
Gets a pointer spanning all reads in the BAM file.- Specified by:
getFilePointerSpanningReads
in interfaceSamReader.Indexing
- Specified by:
getFilePointerSpanningReads
in interfaceSamReader.PrimitiveSamReader
- Returns:
- Unbounded pointer to the first record, in chunk format.
-
queryAlignmentStart
- Specified by:
queryAlignmentStart
in interfaceSamReader.PrimitiveSamReader
-
queryUnmapped
- Specified by:
queryUnmapped
in interfaceSamReader.PrimitiveSamReader
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSamReader.PrimitiveSamReader
-
getValidationStringency
- Specified by:
getValidationStringency
in interfaceSamReader.PrimitiveSamReader
-
query
- Specified by:
query
in interfaceSamReader.PrimitiveSamReader
-
type
- Specified by:
type
in interfaceSamReader.PrimitiveSamReader
-
createIndexIterator
public CloseableIterator<SAMRecord> createIndexIterator(QueryInterval[] intervals, boolean contained, long[] filePointers) Prepare to iterate through SAMRecords that match the intersection of the given intervals and chunk boundaries.- Parameters:
intervals
- the intervals to restrict reads tocontained
- iftrue
, return records that are strictly contained in the intervals, otherwise return records that overlapfilePointers
- file pointer pairs corresponding to chunk boundaries for the intervals
-