find incrementally searches ID then subsequence matches.
authorjprocter <Jim Procter>
Wed, 28 Apr 2010 14:03:21 +0000 (14:03 +0000)
committerjprocter <Jim Procter>
Wed, 28 Apr 2010 14:03:21 +0000 (14:03 +0000)
src/jalview/analysis/Finder.java

index 1fa15e3..3d1a70c 100644 (file)
@@ -44,7 +44,7 @@ public class Finder
   /**
    * hold's last-searched position between calles to find(false)
    */
-  int seqIndex = 0, resIndex = 0;
+  int seqIndex = 0, resIndex = -1;
 
   public Finder(AlignmentI alignment, SequenceGroup selection)
   {
@@ -52,6 +52,13 @@ public class Finder
     this.selection = selection;
   }
 
+  /**
+   * restart search at given sequence and residue on alignment and (optionally) contained in selection
+   * @param alignment
+   * @param selectionGroup
+   * @param seqIndex
+   * @param resIndex
+   */
   public Finder(AlignmentI alignment, SequenceGroup selectionGroup,
           int seqIndex, int resIndex)
   {
@@ -116,11 +123,24 @@ public class Finder
               && !selection.getSequences(null).contains(seq))
       {
         seqIndex++;
-        resIndex = 0;
+        resIndex = -1;
 
         continue;
       }
-
+      if (resIndex<0) {
+        resIndex=0;
+        if (regex.search(seq.getName()))
+        {
+          idMatch.addElement(seq);
+          hasResults = true;
+          if (!findAll)
+          {
+            // stop and return the match
+            found=true;
+            break;
+          }
+        }
+      }
       item = seq.getSequenceAsString();
 
       if ((selection != null)
@@ -194,18 +214,20 @@ public class Finder
       if (!found)
       {
         seqIndex++;
-        resIndex = 0;
+        resIndex = -1;
       }
     }
 
-    for (int id = 0; id < alignment.getHeight(); id++)
+    /**
+     * We now search the Id string in the main search loop.
+     * for (int id = 0; id < alignment.getHeight(); id++)
     {
       if (regex.search(alignment.getSequenceAt(id).getName()))
       {
         idMatch.addElement(alignment.getSequenceAt(id));
         hasResults = true;
       }
-    }
+    } */
     return hasResults;
   }