Program: 50441
Project: 50441
Buggy source:
@Test public void testIterateSortedReferenceInsertions() throws IOException {
  final String basename="String_Node_Str";
  final String basenamePath=FilenameUtils.concat(BASE_TEST_DIR,basename);
  final AlignmentWriter writer=new AlignmentWriter(basenamePath);
  writer.setNumAlignmentEntriesPerChunk(1);
  final int numTargets=3;
  final int[] targetLengths=new int[numTargets];
  for (int referenceIndex=0; referenceIndex < numTargets; referenceIndex++) {
    targetLengths[referenceIndex]=1000;
  }
  writer.setTargetLengths(targetLengths);
  writer.setSorted(true);
  Alignments.AlignmentEntry.Builder newEntry;
  newEntry=prepareAlignmentEntryWithReferenceInsertion(0,1,100,30,false,new int[]{4,3});
  writer.appendEntry(newEntry.build());
  writer.close();
  writer.printStats(System.out);
  final Int2IntMap positionMap=new Int2IntOpenHashMap();
  final IntSet variantReadIndices=new IntOpenHashSet();
  IterateSortedAlignmentsListImpl iterator=new IterateSortedAlignmentsListImpl(){
    @Override public void observeVariantBase(    ConcatSortedAlignmentReader sortedReaders,    Alignments.AlignmentEntry alignmentEntry,    Int2ObjectMap<ObjectArrayList<PositionBaseInfo>> positionToBases,    Alignments.SequenceVariation var,    char toChar,    char fromChar,    int currentReferenceIndex,    int currentRefPosition,    int currentReadIndex){
      variantReadIndices.add(currentReadIndex);
    }
    @Override public void processPositions(    int referenceIndex,    int intermediatePosition,    ObjectArrayList<PositionBaseInfo> positionBaseInfos){
      int coverage=0;
      for (      PositionBaseInfo info : positionBaseInfos) {
        coverage+=info.to != '-' ? 1 : 0;
      }
      positionMap.put(intermediatePosition,coverage);
      System.out.printf("String_Node_Str",referenceIndex,coverage);
    }
  }
;
  iterator.iterate(basenamePath);
  for (int i=0; i < 100; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
  for (int i=100; i < 103; i++) {
    assertEquals("String_Node_Str" + i,1,positionMap.get(i));
  }
  for (int i=103; i < 106; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
  for (int i=106; i < 137; i++) {
    assertEquals("String_Node_Str" + i,1,positionMap.get(i));
  }
  for (int i=138; i < 150; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
}

Fixed version (ground truth):
@Test public void testIterateSortedReferenceInsertions() throws IOException {
  final String basename="String_Node_Str";
  final String basenamePath=FilenameUtils.concat(BASE_TEST_DIR,basename);
  final AlignmentWriter writer=new AlignmentWriter(basenamePath);
  writer.setNumAlignmentEntriesPerChunk(1);
  final int numTargets=3;
  final int[] targetLengths=new int[numTargets];
  for (int referenceIndex=0; referenceIndex < numTargets; referenceIndex++) {
    targetLengths[referenceIndex]=1000;
  }
  writer.setTargetLengths(targetLengths);
  writer.setSorted(true);
  Alignments.AlignmentEntry.Builder newEntry;
  newEntry=prepareAlignmentEntryWithReferenceInsertion(0,1,100,30,false,new int[]{4,3});
  writer.appendEntry(newEntry.build());
  writer.close();
  writer.printStats(System.out);
  final Int2IntMap positionMap=new Int2IntOpenHashMap();
  final IntSet variantReadIndices=new IntOpenHashSet();
  IterateSortedAlignmentsListImpl iterator=new IterateSortedAlignmentsListImpl(){
    @Override public void observeVariantBase(    ConcatSortedAlignmentReader sortedReaders,    Alignments.AlignmentEntry alignmentEntry,    Int2ObjectMap<ObjectArrayList<IterateSortedAlignmentsListImpl.PositionBaseInfo>> positionToBases,    Alignments.SequenceVariation var,    char toChar,    char fromChar,    int currentReferenceIndex,    int currentRefPosition,    int currentReadIndex){
      variantReadIndices.add(currentReadIndex);
    }
    @Override public void processPositions(    int referenceIndex,    int intermediatePosition,    ObjectArrayList<PositionBaseInfo> positionBaseInfos){
      int coverage=0;
      for (      PositionBaseInfo info : positionBaseInfos) {
        coverage+=info.to != '-' ? 1 : 0;
      }
      positionMap.put(intermediatePosition,coverage);
      System.out.printf("String_Node_Str",referenceIndex,coverage);
    }
  }
;
  iterator.iterate(basenamePath);
  for (int i=0; i < 100; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
  for (int i=100; i < 103; i++) {
    assertEquals("String_Node_Str" + i,1,positionMap.get(i));
  }
  for (int i=103; i < 106; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
  for (int i=106; i < 137; i++) {
    assertEquals("String_Node_Str" + i,1,positionMap.get(i));
  }
  for (int i=138; i < 150; i++) {
    assertEquals("String_Node_Str" + i,0,positionMap.get(i));
  }
}