Program: 16997
Project: 16997
Buggy source:
/** 
 * Takes a structure and sequence corresponding to an alignment between a structure or sequence and itself (or even a structure with a sequence), where the result has a circular permutation site  {@link cpSite} residues to the right.
 * @param cpSite The number of residues from the beginning of the sequence at which the circular permutation site occurs; can be positive or negative; values greater than the length of the sequence are acceptable
 */
public static AFPChain cpFastaToAfpChain(ProteinSequence sequence,ProteinSequence second,Structure structure,int cpSite) throws StructureException {
  if (structure == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sequence == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Atom[] ca1=StructureTools.getAtomCAArray(structure);
  Atom[] ca2=StructureTools.getAtomCAArray(structure);
  ProteinSequence antipermuted=new ProteinSequence(SequenceTools.permuteCyclic(second.getSequenceAsString(),-cpSite));
  ResidueNumber[] residues=StructureSequenceMatcher.matchSequenceToStructure(sequence,structure);
  ResidueNumber[] antipermutedResidues=StructureSequenceMatcher.matchSequenceToStructure(antipermuted,structure);
  ResidueNumber[] nonpermutedResidues=new ResidueNumber[antipermutedResidues.length];
  SequenceTools.permuteCyclic(antipermutedResidues,nonpermutedResidues,+cpSite);
  if (sequence.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(sequence,residues);
  }
  if (antipermuted.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(second,nonpermutedResidues);
  }
  for (  ResidueNumber r : residues)   System.err.print(r + "String_Node_Str");
  System.err.println();
  for (  char c : sequence.getSequenceAsString().toCharArray())   System.err.print(c + "String_Node_Str");
  System.err.println();
  for (  ResidueNumber r : nonpermutedResidues)   System.err.print(r + "String_Node_Str");
  System.err.println();
  for (  char c : second.getSequenceAsString().toCharArray())   System.err.print(c + "String_Node_Str");
  System.err.println();
  return buildAlignment(ca1,ca2,residues,nonpermutedResidues);
}

Fixed version (ground truth):
/** 
 * Takes a structure and sequence corresponding to an alignment between a structure or sequence and itself (or even a structure with a sequence), where the result has a circular permutation site  {@link cpSite} residues to the right.
 * @param cpSite The number of residues from the beginning of the sequence at which the circular permutation site occurs; can be positive or negative; values greater than the length of the sequence are acceptable
 */
public static AFPChain cpFastaToAfpChain(ProteinSequence sequence,ProteinSequence second,Structure structure,int cpSite) throws StructureException {
  if (structure == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sequence == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Atom[] ca1=StructureTools.getAtomCAArray(structure);
  Atom[] ca2=StructureTools.getAtomCAArray(structure);
  ProteinSequence antipermuted=new ProteinSequence(SequenceTools.permuteCyclic(second.getSequenceAsString(),-cpSite));
  ResidueNumber[] residues=StructureSequenceMatcher.matchSequenceToStructure(sequence,structure);
  ResidueNumber[] antipermutedResidues=StructureSequenceMatcher.matchSequenceToStructure(antipermuted,structure);
  ResidueNumber[] nonpermutedResidues=new ResidueNumber[antipermutedResidues.length];
  SequenceTools.permuteCyclic(antipermutedResidues,nonpermutedResidues,+cpSite);
  if (sequence.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(sequence,residues);
  }
  if (second.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(second,nonpermutedResidues);
  }
  for (  ResidueNumber r : residues)   System.err.print(r + "String_Node_Str");
  System.out.println();
  for (  char c : sequence.getSequenceAsString().toCharArray())   System.err.print(c + "String_Node_Str");
  System.out.println();
  for (  ResidueNumber r : nonpermutedResidues)   System.err.print(r + "String_Node_Str");
  System.out.println();
  for (  char c : second.getSequenceAsString().toCharArray())   System.err.print(c + "String_Node_Str");
  System.out.println();
  for (int i=0; i < residues.length; i++) {
    if (residues[i] == null && nonpermutedResidues[i] != null || residues[i] != null && nonpermutedResidues[i] == null) {
      System.out.println("String_Node_Str" + i);
    }
  }
  for (int i=0; i < residues.length; i++) {
    if (residues[i] == null) {
      System.out.print("String_Node_Str");
    }
 else {
      System.out.print(sequence.getSequenceAsString().charAt(i));
    }
  }
  System.out.println();
  for (int i=0; i < residues.length; i++) {
    if (nonpermutedResidues[i] == null) {
      System.out.print("String_Node_Str");
    }
 else {
      System.out.print(second.getSequenceAsString().charAt(i));
    }
  }
  int x=0;
  for (int i=0; i < nonpermutedResidues.length; i++)   if (nonpermutedResidues[i] == null)   x++;
  System.out.println();
  System.out.println("String_Node_Str" + x);
  return buildAlignment(ca1,ca2,residues,nonpermutedResidues);
}