From 13a74c42398c4a2d3794242efec6e52b949b5e5d Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 15 Sep 2022 17:05:03 +0100 Subject: [PATCH] JAL-4061 tests, bugfixes and TODOs for matching feature(s) and descriptions incrementally --- src/jalview/analysis/Finder.java | 6 +++-- test/jalview/analysis/FinderTest.java | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index ee296d7..181cc9f 100644 --- a/src/jalview/analysis/Finder.java +++ b/src/jalview/analysis/Finder.java @@ -387,6 +387,7 @@ public class Finder implements FinderI { if (matchFeatureDesc) { + // TODO - record last matched matched = searchSequenceFeatures(residueIndex, searchPattern); } residueIndex = Integer.MAX_VALUE; @@ -556,6 +557,8 @@ public class Finder implements FinderI * sequence to the list of match ids, (but not as a duplicate). Answers true * if a match was added, else false. * + * TODO: allow incremental searching (ie next feature matched after last) + * * @param seq * @param searchPattern * @return @@ -571,8 +574,7 @@ public class Finder implements FinderI if (searchPattern.search(feature.type) || (feature.description != null && searchPattern.search(feature.description))) { - searchResults.addResult(seq, seq.findIndex(feature.getBegin()), - seq.findIndex(feature.getEnd())); + searchResults.addResult(seq, feature.getBegin(), feature.getEnd()); matched = true; } } diff --git a/test/jalview/analysis/FinderTest.java b/test/jalview/analysis/FinderTest.java index 42225e8..62e219d 100644 --- a/test/jalview/analysis/FinderTest.java +++ b/test/jalview/analysis/FinderTest.java @@ -40,7 +40,9 @@ import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; import jalview.gui.JvOptionPane; @@ -81,6 +83,12 @@ public class FinderTest DataSourceType.PASTE); av = af.getViewport(); al = av.getAlignment(); + al.getSequenceAt(0).addSequenceFeature( + new SequenceFeature("BBBB", "FeatureB", 9, 11, "")); + al.getSequenceAt(3).addSequenceFeature( + new SequenceFeature("BBAB", "FeatureA", 1, 3, "")); + al.getSequenceAt(3).addSequenceFeature( + new SequenceFeature("AAAA", "FeatureA", 9, 11, "")); } @AfterMethod(alwaysRun = true) @@ -925,4 +933,36 @@ public class FinderTest assertEquals(match.getStart(), 7); // H (there is no G) assertEquals(match.getEnd(), 7); } + + @Test(groups = "Functional") + public void testFind_featuresOnly() + { + Finder f = new Finder(av); + // no match when not searching feature descriptions + f.findAll("Feature", false, false, false, true); + assertEquals(f.getSearchResults().getCount(), 0); + + // no match when case sensitive on feature descriptions + f.findAll("feature", true, false, true, true); + assertEquals(f.getSearchResults().getCount(), 0); + + // search feature descriptions - all match + f.findAll("Feature", false, false, true, true); + assertEquals(f.getSearchResults().getCount(), 3); + + List seqs = f.getSearchResults().getMatchingSubSequences(); + // assume order is preserved in results + assertEquals(al.getSequenceAt(0).getDatasetSequence(), + seqs.get(0).getDatasetSequence()); + assertEquals(seqs.get(0).getStart(), 9); + assertEquals(seqs.get(0).getEnd(), 11); + assertEquals(al.getSequenceAt(3).getDatasetSequence(), + seqs.get(1).getDatasetSequence()); + assertEquals(seqs.get(1).getStart(), 9); + assertEquals(seqs.get(1).getEnd(), 11); + assertEquals(al.getSequenceAt(3).getDatasetSequence(), + seqs.get(2).getDatasetSequence()); + assertEquals(seqs.get(2).getStart(), 1); + assertEquals(seqs.get(2).getEnd(), 3); + } } -- 1.7.10.2