Program: 30635
Project: 30635
Buggy source:
private void collectQualityData(final SAMRecord record,final ReferenceSequence reference){
  if (record.getReadUnmappedFlag() || !doRefMetrics) {
    final byte[] readBases=record.getReadBases();
    for (int i=0; i < readBases.length; i++) {
      if (SequenceUtil.isNoCall(readBases[i])) {
        badCycleHistogram.increment(CoordMath.getCycle(record.getReadNegativeStrandFlag(),readBases.length,i));
      }
    }
  }
 else {
    final boolean highQualityMapping=isHighQualityMapping(record);
    if (highQualityMapping)     metrics.PF_HQ_ALIGNED_READS++;
    final byte[] readBases=record.getReadBases();
    final byte[] refBases=reference.getBases();
    final byte[] qualities=record.getBaseQualities();
    final int refLength=refBases.length;
    long mismatchCount=0;
    long hqMismatchCount=0;
    for (    final AlignmentBlock alignmentBlock : record.getAlignmentBlocks()) {
      final int readIndex=alignmentBlock.getReadStart() - 1;
      final int refIndex=alignmentBlock.getReferenceStart() - 1;
      final int length=alignmentBlock.getLength();
      for (int i=0; i < length && refIndex + i < refLength; ++i) {
        final int readBaseIndex=readIndex + i;
        boolean mismatch=!SequenceUtil.basesEqual(readBases[readBaseIndex],refBases[refIndex + i]);
        boolean bisulfiteBase=false;
        if (mismatch && IS_BISULFITE_SEQUENCED) {
          if ((record.getReadNegativeStrandFlag() && (refBases[refIndex + i] == 'G' || refBases[refIndex + i] == 'g') && (readBases[readBaseIndex] == 'A' || readBases[readBaseIndex] == 'a')) || ((!record.getReadNegativeStrandFlag()) && (refBases[refIndex + i] == 'C' || refBases[refIndex + i] == 'c') && (readBases[readBaseIndex] == 'T') || readBases[readBaseIndex] == 't')) {
            bisulfiteBase=true;
            mismatch=false;
          }
        }
        if (mismatch)         mismatchCount++;
        metrics.PF_ALIGNED_BASES++;
        if (!bisulfiteBase) {
          nonBisulfiteAlignedBases++;
        }
        if (highQualityMapping) {
          metrics.PF_HQ_ALIGNED_BASES++;
          if (!bisulfiteBase) {
            hqNonBisulfiteAlignedBases++;
          }
          if (qualities[readBaseIndex] >= BASE_QUALITY_THRESHOLD) {
            metrics.PF_HQ_ALIGNED_Q20_BASES++;
          }
          if (mismatch) {
            hqMismatchCount++;
          }
        }
        if (mismatch || SequenceUtil.isNoCall(readBases[readBaseIndex])) {
          badCycleHistogram.increment(CoordMath.getCycle(record.getReadNegativeStrandFlag(),readBases.length,i));
        }
      }
    }
    mismatchHistogram.increment(mismatchCount);
    hqMismatchHistogram.increment(hqMismatchCount);
    for (    final CigarElement elem : record.getCigar().getCigarElements()) {
      final CigarOperator op=elem.getOperator();
      if (op == CigarOperator.INSERTION || op == CigarOperator.DELETION)       ++this.indels;
    }
  }
}

Fixed version (ground truth):
private void collectQualityData(final SAMRecord record,final ReferenceSequence reference){
  if (record.getReadUnmappedFlag() || record.getReadFailsVendorQualityCheckFlag() || !doRefMetrics) {
    final byte[] readBases=record.getReadBases();
    for (int i=0; i < readBases.length; i++) {
      if (SequenceUtil.isNoCall(readBases[i])) {
        badCycleHistogram.increment(CoordMath.getCycle(record.getReadNegativeStrandFlag(),readBases.length,i));
      }
    }
  }
 else   if (!record.getReadFailsVendorQualityCheckFlag()) {
    final boolean highQualityMapping=isHighQualityMapping(record);
    if (highQualityMapping)     metrics.PF_HQ_ALIGNED_READS++;
    final byte[] readBases=record.getReadBases();
    final byte[] refBases=reference.getBases();
    final byte[] qualities=record.getBaseQualities();
    final int refLength=refBases.length;
    long mismatchCount=0;
    long hqMismatchCount=0;
    for (    final AlignmentBlock alignmentBlock : record.getAlignmentBlocks()) {
      final int readIndex=alignmentBlock.getReadStart() - 1;
      final int refIndex=alignmentBlock.getReferenceStart() - 1;
      final int length=alignmentBlock.getLength();
      for (int i=0; i < length && refIndex + i < refLength; ++i) {
        final int readBaseIndex=readIndex + i;
        boolean mismatch=!SequenceUtil.basesEqual(readBases[readBaseIndex],refBases[refIndex + i]);
        boolean bisulfiteBase=false;
        if (mismatch && IS_BISULFITE_SEQUENCED) {
          if ((record.getReadNegativeStrandFlag() && (refBases[refIndex + i] == 'G' || refBases[refIndex + i] == 'g') && (readBases[readBaseIndex] == 'A' || readBases[readBaseIndex] == 'a')) || ((!record.getReadNegativeStrandFlag()) && (refBases[refIndex + i] == 'C' || refBases[refIndex + i] == 'c') && (readBases[readBaseIndex] == 'T') || readBases[readBaseIndex] == 't')) {
            bisulfiteBase=true;
            mismatch=false;
          }
        }
        if (mismatch)         mismatchCount++;
        metrics.PF_ALIGNED_BASES++;
        if (!bisulfiteBase)         nonBisulfiteAlignedBases++;
        if (highQualityMapping) {
          metrics.PF_HQ_ALIGNED_BASES++;
          if (!bisulfiteBase)           hqNonBisulfiteAlignedBases++;
          if (qualities[readBaseIndex] >= BASE_QUALITY_THRESHOLD)           metrics.PF_HQ_ALIGNED_Q20_BASES++;
          if (mismatch)           hqMismatchCount++;
        }
        if (mismatch || SequenceUtil.isNoCall(readBases[readBaseIndex])) {
          badCycleHistogram.increment(CoordMath.getCycle(record.getReadNegativeStrandFlag(),readBases.length,i));
        }
      }
    }
    mismatchHistogram.increment(mismatchCount);
    hqMismatchHistogram.increment(hqMismatchCount);
    for (    final CigarElement elem : record.getCigar().getCigarElements()) {
      final CigarOperator op=elem.getOperator();
      if (op == CigarOperator.INSERTION || op == CigarOperator.DELETION)       ++this.indels;
    }
  }
}