Alignments { public static List<Range<Long>> matches(final AlignmentPair alignmentPair) { checkNotNull(alignmentPair); List<Range<Long>> matches = new ArrayList<Range<Long>>(); int matchStart = -1; for (int i = 1, length = alignmentPair.length() + 1; i < length; i++) { if (isMatchSymbol(alignmentPair.symbolAt(i))) { if (matchStart < 0) { matchStart = i; } } else { if (matchStart > 0) { matches.add(Range.closedOpen(Long.valueOf(matchStart - 1L), Long.valueOf(i - 1L))); matchStart = -1; } } } if (matchStart > 0) { matches.add(Range.closedOpen(Long.valueOf(matchStart - 1L), Long.valueOf(alignmentPair.length()))); } return matches; } private  Alignments(); static long length(final Range<Long> range); static List<Long> lengths(final Iterable<Range<Long>> ranges); static long length(final Iterable<Range<Long>> ranges); static long maximumLength(final Iterable<Range<Long>> ranges); static int count(final Iterable<Range<Long>> ranges); static List<Long> starts(final Iterable<Range<Long>> ranges); static List<Long> ends(final Iterable<Range<Long>> ranges); static List<Range<Long>> gaps(final GappedSymbolList gappedSymbols); static List<Range<Long>> matches(final AlignmentPair alignmentPair); static List<Range<Long>> mismatches(final AlignmentPair alignmentPair);  }
@Test(expected=NullPointerException.class) public void testMatchesNull() { matches(null); }
@Test public void testMatchesNoMatches() throws Exception { GappedSequence mismatch = DNATools.createGappedDNASequence("gggggggggggggggggggg", "mismatch"); AlignmentPair allMismatches = new AlignmentPair(mismatch, subject, substitutionMatrix); assertEquals(Collections.<Range<Long>>emptyList(), matches(allMismatches)); }
@Test public void testMatchesAllMatches() throws Exception { AlignmentPair allMatches = new AlignmentPair(subject, subject, substitutionMatrix); List<Range<Long>> matches = matches(allMatches); assertEquals(1, matches.size()); assertEquals(Range.closedOpen(0L, 20L), matches.get(0)); }
@Test public void testMatches() throws Exception { List<Range<Long>> matches = matches(alignmentPair); assertEquals(3, matches.size()); assertEquals(Range.closedOpen(0L, 4L), matches.get(0)); assertEquals(Range.closedOpen(8L, 12L), matches.get(1)); assertEquals(Range.closedOpen(16L, 20L), matches.get(2)); }