Program: 17141
Project: 17141
Buggy source:
private AFPChain convert(AlignmentAlgorithm aligner,Atom[] ca1,Atom[] ca2,AlignmentPair aligPair) throws StructureException {
  AFPChain afpChain=new AFPChain();
  int ca1Length=ca1.length;
  int ca2Length=ca2.length;
  afpChain.setAlignScore(aligPair.getScore());
  int nAtom=0;
  int nGaps=0;
  List<String> labels=aligPair.getLabels();
  if (!(labels.size() == 2)) {
    throw new StructureException("String_Node_Str" + labels.size());
  }
  SymbolList symb1=aligPair.symbolListForLabel(labels.get(0));
  SymbolList symb2=aligPair.symbolListForLabel(labels.get(1));
  int queryEnd=aligPair.getQueryEnd();
  int queryStart=aligPair.getQueryStart();
  int subjectEnd=aligPair.getSubjectEnd();
  int subjectStart=aligPair.getSubjectStart();
  List<Alphabet> alphas=new ArrayList<Alphabet>();
  alphas.add(symb1.getAlphabet());
  Symbol gapSymbol=AlphabetManager.getGapSymbol(alphas);
  int lcmp=aligPair.getQueryLength() - 1;
  Atom[] strBuf1=new Atom[lcmp];
  Atom[] strBuf2=new Atom[lcmp];
  int pos1=queryStart - 2;
  int pos2=subjectStart - 2;
  char[] alnseq1=new char[ca1Length + ca2Length + 1];
  char[] alnseq2=new char[ca1Length + ca2Length + 1];
  char[] alnsymb=new char[ca1Length + ca2Length + 1];
  int nrIdent=0;
  int nrSim=0;
  int pos=0;
  int[] align_se1=new int[lcmp];
  int[] align_se2=new int[lcmp];
  int aligLength=0;
  for (int ia=0; ia < Math.min(queryEnd - queryStart,subjectEnd - subjectStart) + 1; ia++) {
    aligLength++;
    Symbol s1=symb1.symbolAt(ia + queryStart);
    Symbol s2=symb2.symbolAt(ia + subjectStart);
    if (!s1.equals(gapSymbol))     pos1++;
    if (!s2.equals(gapSymbol))     pos2++;
    if ((!s1.equals(gapSymbol)) && (!s2.equals(gapSymbol))) {
      strBuf1[nAtom]=ca1[pos1];
      strBuf2[nAtom]=ca2[pos2];
      char l1=getOneLetter(ca1[pos1].getParent());
      char l2=getOneLetter(ca2[pos2].getParent());
      alnseq1[ia]=Character.toUpperCase(l1);
      alnseq2[ia]=Character.toUpperCase(l2);
      alnsymb[ia]=' ';
      if (l1 == l2) {
        nrIdent++;
        nrSim++;
        alnsymb[ia]='|';
      }
 else       if (AFPAlignmentDisplay.aaScore(l1,l2) > 0) {
        nrSim++;
        alnsymb[ia]=':';
      }
      align_se1[ia]=pos1;
      align_se2[ia]=pos2;
      pos++;
      nAtom++;
    }
 else {
      nGaps++;
      alnsymb[ia]=' ';
      align_se1[ia]=-1;
      align_se2[ia]=-1;
      if (s1.equals(gapSymbol)) {
        alnseq1[ia]='-';
      }
 else {
        char l1=getOneLetter(ca1[pos1].getParent());
        alnseq1[ia]=Character.toUpperCase(l1);
        align_se1[ia]=pos1;
      }
      if (s2.equals(gapSymbol)) {
        alnseq2[ia]='-';
      }
 else {
        char l2=getOneLetter(ca2[pos2].getParent());
        alnseq2[ia]=Character.toUpperCase(l2);
        align_se2[ia]=pos2;
      }
    }
  }
  afpChain.setGapLen(nGaps);
  afpChain.setAlnseq1(alnseq1);
  afpChain.setAlnseq2(alnseq2);
  afpChain.setAlnsymb(alnsymb);
  afpChain.setIdentity(nrIdent * 1.0 / pos);
  afpChain.setSimilarity(nrSim * 1.0 / pos);
  afpChain.setAlnLength(aligLength);
  afpChain.setOptLength(aligLength);
  int[] optLen=new int[]{nAtom};
  afpChain.setOptLen(optLen);
  if (nAtom < 4)   return afpChain;
  CeParameters params=new CeParameters();
  CECalculator cecalc=new CECalculator(params);
  double rmsd=cecalc.calc_rmsd(strBuf1,strBuf2,nAtom,true,false);
  afpChain.setBlockRmsd(new double[]{rmsd});
  afpChain.setOptRmsd(new double[]{rmsd});
  afpChain.setTotalRmsdOpt(rmsd);
  afpChain.setChainRmsd(rmsd);
  cecalc.setnAtom(nAtom);
  afpChain.setAlnbeg1(queryStart - 1);
  afpChain.setAlnbeg2(subjectStart - 1);
  cecalc.setAlign_se1(align_se1);
  cecalc.setAlign_se2(align_se2);
  cecalc.setLcmp(aligLength);
  cecalc.convertAfpChain(afpChain,ca1,ca2);
  afpChain.setAlgorithmName(algorithmName);
  afpChain.setVersion(version);
  return afpChain;
}

Fixed version (ground truth):
private AFPChain convert(AlignmentAlgorithm aligner,Atom[] ca1,Atom[] ca2,AlignmentPair aligPair) throws StructureException {
  AFPChain afpChain=new AFPChain();
  int ca1Length=ca1.length;
  int ca2Length=ca2.length;
  afpChain.setAlignScore(aligPair.getScore());
  int nAtom=0;
  int nGaps=0;
  List<String> labels=aligPair.getLabels();
  if (!(labels.size() == 2)) {
    throw new StructureException("String_Node_Str" + labels.size());
  }
  SymbolList symb1=aligPair.symbolListForLabel(labels.get(0));
  SymbolList symb2=aligPair.symbolListForLabel(labels.get(1));
  int queryEnd=aligPair.getQueryEnd();
  int queryStart=aligPair.getQueryStart();
  int subjectEnd=aligPair.getSubjectEnd();
  int subjectStart=aligPair.getSubjectStart();
  List<Alphabet> alphas=new ArrayList<Alphabet>();
  alphas.add(symb1.getAlphabet());
  Symbol gapSymbol=AlphabetManager.getGapSymbol(alphas);
  int lcmp=aligPair.getQueryLength() - 1;
  Atom[] strBuf1=new Atom[lcmp];
  Atom[] strBuf2=new Atom[lcmp];
  int pos1=queryStart - 2;
  int pos2=subjectStart - 2;
  char[] alnseq1=new char[ca1Length + ca2Length + 1];
  char[] alnseq2=new char[ca1Length + ca2Length + 1];
  char[] alnsymb=new char[ca1Length + ca2Length + 1];
  int nrIdent=0;
  int nrSim=0;
  int pos=0;
  int[] align_se1=new int[lcmp];
  int[] align_se2=new int[lcmp];
  int aligLength=0;
  for (int ia=0; ia < Math.min(queryEnd - queryStart,subjectEnd - subjectStart); ia++) {
    aligLength++;
    Symbol s1=symb1.symbolAt(ia + queryStart);
    Symbol s2=symb2.symbolAt(ia + subjectStart);
    if (!s1.equals(gapSymbol))     pos1++;
    if (!s2.equals(gapSymbol))     pos2++;
    if ((!s1.equals(gapSymbol)) && (!s2.equals(gapSymbol))) {
      System.out.println(ia + "String_Node_Str" + queryStart+ "String_Node_Str"+ subjectStart+ "String_Node_Str"+ s1.getName()+ "String_Node_Str"+ s2.getName()+ pos1+ "String_Node_Str"+ ca1.length);
      strBuf1[nAtom]=ca1[pos1];
      strBuf2[nAtom]=ca2[pos2];
      char l1=getOneLetter(ca1[pos1].getParent());
      char l2=getOneLetter(ca2[pos2].getParent());
      alnseq1[ia]=Character.toUpperCase(l1);
      alnseq2[ia]=Character.toUpperCase(l2);
      alnsymb[ia]=' ';
      if (l1 == l2) {
        nrIdent++;
        nrSim++;
        alnsymb[ia]='|';
      }
 else       if (AFPAlignmentDisplay.aaScore(l1,l2) > 0) {
        nrSim++;
        alnsymb[ia]=':';
      }
      align_se1[ia]=pos1;
      align_se2[ia]=pos2;
      pos++;
      nAtom++;
    }
 else {
      nGaps++;
      alnsymb[ia]=' ';
      align_se1[ia]=-1;
      align_se2[ia]=-1;
      if (s1.equals(gapSymbol)) {
        alnseq1[ia]='-';
      }
 else {
        char l1=getOneLetter(ca1[pos1].getParent());
        alnseq1[ia]=Character.toUpperCase(l1);
        align_se1[ia]=pos1;
      }
      if (s2.equals(gapSymbol)) {
        alnseq2[ia]='-';
      }
 else {
        char l2=getOneLetter(ca2[pos2].getParent());
        alnseq2[ia]=Character.toUpperCase(l2);
        align_se2[ia]=pos2;
      }
    }
  }
  afpChain.setGapLen(nGaps);
  afpChain.setAlnseq1(alnseq1);
  afpChain.setAlnseq2(alnseq2);
  afpChain.setAlnsymb(alnsymb);
  afpChain.setIdentity(nrIdent * 1.0 / pos);
  afpChain.setSimilarity(nrSim * 1.0 / pos);
  afpChain.setAlnLength(aligLength);
  afpChain.setOptLength(aligLength);
  int[] optLen=new int[]{nAtom};
  afpChain.setOptLen(optLen);
  if (nAtom < 4)   return afpChain;
  CeParameters params=new CeParameters();
  CECalculator cecalc=new CECalculator(params);
  double rmsd=cecalc.calc_rmsd(strBuf1,strBuf2,nAtom,true,false);
  afpChain.setBlockRmsd(new double[]{rmsd});
  afpChain.setOptRmsd(new double[]{rmsd});
  afpChain.setTotalRmsdOpt(rmsd);
  afpChain.setChainRmsd(rmsd);
  cecalc.setnAtom(nAtom);
  afpChain.setAlnbeg1(queryStart - 1);
  afpChain.setAlnbeg2(subjectStart - 1);
  cecalc.setAlign_se1(align_se1);
  cecalc.setAlign_se2(align_se2);
  cecalc.setLcmp(aligLength);
  cecalc.convertAfpChain(afpChain,ca1,ca2);
  afpChain.setAlgorithmName(algorithmName);
  afpChain.setVersion(version);
  return afpChain;
}