*/
public MapList()
{
- fromShifts = new ArrayList<int[]>();
- toShifts = new ArrayList<int[]>();
+ fromShifts = new ArrayList<>();
+ toShifts = new ArrayList<>();
}
/**
}
boolean changed = false;
- List<int[]> merged = new ArrayList<int[]>();
+ List<int[]> merged = new ArrayList<>();
int[] lastRange = ranges.get(0);
int lastDirection = lastRange[1] >= lastRange[0] ? 1 : -1;
lastRange = new int[] { lastRange[0], lastRange[1] };
{
return null;
}
- List<int[]> ranges = new ArrayList<int[]>();
+ List<int[]> ranges = new ArrayList<>();
if (fs <= fe)
{
intv = fs;
*/
public boolean isFromForwardStrand()
{
+ return isForwardStrand(getFromRanges());
+ }
+
+ /**
+ * Returns true if mapping is to forward strand, false if to reverse strand.
+ * Result is just based on the first 'to' range that is not a single position.
+ * Default is true unless proven to be false. Behaviour is not well defined if
+ * the mapping has a mixture of forward and reverse ranges.
+ *
+ * @return
+ */
+ public boolean isToForwardStrand()
+ {
+ return isForwardStrand(getToRanges());
+ }
+
+ /**
+ * A helper method that returns true unless at least one range has start > end.
+ * Behaviour is undefined for a mixture of forward and reverse ranges.
+ *
+ * @param ranges
+ * @return
+ */
+ private boolean isForwardStrand(List<int[]> ranges)
+ {
boolean forwardStrand = true;
- for (int[] range : getFromRanges())
+ for (int[] range : ranges)
{
if (range[1] > range[0])
{
@Test(groups = { "Functional" })
public void testGetRanges()
{
- List<int[]> ranges = new ArrayList<int[]>();
+ List<int[]> ranges = new ArrayList<>();
ranges.add(new int[] { 2, 3 });
ranges.add(new int[] { 5, 6 });
assertEquals("[2, 3, 5, 6]", Arrays.toString(MapList.getRanges(ranges)));
public void testAddRange()
{
int[] range = { 1, 5 };
- List<int[]> ranges = new ArrayList<int[]>();
+ List<int[]> ranges = new ArrayList<>();
// add to empty list:
MapList.addRange(range, ranges);
public void testCoalesceRanges()
{
assertNull(MapList.coalesceRanges(null));
- List<int[]> ranges = new ArrayList<int[]>();
+ List<int[]> ranges = new ArrayList<>();
assertSame(ranges, MapList.coalesceRanges(ranges));
ranges.add(new int[] { 1, 3 });
assertSame(ranges, MapList.coalesceRanges(ranges));
@Test(groups = { "Functional" })
public void testCoalesceRanges_withOverlap()
{
- List<int[]> ranges = new ArrayList<int[]>();
+ List<int[]> ranges = new ArrayList<>();
ranges.add(new int[] { 1, 3 });
ranges.add(new int[] { 2, 5 });
compound = ml1.traverse(ml2);
assertNull(compound);
}
+
+ /**
+ * Test that method that inspects for the (first) forward or reverse 'to' range.
+ * Single position ranges are ignored.
+ */
+ @Test(groups = { "Functional" })
+ public void testIsToForwardsStrand()
+ {
+ // [3-9] declares forward strand
+ MapList ml = new MapList(new int[] { 20, 11 },
+ new int[]
+ { 2, 2, 3, 9, 12, 11 }, 1, 1);
+ assertTrue(ml.isToForwardStrand());
+
+ // [11-5] declares reverse strand ([13-14] is ignored)
+ ml = new MapList(new int[] { 20, 11 },
+ new int[]
+ { 2, 2, 11, 5, 13, 14 }, 1, 1);
+ assertFalse(ml.isToForwardStrand());
+
+ // all single position ranges - defaults to forward strand
+ ml = new MapList(new int[] { 3, 1 }, new int[] { 2, 2, 4, 4, 6, 6 }, 1,
+ 1);
+ assertTrue(ml.isToForwardStrand());
+ }
}