From: gmungoc Date: Wed, 11 Dec 2019 14:38:39 +0000 (+0000) Subject: JAL-3490 tests for skip hidden regions (and a bug fix) X-Git-Tag: Release_2_11_1_1~13^2~10^2~1^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4016a0a5baf92cea3f1303fdaae3804244857427;p=jalview.git JAL-3490 tests for skip hidden regions (and a bug fix) --- diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index fc65379..5d42905 100644 --- a/src/jalview/analysis/Finder.java +++ b/src/jalview/analysis/Finder.java @@ -223,6 +223,7 @@ public class Finder implements FinderI if (ignoreHidden) { seqString = getVisibleSequence(seq); + this.searchedSequenceStartPosition = 1; } else { @@ -262,8 +263,12 @@ public class Finder implements FinderI */ private String getVisibleSequence(SequenceI seq) { - int seqStartCol = seq.findIndex(seq.getStart()); - int seqEndCol = seq.findIndex(seq.getStart() + seq.getLength() - 1); + /* + * get start / end columns of sequence and convert to base 0 + * (so as to match the visible column ranges) + */ + int seqStartCol = seq.findIndex(seq.getStart()) - 1; + int seqEndCol = seq.findIndex(seq.getStart() + seq.getLength() - 1) - 1; Iterator visibleColumns = viewport.getViewAsVisibleContigs(true); StringBuilder visibleSeq = new StringBuilder(seqEndCol - seqStartCol); List fromRanges = new ArrayList<>(); @@ -291,7 +296,7 @@ public class Finder implements FinderI * so add the range to the mapping being constructed */ int seqResFrom = seq.findPosition(range[0]); - int seqResTo = seq.findPosition(range[1]); + int seqResTo = seqResFrom + ungapped.length() - 1; fromRanges.add(new int[] { seqResFrom, seqResTo }); } } diff --git a/test/jalview/analysis/FinderTest.java b/test/jalview/analysis/FinderTest.java index 43c48d0..78a27ac 100644 --- a/test/jalview/analysis/FinderTest.java +++ b/test/jalview/analysis/FinderTest.java @@ -144,8 +144,11 @@ public class FinderTest /* * find all matches should return seq1 and seq4 (others are too short) + * (and not matches in sequence ids) */ f = new Finder(av); + String name = al.getSequenceAt(0).getName(); + al.getSequenceAt(0).setName("Q9XA0"); f.findAll("9", false, false, false); sr = f.getSearchResults(); assertEquals(sr.getSize(), 2); @@ -156,6 +159,7 @@ public class FinderTest assertEquals(matches.get(0).getEnd(), 9); assertEquals(matches.get(1).getStart(), 9); assertEquals(matches.get(1).getEnd(), 9); + al.getSequenceAt(0).setName(name); /* * parsing of search string as integer is strict @@ -452,7 +456,7 @@ public class FinderTest * Test finding all matches, case-sensitive */ @Test(groups = "Functional") - public void testFind_findAllCaseSensitive() + public void testFindAll_caseSensitive() { Finder f = new Finder(av); @@ -789,4 +793,90 @@ public class FinderTest assertEquals(match.getStart(), 7); assertEquals(match.getEnd(), 7); } + + @Test(groups = "Functional") + public void testFind_skipHiddenColumns() + { + /* + * 0 5 9 + * ABCD--EF-GHI + * A--BCDefHI + * --bcdEFH + * aa---aMMMMMaaa + */ + HiddenColumns hc = new HiddenColumns(); + hc.hideColumns(2, 4); + hc.hideColumns(7, 7); + al.setHiddenColumns(hc); + + /* + * now have + * 015689 + * AB-E-GHI + * A-DeHI + * --EF + * aaaMMMMaaa + */ + Finder f = new Finder(av); + f.findAll("abe", false, false, true); // true = ignore hidden + SearchResultsI searchResults = f.getSearchResults(); + + /* + * match of seq1 ABE made up of AB and E + */ + assertEquals(searchResults.getSize(), 2); + SearchResultMatchI match = searchResults.getResults().get(0); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 8); // A + assertEquals(match.getEnd(), 9); // B + match = searchResults.getResults().get(1); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 12); // E + assertEquals(match.getEnd(), 12); + + f = new Finder(av); + f.findNext("a.E", false, false, true); + searchResults = f.getSearchResults(); + assertEquals(searchResults.getSize(), 2); + match = searchResults.getResults().get(0); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 8); // A + assertEquals(match.getEnd(), 9); // B + match = searchResults.getResults().get(1); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 12); // E + assertEquals(match.getEnd(), 12); + + f.findNext("a.E", false, false, true); + searchResults = f.getSearchResults(); + assertEquals(searchResults.getSize(), 2); + match = searchResults.getResults().get(0); + assertSame(match.getSequence(), al.getSequenceAt(1)); + assertEquals(match.getStart(), 1); // a + assertEquals(match.getEnd(), 1); + match = searchResults.getResults().get(1); + assertSame(match.getSequence(), al.getSequenceAt(1)); + assertEquals(match.getStart(), 4); // D + assertEquals(match.getEnd(), 5); // e + + /* + * find all matching across two hidden column regions + * note one 'match' is reported as three contiguous matches + */ + f.findAll("BEG", false, false, true); + searchResults = f.getSearchResults(); + assertEquals(searchResults.getSize(), 3); + match = searchResults.getResults().get(0); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 9); // B + assertEquals(match.getEnd(), 9); + match = searchResults.getResults().get(1); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 12); // E + assertEquals(match.getEnd(), 12); + match = searchResults.getResults().get(2); + assertSame(match.getSequence(), al.getSequenceAt(0)); + assertEquals(match.getStart(), 14); // G + assertEquals(match.getEnd(), 14); + } }