Merge branch 'features/JAL-4061_and_JAL-4062_findselectfeatures' into features/r2_11_...
authorJim Procter <j.procter@dundee.ac.uk>
Sat, 29 Oct 2022 11:16:14 +0000 (12:16 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Sat, 29 Oct 2022 11:16:14 +0000 (12:16 +0100)
19 files changed:
help/help/html/features/search.html
help/help/html/keys.html
help/help/html/menus/alignmentMenu.html
help/help/html/menus/alwedit.html
resources/lang/Messages.properties
src/jalview/analysis/Finder.java
src/jalview/api/AlignViewControllerI.java
src/jalview/api/FinderI.java
src/jalview/appletgui/Finder.java
src/jalview/controller/AlignViewController.java
src/jalview/datamodel/SearchResults.java
src/jalview/datamodel/SearchResultsI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/Finder.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GFinder.java
test/jalview/analysis/FinderTest.java
test/jalview/controller/AlignViewControllerTest.java
test/jalview/datamodel/SearchResultsTest.java

index 837d7b3..d559db8 100755 (executable)
@@ -38,8 +38,8 @@ td {
     selecting &quot;Find...&quot; from the &quot;Search&quot; menu.</p>
   <img src="search.png" width="400" height="152">
   <p>&quot;Find next&quot; will find the next occurrence of the
-    specified and adjust the alignment window view to show it, and
-    &quot;Find all&quot; highlights all matches for a pattern. The
+    query and adjust the alignment window view to show it, and
+    &quot;Find all&quot; highlights all matches for a query. The
     &quot;New Feature&quot; is a quick way to highlight and group
     residues matching the specified search pattern throughout the
     alignment.
@@ -49,9 +49,9 @@ td {
     <li>Gaps are ignored when matching the query to the sequences
       in the alignment.</li>
     <li>Hidden columns can optionally be ignored (<em>since Jalview 2.11</em>)</li>
-    <li>The search is applied to both sequences and their IDs, and
-      optionally also to the description string (<em>since Jalview
-        2.10</em>)
+    <li>The search is applied to both sequences and their IDs. It can
+      optionally also be applied to the description string (<em>since Jalview
+        2.10</em>), and sequence feature descriptions (<em>since Jalview 2.11.2.5</em>).
     </li>
     <li>If a region is selected, then search will <strong>only</strong>
       be performed on that region.<br />
@@ -84,6 +84,12 @@ td {
     highlighted region.
   </p>
   <p>
+  <strong>Copying highlighted regions to a new alignment</strong>
+  </p>
+  <p>
+    You can copy the currently highlighted matching regions of sequences to the clipboard with alt-Command-C.    
+  </p>
+  <p>
 
     <strong>A quick Regular Expression Guide</strong>
   </p>
index 0faa1d5..12457b8 100755 (executable)
       </td>
     </tr>
     <tr>
+      <td><strong>Control Shift 'C'</strong></td>
+      <td>Both</td>
+      <td>Copies highlighted regions, such as from Find or a
+        structure based highlight, as new sequences in the clipboard.</td>
+    </tr>
+    <tr>
       <td><strong>Control 'V'</strong></td>
       <td>Both</td>
       <td>Paste the contents of the clipboard to the current
index 6532933..1a7286f 100755 (executable)
             paste the clipboard contents to a text editor, you will see
             the format of the copied residues FASTA.
         </em></li>
+        <li><strong>Copy Highlighted region (Control Shift
+            C)</strong><br> <em>Copies each stretch of highlighted
+            residues as a new sequence on the system clipboard - you can
+            also do this by pressing &lt;CTRL&gt; &lt;SHIFT&gt; and C
+            (&lt;APPLE&gt; &lt;SHIFT&gt; and C on MacOSX). <br>Use
+            this when you want to extract sequence regions highlighted
+            as a result of a Find operation, or due to mouseovers or
+            selections made in other views such as an assocated 3D
+            structure viewer.
+        </em></li>
         <li><strong>Paste </strong>
           <ul>
             <li><strong>To New Alignment (Control Shift V)<br>
index eb8e839..7384cda 100755 (executable)
         and C on MacOSX). <br> If you try to paste the clipboard
         contents to a text editor, you will see the format of the copied
         residues FASTA.
+    </em></li>    
+    <li><strong>Copy Highlighted region (Control Shift C)</strong><br> <em>Copies
+        each stretch of highlighted residues as a new sequence on the
+        system clipboard - you can also do this by pressing &lt;CTRL&gt;
+        &lt;SHIFT&gt; and C (&lt;APPLE&gt; &lt;SHIFT&gt; and C on
+        MacOSX). <br>Use this when you want to extract sequence regions
+        highlighted as a result of a Find operation, or due to
+        mouseovers or selections made in other views such as an
+        assocated 3D structure viewer.
     </em></li>
     <li><strong>Paste </strong>
       <ul>
index 3843ddb..30a154d 100644 (file)
@@ -130,6 +130,8 @@ action.calculate = Calculate
 action.select_all = Select all
 action.select_highlighted_columns = Select Highlighted Columns
 tooltip.select_highlighted_columns = Press B to mark highlighted columns, Ctrl-(or Cmd)-B to toggle, and Alt-B to mark all but highlighted columns 
+action.copy_highlighted_regions = Copy Highlighted Regions
+tooltip.copy_highlighted_regions = Copies highlighted sequence regions to the clipboard for export or further analysis
 action.deselect_all = Deselect all
 action.invert_selection = Invert selection
 action.using_jmol = Using Jmol
@@ -1398,6 +1400,8 @@ label.click_to_edit = Click to edit, right-click for menu
 label.by_annotation_tooltip = Annotation Colour is configured from the main Colour menu
 label.show_linked_features = Show {0} features
 label.on_top = on top
+label.include_features = Include Features
+label.search_features = Search descriptions of displayed features
 label.include_linked_features = Include {0} features
 label.include_linked_tooltip = Include visible {0} features<br>converted to local sequence coordinates
 label.features_not_shown = {0} feature(s) not shown
@@ -1406,6 +1410,7 @@ label.ignore_hidden = Ignore hidden columns
 label.ignore_hidden_tooltip = Ignore any characters in hidden columns when matching
 label.log_level = Log level
 label.log_level_tooltip = Temporarily set the log level for this console. The log level will revert to {0} when this Java console is closed.
+label.copy = Copy
 label.copy_to_clipboard = Copy to clipboard
 label.copy_to_clipboard_tooltip = Copy all of the log text in this console to the system clipboard
 label.startup = Startup
index f8cfcbf..21fa2f1 100644 (file)
  */
 package jalview.analysis;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
 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;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.SequenceFeaturesI;
 import jalview.util.Comparison;
 import jalview.util.MapList;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import com.stevesoft.pat.Regex;
-
 /**
  * Implements the search algorithm for the Find dialog
  */
@@ -61,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;
@@ -72,6 +79,16 @@ public class Finder implements FinderI
   private int residueIndex;
 
   /*
+   * last feature matched when incrementally searching sequence features
+   */
+  private SequenceFeature lastFeature;
+
+  /*
+   * last sequenceIndex used when lastFeature was discovered
+   */
+  private int lastFeatureSequenceIndex;
+
+  /*
    * the true sequence position of the start of the 
    * last sequence searched (when 'ignore hidden regions' does not apply)
    */
@@ -99,30 +116,36 @@ public class Finder implements FinderI
 
   @Override
   public void findAll(String theSearchString, boolean matchCase,
-          boolean searchDescription, boolean ignoreHidden)
+          boolean searchDescription, boolean searchFeatureDesc,
+          boolean ignoreHidden)
   {
     /*
      * search from the start
      */
+    lastFeature = null;
+    lastFeatureSequenceIndex = 0;
     sequenceIndex = 0;
     residueIndex = -1;
 
-    doFind(theSearchString, matchCase, searchDescription, true,
-            ignoreHidden);
+    doFind(theSearchString, matchCase, searchDescription, searchFeatureDesc,
+            true, ignoreHidden);
 
     /*
      * reset to start for next search
      */
     sequenceIndex = 0;
     residueIndex = -1;
+    lastFeature = null;
+    lastFeatureSequenceIndex = 0;
   }
 
   @Override
   public void findNext(String theSearchString, boolean matchCase,
-          boolean searchDescription, boolean ignoreHidden)
+          boolean searchDescription, boolean searchFeatureDesc,
+          boolean ignoreHidden)
   {
-    doFind(theSearchString, matchCase, searchDescription, false,
-            ignoreHidden);
+    doFind(theSearchString, matchCase, searchDescription, searchFeatureDesc,
+            false, ignoreHidden);
 
     if (searchResults.isEmpty() && idMatches.isEmpty())
     {
@@ -131,6 +154,8 @@ public class Finder implements FinderI
        */
       sequenceIndex = 0;
       residueIndex = -1;
+      lastFeature = null;
+      lastFeatureSequenceIndex = 0;
     }
   }
 
@@ -144,7 +169,8 @@ public class Finder implements FinderI
    * @param ignoreHidden
    */
   protected void doFind(String theSearchString, boolean matchCase,
-          boolean searchDescription, boolean findAll, boolean ignoreHidden)
+          boolean searchDescription, boolean searchFeatureDesc,
+          boolean findAll, boolean ignoreHidden)
   {
     searchResults = new SearchResults();
     idMatches = new ArrayList<>();
@@ -169,7 +195,7 @@ public class Finder implements FinderI
     while ((!found || findAll) && sequenceIndex < end)
     {
       found = findNextMatch(searchString, searchPattern, searchDescription,
-              ignoreHidden);
+              searchFeatureDesc, ignoreHidden);
     }
   }
 
@@ -350,7 +376,8 @@ public class Finder implements FinderI
    * @return
    */
   protected boolean findNextMatch(String searchString, Regex searchPattern,
-          boolean matchDescription, boolean ignoreHidden)
+          boolean matchDescription, boolean matchFeatureDesc,
+          boolean ignoreHidden)
   {
     if (residueIndex < 0)
     {
@@ -380,6 +407,15 @@ public class Finder implements FinderI
       }
       else
       {
+        if (matchFeatureDesc)
+        {
+          matched = searchSequenceFeatures(residueIndex, searchPattern);
+          if (matched)
+          {
+            return true;
+          }
+          lastFeature = null;
+        }
         residueIndex = Integer.MAX_VALUE;
       }
     }
@@ -543,6 +579,69 @@ public class Finder implements FinderI
   }
 
   /**
+   * Searches for a match with the sequence features, and if found, adds the
+   * sequence to the list of match ids, (but not as a duplicate). Answers true
+   * if a match was added, else false.
+   * 
+   * @param seq
+   * @param searchPattern
+   * @return
+   */
+  protected boolean searchSequenceFeatures(int from, Regex searchPattern)
+  {
+    if (lastFeatureSequenceIndex != sequenceIndex)
+    {
+      lastFeatureSequenceIndex = sequenceIndex;
+      lastFeature = null;
+    }
+    SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
+    SequenceFeaturesI sf = seq.getFeatures();
+
+    // 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)
+      {
+        // iterate till we find last feature matched
+        if (lastFeature != feature)
+        {
+          continue;
+        }
+        else
+        {
+          lastFeature = null;
+          continue;
+        }
+      }
+
+      if (searchPattern.search(feature.type) || (feature.description != null
+              && searchPattern.search(feature.description)))
+      {
+        searchResults.addResult(seq, feature.getBegin(), feature.getEnd());
+        lastFeature = feature;
+        return true;
+      }
+    }
+    residueIndex = Integer.MAX_VALUE;
+    lastFeature = null;
+    return false;
+  }
+
+  /**
    * Searches for a match with the sequence description, and if found, adds the
    * sequence to the list of match ids (but not as a duplicate). Answers true if
    * a match was added, else false.
@@ -634,4 +733,10 @@ public class Finder implements FinderI
   {
     return searchResults;
   }
+
+  @Override
+  public void setFeatureRenderer(FeatureRenderer featureRenderer)
+  {
+    frm = featureRenderer;
+  }
 }
index 58a58e9..3e689d1 100644 (file)
  */
 package jalview.api;
 
-import jalview.io.DataSourceType;
-
 import java.util.List;
 
+import jalview.io.DataSourceType;
+
 /**
  * prototype abstract controller for a Jalview alignment view
  * 
@@ -111,4 +111,12 @@ public interface AlignViewControllerI
   boolean markHighlightedColumns(boolean invert, boolean extendCurrent,
           boolean toggle);
 
+  /**
+   * copies each distinct highlighted region on the current view as a new
+   * sequence on the clipboard
+   * 
+   * @return
+   */
+  boolean copyHighlightedRegionsToClipboard();
+
 }
index 1d57d81..697072b 100644 (file)
  */
 package jalview.api;
 
+import java.util.List;
+
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceI;
 
-import java.util.List;
-
 /**
  * An interface for searching for a pattern in an aligment
  */
@@ -49,11 +49,13 @@ public interface FinderI
    * @param theSearchString
    * @param caseSensitive
    * @param searchDescription
+   * @param searchFeatureDesc
    * @param ignoreHidden
    * @return
    */
   void findAll(String theSearchString, boolean caseSensitive,
-          boolean searchDescription, boolean ignoreHidden);
+          boolean searchDescription, boolean searchFeatureDesc,
+          boolean ignoreHidden);
 
   /**
    * Finds the next match for the given search string (interpreted as a regular
@@ -71,11 +73,13 @@ public interface FinderI
    * @param theSearchString
    * @param caseSensitive
    * @param searchDescription
+   * @param searchFeatureDesc
    * @param ignoreHidden
    * @return
    */
   void findNext(String theSearchString, boolean caseSensitive,
-          boolean searchDescription, boolean ignoreHidden);
+          boolean searchDescription, boolean searchFeatureDesc,
+          boolean ignoreHidden);
 
   /**
    * Returns the (possibly empty) list of sequences matched on sequence name or
@@ -92,4 +96,6 @@ public interface FinderI
    */
   SearchResultsI getSearchResults();
 
+  void setFeatureRenderer(FeatureRenderer featureRenderer);
+
 }
\ No newline at end of file
index 31c914a..167d899 100644 (file)
  */
 package jalview.appletgui;
 
-import jalview.api.AlignViewportI;
-import jalview.api.FinderI;
-import jalview.datamodel.SearchResultMatchI;
-import jalview.datamodel.SearchResultsI;
-import jalview.datamodel.SequenceFeature;
-import jalview.datamodel.SequenceI;
-import jalview.util.MessageManager;
-
 import java.awt.Button;
 import java.awt.Checkbox;
 import java.awt.Font;
@@ -47,6 +39,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
+import jalview.datamodel.SearchResultMatchI;
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.util.MessageManager;
+
 public class Finder extends Panel implements ActionListener
 {
   private AlignViewportI av;
@@ -172,12 +172,12 @@ public class Finder extends Panel implements ActionListener
     if (doFindAll)
     {
       finder.findAll(searchString, isCaseSensitive, doSearchDescription,
-              false);
+              false, false);
     }
     else
     {
       finder.findNext(searchString, isCaseSensitive, doSearchDescription,
-              false);
+              false, false);
     }
 
     searchResults = finder.getSearchResults();
index 2fb9cdd..4434331 100644 (file)
  */
 package jalview.controller;
 
+import java.awt.Color;
+import java.util.BitSet;
+import java.util.List;
+
 import jalview.analysis.AlignmentSorter;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
@@ -29,19 +33,17 @@ import jalview.api.FeatureRenderer;
 import jalview.commands.OrderCommand;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.Desktop;
 import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
 import jalview.schemes.ColourSchemeI;
 import jalview.util.MessageManager;
 
-import java.awt.Color;
-import java.util.BitSet;
-import java.util.List;
-
 public class AlignViewController implements AlignViewControllerI
 {
   AlignViewportI viewport = null;
@@ -471,4 +473,31 @@ public class AlignViewController implements AlignViewControllerI
     return false;
   }
 
+  @Override
+  public boolean copyHighlightedRegionsToClipboard()
+  {
+    if (!viewport.hasSearchResults())
+    {
+      // do nothing if no selection exists
+      return false;
+    }
+
+    SearchResultsI searchResults = viewport.getSearchResults();
+    if (searchResults.isEmpty())
+    {
+      return false; // shouldn't happen
+    }
+    List<SequenceI> seqs = searchResults.getMatchingSubSequences();
+
+    // TODO: pass in hiddenColumns according to intersection of searchResults
+    // and visible columns. Currently this isn't done, since each contig becomes
+    // a single subsequence
+    Desktop.jalviewClipboard = new Object[] {
+        seqs.toArray(new SequenceI[0]),
+        alignPanel.getAlignment().getDataset(), null };
+    avcg.setStatus(MessageManager.formatMessage(
+            "label.copied_sequences_to_clipboard", seqs.size()));
+    // Technically we should return false, since view has not changed
+    return false;
+  }
 }
index 880f970..909a0fe 100755 (executable)
@@ -370,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;
+  }
 }
index c89f363..7946824 100644 (file)
@@ -118,4 +118,12 @@ public interface SearchResultsI
    * @return number of bits set
    */
   int markColumns(SequenceCollectionI sqcol, BitSet bs);
+
+  /**
+   * Return sub-sequences corresponding to distinct contiguous ranges in the
+   * matching set
+   * 
+   * @return list of sequence objects
+   */
+  List<SequenceI> getMatchingSubSequences();
 }
\ No newline at end of file
index e24cbea..032b0bb 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import java.util.Locale;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -59,6 +57,7 @@ import java.util.Deque;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Locale;
 import java.util.Vector;
 
 import javax.swing.ButtonGroup;
@@ -5829,6 +5828,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     | ActionEvent.CTRL_MASK)) != 0);
   }
 
+  @Override
+  protected void copyHighlightedColumns_actionPerformed(
+          ActionEvent actionEvent)
+  {
+    avc.copyHighlightedRegionsToClipboard();
+  }
+
   /**
    * Rebuilds the Colour menu, including any user-defined colours which have
    * been loaded either on startup or during the session
index 358d9a4..c40b958 100755 (executable)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import java.util.Locale;
-
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.FocusAdapter;
@@ -30,6 +28,7 @@ import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -254,6 +253,17 @@ public class Finder extends GFinder
     new FeatureEditor(ap, seqs, features, true).showDialog();
   }
 
+  @Override
+  protected void copyToClipboard_actionPerformed()
+  {
+    if (searchResults.isEmpty())
+    {
+      return; // shouldn't happen
+    }
+    // assume viewport controller has same searchResults as we do...
+    ap.alignFrame.avc.copyHighlightedRegionsToClipboard();
+  }
+
   /**
    * Search the alignment for the next or all matches. If 'all matches', a
    * dialog is shown with the number of sequence ids and subsequences matched.
@@ -263,6 +273,7 @@ public class Finder extends GFinder
   void doSearch(boolean doFindAll)
   {
     createFeatures.setEnabled(false);
+    copyToClipboard.setEnabled(false);
 
     String searchString = searchBox.getUserInput();
 
@@ -283,19 +294,21 @@ 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();
+    boolean doSearchfeatures = searchFeatures.isSelected();
     boolean skipHidden = ignoreHidden.isSelected();
     if (doFindAll)
     {
       finder.findAll(searchString, isCaseSensitive, doSearchDescription,
-              skipHidden);
+              doSearchfeatures, skipHidden);
     }
     else
     {
       finder.findNext(searchString, isCaseSensitive, doSearchDescription,
-              skipHidden);
+              doSearchfeatures, skipHidden);
     }
 
     searchResults = finder.getSearchResults();
@@ -309,6 +322,7 @@ public class Finder extends GFinder
     else
     {
       createFeatures.setEnabled(true);
+      copyToClipboard.setEnabled(true);
     }
 
     searchBox.updateCache();
index 71b6b9e..8ae97b0 100755 (executable)
  */
 package jalview.jbgui;
 
-import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.analysis.GeneticCodeI;
-import jalview.analysis.GeneticCodes;
-import jalview.api.SplitContainerI;
-import jalview.bin.Cache;
-import jalview.gui.JvSwingUtils;
-import jalview.gui.Preferences;
-import jalview.io.FileFormats;
-import jalview.schemes.ResidueColourScheme;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.GridLayout;
@@ -61,6 +49,18 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.analysis.GeneticCodeI;
+import jalview.analysis.GeneticCodes;
+import jalview.api.SplitContainerI;
+import jalview.bin.Cache;
+import jalview.gui.JvSwingUtils;
+import jalview.gui.Preferences;
+import jalview.io.FileFormats;
+import jalview.schemes.ResidueColourScheme;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
 @SuppressWarnings("serial")
 public class GAlignFrame extends JInternalFrame
 {
@@ -104,6 +104,8 @@ public class GAlignFrame extends JInternalFrame
 
   JMenuItem copy = new JMenuItem();
 
+  JMenuItem copyHighlighted = new JMenuItem();
+
   JMenuItem cut = new JMenuItem();
 
   JMenu pasteMenu = new JMenu();
@@ -1756,6 +1758,26 @@ public class GAlignFrame extends JInternalFrame
       }
     };
     selectHighlighted.addActionListener(al);
+
+    copyHighlighted = new JMenuItem(
+            MessageManager.getString("action.copy_highlighted_regions"));
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    + jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK,
+            false);
+    copyHighlighted.setToolTipText(
+            MessageManager.getString("tooltip.copy_highlighted_regions"));
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        copyHighlightedColumns_actionPerformed(actionEvent);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, copyHighlighted, al);
+    copyHighlighted.addActionListener(al);
+
     JMenu tooltipSettingsMenu = new JMenu(
             MessageManager.getString("label.sequence_id_tooltip"));
     JMenu autoAnnMenu = new JMenu(
@@ -1806,6 +1828,7 @@ public class GAlignFrame extends JInternalFrame
     editMenu.add(redoMenuItem);
     editMenu.add(cut);
     editMenu.add(copy);
+    editMenu.add(copyHighlighted);
     editMenu.add(pasteMenu);
     editMenu.add(delete);
     editMenu.addSeparator();
@@ -1951,6 +1974,12 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  protected void copyHighlightedColumns_actionPerformed(
+          ActionEvent actionEvent)
+  {
+
+  }
+
   protected void loadVcf_actionPerformed()
   {
   }
index c5488f0..9ed2127 100755 (executable)
  */
 package jalview.jbgui;
 
-import jalview.datamodel.AlignmentI;
-import jalview.io.DataSourceType;
-import jalview.io.FileFormat;
-import jalview.io.FormatAdapter;
-import jalview.io.cache.JvCacheableInputBox;
-import jalview.util.MessageManager;
-
 import java.awt.BorderLayout;
 import java.awt.Font;
 import java.awt.GridLayout;
@@ -44,6 +37,13 @@ import javax.swing.SwingUtilities;
 import javax.swing.event.CaretEvent;
 import javax.swing.event.CaretListener;
 
+import jalview.datamodel.AlignmentI;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FormatAdapter;
+import jalview.io.cache.JvCacheableInputBox;
+import jalview.util.MessageManager;
+
 public class GFinder extends JPanel
 {
   private static final java.awt.Font VERDANA_12 = new Font("Verdana",
@@ -59,12 +59,16 @@ public class GFinder extends JPanel
 
   protected JButton createFeatures;
 
+  protected JButton copyToClipboard;
+
   protected JvCacheableInputBox<String> searchBox;
 
   protected JCheckBox caseSensitive;
 
   protected JCheckBox searchDescription;
 
+  protected JCheckBox searchFeatures;
+
   protected JCheckBox ignoreHidden;
 
   public GFinder()
@@ -152,6 +156,10 @@ public class GFinder extends JPanel
     searchDescription
             .setText(MessageManager.getString("label.include_description"));
 
+    searchFeatures = new JCheckBox();
+    searchFeatures
+            .setText(MessageManager.getString("label.include_features"));
+
     ignoreHidden = new JCheckBox();
     ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
     ignoreHidden.setToolTipText(
@@ -159,6 +167,7 @@ public class GFinder extends JPanel
 
     centrePanel.add(caseSensitive);
     centrePanel.add(searchDescription);
+    centrePanel.add(searchFeatures);
     centrePanel.add(ignoreHidden);
 
     /*
@@ -198,9 +207,26 @@ public class GFinder extends JPanel
         createFeatures_actionPerformed();
       }
     });
+    copyToClipboard = new JButton();
+    copyToClipboard.setEnabled(false);
+    copyToClipboard.setFont(VERDANA_12);
+    copyToClipboard.setText(MessageManager.getString("label.copy"));
+    copyToClipboard.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        copyToClipboard_actionPerformed();
+      }
+    });
     eastPanel.add(findNext);
     eastPanel.add(findAll);
     eastPanel.add(createFeatures);
+    eastPanel.add(copyToClipboard);
+  }
+
+  protected void copyToClipboard_actionPerformed()
+  {
   }
 
   protected void textfield_keyPressed(KeyEvent e)
index 7e3bd86..0220c36 100644 (file)
@@ -24,6 +24,12 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import java.util.List;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
 import jalview.api.AlignViewportI;
 import jalview.api.FinderI;
 import jalview.bin.Cache;
@@ -34,19 +40,14 @@ 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;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-
-import java.util.List;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
 import junit.extensions.PA;
 
 public class FinderTest
@@ -82,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)
@@ -100,7 +107,7 @@ public class FinderTest
      * find next match only
      */
     Finder f = new Finder(av);
-    f.findNext("E.H", false, false, false); // 'E, any character, H'
+    f.findNext("E.H", false, false, false, false); // 'E, any character, H'
     // should match seq2 efH only
     SearchResultsI sr = f.getSearchResults();
     assertEquals(sr.getCount(), 1);
@@ -110,7 +117,7 @@ public class FinderTest
     assertEquals(matches.get(0).getEnd(), 7);
 
     f = new Finder(av);
-    f.findAll("E.H", false, false, false); // 'E, any character, H'
+    f.findAll("E.H", false, false, false, false); // 'E, any character, H'
     // should match seq2 efH and seq3 EFH
     sr = f.getSearchResults();
     assertEquals(sr.getCount(), 2);
@@ -131,7 +138,7 @@ public class FinderTest
      * single symbol should find *all* matching symbols 
      */
     Finder f = new Finder(av);
-    f.findAll("M", false, false, false);
+    f.findAll("M", false, false, false, false);
     SearchResultsI sr = f.getSearchResults();
     assertEquals(sr.getCount(), 5);
 
@@ -148,7 +155,7 @@ public class FinderTest
     /*
      * find first match should return seq1 residue 9
      */
-    f.findNext("9", false, false, false);
+    f.findNext("9", false, false, false, false);
     SearchResultsI sr = f.getSearchResults();
     assertEquals(sr.getCount(), 1);
     List<SearchResultMatchI> matches = sr.getResults();
@@ -163,7 +170,7 @@ public class FinderTest
     f = new Finder(av);
     String name = al.getSequenceAt(0).getName();
     al.getSequenceAt(0).setName("Q9XA0");
-    f.findAll("9", false, false, false);
+    f.findAll("9", false, false, false, false);
     sr = f.getSearchResults();
     assertEquals(sr.getCount(), 2);
     matches = sr.getResults();
@@ -179,7 +186,7 @@ public class FinderTest
      * parsing of search string as integer is strict
      */
     f = new Finder(av);
-    f.findNext(" 9", false, false, false);
+    f.findNext(" 9", false, false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
   }
 
@@ -196,7 +203,7 @@ public class FinderTest
     Finder f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
     PA.setValue(f, "residueIndex", -1);
-    f.findNext("e", false, false, false); // matches id
+    f.findNext("e", false, false, false, false); // matches id
 
     assertTrue(f.getSearchResults().isEmpty());
     assertEquals(f.getIdMatches().size(), 1);
@@ -208,7 +215,7 @@ public class FinderTest
     f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
     PA.setValue(f, "residueIndex", 0);
-    f.findNext("e", false, false, false); // matches in sequence
+    f.findNext("e", false, false, false, false); // matches in sequence
     assertTrue(f.getIdMatches().isEmpty());
     assertEquals(f.getSearchResults().getCount(), 1);
     List<SearchResultMatchI> matches = f.getSearchResults().getResults();
@@ -224,7 +231,7 @@ public class FinderTest
     f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
     PA.setValue(f, "residueIndex", 7);
-    f.findNext("e", false, false, false);
+    f.findNext("e", false, false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(2));
     assertTrue(f.getSearchResults().isEmpty());
@@ -246,7 +253,7 @@ public class FinderTest
      * find first match only
      */
     Finder f = new Finder(av2);
-    f.findNext("rAF", false, true, false);
+    f.findNext("rAF", false, true, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
@@ -255,7 +262,7 @@ public class FinderTest
      * find all matches
      */
     f = new Finder(av2);
-    f.findAll("rAF", false, true, false);
+    f.findAll("rAF", false, true, false, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
@@ -265,7 +272,7 @@ public class FinderTest
      * case sensitive
      */
     f = new Finder(av2);
-    f.findAll("RAF", true, true, false);
+    f.findAll("RAF", true, true, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
@@ -281,7 +288,7 @@ public class FinderTest
     /*
      * sequence matches should have no duplicates
      */
-    f.findAll("EFH", false, true, false);
+    f.findAll("EFH", false, true, false, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
@@ -309,7 +316,7 @@ public class FinderTest
      * case insensitive; seq1 occurs twice in sequence id but
      * only one match should be returned
      */
-    f.findAll("SEQ1", false, false, false);
+    f.findAll("SEQ1", false, false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(0));
     SearchResultsI searchResults = f.getSearchResults();
@@ -319,7 +326,7 @@ public class FinderTest
      * case sensitive
      */
     f = new Finder(av);
-    f.findAll("SEQ1", true, false, false);
+    f.findAll("SEQ1", true, false, false, false);
     searchResults = f.getSearchResults();
     assertTrue(searchResults.isEmpty());
 
@@ -330,7 +337,7 @@ public class FinderTest
     AlignViewportI av2 = new AlignViewport(al2);
     al2.addSequence(new Sequence("aBz", "xyzabZpqrAbZ"));
     f = new Finder(av2);
-    f.findAll("ABZ", false, false, false);
+    f.findAll("ABZ", false, false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(4));
     searchResults = f.getSearchResults();
@@ -359,7 +366,7 @@ public class FinderTest
      * efh should be matched in seq2 only
      */
     FinderI f = new Finder(av);
-    f.findNext("EfH", false, false, false);
+    f.findNext("EfH", false, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -371,7 +378,7 @@ public class FinderTest
      * I should be found in seq1 (twice) and seq2 (once)
      */
     f = new Finder(av);
-    f.findNext("I", false, false, false); // find next: seq1/16
+    f.findNext("I", false, false, false, false); // find next: seq1/16
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -379,7 +386,7 @@ public class FinderTest
     assertEquals(match.getStart(), 16);
     assertEquals(match.getEnd(), 16);
 
-    f.findNext("I", false, false, false); // find next: seq1/18
+    f.findNext("I", false, false, false, false); // find next: seq1/18
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -387,7 +394,7 @@ public class FinderTest
     assertEquals(match.getStart(), 18);
     assertEquals(match.getEnd(), 18);
 
-    f.findNext("I", false, false, false); // find next: seq2/8
+    f.findNext("I", false, false, false, false); // find next: seq2/8
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -395,13 +402,13 @@ public class FinderTest
     assertEquals(match.getStart(), 8);
     assertEquals(match.getEnd(), 8);
 
-    f.findNext("I", false, false, false);
+    f.findNext("I", false, false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
 
     /*
      * find should reset to start of alignment after a failed search
      */
-    f.findNext("I", false, false, false); // find next: seq1/16
+    f.findNext("I", false, false, false, false); // find next: seq1/16
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -418,7 +425,7 @@ public class FinderTest
   public void testFindAll_maximalResultOnly()
   {
     Finder f = new Finder(av);
-    f.findAll("M+", false, false, false);
+    f.findAll("M+", false, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -434,7 +441,7 @@ public class FinderTest
   public void testFindAll()
   {
     Finder f = new Finder(av);
-    f.findAll("EfH", false, false, false);
+    f.findAll("EfH", false, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -449,7 +456,7 @@ public class FinderTest
     /*
      * find all I should find 2 positions in seq1, 1 in seq2
      */
-    f.findAll("I", false, false, false);
+    f.findAll("I", false, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 3);
     match = searchResults.getResults().get(0);
@@ -477,7 +484,7 @@ public class FinderTest
     /*
      * BC should match seq1/9-10 and seq2/2-3
      */
-    f.findAll("BC", true, false, false);
+    f.findAll("BC", true, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -493,7 +500,7 @@ public class FinderTest
      * bc should match seq3/1-2
      */
     f = new Finder(av);
-    f.findAll("bc", true, false, false);
+    f.findAll("bc", true, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -501,7 +508,7 @@ public class FinderTest
     assertEquals(match.getStart(), 1);
     assertEquals(match.getEnd(), 2);
 
-    f.findAll("bC", true, false, false);
+    f.findAll("bC", true, false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
   }
 
@@ -524,7 +531,7 @@ public class FinderTest
     av.setSelectionGroup(sg);
 
     FinderI f = new Finder(av);
-    f.findNext("b", false, false, false);
+    f.findNext("b", false, false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
@@ -536,12 +543,12 @@ public class FinderTest
     /*
      * a second Find should not return the 'b' in seq3 as outside the selection
      */
-    f.findNext("b", false, false, false);
+    f.findNext("b", false, false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
     assertTrue(f.getIdMatches().isEmpty());
 
     f = new Finder(av);
-    f.findNext("d", false, false, false);
+    f.findNext("d", false, false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
@@ -549,7 +556,7 @@ public class FinderTest
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 4);
     assertEquals(match.getEnd(), 4);
-    f.findNext("d", false, false, false);
+    f.findNext("d", false, false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
@@ -581,7 +588,7 @@ public class FinderTest
      * search for 'e' should match two sequence ids and one residue
      */
     Finder f = new Finder(av);
-    f.findAll("e", false, false, false);
+    f.findAll("e", false, false, false, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
     assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
@@ -596,7 +603,7 @@ public class FinderTest
      * search for 'Q' should match two sequence ids only
      */
     f = new Finder(av);
-    f.findAll("Q", false, false, false);
+    f.findAll("Q", false, false, false, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
     assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
@@ -627,7 +634,7 @@ public class FinderTest
      * search for 'I' should match two sequence positions
      */
     Finder f = new Finder(av);
-    f.findAll("I", false, false, false);
+    f.findAll("I", false, false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
@@ -664,7 +671,7 @@ public class FinderTest
     hc.hideColumns(3, 3);
     al.setHiddenColumns(hc);
     Finder f = new Finder(av);
-    f.findAll("aaa", false, false, false);
+    f.findAll("aaa", false, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -686,7 +693,7 @@ public class FinderTest
      * find the visible D in seq2
      */
     f = new Finder(av);
-    f.findAll("D", false, false, false);
+    f.findAll("D", false, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -699,7 +706,7 @@ public class FinderTest
      * consecutive in the visible columns
      */
     f = new Finder(av);
-    f.findAll("AD", false, false, false);
+    f.findAll("AD", false, false, false, false);
     searchResults = f.getSearchResults();
     assertTrue(searchResults.isEmpty());
 
@@ -708,7 +715,7 @@ public class FinderTest
      * (first run includes hidden gaps)
      */
     f = new Finder(av);
-    f.findAll("aaa", false, false, false);
+    f.findAll("aaa", false, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     match = searchResults.getResults().get(0);
@@ -727,7 +734,7 @@ public class FinderTest
      */
     hc.hideColumns(2, 5);
     f = new Finder(av);
-    f.findAll("aaa", false, false, false);
+    f.findAll("aaa", false, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     match = searchResults.getResults().get(0);
@@ -742,7 +749,7 @@ public class FinderTest
     /*
      * find all 'BE' should not match across hidden columns in seq1
      */
-    f.findAll("BE", false, false, false);
+    f.findAll("BE", false, false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
 
     /*
@@ -752,7 +759,7 @@ public class FinderTest
     hc.revealAllHiddenColumns(new ColumnSelection());
     hc.hideColumns(8, 13);
     f = new Finder(av);
-    f.findNext("H", false, false, false);
+    f.findNext("H", false, false, false, false);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
@@ -795,7 +802,7 @@ public class FinderTest
      * should match seq2/1, seq2/7, not seq3/6
      */
     Finder f = new Finder(av);
-    f.findAll("[AH]", false, false, false);
+    f.findAll("[AH]", false, false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
@@ -832,7 +839,7 @@ public class FinderTest
      * aaaMMMMaaa
      */
     Finder f = new Finder(av);
-    f.findAll("abe", false, false, true); // true = ignore hidden
+    f.findAll("abe", false, false, false, true); // true = ignore hidden
     SearchResultsI searchResults = f.getSearchResults();
 
     /*
@@ -851,7 +858,7 @@ public class FinderTest
     assertEquals(match.getEnd(), 12);
 
     f = new Finder(av);
-    f.findNext("a.E", false, false, true);
+    f.findNext("a.E", false, false, false, true);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     assertEquals(searchResults.getResults().size(), 2);
@@ -864,7 +871,7 @@ public class FinderTest
     assertEquals(match.getStart(), 12); // E
     assertEquals(match.getEnd(), 12);
 
-    f.findNext("a.E", false, false, true);
+    f.findNext("a.E", false, false, false, true);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     assertEquals(searchResults.getResults().size(), 2);
@@ -881,7 +888,7 @@ public class FinderTest
      * find all matching across two hidden column regions
      * note one 'match' is returned as three contiguous matches
      */
-    f.findAll("BEG", false, false, true);
+    f.findAll("BEG", false, false, false, true);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     assertEquals(searchResults.getResults().size(), 3);
@@ -908,7 +915,7 @@ public class FinderTest
     selection.setEndRes(9);
     al.getSequences().forEach(seq -> selection.addSequence(seq, false));
     av.setSelectionGroup(selection);
-    f.findAll("A.*H", false, false, true);
+    f.findAll("A.*H", false, false, false, true);
     searchResults = f.getSearchResults();
     assertEquals(searchResults.getCount(), 1);
     assertEquals(searchResults.getResults().size(), 3);
@@ -926,4 +933,60 @@ 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);
+
+    SequenceI sq = null;
+    // search feature descriptions incrementally
+    // assume same order as before
+    f.findNext("Feature", false, false, true, true);
+    assertEquals(f.getSearchResults().getCount(), 1);
+    sq = f.getSearchResults().getMatchingSubSequences().get(0);
+    assertEquals(sq.getSequenceAsString(),
+            seqs.get(0).getSequenceAsString());
+
+    // ..
+    f.findNext("Feature", false, false, true, true);
+    assertEquals(f.getSearchResults().getCount(), 1);
+    sq = f.getSearchResults().getMatchingSubSequences().get(0);
+    assertEquals(sq.getSequenceAsString(),
+            seqs.get(1).getSequenceAsString());
+
+    // ..
+    f.findNext("Feature", false, false, true, true);
+    assertEquals(f.getSearchResults().getCount(), 1);
+    sq = f.getSearchResults().getMatchingSubSequences().get(0);
+    assertEquals(sq.getSequenceAsString(),
+            seqs.get(2).getSequenceAsString());
+
+  }
 }
index ca3b55c..e8e0bb1 100644 (file)
@@ -23,6 +23,13 @@ package jalview.controller;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertTrue;
 
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.BitSet;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
 import jalview.analysis.Finder;
 import jalview.api.AlignViewControllerI;
 import jalview.api.FeatureColourI;
@@ -40,13 +47,6 @@ import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.schemes.FeatureColour;
 
-import java.awt.Color;
-import java.util.Arrays;
-import java.util.BitSet;
-
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
 public class AlignViewControllerTest
 {
 
@@ -226,7 +226,7 @@ public class AlignViewControllerTest
      *  test Match/Find works first
      */
     FinderI f = new Finder(af.getViewport());
-    f.findAll("M+", true, false, false);
+    f.findAll("M+", true, false, false, false);
     assertEquals(
             "Finder found different set of results to manually created SearchResults",
             sr, f.getSearchResults());
index 5d2b8a4..b1bb43c 100644 (file)
@@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
 import java.util.BitSet;
+import java.util.List;
 
 import org.junit.Assert;
 import org.testng.annotations.BeforeClass;
@@ -369,4 +370,44 @@ public class SearchResultsTest
     sr.addResult(cds2, 7, 9); // start-end overlap
     assertTrue(sr.involvesSequence(cds2));
   }
+
+  /**
+   * Test extraction of Sequence objects for matched ranges on a sequence
+   */
+  @Test(groups = { "Functional" })
+  public void testGetSequences()
+  {
+    SequenceI seq1 = new Sequence("", "abcdefghijklm");
+    SequenceI seq2 = new Sequence("", "nopqrstuvwxyz");
+    seq2.setStart(23);
+    seq2.setEnd(35);
+    List<SequenceI> seqres = null;
+
+    SearchResultsI sr = new SearchResults();
+    seqres = sr.getMatchingSubSequences();
+    assertEquals(0, seqres.size());
+
+    sr.addResult(seq1, 3, 5);
+    seqres = sr.getMatchingSubSequences();
+
+    assertEquals(1, seqres.size());
+    assertEquals("cde", seqres.get(0).getSequenceAsString());
+    assertEquals(3, seqres.get(0).getStart());
+    assertEquals(seq1, seqres.get(0).getDatasetSequence());
+
+    sr.addResult(seq1, 3, 6);
+    seqres = sr.getMatchingSubSequences();
+
+    assertEquals(2, seqres.size());
+    assertEquals("cdef", seqres.get(1).getSequenceAsString());
+    assertEquals(3, seqres.get(1).getStart());
+
+    // this is a quirk - match on 26-29 yields subsequence 27-30
+    sr.addResult(seq2, 26, 29);
+    seqres = sr.getMatchingSubSequences();
+    assertEquals(3, seqres.size());
+    assertEquals("qrst", seqres.get(2).getSequenceAsString());
+    assertEquals(26, seqres.get(2).getStart());
+  }
+
 }