Program: 16602
Project: 16602
Buggy source:
/** 
 * The dissimilarity score is the additive inverse of the similarity score (sum of scores) between two aligned sequences using a substitution model (Substitution Matrix). The maximum dissimilarity score is taken to be the maximum similarity score between self-alignments (each sequence against itself). Calculation of the score is as follows: <pre> Ds = maxScore - sum(M<sub>ai,bi</sub>) </pre> It is recommended to use the method  {@link #fractionalDissimilarityScore(MultipleSequenceAlignment,SubstitutionMatrix)}, since the maximum similarity score is not relative to the data set, but relative to the Substitution Matrix, and the score is normalized by the alignment length (fractional). <p> Gaps do not have a contribution to the similarity score calculation (gap penalty = 0).
 * @param msa MultipleSequenceAlignment
 * @param M SubstitutionMatrix for similarity scoring
 * @return DistanceMatrix
 */
public static <C extends Sequence<D>,D extends Compound>DistanceMatrix dissimilarityScore(MultipleSequenceAlignment<C,D> msa,SubstitutionMatrix<D> M){
  logger.info("String_Node_Str","String_Node_Str",0);
  int n=msa.getSize();
  List<C> seqs=msa.getAlignedSequences();
  DistanceMatrix DM=new BasicSymmetricalDistanceMatrix(n);
  int totalloopcount=(n / 2) * (n + 1);
  double maxscore=0;
  int end=msa.getLength();
  int loopcount=0;
  for (int i=0; i < (n - 1); i++) {
    logger.info("String_Node_Str","String_Node_Str",(loopcount * 100) / totalloopcount);
    for (int j=i; j < n; j++) {
      double score=0;
      loopcount++;
      for (int k=0; k < end; k++) {
        D from=seqs.get(i).getCompoundAt(k);
        D to=seqs.get(i).getCompoundAt(k);
        if (Comparison.isGap(from.getShortName().charAt(0)) || Comparison.isGap(to.getShortName().charAt(0)))         continue;
        score+=M.getValue(from,to);
      }
      DM.setValue(i,j,score);
      if (score > maxscore) {
        maxscore=score;
      }
    }
  }
  for (int i=0; i < n; i++) {
    DM.setIdentifier(i,msa.getAlignedSequence(i + 1).getAccession().getID());
    for (int j=i; j < n; j++) {
      if (i == j)       DM.setValue(i,j,0.0);
 else {
        double dS=maxscore - DM.getValue(i,j);
        DM.setValue(i,j,dS);
        DM.setValue(j,i,dS);
      }
    }
  }
  logger.info("String_Node_Str","String_Node_Str",100);
  return DM;
}

Fixed version (ground truth):
/** 
 * The dissimilarity score is the additive inverse of the similarity score (sum of scores) between two aligned sequences using a substitution model (Substitution Matrix). The maximum dissimilarity score is taken to be the maximum similarity score between self-alignments (each sequence against itself). Calculation of the score is as follows: <pre> Ds = maxScore - sum(M<sub>ai,bi</sub>) </pre> It is recommended to use the method  {@link #fractionalDissimilarityScore(MultipleSequenceAlignment,SubstitutionMatrix)}, since the maximum similarity score is not relative to the data set, but relative to the Substitution Matrix, and the score is normalized by the alignment length (fractional). <p> Gaps do not have a contribution to the similarity score calculation (gap penalty = 0).
 * @param msa MultipleSequenceAlignment
 * @param M SubstitutionMatrix for similarity scoring
 * @return DistanceMatrix
 */
public static <C extends Sequence<D>,D extends Compound>DistanceMatrix dissimilarityScore(MultipleSequenceAlignment<C,D> msa,SubstitutionMatrix<D> M){
  logger.info("String_Node_Str","String_Node_Str",0);
  int n=msa.getSize();
  String[] sequenceString=new String[n];
  for (int i=0; i < n; i++) {
    sequenceString[i]=msa.getAlignedSequence(i + 1).getSequenceAsString();
  }
  List<C> seqs=msa.getAlignedSequences();
  DistanceMatrix DM=new BasicSymmetricalDistanceMatrix(n);
  int totalloopcount=(n / 2) * (n + 1);
  double maxscore=0;
  int end=msa.getLength();
  int loopcount=0;
  for (int i=0; i < (n - 1); i++) {
    logger.info("String_Node_Str","String_Node_Str",(loopcount * 100) / totalloopcount);
    for (int j=i; j < n; j++) {
      double score=0;
      loopcount++;
      for (int k=0; k < end; k++) {
        if (Comparison.isGap(sequenceString[i].charAt(k)) || Comparison.isGap(sequenceString[j].charAt(k)))         continue;
        score+=M.getValue(seqs.get(i).getCompoundAt(k),seqs.get(j).getCompoundAt(k));
      }
      DM.setValue(i,j,score);
      if (score > maxscore) {
        maxscore=score;
      }
    }
  }
  for (int i=0; i < n; i++) {
    DM.setIdentifier(i,msa.getAlignedSequence(i + 1).getAccession().getID());
    for (int j=i; j < n; j++) {
      if (i == j)       DM.setValue(i,j,0.0);
 else {
        double dS=maxscore - DM.getValue(i,j);
        DM.setValue(i,j,dS);
        DM.setValue(j,i,dS);
      }
    }
  }
  logger.info("String_Node_Str","String_Node_Str",100);
  return DM;
}