JAL-4061 use alignment panel’s feature renderer to limit search to just the visible...
authorJim Procter <j.procter@dundee.ac.uk>
Thu, 15 Sep 2022 17:56:41 +0000 (18:56 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Thu, 15 Sep 2022 17:56:41 +0000 (18:56 +0100)
src/jalview/analysis/Finder.java
src/jalview/api/FinderI.java
src/jalview/gui/Finder.java

index 6061d76..21fa2f1 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Locale;
 import com.stevesoft.pat.Regex;
 
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
 import jalview.api.FinderI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SearchResultMatchI;
@@ -62,6 +63,11 @@ public class Finder implements FinderI
   private AlignViewportI viewport;
 
   /*
+   * feature renderer model - if available
+   */
+  FeatureRenderer frm = null;
+
+  /*
    * sequence index in alignment to search from
    */
   private int sequenceIndex;
@@ -589,9 +595,23 @@ public class Finder implements FinderI
       lastFeature = null;
     }
     SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
-    long fpos = 0;
     SequenceFeaturesI sf = seq.getFeatures();
-    for (SequenceFeature feature : sf.getAllFeatures(null))
+
+    // TODO - stash feature list and search incrementally
+    List<SequenceFeature> allFeatures = null;
+    if (frm != null)
+    {
+      allFeatures = frm.findFeaturesAtResidue(seq, seq.getStart(),
+              seq.getEnd());
+    }
+    else
+    {
+      allFeatures = sf.getAllFeatures(null);
+    }
+    // so we can check we are advancing when debugging
+    long fpos = 0;
+
+    for (SequenceFeature feature : allFeatures)
     {
       fpos++;
       if (lastFeature != null)
@@ -607,6 +627,7 @@ public class Finder implements FinderI
           continue;
         }
       }
+
       if (searchPattern.search(feature.type) || (feature.description != null
               && searchPattern.search(feature.description)))
       {
@@ -712,4 +733,10 @@ public class Finder implements FinderI
   {
     return searchResults;
   }
+
+  @Override
+  public void setFeatureRenderer(FeatureRenderer featureRenderer)
+  {
+    frm = featureRenderer;
+  }
 }
index 967bd5c..697072b 100644 (file)
@@ -96,4 +96,6 @@ public interface FinderI
    */
   SearchResultsI getSearchResults();
 
+  void setFeatureRenderer(FeatureRenderer featureRenderer);
+
 }
\ No newline at end of file
index 6527cdc..c40b958 100755 (executable)
@@ -294,6 +294,7 @@ public class Finder extends GFinder
       finder = new jalview.analysis.Finder(av);
       finders.put(av, finder);
     }
+    finder.setFeatureRenderer(ap.getFeatureRenderer());
 
     boolean isCaseSensitive = caseSensitive.isSelected();
     boolean doSearchDescription = searchDescription.isSelected();