BIOLayeredSequence extends SimpleLayeredSequence { public void addSpanLayerRanges(String layerName, String tag, List<Range> ranges) throws SequenceException { List<Range> rangesCopy = new ArrayList<Range>(ranges.size()); rangesCopy.addAll(ranges); Collections.sort(ranges); if (!Range.isDisjoint(ranges)) { throw new SequenceException("ranges cannot overlap"); } List<String> sequence = new ArrayList<String>(getLength()); for (int i = 0; i < getLength(); i++) sequence.add("O"); for (Range range : ranges) { int first = range.getStart(); int end = range.getEnd(); if (end > getLength()) { throw new IndexOutOfBoundsException("Range out of bounds: " + range); } sequence.set(first, "B-" + tag); for (int i = first + 1; i < end; i++) { sequence.set(i, "I-" + tag); } } addSpanLayer(layerName, sequence); } BIOLayeredSequence(int length); BIOLayeredSequence clone(); List<Range> getSpans(String layerName); ImmutableCollection<Range> getSpans(String layerName, String type); void addSpanLayer(String layerName, List<String> input); void addSpanLayerRanges(String layerName, String tag,
            List<Range> ranges); ImmutableList<String> getSubSequence(String layerName, int start,
            int length); ImmutableList<String> getSubSequence(String layerName, Range r); BIOLayeredSequence getSubSequence(int start, int length); BIOLayeredSequence getSubSequence(Range r);  }
@Test(expected=IndexOutOfBoundsException.class) public void test5() throws SequenceException { BIOLayeredSequence seq = new BIOLayeredSequence(5); List<Range> ranges = new ArrayList<Range>(); ranges.add(new Range(1,10)); seq.addSpanLayerRanges("layer", "X", ranges); }
@Test(expected=SequenceException.class) public void test6() throws SequenceException { BIOLayeredSequence seq = new BIOLayeredSequence(5); List<Range> ranges = new ArrayList<Range>(); ranges.add(new Range(1,2)); ranges.add(new Range(2,1)); seq.addSpanLayerRanges("layer", "X", ranges); }
@Test public void test7() throws SequenceException { BIOLayeredSequence seq = new BIOLayeredSequence(5); List<Range> ranges = new ArrayList<Range>(); ranges.add(new Range(0,2)); ranges.add(new Range(3,2)); seq.addSpanLayerRanges("layer", "X", ranges); List<String> expected = split("B-X I-X O B-X I-X"); assertEquals(expected, seq.getLayer("layer")); }