Program: 16725
Project: 16725
Buggy source:
/** 
 * This method takes a list of pairwise alignments to the reference structure and calculates the  MultipleAlignment resulting from them. It ignores blocks in AFPChain (flexible parts) and builds  the Blocks as the definition of MultipleAlignment dictates   {@link Block}. Gaps are not included.
 * @param afpList the list of pairwise alignments to the reference
 * @param atomArrays List of Atoms of the structures
 * @param ref index of the reference structure
 * @return MultipleAlignment seed alignment
 * @throws StructureAlignmentException 
 * @throws StructureException 
 */
private static MultipleAlignment seedFromReference(List<AFPChain> afpList,List<Atom[]> atomArrays,int ref) throws StructureAlignmentException, StructureException {
  int size=atomArrays.size();
  int length=0;
  if (ref == 0)   length=afpList.get(1).getCa1Length();
 else   length=afpList.get(0).getCa2Length();
  List<List<Integer>> equivalencies=new ArrayList<List<Integer>>();
  for (int i=0; i < length; i++) {
    equivalencies.add(new ArrayList<Integer>());
    for (int j=0; j < size; j++) {
      if (j == ref)       equivalencies.get(i).add(i);
 else       equivalencies.get(i).add(null);
    }
  }
  for (int j=0; j < size; j++) {
    if (j == ref)     continue;
    for (int bk=0; bk < afpList.get(j).getBlockNum(); bk++) {
      for (int i=0; i < afpList.get(j).getOptLen()[bk]; i++) {
        int res1=0;
        int res2=0;
        if (j > ref) {
          res1=afpList.get(j).getOptAln()[bk][0][i];
          res2=afpList.get(j).getOptAln()[bk][1][i];
        }
 else         if (j < ref) {
          res1=afpList.get(j).getOptAln()[bk][1][i];
          res2=afpList.get(j).getOptAln()[bk][0][i];
        }
        equivalencies.get(res1).set(j,res2);
      }
    }
  }
  MultipleAlignment seed=new MultipleAlignmentImpl(atomArrays);
  BlockSet blockSet=new BlockSetImpl(seed);
  new BlockImpl(blockSet);
  for (int i=0; i < length; i++) {
    boolean gap=false;
    boolean cp=false;
    for (int j=0; j < size; j++) {
      if (equivalencies.get(i).get(j) == null) {
        gap=true;
        break;
      }
      if (blockSet.getBlocks().get(blockSet.getBlockNum() - 1).length() > 0) {
        if (equivalencies.get(i).get(j) < blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().get(j).get(blockSet.getBlocks().get(blockSet.getBlockNum() - 1).length() - 1)) {
          cp=true;
        }
      }
    }
    if (gap)     continue;
    if (cp)     new BlockImpl(blockSet);
    for (int j=0; j < size; j++) {
      if (blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().size() == 0)       for (int k=0; k < size; k++)       blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().add(new ArrayList<Integer>());
      blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().get(j).add(equivalencies.get(i).get(j));
    }
  }
  seed.updateCache(PoseMethod.REFERENCE);
  return seed;
}

Fixed version (ground truth):
/** 
 * This method takes a list of pairwise alignments to the reference structure and calculates the  MultipleAlignment resulting from them. It ignores blocks in AFPChain (flexible parts) and builds  the Blocks as the definition of MultipleAlignment dictates   {@link Block}. Gaps are not included.
 * @param afpList the list of pairwise alignments to the reference
 * @param atomArrays List of Atoms of the structures
 * @param ref index of the reference structure
 * @return MultipleAlignment seed alignment
 * @throws StructureAlignmentException 
 * @throws StructureException 
 */
private MultipleAlignment seedFromReference(List<AFPChain> afpList,List<Atom[]> atomArrays,int ref) throws StructureAlignmentException, StructureException {
  int size=atomArrays.size();
  int length=0;
  if (ref == 0)   length=afpList.get(1).getCa1Length();
 else   length=afpList.get(0).getCa2Length();
  List<List<Integer>> equivalencies=new ArrayList<List<Integer>>();
  for (int i=0; i < length; i++) {
    equivalencies.add(new ArrayList<Integer>());
    for (int j=0; j < size; j++) {
      if (j == ref)       equivalencies.get(i).add(i);
 else       equivalencies.get(i).add(null);
    }
  }
  for (int j=0; j < size; j++) {
    if (j == ref)     continue;
    for (int bk=0; bk < afpList.get(j).getBlockNum(); bk++) {
      for (int i=0; i < afpList.get(j).getOptLen()[bk]; i++) {
        int res1=0;
        int res2=0;
        if (j > ref) {
          res1=afpList.get(j).getOptAln()[bk][0][i];
          res2=afpList.get(j).getOptAln()[bk][1][i];
        }
 else         if (j < ref) {
          res1=afpList.get(j).getOptAln()[bk][1][i];
          res2=afpList.get(j).getOptAln()[bk][0][i];
        }
        equivalencies.get(res1).set(j,res2);
      }
    }
  }
  MultipleAlignment seed=new MultipleAlignmentImpl(ensemble);
  BlockSet blockSet=new BlockSetImpl(seed);
  new BlockImpl(blockSet);
  for (int i=0; i < length; i++) {
    boolean gap=false;
    boolean cp=false;
    for (int j=0; j < size; j++) {
      if (equivalencies.get(i).get(j) == null) {
        gap=true;
        break;
      }
      if (blockSet.getBlocks().get(blockSet.getBlockNum() - 1).length() > 0) {
        if (equivalencies.get(i).get(j) < blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().get(j).get(blockSet.getBlocks().get(blockSet.getBlockNum() - 1).length() - 1)) {
          cp=true;
        }
      }
    }
    if (gap)     continue;
    if (cp)     new BlockImpl(blockSet);
    for (int j=0; j < size; j++) {
      if (blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().size() == 0)       for (int k=0; k < size; k++)       blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().add(new ArrayList<Integer>());
      blockSet.getBlocks().get(blockSet.getBlockNum() - 1).getAlignRes().get(j).add(equivalencies.get(i).get(j));
    }
  }
  seed.updateCache(PoseMethod.REFERENCE);
  return seed;
}