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
ConstructorsConstructorDescriptionCRAMFileReader(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 TypeMethodDescriptionvoidclose()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.booleanReturns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.booleanhasIndex()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, waitMethods 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 thecramFileand theinputStreamare both nullIllegalStateException- if adefaultreference 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- asourceof reference sequences. May not be null.- Throws:
IllegalArgumentException- if thecramFileand theinputStreamare both null or if theCRAMReferenceSourceis 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- asourceof reference sequences. May not be null.- Throws:
IllegalArgumentException- if thecramFileor theCRAMReferenceSourceis null
-
CRAMFileReader
Create a CRAMFileReader from a file using the supplied reference source.- Parameters:
cramFile- CRAM file to read. Can not be null.referenceSource- asourceof reference sequences. May not be null.- Throws:
IllegalArgumentException- if thecramFileor theCRAMReferenceSourceis 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- asourceof reference sequences. May not be null.validationStringency- Validation stringency to be used when reading- Throws:
IllegalArgumentException- if theinputStreamor theCRAMReferenceSourceis 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- asourceof reference sequences. May not be null.validationStringency- Validation stringency to be used when reading- Throws:
IllegalArgumentException- if theinputStreamor theCRAMReferenceSourceis 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- asourceof reference sequences. May not be null.validationStringency- Validation stringency to be used when reading- Throws:
IllegalArgumentException- if thecramFileor theCRAMReferenceSourceis nullIOException
-
-
Method Details
-
hasIndex
public boolean hasIndex()- Specified by:
hasIndexin interfaceSamReader.PrimitiveSamReader
-
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- Specified by:
getIndexin interfaceSamReader.PrimitiveSamReader- Returns:
- An index of the given type.
-
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
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
Description copied from interface:SamReader.IndexingIterate through the given chunks in the file.- Specified by:
iteratorin interfaceSamReader.Indexing- Parameters:
fileSpan- List of chunks for which to retrieve data.- Returns:
- An iterator over the given chunks.
-
getFileHeader
- Specified by:
getFileHeaderin interfaceSamReader.PrimitiveSamReader
-
getIterator
- Specified by:
getIteratorin 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:
getIteratorin interfaceSamReader.PrimitiveSamReader
-
getFilePointerSpanningReads
Description copied from interface:SamReader.IndexingGets a pointer spanning all reads in the BAM file.- Specified by:
getFilePointerSpanningReadsin interfaceSamReader.Indexing- Specified by:
getFilePointerSpanningReadsin interfaceSamReader.PrimitiveSamReader- Returns:
- Unbounded pointer to the first record, in chunk format.
-
queryAlignmentStart
- Specified by:
queryAlignmentStartin interfaceSamReader.PrimitiveSamReader
-
queryUnmapped
- Specified by:
queryUnmappedin interfaceSamReader.PrimitiveSamReader
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSamReader.PrimitiveSamReader
-
getValidationStringency
- Specified by:
getValidationStringencyin interfaceSamReader.PrimitiveSamReader
-
query
- Specified by:
queryin interfaceSamReader.PrimitiveSamReader
-
type
- Specified by:
typein 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
-