public BAQCalculationResult calcBAQFromHMM(SAMRecord read, IndexedFastaSequenceFile refReader) { // start is alignment start - band width / 2 - size of first I element, if there is one. Stop // is similar int offset = getBandWidth() / 2; long readStart = includeClippedBases ? read.getUnclippedStart() : read.getAlignmentStart(); long start = Math.max(readStart - offset - ReadUtils.getFirstInsertionOffset(read), 0); long stop = (includeClippedBases ? read.getUnclippedEnd() : read.getAlignmentEnd()) + offset + ReadUtils.getLastInsertionOffset(read); if (stop > refReader .getSequenceDictionary() .getSequence(read.getReferenceName()) .getSequenceLength()) { return null; } else { // now that we have the start and stop, get the reference sequence covering it ReferenceSequence refSeq = refReader.getSubsequenceAt(read.getReferenceName(), start, stop); return calcBAQFromHMM(read, refSeq.getBases(), (int) (start - readStart)); } }