SAMFileReader reader = new SAMFileReader(file);
source.reader = reader;
if (query == null)
source.it = reader.iterator();
else {
SeekableFileStream is = new SeekableFileStream(file);
FileInputStream fis = new FileInputStream(index);
GZIPInputStream gis = new GZIPInputStream(
new BufferedInputStream(fis));
BufferedInputStream bis = new BufferedInputStream(gis);
List<CramIndex.Entry> full = CramIndex.readIndex(gis);
List<CramIndex.Entry> entries = new LinkedList<CramIndex.Entry>();
SAMSequenceRecord sequence = reader.getFileHeader()
.getSequence(query.sequence);
if (sequence == null)
throw new RuntimeException("Sequence not found: "
+ query.sequence);
entries.addAll(CramIndex.find(full,
sequence.getSequenceIndex(), query.start,
query.end - query.start));
bis.close();
SAMIterator it = new SAMIterator(is, refFile);
is.seek(entries.get(0).containerStartOffset);
BAMQueryFilteringIterator bit = new BAMQueryFilteringIterator(
it, query.sequence, query.start, query.end,
BAMQueryFilteringIterator.QueryType.CONTAINED,
reader.getFileHeader());
source.it = bit;