Program: 16516
Project: 16516
Buggy source:
private TreeMap<String,Compound> findCompoundsFromAlignment(){
  Set<Integer> polyChainIndices=new TreeSet<Integer>();
  List<Chain> pureNonPolymerChains=new ArrayList<Chain>();
  for (int i=0; i < s.getChains().size(); i++) {
    if (StructureTools.isChainPureNonPolymer(s.getChain(i))) {
      pureNonPolymerChains.add(s.getChain(i));
    }
 else {
      polyChainIndices.add(i);
    }
  }
  TreeMap<String,Compound> chainIds2compounds=new TreeMap<String,Compound>();
  int molId=1;
  outer:   for (  int i : polyChainIndices) {
    for (    int j : polyChainIndices) {
      if (j <= i)       continue;
      Chain c1=s.getChain(i);
      Chain c2=s.getChain(j);
      Map<Integer,Integer> positionIndex1=new HashMap<Integer,Integer>();
      Map<Integer,Integer> positionIndex2=new HashMap<Integer,Integer>();
      String str1=SeqRes2AtomAligner.getFullAtomSequence(c1.getAtomGroups(),positionIndex1);
      String str2=SeqRes2AtomAligner.getFullAtomSequence(c2.getAtomGroups(),positionIndex2);
      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.getChainID(),c2.getChainID(),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 (!chainIds2compounds.containsKey(c1.getChainID()) && !chainIds2compounds.containsKey(c2.getChainID())) {
          logger.debug("String_Node_Str",c1.getChainID(),c2.getChainID());
          Compound ent=new Compound();
          ent.addChain(c1);
          ent.addChain(c2);
          ent.setMolId(molId++);
          chainIds2compounds.put(c1.getChainID(),ent);
          chainIds2compounds.put(c2.getChainID(),ent);
        }
 else {
          Compound ent=chainIds2compounds.get(c1.getChainID());
          if (ent == null) {
            logger.debug("String_Node_Str",c1.getChainID(),c2.getChainID());
            ent=chainIds2compounds.get(c2.getChainID());
            ent.addChain(c1);
            chainIds2compounds.put(c1.getChainID(),ent);
          }
 else {
            logger.debug("String_Node_Str",c2.getChainID(),c1.getChainID());
            ent.addChain(c2);
            chainIds2compounds.put(c2.getChainID(),ent);
          }
        }
        if (!areResNumbersAligned(c1,c2)) {
          logger.warn("String_Node_Str",c1.getChainID(),c2.getChainID());
        }
      }
      if (identity > 1) {
        logger.warn("String_Node_Str",c1.getChainID(),c2.getChainID(),pair.getNumIdenticals(),nonGaps,identity);
        logger.warn("String_Node_Str" + pair.toString(100));
      }
      if (chainIds2compounds.size() == polyChainIndices.size())       break outer;
    }
  }
  for (  int i : polyChainIndices) {
    Chain c=s.getChain(i);
    if (!chainIds2compounds.containsKey(c.getChainID())) {
      logger.debug("String_Node_Str",c.getChainID());
      Compound ent=new Compound();
      ent.addChain(c);
      ent.setMolId(molId++);
      chainIds2compounds.put(c.getChainID(),ent);
    }
  }
  return chainIds2compounds;
}

Fixed version (ground truth):
private TreeMap<String,Compound> findCompoundsFromAlignment(){
  Set<Integer> polyChainIndices=new TreeSet<Integer>();
  List<Chain> pureNonPolymerChains=new ArrayList<Chain>();
  for (int i=0; i < s.getChains().size(); i++) {
    if (StructureTools.isChainPureNonPolymer(s.getChain(i))) {
      pureNonPolymerChains.add(s.getChain(i));
    }
 else {
      polyChainIndices.add(i);
    }
  }
  TreeMap<String,Compound> chainIds2compounds=new TreeMap<String,Compound>();
  int molId=1;
  outer:   for (  int i : polyChainIndices) {
    for (    int j : polyChainIndices) {
      if (j <= i)       continue;
      Chain c1=s.getChain(i);
      Chain c2=s.getChain(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.getChainID(),c2.getChainID(),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 (!chainIds2compounds.containsKey(c1.getChainID()) && !chainIds2compounds.containsKey(c2.getChainID())) {
          logger.debug("String_Node_Str",c1.getChainID(),c2.getChainID());
          Compound ent=new Compound();
          ent.addChain(c1);
          ent.addChain(c2);
          ent.setMolId(molId++);
          chainIds2compounds.put(c1.getChainID(),ent);
          chainIds2compounds.put(c2.getChainID(),ent);
        }
 else {
          Compound ent=chainIds2compounds.get(c1.getChainID());
          if (ent == null) {
            logger.debug("String_Node_Str",c1.getChainID(),c2.getChainID());
            ent=chainIds2compounds.get(c2.getChainID());
            ent.addChain(c1);
            chainIds2compounds.put(c1.getChainID(),ent);
          }
 else {
            logger.debug("String_Node_Str",c2.getChainID(),c1.getChainID());
            ent.addChain(c2);
            chainIds2compounds.put(c2.getChainID(),ent);
          }
        }
        if (!areResNumbersAligned(c1,c2)) {
          logger.warn("String_Node_Str",c1.getChainID(),c2.getChainID());
        }
      }
      if (identity > 1) {
        logger.warn("String_Node_Str",c1.getChainID(),c2.getChainID(),pair.getNumIdenticals(),nonGaps,identity);
        logger.warn("String_Node_Str" + pair.toString(100));
      }
      if (chainIds2compounds.size() == polyChainIndices.size())       break outer;
    }
  }
  for (  int i : polyChainIndices) {
    Chain c=s.getChain(i);
    if (!chainIds2compounds.containsKey(c.getChainID())) {
      logger.debug("String_Node_Str",c.getChainID());
      Compound ent=new Compound();
      ent.addChain(c);
      ent.setMolId(molId++);
      chainIds2compounds.put(c.getChainID(),ent);
    }
  }
  return chainIds2compounds;
}