From 3a20b7a1383c3b62cb91bc21e8aef8bbcd8c21a8 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 21 Jan 2016 14:40:17 +0000 Subject: [PATCH] JAL-1705 isFromForwardStrand added; toString (for debug) tweaked --- src/jalview/util/MapList.java | 29 +++++++++++++++++++++++++++-- test/jalview/util/MapListTest.java | 26 +++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index e0cad6e..c32447c 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -889,8 +889,7 @@ public class MapList public String toString() { StringBuilder sb = new StringBuilder(64); - sb.append("From (").append(fromRatio).append(":").append(toRatio) - .append(") ["); + sb.append("["); for (int[] shift : fromShifts) { sb.append(" ").append(Arrays.toString(shift)); @@ -975,4 +974,30 @@ public class MapList */ addTo.add(range); } + + /** + * Returns true if mapping is from forward strand, false if from reverse + * strand. Result is just based on the first 'from' 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 isFromForwardStrand() + { + boolean forwardStrand = true; + for (int[] range : getFromRanges()) + { + if (range[1] > range[0]) + { + break; // forward strand confirmed + } + else if (range[1] < range[0]) + { + forwardStrand = false; + break; // reverse strand confirmed + } + } + return forwardStrand; + } } diff --git a/test/jalview/util/MapListTest.java b/test/jalview/util/MapListTest.java index 54e8311..22a3ad9 100644 --- a/test/jalview/util/MapListTest.java +++ b/test/jalview/util/MapListTest.java @@ -534,7 +534,7 @@ public class MapListTest MapList ml = new MapList(new int[] { 1, 5, 10, 15, 25, 20 }, new int[] { 51, 1 }, 1, 3); String s = ml.toString(); - assertEquals("From (1:3) [ [1, 5] [10, 15] [25, 20] ] To [ [51, 1] ]", + assertEquals("[ [1, 5] [10, 15] [25, 20] ] To [ [51, 1] ]", s); } @@ -558,7 +558,7 @@ public class MapListTest String s = ml.toString(); assertEquals( - "From (1:3) [ [11, 15] [20, 25] [35, 30] [2, 4] [37, 40] ] To [ [72, 22] [12, 17] [78, 83] [88, 96] ]", + "[ [11, 15] [20, 25] [35, 30] [2, 4] [37, 40] ] To [ [72, 22] [12, 17] [78, 83] [88, 96] ]", s); } @@ -571,7 +571,7 @@ public class MapListTest MapList ml2 = new MapList(new int[] { 15, 16 }, new int[] { 58, 53 }, 1, 3); ml.addMapList(ml2); - assertEquals("From (1:3) [ [11, 16] ] To [ [72, 53] ]", ml.toString()); + assertEquals("[ [11, 16] ] To [ [72, 53] ]", ml.toString()); } @Test(groups = "Functional") @@ -646,4 +646,24 @@ public class MapListTest assertEquals(79, ml.getToLowest()); assertEquals(100, ml.getToHighest()); } + + /** + * Test that method that inspects for the (first) forward or reverse from + * range. Single position ranges are ignored. + */ + @Test(groups = { "Functional" }) + public void testIsFromForwardStrand() + { + MapList ml = new MapList(new int[] { 2, 2, 3, 9, 12, 11 }, + new int[] { 20, 11 }, 1, 1); + assertTrue(ml.isFromForwardStrand()); + + ml = new MapList(new int[] { 2, 2, 11, 5, 13, 14 }, + new int[] { 20, 11 }, 1, 1); + assertFalse(ml.isFromForwardStrand()); + + ml = new MapList(new int[] { 2, 2, 4, 4, 6, 6 }, new int[] { 3, 1 }, 1, + 1); + assertTrue(ml.isFromForwardStrand()); + } } -- 1.7.10.2