Program: 16407
Project: 16407
Buggy source:
private TreeMap<String,EntityInfo> findEntitiesFromAlignment(){
  TreeMap<String,EntityInfo> chainIds2entities=new TreeMap<String,EntityInfo>();
  if (polyModels.isEmpty())   return chainIds2entities;
  Set<Integer> polyChainIndices=new TreeSet<Integer>();
  for (int i=0; i < polyModels.get(0).size(); i++) {
    polyChainIndices.add(i);
  }
  int molId=1;
  outer:   for (  int i : polyChainIndices) {
    for (    int j : polyChainIndices) {
      if (j <= i)       continue;
      Chain c1=polyModels.get(0).get(i);
      Chain c2=polyModels.get(0).get(j);
      Map<Integer,Integer> positionIndex1=new HashMap<Integer,Integer>();
      Map<Integer,Integer> positionIndex2=new HashMap<Integer,Integer>();
      String str1=SeqRes2AtomAligner.getFullAtomSequence(c1.getAtomGroups(),positionIndex1,false);
      String str2=SeqRes2AtomAligner.getFullAtomSequence(c2.getAtomGroups(),positionIndex2,false);
      int seq1Length=0;
      int seq2Length=0;
      SequencePair<?,?> pair=null;
      if (isProteinSequence(str1) && isProteinSequence(str2)) {
        ProteinSequence s1=getProteinSequence(str1);
        ProteinSequence s2=getProteinSequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignProtein(s1,s2);
      }
 else       if (isDNASequence(str1) && isDNASequence(str2)) {
        DNASequence s1=getDNASequence(str1);
        DNASequence s2=getDNASequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignDNA(s1,s2);
      }
 else       if (isRNASequence(str1) && isRNASequence(str2)) {
        RNASequence s1=getRNASequence(str1);
        RNASequence s2=getRNASequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignRNA(s1,s2);
      }
 else {
        logger.debug("String_Node_Str");
        continue;
      }
      int numGaps=getNumGaps(pair);
      int numGaps1=getNumGapsQuery(pair);
      int numGaps2=getNumGapsTarget(pair);
      int nonGaps=pair.getLength() - numGaps;
      double identity=(double)pair.getNumIdenticals() / (double)nonGaps;
      double gapCov1=(double)numGaps1 / (double)seq1Length;
      double gapCov2=(double)numGaps2 / (double)seq2Length;
      logger.debug("String_Node_Str",c1.getId(),c2.getId(),String.format("String_Node_Str",identity),String.format("String_Node_Str",gapCov1),String.format("String_Node_Str",gapCov2));
      logger.debug("String_Node_Str" + pair.toString(100));
      if (identity > IDENTITY_THRESHOLD && gapCov1 < GAP_COVERAGE_THRESHOLD && gapCov2 < GAP_COVERAGE_THRESHOLD) {
        if (!chainIds2entities.containsKey(c1.getId()) && !chainIds2entities.containsKey(c2.getId())) {
          logger.debug("String_Node_Str",c1.getId(),c2.getId());
          EntityInfo ent=new EntityInfo();
          ent.addChain(c1);
          ent.addChain(c2);
          ent.setMolId(molId++);
          ent.setType(EntityType.POLYMER);
          c1.setEntityInfo(ent);
          c2.setEntityInfo(ent);
          chainIds2entities.put(c1.getId(),ent);
          chainIds2entities.put(c2.getId(),ent);
        }
 else {
          EntityInfo ent=chainIds2entities.get(c1.getId());
          if (ent == null) {
            logger.debug("String_Node_Str",c1.getId(),c2.getId());
            ent=chainIds2entities.get(c2.getId());
            ent.addChain(c1);
            c1.setEntityInfo(ent);
            chainIds2entities.put(c1.getId(),ent);
          }
 else {
            logger.debug("String_Node_Str",c2.getId(),c1.getId());
            ent.addChain(c2);
            c2.setEntityInfo(ent);
            chainIds2entities.put(c2.getId(),ent);
          }
        }
        if (!areResNumbersAligned(c1,c2)) {
          logger.warn("String_Node_Str",c1.getId(),c2.getId());
        }
      }
      if (identity > 1) {
        logger.warn("String_Node_Str",c1.getId(),c2.getId(),pair.getNumIdenticals(),nonGaps,identity);
        logger.warn("String_Node_Str" + pair.toString(100));
      }
      if (chainIds2entities.size() == polyChainIndices.size())       break outer;
    }
  }
  for (  int i : polyChainIndices) {
    Chain c=polyModels.get(0).get(i);
    if (!chainIds2entities.containsKey(c.getId())) {
      logger.debug("String_Node_Str",c.getId());
      EntityInfo ent=new EntityInfo();
      ent.addChain(c);
      ent.setMolId(molId++);
      c.setEntityInfo(ent);
      chainIds2entities.put(c.getId(),ent);
    }
  }
  for (int i=1; i < polyModels.size(); i++) {
    for (    Chain chain : polyModels.get(i)) {
      EntityInfo e=chainIds2entities.get(chain.getId());
      chain.setEntityInfo(e);
      e.addChain(chain);
    }
  }
  return chainIds2entities;
}

Fixed version (ground truth):
private static TreeMap<String,EntityInfo> findEntitiesFromAlignment(List<List<Chain>> polyModels){
  TreeMap<String,EntityInfo> chainIds2entities=new TreeMap<String,EntityInfo>();
  if (polyModels.isEmpty())   return chainIds2entities;
  Set<Integer> polyChainIndices=new TreeSet<Integer>();
  for (int i=0; i < polyModels.get(0).size(); i++) {
    polyChainIndices.add(i);
  }
  int molId=1;
  outer:   for (  int i : polyChainIndices) {
    for (    int j : polyChainIndices) {
      if (j <= i)       continue;
      Chain c1=polyModels.get(0).get(i);
      Chain c2=polyModels.get(0).get(j);
      Map<Integer,Integer> positionIndex1=new HashMap<Integer,Integer>();
      Map<Integer,Integer> positionIndex2=new HashMap<Integer,Integer>();
      String str1=SeqRes2AtomAligner.getFullAtomSequence(c1.getAtomGroups(),positionIndex1,false);
      String str2=SeqRes2AtomAligner.getFullAtomSequence(c2.getAtomGroups(),positionIndex2,false);
      int seq1Length=0;
      int seq2Length=0;
      SequencePair<?,?> pair=null;
      if (isProteinSequence(str1) && isProteinSequence(str2)) {
        ProteinSequence s1=getProteinSequence(str1);
        ProteinSequence s2=getProteinSequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignProtein(s1,s2);
      }
 else       if (isDNASequence(str1) && isDNASequence(str2)) {
        DNASequence s1=getDNASequence(str1);
        DNASequence s2=getDNASequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignDNA(s1,s2);
      }
 else       if (isRNASequence(str1) && isRNASequence(str2)) {
        RNASequence s1=getRNASequence(str1);
        RNASequence s2=getRNASequence(str2);
        seq1Length=s1.getLength();
        seq2Length=s2.getLength();
        pair=alignRNA(s1,s2);
      }
 else {
        logger.debug("String_Node_Str");
        continue;
      }
      int numGaps=getNumGaps(pair);
      int numGaps1=getNumGapsQuery(pair);
      int numGaps2=getNumGapsTarget(pair);
      int nonGaps=pair.getLength() - numGaps;
      double identity=(double)pair.getNumIdenticals() / (double)nonGaps;
      double gapCov1=(double)numGaps1 / (double)seq1Length;
      double gapCov2=(double)numGaps2 / (double)seq2Length;
      logger.debug("String_Node_Str",c1.getId(),c2.getId(),String.format("String_Node_Str",identity),String.format("String_Node_Str",gapCov1),String.format("String_Node_Str",gapCov2));
      logger.debug("String_Node_Str" + pair.toString(100));
      if (identity > IDENTITY_THRESHOLD && gapCov1 < GAP_COVERAGE_THRESHOLD && gapCov2 < GAP_COVERAGE_THRESHOLD) {
        if (!chainIds2entities.containsKey(c1.getId()) && !chainIds2entities.containsKey(c2.getId())) {
          logger.debug("String_Node_Str",c1.getId(),c2.getId());
          EntityInfo ent=new EntityInfo();
          ent.addChain(c1);
          ent.addChain(c2);
          ent.setMolId(molId++);
          ent.setType(EntityType.POLYMER);
          c1.setEntityInfo(ent);
          c2.setEntityInfo(ent);
          chainIds2entities.put(c1.getId(),ent);
          chainIds2entities.put(c2.getId(),ent);
        }
 else {
          EntityInfo ent=chainIds2entities.get(c1.getId());
          if (ent == null) {
            logger.debug("String_Node_Str",c1.getId(),c2.getId());
            ent=chainIds2entities.get(c2.getId());
            ent.addChain(c1);
            c1.setEntityInfo(ent);
            chainIds2entities.put(c1.getId(),ent);
          }
 else {
            logger.debug("String_Node_Str",c2.getId(),c1.getId());
            ent.addChain(c2);
            c2.setEntityInfo(ent);
            chainIds2entities.put(c2.getId(),ent);
          }
        }
        if (!areResNumbersAligned(c1,c2)) {
          logger.warn("String_Node_Str",c1.getId(),c2.getId());
        }
      }
      if (identity > 1) {
        logger.warn("String_Node_Str",c1.getId(),c2.getId(),pair.getNumIdenticals(),nonGaps,identity);
        logger.warn("String_Node_Str" + pair.toString(100));
      }
      if (chainIds2entities.size() == polyChainIndices.size())       break outer;
    }
  }
  for (  int i : polyChainIndices) {
    Chain c=polyModels.get(0).get(i);
    if (!chainIds2entities.containsKey(c.getId())) {
      logger.debug("String_Node_Str",c.getId());
      EntityInfo ent=new EntityInfo();
      ent.addChain(c);
      ent.setMolId(molId++);
      c.setEntityInfo(ent);
      chainIds2entities.put(c.getId(),ent);
    }
  }
  for (int i=1; i < polyModels.size(); i++) {
    for (    Chain chain : polyModels.get(i)) {
      EntityInfo e=chainIds2entities.get(chain.getId());
      chain.setEntityInfo(e);
      e.addChain(chain);
    }
  }
  return chainIds2entities;
}