Skip to content

Commit d66cc12

Browse files
committed
Handle symmetry refinement Exceptions
1 parent 36b9bf2 commit d66cc12

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,13 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
307307
.get(j).getCompoundAt(k + 1));
308308
}
309309

310-
if (i != j)
310+
if (i != j){
311+
score = Math.max(score, 0.0);
311312
DM.setValue(i, j, score);
313+
}
312314

313-
if (score > maxscore) {
315+
if (score > maxscore)
314316
maxscore = score;
315-
}
316317
}
317318
}
318319

@@ -324,7 +325,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
324325
if (i == j)
325326
DM.setValue(i, j, 0.0);
326327
else {
327-
double dS = maxscore - DM.getValue(i, j);
328+
double dS = Math.max(maxscore - DM.getValue(i, j), 0);
328329
DM.setValue(i, j, dS);
329330
DM.setValue(j, i, dS);
330331
}

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SequenceFunctionRefiner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public static AFPChain refineSymmetry(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
8686
try {
8787
AFPChain refinedAFP = AlignmentTools.replaceOptAln(afpChain, ca1, ca2, refined);
8888
refinedAFP = partitionAFPchain(refinedAFP, ca1, ca2, k);
89+
if (refinedAFP.getOptLength() < 1)
90+
throw new IndexOutOfBoundsException("Refined alignment is empty.");
8991
return refinedAFP;
9092
} catch (IndexOutOfBoundsException e){
9193
// This Exception is thrown when the refined alignment is not consistent

0 commit comments

Comments
 (0)