Program: 16603
Project: 16603
Buggy source:
/** 
 * The fractional dissimilarity score (Ds) is the average character dissimilarity between two aligned sequences. It is calculated as: <pre> Ds = sum(max(M) - M<sub>ai,bi</sub>) / L </pre> Where the sum through i runs for all the alignment positions, ai and bi are the AA at position i in the first and second aligned sequences, respectively, and L is the total length of the alignment (normalization). <p> The fractional dissimilarity score (Ds) is defined in the interval [0, 1], where 0 means that the sequences are identical and 1 that the sequences are completely different (similarity score of 0). Note that a value higher than one can be obtained, if the similarity score of the alignment is negative (rare case). <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 fractionalDissimilarityScore(MultipleSequenceAlignment<C,D> msa,SubstitutionMatrix<D> M){
  int n=msa.getSize();
  DistanceMatrix DM=new BasicSymmetricalDistanceMatrix(n);
  double[] scores=Alignments.getAllPairsScores(msa.getAlignedSequences(),PairwiseSequenceScorerType.GLOBAL_SIMILARITIES,new SimpleGapPenalty(0,0),M);
  int maxScore=M.getMaxValue() * msa.getLength();
  int indx=0;
  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 - scores[indx]) / msa.getLength();
        DM.setValue(i,j,dS);
        DM.setValue(j,i,dS);
        indx++;
      }
    }
  }
  return DM;
}

Fixed version (ground truth):
/** 
 * The fractional dissimilarity score (Ds) is the average character dissimilarity between two aligned sequences. It is calculated as: <pre> Ds = sum(max(M) - M<sub>ai,bi</sub>) / L </pre> Where the sum through i runs for all the alignment positions, ai and bi are the AA at position i in the first and second aligned sequences, respectively, and L is the total length of the alignment (normalization). <p> The fractional dissimilarity score (Ds) is defined in the interval [0, 1], where 0 means that the sequences are identical and 1 that the sequences are completely different (similarity score of 0). Note that a value higher than one can be obtained, if the similarity score of the alignment is negative (big evolutionary distance). <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 fractionalDissimilarityScore(MultipleSequenceAlignment<C,D> msa,SubstitutionMatrix<D> M){
  int n=msa.getSize();
  DistanceMatrix DM=new BasicSymmetricalDistanceMatrix(n);
  double[] scores=Alignments.getAllPairsScores(msa.getAlignedSequences(),PairwiseSequenceScorerType.GLOBAL_SIMILARITIES,new SimpleGapPenalty(0,0),M);
  ConcurrencyTools.shutdown();
  int maxScore=M.getMaxValue() * msa.getLength();
  int indx=0;
  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 - scores[indx]) / msa.getLength();
        DM.setValue(i,j,dS);
        DM.setValue(j,i,dS);
        indx++;
      }
    }
  }
  return DM;
}