Program: 16996
Project: 16996
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 {
  setUserCollection(sequence);
  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.cloneCAArray(ca1);
  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);
  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();
  if (sequence.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(sequence,residues);
  }
  if (antipermuted.getUserCollection() != null) {
    CasePreservingProteinSequenceCreator.setLowercaseToNull(second,nonpermutedResidues);
  }
  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 (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);
}