Program: 50370
Project: 50370
Buggy source:
/** 
 * Score the realignment of an entry with respect to a potential indel.
 * @param entry            The entry to score as if it was realigned with respect to the indel
 * @param indel            The indel under consideration.
 * @param shiftForward     Whether the indel should be introduced by shifting bases forward
 * @param currentBestScore The current maximum score over a set of indels under consideration.  @return The score obtained when realigning the entry with respect to the provided indel.
 * @param genome           The genome to use to lookup reference bases
 * @return The score that would be observed if the indel was inserted into the alignment represented by entry.
 */
public final int score(final Alignments.AlignmentEntry entry,final ObservedIndel indel,final boolean shiftForward,final int currentBestScore,final RandomAccessSequenceInterface genome){
  int entryPosition=entry.getPosition();
  int indelOffsetInAlignment=indel.getStart() - entryPosition;
  int indelLength=indel.positionSpan();
  int varCount=entry.getSequenceVariationsCount();
  int targetIndex=entry.getTargetIndex();
  int score=0;
  int direction=shiftForward ? 1 : -1;
  if (genome == null) {
    genomeNull.warn(LOG,"String_Node_Str");
    return Integer.MIN_VALUE;
  }
  final int targetLength=genome.getLength(targetIndex);
  IntArraySet variantPositions=new IntArraySet();
  for (int i=0; i < varCount; i++) {
    Alignments.SequenceVariation var=entry.getSequenceVariations(i);
    final int newGenomicPosition=var.getPosition() + (direction * indelLength) + entryPosition - 1;
    for (int j=0; j < var.getTo().length(); ++j) {
      final char toBase=var.getTo().charAt(j);
      final int index=newGenomicPosition + j;
      if (index < 0 || index > genome.getLength(targetIndex)) {
        score+=-10;
      }
 else {
        final boolean compatible=genome.get(targetIndex,newGenomicPosition + j) == toBase;
        score+=compatible ? 1 : 0;
        variantPositions.add(var.getPosition() + entryPosition + j - 1);
      }
    }
  }
  int startAlignment=shiftForward ? entryPosition + indelOffsetInAlignment : entryPosition;
  int endAlignment=shiftForward ? entry.getTargetAlignedLength() + entryPosition : indelOffsetInAlignment + entryPosition + (direction * indelLength);
  for (int pos=startAlignment; pos < endAlignment; pos++) {
    if (!variantPositions.contains(pos)) {
      final int realignedPos=pos + (direction * indelLength);
      if (realignedPos < 0 || realignedPos >= targetLength) {
        score+=-10;
      }
 else {
        final char refBase=genome.get(targetIndex,pos);
        final char newRefBase=genome.get(targetIndex,realignedPos);
        score+=(refBase == newRefBase) ? 0 : -1;
      }
    }
  }
  return score;
}

Fixed version (ground truth):
/** 
 * Score the realignment of an entry with respect to a potential indel.
 * @param entry            The entry to score as if it was realigned with respect to the indel
 * @param indel            The indel under consideration.
 * @param shiftForward     Whether the indel should be introduced by shifting bases forward
 * @param currentBestScore The current maximum score over a set of indels under consideration.  @return The score obtained when realigning the entry with respect to the provided indel.
 * @param genome           The genome to use to lookup reference bases
 * @return The score that would be observed if the indel was inserted into the alignment represented by entry.
 */
public final int score(final Alignments.AlignmentEntry entry,final ObservedIndel indel,final boolean shiftForward,final int currentBestScore,final RandomAccessSequenceInterface genome){
  int entryPosition=entry.getPosition();
  int indelOffsetInAlignment=indel.getStart() - entryPosition;
  int indelLength=indel.positionSpan();
  int varCount=entry.getSequenceVariationsCount();
  int targetIndex=entry.getTargetIndex();
  int score=0;
  int direction=shiftForward ? 1 : -1;
  if (genome == null) {
    genomeNull.warn(LOG,"String_Node_Str");
    return Integer.MIN_VALUE;
  }
  final int targetLength=genome.getLength(targetIndex);
  IntArraySet variantPositions=new IntArraySet();
  for (int i=0; i < varCount; i++) {
    Alignments.SequenceVariation var=entry.getSequenceVariations(i);
    final int newGenomicPosition=var.getPosition() + (direction * indelLength) + entryPosition - 1;
    for (int j=0; j < var.getTo().length(); ++j) {
      final char toBase=var.getTo().charAt(j);
      final int index=newGenomicPosition + j;
      if (index < 0 || index > genome.getLength(targetIndex)) {
        score+=-10;
      }
 else {
        final boolean compatible=genome.get(targetIndex,newGenomicPosition + j) == toBase;
        score+=compatible ? 1 : 0;
        variantPositions.add(var.getPosition() + entryPosition + j - 1);
      }
    }
  }
  int startAlignment=shiftForward ? entryPosition + indelOffsetInAlignment : entryPosition;
  int endAlignment=shiftForward ? entry.getTargetAlignedLength() + entryPosition : indelOffsetInAlignment + entryPosition + (direction * indelLength);
  endAlignment=Math.min(endAlignment,genome.getLength(targetIndex) - 1);
  for (int pos=startAlignment; pos < endAlignment; pos++) {
    if (!variantPositions.contains(pos)) {
      final int realignedPos=pos + (direction * indelLength);
      if (realignedPos < 0 || realignedPos >= targetLength) {
        score+=-10;
      }
 else {
        final char refBase=genome.get(targetIndex,pos);
        final char newRefBase=genome.get(targetIndex,realignedPos);
        score+=(refBase == newRefBase) ? 0 : -1;
      }
    }
  }
  return score;
}