if (!ASSUME_SORTED && sam.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
throw new PicardException("Header of input file " + INPUT.getAbsolutePath() + " indicates that it is not coordinate sorted. " +
"If you believe the records are in coordinate order, pass option ASSUME_SORTED=true. If not, sort the file with SortSam.");
}
final PeekableIterator<SAMRecord> iterator = new PeekableIterator<SAMRecord>(sam.iterator());
final ReferenceSequenceFile referenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
{
// Check that the sequence dictionaries match if present
final SAMSequenceDictionary referenceDictionary= referenceFile.getSequenceDictionary();
final SAMSequenceDictionary samFileDictionary = sam.getFileHeader().getSequenceDictionary();
if (referenceDictionary != null && samFileDictionary != null) {
SequenceUtil.assertSequenceDictionariesEqual(referenceDictionary, samFileDictionary);
}
}
////////////////////////////////////////////////////////////////////////////
// Loop over the reference and the reads and calculate the basic metrics
////////////////////////////////////////////////////////////////////////////
ReferenceSequence ref = null;
final ProgressLogger
progress = new ProgressLogger(log);
while ((ref = referenceFile.nextSequence()) != null) {
final byte[] refBases = ref.getBases();
StringUtil.toUpperCase(refBases);
final int refLength = refBases.length;
final int lastWindowStart = refLength - WINDOW_SIZE;