Skip to content

Commit a306991

Browse files
committed
Alignments of zero length return a null Location instead of crashing during alignment
1 parent 14471c1 commit a306991

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

biojava3-alignment/src/main/java/org/biojava3/alignment/SimpleAlignedSequence.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,15 @@ private void setLocation(List<Step> steps) {
359359
}
360360

361361
// combine sublocations into 1 Location
362-
location = (sublocations.size() == 1) ? sublocations.get(0) : new SimpleLocation(
363-
sublocations.get(0).getStart(), sublocations.get(sublocations.size() - 1).getEnd(), Strand.UNDEFINED,
364-
false, sublocations);
362+
if (sublocations.size() == 0) {
363+
location = null;
364+
} else if (sublocations.size() == 1) {
365+
location = sublocations.get(0);
366+
} else {
367+
location = new SimpleLocation(sublocations.get(0).getStart(), sublocations.get(sublocations.size() - 1).getEnd(),
368+
Strand.UNDEFINED,
369+
false, sublocations);
370+
}
365371
// TODO handle circular alignments
366372

367373
// check that alignment has correct number of compounds in it to fit original sequence

biojava3-alignment/src/test/java/org/biojava3/alignment/LocalAlignmentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public void shouldAllowZeroLengthMatches() {
4545
SimpleGapPenalty gapP = new SimpleGapPenalty((short)5, (short)2);
4646
PairwiseSequenceAligner<DNASequence, NucleotideCompound> result = Alignments.getPairwiseAligner(query, target, PairwiseSequenceAlignerType.LOCAL, gapP, matrix);
4747
assertEquals(0, result.getScore());
48-
assertEquals(0, result.getProfile().getSize());
48+
assertEquals(0, result.getProfile().getLength());
4949
}
5050
}

0 commit comments

Comments
 (0)