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
BAMFileReaderanalogue for CRAM files. Supports random access using BAI index file formats.
-
-
Constructor Summary
Constructors Constructor Description CRAMFileReader(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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.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.SAMRecordIteratorgetIterator()CloseableIterator<SAMRecord>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.ValidationStringencygetValidationStringency()booleanhasBrowseableIndex()Returns true if the supported index is browseable, meaning the bins in it can be traversed and chunk data inspected and retrieved.booleanhasIndex()SAMRecordIteratoriterator(SAMFileSpan fileSpan)Iterate through the given chunks in the file.CloseableIterator<SAMRecord>query(QueryInterval[] intervals, boolean contained)CloseableIterator<SAMRecord>queryAlignmentStart(String sequence, int start)CloseableIterator<SAMRecord>queryUnmapped()SamReader.Typetype()-
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 Detail
-
CRAMFileReader
public CRAMFileReader(File cramFile, InputStream inputStream)
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
public CRAMFileReader(File cramFile, InputStream inputStream, CRAMReferenceSource referenceSource)
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
public CRAMFileReader(File cramFile, File indexFile, CRAMReferenceSource referenceSource)
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
public CRAMFileReader(File cramFile, CRAMReferenceSource referenceSource)
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 Detail
-
hasIndex
public boolean hasIndex()
- Specified by:
hasIndexin interfaceSamReader.PrimitiveSamReader
-
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- 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
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(SAMFileSpan fileSpan)
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
public SAMFileHeader getFileHeader()
- Specified by:
getFileHeaderin interfaceSamReader.PrimitiveSamReader
-
getIterator
public SAMRecordIterator getIterator()
- Specified by:
getIteratorin interfaceSamReader.PrimitiveSamReader
-
getIterator
public CloseableIterator<SAMRecord> 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.- Specified by:
getIteratorin interfaceSamReader.PrimitiveSamReader
-
getFilePointerSpanningReads
public SAMFileSpan 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
public CloseableIterator<SAMRecord> queryAlignmentStart(String sequence, int start)
- Specified by:
queryAlignmentStartin interfaceSamReader.PrimitiveSamReader
-
queryUnmapped
public CloseableIterator<SAMRecord> queryUnmapped()
- Specified by:
queryUnmappedin interfaceSamReader.PrimitiveSamReader
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSamReader.PrimitiveSamReader
-
getValidationStringency
public ValidationStringency getValidationStringency()
- Specified by:
getValidationStringencyin interfaceSamReader.PrimitiveSamReader
-
query
public CloseableIterator<SAMRecord> query(QueryInterval[] intervals, boolean contained)
- Specified by:
queryin interfaceSamReader.PrimitiveSamReader
-
type
public SamReader.Type 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
-
-