Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / src / jalview / datamodel / SearchResults.java
index 7c3bba7..8d6cbb1 100755 (executable)
@@ -234,8 +234,8 @@ public class SearchResults implements SearchResultsI
       {
         mfound = true;
         matchStart = sequence.findIndex(m.start) - 1;
-        matchEnd = m.start == m.end ? matchStart : sequence
-                .findIndex(m.end) - 1;
+        matchEnd = m.start == m.end ? matchStart
+                : sequence.findIndex(m.end) - 1;
       }
 
       if (mfound)
@@ -269,7 +269,7 @@ public class SearchResults implements SearchResultsI
         else
         {
           // debug
-          // System.err.println("Outwith bounds!" + matchStart+">"+end +" or "
+          // jalview.bin.Console.errPrintln("Outwith bounds!" + matchStart+">"+end +" or "
           // + matchEnd+"<"+start);
         }
       }
@@ -349,8 +349,10 @@ public class SearchResults implements SearchResultsI
   }
 
   /**
-   * Two SearchResults are considered equal if they contain the same matches in
-   * the same order.
+   * Two SearchResults are considered equal if they contain the same matches
+   * (Sequence, start position, end position) in the same order
+   * 
+   * @see Match#equals(Object)
    */
   @Override
   public boolean equals(Object obj)
@@ -368,4 +370,27 @@ public class SearchResults implements SearchResultsI
   {
     matches.addAll(toAdd.getResults());
   }
+
+  @Override
+  public List<SequenceI> getMatchingSubSequences()
+  {
+    List<SequenceI> seqs = new ArrayList<>();
+
+    /*
+     * assemble dataset sequences, and template new sequence features,
+     * for the amend features dialog
+     */
+    for (SearchResultMatchI match : matches)
+    {
+      SequenceI seq = match.getSequence();
+      while (seq.getDatasetSequence() != null)
+      {
+        seq = seq.getDatasetSequence();
+      }
+      // getSubSequence is index-base0, findIndex returns index-base1
+      seqs.add(seq.getSubSequence(seq.findIndex(match.getStart()) - 1,
+              seq.findIndex(match.getEnd())));
+    }
+    return seqs;
+  }
 }