JAL-4061 tests, bugfixes and TODOs for matching feature(s) and descriptions incrementally
authorJim Procter <j.procter@dundee.ac.uk>
Thu, 15 Sep 2022 16:05:03 +0000 (17:05 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Thu, 15 Sep 2022 16:05:03 +0000 (17:05 +0100)
src/jalview/analysis/Finder.java
test/jalview/analysis/FinderTest.java

index ee296d7..181cc9f 100644 (file)
@@ -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;
       }
     }
index 42225e8..62e219d 100644 (file)
@@ -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<SequenceI> 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);
+  }
 }