Skip to content

Commit 9cabf41

Browse files
committed
Fix bug in distance matrix calculation
1 parent 7901603 commit 9cabf41

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

biojava-phylo/src/main/java/demo/DemoDistanceTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* This demo contains the CookBook example to create a phylogenetic tree from a
26-
* given multiple sequence alignment (MSA).
26+
* multiple sequence alignment (MSA).
2727
*
2828
* @author Scooter Willis
2929
* @author Aleix Lafita

biojava-phylo/src/main/java/org/biojava/nbio/phylo/DistanceMatrixCalculator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix fractio
263263
* itself). Calculation of the score is as follows:
264264
*
265265
* <pre>
266-
* Ds = maxScore - sum(M<sub>ai,bi</sub>)
266+
* Ds = maxScore - sum<sub>i</sub>(M<sub>ai,bi</sub>)
267267
* </pre>
268268
*
269269
* It is recommended to use the method
@@ -307,17 +307,20 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
307307

308308
// Obtain the similarity scores
309309
for (int j = i; j < n; j++) {
310+
310311
double score = 0;
311312
loopcount++;
313+
312314
for (int k = 0; k < end; k++) {
313315
if (Comparison.isGap(sequenceString[i].charAt(k))
314316
|| Comparison.isGap(sequenceString[j].charAt(k)))
315317
continue;
316-
// TODO bug
317-
score += M.getValue(seqs.get(i).getCompoundAt(k),
318-
seqs.get(j).getCompoundAt(k));
318+
score += M.getValue(seqs.get(i).getCompoundAt(k + 1),
319+
seqs.get(j).getCompoundAt(k + 1));
319320
}
320-
DM.setValue(i, j, score);
321+
322+
if (i != j)
323+
DM.setValue(i, j, score);
321324

322325
if (score > maxscore) {
323326
maxscore = score;

biojava-phylo/src/main/java/org/biojava/nbio/phylo/DistanceTreeEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static double evaluate(Phylogeny tree, DistanceMatrix matrix) {
116116
logger.info("Average tree distance: {}", averageTreeDistance);
117117
logger.info("Average LS error: {}", averageTreeErrorDistance);
118118

119-
return Math.sqrt((averageTreeErrorDistance)) / (averageMatrixDistance);
119+
return Math.sqrt(averageTreeErrorDistance) / averageMatrixDistance;
120120
}
121121

122122
private static double getNodeDistance(PhylogenyNode parentNode,

0 commit comments

Comments
 (0)