}
/**
- * Returns the total length of the supplied ranges
+ * Returns the total length of the supplied ranges, which may be as single
+ * [start, end] or multiple [start, end, start, end ...]
*
* @param ranges
* @return
int length = 0;
for (int[] range : ranges)
{
- length += Math.abs(range[1] - range[0]) + 1;
+ if (range.length % 2 != 0)
+ {
+ System.err.println("Error unbalance start/end ranges: "
+ + ranges.toString());
+ return 0;
+ }
+ for (int i = 0; i < range.length - 1; i += 2)
+ {
+ length += Math.abs(range[i + 1] - range[i]) + 1;
+ }
}
return length;
}
int cdspos = 0;
for (int x = 0; x < copy.length && sxpos == -1; x += 2)
{
- // fixme handle reverse strand
cdspos += Math.abs(copy[x + 1] - copy[x]) + 1;
if (removeCount < cdspos)
{
public void testGetLength()
{
assertEquals(0, MappingUtils.getLength(null));
+
+ /*
+ * [start, end] ranges
+ */
List<int[]> ranges = new ArrayList<int[]>();
assertEquals(0, MappingUtils.getLength(ranges));
ranges.add(new int[] { 1, 1 });
assertEquals(10, MappingUtils.getLength(ranges));
ranges.add(new int[] { 20, 10 });
assertEquals(21, MappingUtils.getLength(ranges));
+
+ /*
+ * [start, end, start, end...] ranges
+ */
+ ranges.clear();
+ ranges.add(new int[] { 1, 5, 8, 4 });
+ ranges.add(new int[] { 8, 2 });
+ ranges.add(new int[] { 12, 12 });
+ assertEquals(18, MappingUtils.getLength(ranges));
}
@Test(groups = { "Functional" })