Program: 16648
Project: 16648
Buggy source:
/** 
 * Given a Group g of Chain c (member of this Compound) return the corresponding position in the  alignment of all member sequences (1-based numbering), i.e. the index (1-based) in the SEQRES sequence. This allows for comparisons of residues belonging to different chains of the same Compound (entity). <p> If   {@link FileParsingParameters#setAlignSeqRes(boolean)} is not used or SEQRES not present, a mapping will not be available and this method will return  {@link ResidueNumber#getSeqNum()} for all residues, whichin some cases will be correctly aligned indices (when no insertion codes are  used and when all chains within the entity are numbered in the same way), but in general they will be neither unique (because of insertion codes) nor aligned. </p>
 * @param g
 * @param c
 * @return the aligned residue index (1 to n), if no SEQRES groups are available at all then {@link ResidueNumber#getSeqNum()} is returned as a fall-back, if the group is not found in the SEQRES groups then -1 is returned  for the given group and chain
 * @throws IllegalArgumentException if the given Chain is not a member of this Compound
 * @see {@link Chain#getSeqResGroup(int)} 
 */
public int getAlignedResIndex(Group g,Chain c){
  boolean contained=false;
  for (  Chain member : getChains()) {
    if (c.getChainID().equals(member.getChainID())) {
      contained=true;
      break;
    }
  }
  if (!contained)   throw new IllegalArgumentException("String_Node_Str" + c.getChainID() + "String_Node_Str"+ getChainIds().toString());
  if (!chains2pdbResNums2ResSerials.containsKey(c.getChainID())) {
    initResSerialsMap(c);
  }
  Map<ResidueNumber,Integer> map=chains2pdbResNums2ResSerials.get(c.getChainID());
  int serial;
  if (map != null) {
    Integer alignedSerial=map.get(g.getResidueNumber());
    if (alignedSerial == null) {
      serial=-1;
    }
 else {
      serial=alignedSerial;
    }
  }
 else {
    serial=g.getResidueNumber().getSeqNum();
  }
  return serial;
}

Fixed version (ground truth):
/** 
 * Given a Group g of Chain c (member of this Compound) return the corresponding position in the  alignment of all member sequences (1-based numbering), i.e. the index (1-based) in the SEQRES sequence. This allows for comparisons of residues belonging to different chains of the same Compound (entity). <p> If   {@link FileParsingParameters#setAlignSeqRes(boolean)} is not used or SEQRES not present, a mapping will not be available and this method will return  {@link ResidueNumber#getSeqNum()} for all residues, whichin some cases will be correctly aligned indices (when no insertion codes are  used and when all chains within the entity are numbered in the same way), but in general they will be neither unique (because of insertion codes) nor aligned. </p>
 * @param g
 * @param c
 * @return the aligned residue index (1 to n), if no SEQRES groups are available at all then {@link ResidueNumber#getSeqNum()} is returned as a fall-back, if the group is not found in the SEQRES groups then -1 is returned  for the given group and chain
 * @throws IllegalArgumentException if the given Chain is not a member of this Compound
 * @see {@link Chain#getSeqResGroup(int)} 
 */
public int getAlignedResIndex(Group g,Chain c){
  boolean contained=false;
  for (  Chain member : getChains()) {
    if (c.getChainID().equals(member.getChainID())) {
      contained=true;
      break;
    }
  }
  if (!contained)   throw new IllegalArgumentException("String_Node_Str" + c.getChainID() + "String_Node_Str"+ getChainIds().toString());
  if (!chains2pdbResNums2ResSerials.containsKey(c.getChainID())) {
    initResSerialsMap(c);
  }
  Map<ResidueNumber,Integer> map=chains2pdbResNums2ResSerials.get(c.getChainID());
  int serial;
  if (map != null) {
    ResidueNumber resNum=g.getResidueNumber();
    if (resNum == null && c.getSeqResGroups() != null && !c.getSeqResGroups().isEmpty()) {
      int index=-1;
      for (int i=0; i < c.getSeqResGroups().size(); i++) {
        if (g == c.getSeqResGroup(i)) {
          index=i;
          break;
        }
      }
      resNum=findResNumInOtherChains(index,c);
    }
    if (resNum == null) {
      serial=-1;
    }
 else {
      Integer alignedSerial=map.get(resNum);
      if (alignedSerial == null) {
        serial=-1;
      }
 else {
        serial=alignedSerial;
      }
    }
  }
 else {
    serial=g.getResidueNumber().getSeqNum();
  }
  return serial;
}