label.show_linked_features = Show {0} features
label.on_top = on top
label.include_linked_features = Include {0} features
-label.include_linked_tooltip = Include visible {0} features<br>converted to local sequence coordinates
\ No newline at end of file
+label.include_linked_tooltip = Include visible {0} features<br>converted to local sequence coordinates
+label.ignore_hidden = Ignore hidden columns
+label.ignore_hidden_tooltip = Ignore any characters in hidden columns when matching
label.show_linked_features = Características de {0}
label.on_top = encima
label.include_linked_features = Incluir características de {0}
-label.include_linked_tooltip = Incluir características de {0}<br>convertidas a coordenadas de secuencia local
\ No newline at end of file
+label.include_linked_tooltip = Incluir características de {0}<br>convertidas a coordenadas de secuencia local
+label.ignore_hidden = Ignorar columnas ocultas
+label.ignore_hidden_tooltip = Ignorar caracteres en columnas ocultas
import jalview.api.AlignViewportI;
import jalview.api.FinderI;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Range;
import jalview.datamodel.SearchResultMatchI;
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.datamodel.VisibleContigsIterator;
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 java.util.Vector;
import com.stevesoft.pat.Regex;
/*
* sequences matched by id or description
*/
- private Vector<SequenceI> idMatches;
+ private List<SequenceI> idMatches;
/*
* the viewport to search over
private int sequenceIndex;
/*
- * column position in sequence to search from, base 0
- * - absolute column number including any hidden columns
- * (position after start of last match for a repeat search)
+ * position offset in sequence to search from, base 0
+ * (position after start of last match for a 'find next')
*/
- private int columnIndex;
+ private int residueIndex;
+
+ /*
+ * the true sequence position of the start of the
+ * last sequence searched (when 'ignore hidden regions' does not apply)
+ */
+ private int searchedSequenceStartPosition;
+
+ /*
+ * when 'ignore hidden regions' applies, this holds the mapping from
+ * the visible sequence positions (1, 2, ...) to true sequence positions
+ */
+ private MapList searchedSequenceMap;
+
+ private String seqToSearch;
/**
* Constructor for searching a viewport
{
this.viewport = av;
this.sequenceIndex = 0;
- this.columnIndex = -1;
+ this.residueIndex = -1;
}
@Override
public void findAll(String theSearchString, boolean matchCase,
- boolean searchDescription)
+ boolean searchDescription, boolean ignoreHidden)
{
/*
* search from the start
*/
sequenceIndex = 0;
- columnIndex = -1;
+ residueIndex = -1;
- doFind(theSearchString, matchCase, searchDescription, true);
+ doFind(theSearchString, matchCase, searchDescription, true,
+ ignoreHidden);
/*
* reset to start for next search
*/
sequenceIndex = 0;
- columnIndex = -1;
+ residueIndex = -1;
}
@Override
public void findNext(String theSearchString, boolean matchCase,
- boolean searchDescription)
+ boolean searchDescription, boolean ignoreHidden)
{
- doFind(theSearchString, matchCase, searchDescription, false);
+ doFind(theSearchString, matchCase, searchDescription, false,
+ ignoreHidden);
if (searchResults.isEmpty() && idMatches.isEmpty())
{
* search failed - reset to start for next search
*/
sequenceIndex = 0;
- columnIndex = -1;
+ residueIndex = -1;
}
}
* @param matchCase
* @param searchDescription
* @param findAll
+ * @param ignoreHidden
*/
protected void doFind(String theSearchString, boolean matchCase,
- boolean searchDescription, boolean findAll)
+ boolean searchDescription, boolean findAll, boolean ignoreHidden)
{
+ searchResults = new SearchResults();
+ idMatches = new ArrayList<>();
+
String searchString = matchCase ? theSearchString
: theSearchString.toUpperCase();
Regex searchPattern = new Regex(searchString);
searchPattern.setIgnoreCase(!matchCase);
- searchResults = new SearchResults();
- idMatches = new Vector<>();
-
SequenceGroup selection = viewport.getSelectionGroup();
if (selection != null && selection.getSize() < 1)
{
AlignmentI alignment = viewport.getAlignment();
int end = alignment.getHeight();
- while (sequenceIndex < end)
+ getSequence(ignoreHidden);
+
+ boolean found = false;
+ while (!found || findAll)
{
- SequenceI seq = alignment.getSequenceAt(sequenceIndex);
- boolean found = findNextMatch(seq, searchString, searchPattern,
- searchDescription);
- if (found && !findAll)
+ found = findNextMatch(searchString, searchPattern, searchDescription,
+ ignoreHidden);
+ if (sequenceIndex >= end)
{
- return;
- }
- if (!found)
- {
- sequenceIndex++;
- columnIndex = -1;
+ break;
}
}
}
/**
- * Answers the start-end column range of the contiguous visible regions of
- * {@code sequence} starting at or after the given {@code column}. If there are
- * no hidden columns, this just returns the remaining width of the sequence.
- * Otherwise, visible columns are added as long as they are contiguous on the
- * sequence (hidden regions only contain gaps). The range is restricted to the
- * current {@code selection} if there is one. Answers null if there are no
- * visible columns at or after {@code column}.
+ * Calculates and saves the sequence string to search. The string is restricted
+ * to the current selection region if there is one, and is saved with all gaps
+ * removed.
+ * <p>
+ * If there are hidden columns, and option {@ignoreHidden} is selected, then
+ * only visible positions of the sequence are included, and a mapping is also
+ * constructed from the returned string positions to the true sequence
+ * positions.
+ * <p>
+ * Note we have to do this each time {@code findNext} or {@code findAll} is
+ * called, in case the alignment, selection group or hidden columns have
+ * changed. In particular, if the sequence at offset {@code sequenceIndex} in
+ * the alignment is (no longer) in the selection group, search is advanced to
+ * the next sequence that is.
+ * <p>
+ * Sets sequence string to the empty string if there are no more sequences (in
+ * selection group if any) at or after {@code sequenceIndex}.
+ * <p>
+ * Returns true if a sequence could be found, false if end of alignment was
+ * reached
*
- * @param sequence
- * @param column
+ * @param ignoreHidden
* @return
*/
- protected Range getNextVisibleSequenceRegion(SequenceI sequence,
- final int column)
+ private boolean getSequence(boolean ignoreHidden)
{
AlignmentI alignment = viewport.getAlignment();
- VisibleContigsIterator visibleRegions = alignment.getHiddenColumns()
- .getVisContigsIterator(column, alignment.getWidth(),
- false);
- if (!visibleRegions.hasNext())
+ if (sequenceIndex >= alignment.getHeight())
+ {
+ seqToSearch = "";
+ return false;
+ }
+ SequenceI seq = alignment.getSequenceAt(sequenceIndex);
+ SequenceGroup selection = viewport.getSelectionGroup();
+ if (selection != null && !selection.contains(seq))
{
- // off the end of the sequence - force search to next sequence
- columnIndex = sequence.getLength();
- return null;
+ if (!nextSequence(ignoreHidden))
+ {
+ return false;
+ }
+ seq = alignment.getSequenceAt(sequenceIndex);
}
- int[] visible = visibleRegions.next();
- int seqColStart = Math.max(column, visible[0]);
- int seqColEnd = visible[1];
- // end residue of region (next residue if end position is gapped)
- int endSeqPos = sequence.findPosition(visible[1]);
- if (Comparison.isGap(sequence.getCharAt(visible[1])))
+ String seqString = null;
+ if (ignoreHidden)
{
- endSeqPos--;
+ seqString = getVisibleSequence(seq);
}
- while (visibleRegions.hasNext())
+ else
{
- visible = visibleRegions.next();
- int startSeqPos = sequence.findPosition(visible[0]);
- if (startSeqPos - endSeqPos > 1)
+ int startCol = 0;
+ int endCol = seq.getLength() - 1;
+ this.searchedSequenceStartPosition = seq.getStart();
+ if (selection != null)
{
- // this visible region is not contiguous - ignore it
- break;
+ startCol = selection.getStartRes();
+ endCol = Math.min(endCol, selection.getEndRes());
+ this.searchedSequenceStartPosition = seq.findPosition(startCol);
}
- endSeqPos = sequence.findPosition(visible[1]);
- seqColEnd = visible[1];
+ seqString = seq.getSequenceAsString(startCol, endCol + 1);
}
- seqColEnd = Math.min(sequence.getLength() - 1, seqColEnd);
/*
- * restrict search to selected region if there is one
+ * remove gaps; note that even if this leaves an empty string, we 'search'
+ * the sequence anyway (for possible match on name or description)
*/
- SequenceGroup selection = viewport.getSelectionGroup();
- if (selection != null)
+ String ungapped = AlignSeq.extractGaps(Comparison.GapChars, seqString);
+ this.seqToSearch = ungapped;
+
+ return true;
+ }
+
+ /**
+ * Returns a string consisting of only the visible residues of {@code seq} from
+ * alignment column {@ fromColumn}, restricted to the current selection region
+ * if there is one.
+ * <p>
+ * As a side-effect, also computes the mapping from the true sequence positions
+ * to the positions (1, 2, ...) of the returned sequence. This is to allow
+ * search matches in the visible sequence to be converted to sequence positions.
+ *
+ * @param seq
+ * @return
+ */
+ private String getVisibleSequence(SequenceI seq)
+ {
+ int seqStartCol = seq.findIndex(seq.getStart());
+ int seqEndCol = seq.findIndex(seq.getStart() + seq.getLength() - 1);
+ Iterator<int[]> visibleColumns = viewport.getViewAsVisibleContigs(true);
+ StringBuilder visibleSeq = new StringBuilder(seqEndCol - seqStartCol);
+ List<int[]> fromRanges = new ArrayList<>();
+
+ while (visibleColumns.hasNext())
{
- int selectionStart = selection.getStartRes();
- int selectionEnd = selection.getEndRes();
- if (selectionStart > seqColEnd || selectionEnd < seqColStart)
+ int[] range = visibleColumns.next();
+ if (range[0] > seqEndCol)
+ {
+ // beyond the end of the sequence
+ break;
+ }
+ if (range[1] < seqStartCol)
+ {
+ // before the start of the sequence
+ continue;
+ }
+ String subseq = seq.getSequenceAsString(range[0], range[1] + 1);
+ String ungapped = AlignSeq.extractGaps(Comparison.GapChars, subseq);
+ visibleSeq.append(ungapped);
+ if (!ungapped.isEmpty())
{
/*
- * sequence region doesn't overlap selection region
+ * visible region includes at least one non-gap character,
+ * so add the range to the mapping being constructed
*/
- columnIndex = seqColEnd + 1;
- return null;
+ int seqResFrom = seq.findPosition(range[0]);
+ int seqResTo = seq.findPosition(range[1]);
+ fromRanges.add(new int[] { seqResFrom, seqResTo });
}
- seqColStart = Math.max(seqColStart, selectionStart);
- seqColEnd = Math.min(seqColEnd, selectionEnd);
}
- return new Range(seqColStart, seqColEnd);
+ /*
+ * construct the mapping
+ * from: visible sequence positions 1..length
+ * to: true residue positions of the alignment sequence
+ */
+ List<int[]> toRange = Arrays
+ .asList(new int[]
+ { 1, visibleSeq.length() });
+ searchedSequenceMap = new MapList(fromRanges, toRange, 1, 1);
+
+ return visibleSeq.toString();
}
/**
- * Finds the next match in the given sequence, starting at column at
- * <code>columnIndex</code>. Answers true if a match is found, else false. If
- * a match is found, <code>columnIndex</code> is advanced to the column after
- * the start of the matched region, ready for a search from the next position.
+ * Advances the search to the next sequence in the alignment. Sequences not in
+ * the current selection group (if there is one) are skipped. The (sub-)sequence
+ * to be searched is extracted, gaps removed, and saved, or set to null if there
+ * are no more sequences to search.
+ * <p>
+ * Returns true if a sequence could be found, false if end of alignment was
+ * reached
*
- * @param seq
+ * @param ignoreHidden
+ */
+ private boolean nextSequence(boolean ignoreHidden)
+ {
+ sequenceIndex++;
+ residueIndex = -1;
+
+ return getSequence(ignoreHidden);
+ }
+
+ /**
+ * Finds the next match in the given sequence, starting at offset
+ * {@code residueIndex}. Answers true if a match is found, else false.
+ * <p>
+ * If a match is found, {@code residueIndex} is advanced to the position after
+ * the start of the matched region, ready for the next search.
+ * <p>
+ * If no match is found, {@code sequenceIndex} is advanced ready to search the
+ * next sequence.
+ *
+ * @param seqToSearch
* @param searchString
* @param searchPattern
* @param matchDescription
+ * @param ignoreHidden
* @return
*/
- protected boolean findNextMatch(SequenceI seq, String searchString,
- Regex searchPattern, boolean matchDescription)
+ protected boolean findNextMatch(String searchString,
+ Regex searchPattern, boolean matchDescription,
+ boolean ignoreHidden)
{
- SequenceGroup selection = viewport.getSelectionGroup();
- if (selection != null && !selection.contains(seq))
- {
- /*
- * this sequence is not in the selection - advance to next sequence
- */
- return false;
- }
-
- if (columnIndex < 0)
+ if (residueIndex < 0)
{
/*
* at start of sequence; try find by residue number, in sequence id,
* or (optionally) in sequence description
*/
- if (doNonMotifSearches(seq, searchString, searchPattern,
+ if (doNonMotifSearches(searchString, searchPattern,
matchDescription))
{
return true;
/*
* search for next match in sequence string
*/
- int end = seq.getLength();
- while (columnIndex < end)
+ int end = seqToSearch.length();
+ while (residueIndex < end)
{
- if (searchNextVisibleRegion(seq, searchPattern))
+ boolean matched = searchPattern.searchFrom(seqToSearch, residueIndex);
+ if (matched)
{
- return true;
+ if (recordMatch(searchPattern, ignoreHidden))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ residueIndex = Integer.MAX_VALUE;
}
- }
- return false;
- }
-
- /**
- * Searches the sequence, starting from <code>columnIndex</code>, and adds the
- * next match (if any) to <code>searchResults</code>. The search is restricted
- * to the next visible column region, and to the <code>selection</code> region
- * if there is one. Answers true if a match is added, else false.
- *
- * @param seq
- * @param searchPattern
- * @return
- */
- protected boolean searchNextVisibleRegion(SequenceI seq, Regex searchPattern)
- {
- Range visible = getNextVisibleSequenceRegion(seq, columnIndex);
- if (visible == null)
- {
- return false;
- }
- String seqString = seq.getSequenceAsString(visible.start, visible.end + 1);
- String noGaps = AlignSeq.extractGaps(Comparison.GapChars, seqString);
-
- if (searchPattern.search(noGaps))
- {
- int sequenceStartPosition = seq.findPosition(visible.start);
- recordMatch(seq, searchPattern, sequenceStartPosition);
- return true;
- }
- else
- {
- /*
- * no match - advance columnIndex past this visible region
- * so the next visible region (if any) is searched next
- */
- columnIndex = visible.end + 1;
}
+ nextSequence(ignoreHidden);
return false;
}
/**
* Adds the match held in the <code>searchPattern</code> Regex to the
* <code>searchResults</code>, unless it is a subregion of the last match
- * recorded. <code>columnIndex</code> is advanced to the position after the
+ * recorded. <code>residueIndex</code> is advanced to the position after the
* start of the matched region, ready for the next search. Answers true if a
* match was added, else false.
+ * <p>
+ * Matches that lie entirely within hidden regions of the alignment are not
+ * added.
*
- * @param seq
* @param searchPattern
- * @param firstResiduePosition
+ * @param ignoreHidden
* @return
*/
- protected boolean recordMatch(SequenceI seq, Regex searchPattern,
- int firstResiduePosition)
+ protected boolean recordMatch(Regex searchPattern, boolean ignoreHidden)
{
+ SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
+
/*
- * get start/end of the match in sequence coordinates
+ * convert start/end of the match to sequence coordinates
*/
int offset = searchPattern.matchedFrom();
- int matchStartPosition = firstResiduePosition + offset;
+ int matchStartPosition = this.searchedSequenceStartPosition + offset;
int matchEndPosition = matchStartPosition
+ searchPattern.charsMatched() - 1;
/*
- * update columnIndex to next column after the start of the match
+ * update residueIndex to next position after the start of the match
* (findIndex returns a value base 1, columnIndex is held base 0)
*/
- columnIndex = seq.findIndex(matchStartPosition);
+ residueIndex += offset + 1;
+
+ /*
+ * return false if the match is entirely in a hidden region
+ */
+ if (allHidden(seq, matchStartPosition, matchEndPosition))
+ {
+ return false;
+ }
/*
* check that this match is not a subset of the previous one (JAL-2302)
if (lastMatch == null || !lastMatch.contains(seq, matchStartPosition,
matchEndPosition))
{
- searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+ addMatch(seq, matchStartPosition, matchEndPosition, ignoreHidden);
return true;
}
}
/**
+ * Adds one match to the stored list. If hidden residues are being skipped, then
+ * the match may need to be split into contiguous positions of the sequence (so
+ * it does not include skipped residues).
+ *
+ * @param seq
+ * @param matchStartPosition
+ * @param matchEndPosition
+ * @param ignoreHidden
+ */
+ private void addMatch(SequenceI seq, int matchStartPosition,
+ int matchEndPosition, boolean ignoreHidden)
+ {
+ if (!ignoreHidden)
+ {
+ /*
+ * simple case
+ */
+ searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+ return;
+ }
+
+ /*
+ * get start-end contiguous ranges in underlying sequence
+ */
+ int[] truePositions = searchedSequenceMap
+ .locateInFrom(matchStartPosition, matchEndPosition);
+ for (int i = 0; i < truePositions.length - 1; i += 2)
+ {
+ searchResults.addResult(seq, truePositions[i], truePositions[i + 1]);
+ }
+ }
+
+ /**
+ * Returns true if all residues are hidden, else false
+ *
+ * @param seq
+ * @param fromPos
+ * @param toPos
+ * @return
+ */
+ private boolean allHidden(SequenceI seq, int fromPos, int toPos)
+ {
+ if (!viewport.hasHiddenColumns())
+ {
+ return false;
+ }
+ for (int res = fromPos; res <= toPos; res++)
+ {
+ if (isVisible(seq, res))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Does searches other than for residue patterns. Currently this includes
* <ul>
* <li>find residue by position (if search string is a number)</li>
* </ul>
* Answers true if a match is found, else false.
*
- * @param seq
* @param searchString
* @param searchPattern
* @param includeDescription
* @return
*/
- protected boolean doNonMotifSearches(SequenceI seq, String searchString,
+ protected boolean doNonMotifSearches(String searchString,
Regex searchPattern, boolean includeDescription)
{
+ SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
+
/*
* position sequence search to start of sequence
*/
- columnIndex = 0;
-
- if (searchForResidueNumber(seq, searchString))
+ residueIndex = 0;
+ try
{
- return true;
+ int res = Integer.parseInt(searchString);
+ return searchForResidueNumber(seq, res);
+ } catch (NumberFormatException ex)
+ {
+ // search pattern is not a number
}
+
if (searchSequenceName(seq, searchPattern))
{
return true;
String desc = seq.getDescription();
if (desc != null && searchPattern.search(desc) && !idMatches.contains(seq))
{
- idMatches.addElement(seq);
+ idMatches.add(seq);
return true;
}
return false;
{
if (searchPattern.search(seq.getName()) && !idMatches.contains(seq))
{
- idMatches.addElement(seq);
+ idMatches.add(seq);
return true;
}
return false;
}
/**
- * Tries to interpret the search string as a residue position, and if valid,
- * adds the position to the search results and returns true, else answers
- * false
+ * If the residue position is valid for the sequence, and in a visible column,
+ * adds the position to the search results and returns true, else answers false.
+ *
+ * @param seq
+ * @param resNo
+ * @return
*/
- protected boolean searchForResidueNumber(SequenceI seq, String searchString)
+ protected boolean searchForResidueNumber(SequenceI seq, int resNo)
{
- try
+ if (seq.getStart() <= resNo && seq.getEnd() >= resNo)
{
- int res = Integer.parseInt(searchString);
- if (seq.getStart() <= res && seq.getEnd() >= res)
+ if (isVisible(seq, resNo))
{
- searchResults.addResult(seq, res, res);
+ searchResults.addResult(seq, resNo, resNo);
return true;
}
- } catch (NumberFormatException ex)
- {
}
return false;
}
- /* (non-Javadoc)
- * @see jalview.analysis.FinderI#getIdMatch()
+ /**
+ * Returns true if the residue is in a visible column, else false
+ *
+ * @param seq
+ * @param res
+ * @return
*/
+ private boolean isVisible(SequenceI seq, int res)
+ {
+ if (!viewport.hasHiddenColumns())
+ {
+ return true;
+ }
+ int col = seq.findIndex(res); // base 1
+ return viewport.getAlignment().getHiddenColumns().isVisible(col - 1); // base 0
+ }
+
@Override
- public Vector<SequenceI> getIdMatches()
+ public List<SequenceI> getIdMatches()
{
return idMatches;
}
- /* (non-Javadoc)
- * @see jalview.analysis.FinderI#getSearchResults()
- */
@Override
public SearchResultsI getSearchResults()
{
/**
* Performs a find for the given search string (interpreted as a regular
* expression). Search may optionally be case-sensitive, and may optionally
- * including match in sequence description (sequence id is always searched).
- * If the viewport has an active selection, then the find is restricted to the
- * selection region. Sequences matched by id or description can be retrieved
- * by getIdMatches(), and matched residue patterns by getSearchResults().
+ * including match in sequence description (sequence id is always searched). If
+ * the viewport has an active selection, then the find is restricted to the
+ * selection region. Sequences matched by id or description can be retrieved by
+ * getIdMatches(), and matched residue patterns by getSearchResults().
+ * <p>
+ * If {@code ignoreHidden} is true, then any residues in hidden columns are
+ * ignored (skipped) when matching, so for example pattern {@code KRT} would
+ * match sequence {@code KRqmT} (where {@code qm} are in hidden columns).
+ * <p>
+ * Matches of entirely hidden patterns are not returned. Matches that span
+ * hidden regions on one or both sides may be returned.
*
* @param theSearchString
* @param caseSensitive
* @param searchDescription
+ * @param ignoreHidden
* @return
*/
void findAll(String theSearchString, boolean caseSensitive,
- boolean searchDescription);
+ boolean searchDescription, boolean ignoreHidden);
/**
* Finds the next match for the given search string (interpreted as a regular
* expression), starting from the position after the last match found. Search
* may optionally be case-sensitive, and may optionally including match in
- * sequence description (sequence id is always searched). If the viewport has
- * an active selection, then the find is restricted to the selection region.
+ * sequence description (sequence id is always searched). If the viewport has an
+ * active selection, then the find is restricted to the selection region.
* Sequences matched by id or description can be retrieved by getIdMatches(),
* and matched residue patterns by getSearchResults().
+ * <p>
+ * If {@code ignoreHidden} is true, any hidden residues are skipped (matches may
+ * span them). If false, they are included for matching purposes. In either
+ * cases, entirely hidden matches are not returned.
*
* @param theSearchString
* @param caseSensitive
* @param searchDescription
+ * @param ignoreHidden
* @return
*/
void findNext(String theSearchString, boolean caseSensitive,
- boolean searchDescription);
+ boolean searchDescription, boolean ignoreHidden);
/**
* Returns the (possibly empty) list of sequences matched on sequence name or
boolean doSearchDescription = searchDescription.getState();
if (doFindAll)
{
- finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+ finder.findAll(searchString, isCaseSensitive, doSearchDescription,
+ false);
}
else
{
- finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+ finder.findNext(searchString, isCaseSensitive, doSearchDescription,
+ false);
}
searchResults = finder.getSearchResults();
private void jbInit() throws Exception
{
- txt_search = new JvCacheableInputBox<>(getCacheKey());
+ txt_search = new JvCacheableInputBox<>(getCacheKey(), 45);
populateCmbSearchTargetOptions();
Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800
: getTempUserPrefs().get("FTSPanel.width");
}
/**
- * DOCUMENT ME!
+ * Opens a Finder dialog
*
* @param e
- * DOCUMENT ME!
*/
@Override
public void findMenuItem_actionPerformed(ActionEvent e)
{
- new Finder();
+ new Finder(alignPanel);
}
/**
private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
- FILTER_BY_ANN_CACHE_KEY);
+ FILTER_BY_ANN_CACHE_KEY, 23);
public SearchPanel(AnnotationColumnChooser aColChooser)
{
this.setBorder(new TitledBorder(
MessageManager.getString("label.search_filter")));
- searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
searchBox.setToolTipText(
MessageManager.getString("info.enter_search_text_here"));
searchBox.getEditor().getEditorComponent()
import jalview.datamodel.SequenceI;
import jalview.jbgui.GFinder;
import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
private static final int MIN_HEIGHT = 120;
- private static final int MY_HEIGHT = 120;
+ private static final int MY_HEIGHT = 150;
private static final int MY_WIDTH = 400;
private SearchResultsI searchResults;
- /*
- * true if we only search a given alignment view
- */
- private boolean focusfixed;
-
- /**
- * Creates a new Finder object with no associated viewport or panel. Each Find
- * or Find Next action will act on whichever viewport has focus at the time.
- */
- public Finder()
- {
- this(null, null);
- }
-
/**
- * Constructor given an associated viewport and alignment panel. Constructs
- * and displays an internal frame where the user can enter a search string.
+ * Constructor given an associated alignment panel. Constructs and displays an
+ * internal frame where the user can enter a search string.
*
- * @param viewport
* @param alignPanel
*/
- public Finder(AlignmentViewport viewport, AlignmentPanel alignPanel)
+ public Finder(AlignmentPanel alignPanel)
{
- av = viewport;
+ av = alignPanel.getAlignViewport();
ap = alignPanel;
finders = new HashMap<>();
- focusfixed = viewport != null;
frame = new JInternalFrame();
frame.setContentPane(this);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
}
});
addEscapeHandler();
+
Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
MY_WIDTH, MY_HEIGHT);
frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
/**
* if !focusfixed and not in a desktop environment, checks that av and ap are
* valid. Otherwise, gets the topmost alignment window and sets av and ap
- * accordingly
+ * accordingly. Also sets the 'ignore hidden' checkbox disabled if the viewport
+ * has no hidden columns.
*
* @return false if no alignment window was found
*/
boolean getFocusedViewport()
{
- if (focusfixed || Desktop.desktop == null)
+ if (Desktop.desktop == null)
{
if (ap != null && av != null)
{
{
av = ((AlignFrame) alignFrame).viewport;
ap = ((AlignFrame) alignFrame).alignPanel;
+ ignoreHidden.setEnabled(av.hasHiddenColumns());
return true;
}
}
boolean isCaseSensitive = caseSensitive.isSelected();
boolean doSearchDescription = searchDescription.isSelected();
+ boolean skipHidden = ignoreHidden.isSelected();
if (doFindAll)
{
- finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+ finder.findAll(searchString, isCaseSensitive, doSearchDescription,
+ skipHidden);
}
else
{
- finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+ finder.findNext(searchString, isCaseSensitive, doSearchDescription,
+ skipHidden);
}
searchResults = finder.getSearchResults();
ap.alignFrame.requestFocus();
}
}
+
+ @Override
+ protected void paintComponent(Graphics g)
+ {
+ /*
+ * enable 'hidden regions' option only if
+ * 'top' viewport has hidden columns
+ */
+ getFocusedViewport();
+ super.paintComponent(g);
+ }
}
if (c != null && c instanceof AlignFrame)
{
AlignFrame af = (AlignFrame) c;
- new Finder(af.viewport, af.alignPanel);
+ new Finder(af.alignPanel);
}
}
};
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
return enterWasPressed;
}
- public JvCacheableInputBox(String newCacheKey)
+ /**
+ * Constructor given the key to cached values, and the (approximate) length in
+ * characters of the input field
+ *
+ * @param newCacheKey
+ * @param length
+ */
+ public JvCacheableInputBox(String newCacheKey, int length)
{
super();
this.cacheKey = newCacheKey;
setEditable(true);
- addKeyListener(new KeyListener()
+ addKeyListener(new KeyAdapter()
{
@Override
}
// let event bubble up
}
-
- @Override
- public void keyReleased(KeyEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void keyPressed(KeyEvent e)
+ });
+ if (length > 0)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++)
{
- // TODO Auto-generated method stub
-
+ sb.append("X");
}
- });
- setPrototypeDisplayValue(
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+ setPrototypeDisplayValue(sb.toString());
+ }
appCache = AppCache.getInstance();
initCachePopupMenu();
initCache(newCacheKey);
import jalview.util.MessageManager;
import java.awt.BorderLayout;
-import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
-import java.awt.Insets;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
public class GFinder extends JPanel
{
- private static final java.awt.Font VERDANA_12 = new java.awt.Font("Verdana", 0,
- 12);
+ private static final java.awt.Font VERDANA_12 = new Font("Verdana",
+ Font.PLAIN, 12);
private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
- protected JButton createFeatures = new JButton();
+ protected JButton createFeatures;
- protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
- getCacheKey());
+ protected JvCacheableInputBox<String> searchBox;
- protected JCheckBox caseSensitive = new JCheckBox();
+ protected JCheckBox caseSensitive;
- protected JCheckBox searchDescription = new JCheckBox();
+ protected JCheckBox searchDescription;
+
+ protected JCheckBox ignoreHidden;
public GFinder()
{
}
}
+ /**
+ * Constructs the widgets and adds them to the layout
+ */
private void jbInit() throws Exception
{
- BorderLayout mainBorderLayout = new BorderLayout();
- this.setLayout(mainBorderLayout);
- mainBorderLayout.setHgap(5);
- mainBorderLayout.setVgap(5);
+ /*
+ * border layout
+ * West: 4 rows
+ * first row 'Find'
+ * remaining rows empty
+ * Center: 4 rows
+ * first row search box
+ * second row 'match case' checkbox
+ * third row 'include description' checkbox
+ * fourth row 'ignore hidden' checkbox
+ * East: four rows
+ * first row 'find next' button
+ * second row 'find all' button
+ * third row 'new feature' button
+ * fourth row empty
+ */
+ this.setLayout(new BorderLayout());
+ JPanel eastPanel = new JPanel();
+ eastPanel.setLayout(new GridLayout(4, 1));
+ this.add(eastPanel, BorderLayout.EAST);
+ JPanel centrePanel = new JPanel();
+ centrePanel.setLayout(new GridLayout(4, 1));
+ this.add(centrePanel, BorderLayout.CENTER);
+ JPanel westPanel = new JPanel();
+ westPanel.setLayout(new GridLayout(4, 1));
+ this.add(westPanel, BorderLayout.WEST);
+
+ /*
+ * 'Find' prompt goes top left
+ */
+ JLabel findLabel = new JLabel(
+ " " + MessageManager.getString("label.find") + " ");
+ findLabel.setFont(VERDANA_12);
+ westPanel.add(findLabel);
+
+ /*
+ * search box
+ */
+ searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
+ searchBox.setFont(VERDANA_12);
+ ((JTextComponent) searchBox.getEditor().getEditorComponent())
+ .addCaretListener(new CaretListener()
+ {
+ @Override
+ public void caretUpdate(CaretEvent e)
+ {
+ textfield_caretUpdate();
+ }
+ });
+ searchBox.getEditor().getEditorComponent()
+ .addKeyListener(new KeyAdapter()
+ {
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+ textfield_keyPressed(e);
+ }
+ });
+ centrePanel.add(searchBox);
- JLabel jLabelFind = new JLabel(MessageManager.getString("label.find"));
- jLabelFind.setFont(VERDANA_12);
+ /*
+ * search options checkboxes
+ */
+ caseSensitive = new JCheckBox();
+ caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
+ caseSensitive.setText(MessageManager.getString("label.match_case"));
+
+ searchDescription = new JCheckBox();
+ searchDescription
+ .setText(MessageManager.getString("label.include_description"));
+ ignoreHidden = new JCheckBox();
+ ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
+ ignoreHidden.setToolTipText(
+ MessageManager.getString("label.ignore_hidden_tooltip"));
+
+ centrePanel.add(caseSensitive);
+ centrePanel.add(searchDescription);
+ centrePanel.add(ignoreHidden);
+
+ /*
+ * action buttons
+ */
JButton findAll = new JButton(
MessageManager.getString("action.find_all"));
findAll.setFont(VERDANA_12);
- findAll.addActionListener(new java.awt.event.ActionListener()
+ findAll.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
findAll_actionPerformed();
}
});
-
JButton findNext = new JButton(
MessageManager.getString("action.find_next"));
findNext.setFont(VERDANA_12);
- findNext.addActionListener(new java.awt.event.ActionListener()
+ findNext.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
findNext_actionPerformed();
}
});
-
- JPanel actionsPanel = new JPanel();
- GridLayout gridLayout1 = new GridLayout();
- actionsPanel.setLayout(gridLayout1);
- gridLayout1.setHgap(0);
- gridLayout1.setRows(3);
- gridLayout1.setVgap(2);
-
+ createFeatures = new JButton();
createFeatures.setEnabled(false);
createFeatures.setFont(VERDANA_12);
- createFeatures.setMargin(new Insets(0, 0, 0, 0));
createFeatures.setText(MessageManager.getString("label.new_feature"));
- createFeatures.addActionListener(new java.awt.event.ActionListener()
+ createFeatures.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
createFeatures_actionPerformed();
}
});
- searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
- ((JTextComponent) searchBox.getEditor().getEditorComponent())
- .addCaretListener(new CaretListener()
- {
- @Override
- public void caretUpdate(CaretEvent e)
- {
- textfield_caretUpdate();
- }
- });
- searchBox.getEditor().getEditorComponent()
- .addKeyListener(new java.awt.event.KeyAdapter()
- {
- @Override
- public void keyPressed(KeyEvent e)
- {
- textfield_keyPressed(e);
- }
- });
-
- caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
- caseSensitive.setText(MessageManager.getString("label.match_case"));
-
- searchDescription
- .setText(MessageManager.getString("label.include_description"));
-
- actionsPanel.add(findNext, null);
- actionsPanel.add(findAll, null);
- actionsPanel.add(createFeatures, null);
- this.add(jLabelFind, java.awt.BorderLayout.WEST);
- this.add(actionsPanel, java.awt.BorderLayout.EAST);
-
- JPanel jPanel2 = new JPanel();
- jPanel2.setPreferredSize(new Dimension(10, 1));
- JPanel jPanel3 = new JPanel();
- jPanel3.setPreferredSize(new Dimension(10, 1));
- JPanel jPanel4 = new JPanel();
- jPanel4.setLayout(new BorderLayout());
- this.add(jPanel2, java.awt.BorderLayout.SOUTH);
- this.add(jPanel3, java.awt.BorderLayout.NORTH);
- this.add(jPanel4, java.awt.BorderLayout.CENTER);
- jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
-
- JPanel optionsPanel = new JPanel();
-
- GridLayout optionsGridLayout = new GridLayout();
- optionsGridLayout.setHgap(0);
- optionsGridLayout.setRows(2);
- optionsGridLayout.setVgap(2);
- optionsPanel.setLayout(optionsGridLayout);
- optionsPanel.add(caseSensitive, null);
- optionsPanel.add(searchDescription, null);
-
- jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
+ eastPanel.add(findNext);
+ eastPanel.add(findAll);
+ eastPanel.add(createFeatures);
}
protected void textfield_keyPressed(KeyEvent e)
}
}
- /**
- * Returns unique key used for storing Finder cache items in the cache data
- * structure
- *
- * @return
- */
- public String getCacheKey()
- {
- return FINDER_CACHE_KEY;
- }
-
}
Cache.applicationProperties.setProperty("PAD_GAPS",
Boolean.FALSE.toString());
- String seqData = "seq1/8-18 ABCD--EF-GHIJI\n" + "seq2 A--BCDefHI\n"
- + "seq3 --bcdEFH\n" + "seq4 aa---aMMMMMaaa\n";
+ //@formatter:off
+ String seqData =
+ "seq1/8-18 ABCD--EF-GHIJI\n" +
+ "seq2 A--BCDefHI\n" +
+ "seq3 --bcdEFH\n" +
+ "seq4 aa---aMMMMMaaa\n";
+ //@formatter:on
af = new FileLoader().LoadFileWaitTillLoaded(seqData,
DataSourceType.PASTE);
av = af.getViewport();
* find next match only
*/
Finder f = new Finder(av);
- f.findNext("E.H", false, false); // 'E, any character, H'
+ f.findNext("E.H", false, false, false); // 'E, any character, H'
// should match seq2 efH only
SearchResultsI sr = f.getSearchResults();
assertEquals(sr.getSize(), 1);
assertEquals(matches.get(0).getEnd(), 7);
f = new Finder(av);
- f.findAll("E.H", false, false); // 'E, any character, H'
+ f.findAll("E.H", false, false, false); // 'E, any character, H'
// should match seq2 efH and seq3 EFH
sr = f.getSearchResults();
assertEquals(sr.getSize(), 2);
/*
* find first match should return seq1 residue 9
*/
- f.findNext("9", false, false);
+ f.findNext("9", false, false, false);
SearchResultsI sr = f.getSearchResults();
assertEquals(sr.getSize(), 1);
List<SearchResultMatchI> matches = sr.getResults();
* find all matches should return seq1 and seq4 (others are too short)
*/
f = new Finder(av);
- f.findAll("9", false, false);
+ f.findAll("9", false, false, false);
sr = f.getSearchResults();
assertEquals(sr.getSize(), 2);
matches = sr.getResults();
* parsing of search string as integer is strict
*/
f = new Finder(av);
- f.findNext(" 9", false, false);
+ f.findNext(" 9", false, false, false);
assertTrue(f.getSearchResults().isEmpty());
}
public void testFindNext()
{
/*
- * start at second sequence; colIndex of -1
+ * start at second sequence; residueIndex of -1
* means sequence id / description is searched
*/
Finder f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
- PA.setValue(f, "columnIndex", -1);
- f.findNext("e", false, false); // matches id
+ PA.setValue(f, "residueIndex", -1);
+ f.findNext("e", false, false, false); // matches id
assertTrue(f.getSearchResults().isEmpty());
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
- // colIndex is now 0 - for use in next find next
+ // residueIndex is now 0 - for use in next find next
// searching A--BCDefHI
- assertEquals(PA.getValue(f, "columnIndex"), 0);
+ assertEquals(PA.getValue(f, "residueIndex"), 0);
f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
- PA.setValue(f, "columnIndex", 0);
- f.findNext("e", false, false); // matches in sequence
+ PA.setValue(f, "residueIndex", 0);
+ f.findNext("e", false, false, false); // matches in sequence
assertTrue(f.getIdMatches().isEmpty());
assertEquals(f.getSearchResults().getSize(), 1);
List<SearchResultMatchI> matches = f.getSearchResults().getResults();
assertSame(matches.get(0).getSequence(), al.getSequenceAt(1));
// still in the second sequence
assertEquals(PA.getValue(f, "sequenceIndex"), 1);
- // next column position to search from is 7
- assertEquals(PA.getValue(f, "columnIndex"), 7);
+ // next residue offset to search from is 5
+ assertEquals(PA.getValue(f, "residueIndex"), 5);
// find next from end of sequence - finds next sequence id
f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
- PA.setValue(f, "columnIndex", 7);
- f.findNext("e", false, false);
+ PA.setValue(f, "residueIndex", 7);
+ f.findNext("e", false, false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(2));
assertTrue(f.getSearchResults().isEmpty());
* find first match only
*/
Finder f = new Finder(av2);
- f.findNext("rAF", false, true);
+ f.findNext("rAF", false, true, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertTrue(f.getSearchResults().isEmpty());
* find all matches
*/
f = new Finder(av2);
- f.findAll("rAF", false, true);
+ f.findAll("rAF", false, true, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
* case sensitive
*/
f = new Finder(av2);
- f.findAll("RAF", true, true);
+ f.findAll("RAF", true, true, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertTrue(f.getSearchResults().isEmpty());
/*
* sequence matches should have no duplicates
*/
- f.findAll("EFH", false, true);
+ f.findAll("EFH", false, true, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
* case insensitive; seq1 occurs twice in sequence id but
* only one match should be returned
*/
- f.findAll("SEQ1", false, false);
+ f.findAll("SEQ1", false, false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(0));
SearchResultsI searchResults = f.getSearchResults();
* case sensitive
*/
f = new Finder(av);
- f.findAll("SEQ1", true, false);
+ f.findAll("SEQ1", true, false, false);
searchResults = f.getSearchResults();
assertTrue(searchResults.isEmpty());
AlignViewportI av2 = new AlignViewport(al2);
al2.addSequence(new Sequence("aBz", "xyzabZpqrAbZ"));
f = new Finder(av2);
- f.findAll("ABZ", false, false);
+ f.findAll("ABZ", false, false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(4));
searchResults = f.getSearchResults();
@Test(groups = "Functional")
public void testFind_findNext()
{
+ // "seq1/8-18 ABCD--EF-GHIJI\n" +
+ // "seq2 A--BCDefHI\n" +
+ // "seq3 --bcdEFH\n" +
+ // "seq4 aa---aMMMMMaaa\n";
/*
* efh should be matched in seq2 only
*/
FinderI f = new Finder(av);
- f.findNext("EfH", false, false);
+ f.findNext("EfH", false, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
SearchResultMatchI match = searchResults.getResults().get(0);
* I should be found in seq1 (twice) and seq2 (once)
*/
f = new Finder(av);
- f.findNext("I", false, false); // find next: seq1/16
+ f.findNext("I", false, false, false); // find next: seq1/16
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 16);
assertEquals(match.getEnd(), 16);
- f.findNext("I", false, false); // find next: seq1/18
+ f.findNext("I", false, false, false); // find next: seq1/18
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 18);
assertEquals(match.getEnd(), 18);
- f.findNext("I", false, false); // find next: seq2/8
+ f.findNext("I", false, false, false); // find next: seq2/8
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 8);
assertEquals(match.getEnd(), 8);
- f.findNext("I", false, false);
+ f.findNext("I", false, false, false);
assertTrue(f.getSearchResults().isEmpty());
/*
* find should reset to start of alignment after a failed search
*/
- f.findNext("I", false, false); // find next: seq1/16
+ f.findNext("I", false, false, false); // find next: seq1/16
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
public void testFind_maximalResultOnly()
{
Finder f = new Finder(av);
- f.findAll("M+", false, false);
+ f.findAll("M+", false, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
SearchResultMatchI match = searchResults.getResults().get(0);
* Test finding all matches of a sequence pattern in an alignment
*/
@Test(groups = "Functional")
- public void testFind_findAll()
+ public void testFindAll()
{
Finder f = new Finder(av);
- f.findAll("EfH", false, false);
+ f.findAll("EfH", false, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
/*
* find all I should find 2 positions in seq1, 1 in seq2
*/
- f.findAll("I", false, false);
+ f.findAll("I", false, false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 3);
match = searchResults.getResults().get(0);
/*
* BC should match seq1/9-10 and seq2/2-3
*/
- f.findAll("BC", true, false);
+ f.findAll("BC", true, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
* bc should match seq3/1-2
*/
f = new Finder(av);
- f.findAll("bc", true, false);
+ f.findAll("bc", true, false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 1);
assertEquals(match.getEnd(), 2);
- f.findAll("bC", true, false);
+ f.findAll("bC", true, false, false);
assertTrue(f.getSearchResults().isEmpty());
}
av.setSelectionGroup(sg);
FinderI f = new Finder(av);
- f.findNext("b", false, false);
+ f.findNext("b", false, false, false);
assertTrue(f.getIdMatches().isEmpty());
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
/*
* a second Find should not return the 'b' in seq3 as outside the selection
*/
- f.findNext("b", false, false);
+ f.findNext("b", false, false, false);
assertTrue(f.getSearchResults().isEmpty());
assertTrue(f.getIdMatches().isEmpty());
f = new Finder(av);
- f.findNext("d", false, false);
+ f.findNext("d", false, false, false);
assertTrue(f.getIdMatches().isEmpty());
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
assertSame(match.getSequence(), al.getSequenceAt(1));
assertEquals(match.getStart(), 4);
assertEquals(match.getEnd(), 4);
- f.findNext("d", false, false);
+ f.findNext("d", false, false, false);
assertTrue(f.getIdMatches().isEmpty());
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
* search for 'e' should match two sequence ids and one residue
*/
Finder f = new Finder(av);
- f.findAll("e", false, false);
+ f.findAll("e", false, false, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
* search for 'Q' should match two sequence ids only
*/
f = new Finder(av);
- f.findAll("Q", false, false);
+ f.findAll("Q", false, false, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
* search for 'I' should match two sequence positions
*/
Finder f = new Finder(av);
- f.findAll("I", false, false);
+ f.findAll("I", false, false, false);
assertTrue(f.getIdMatches().isEmpty());
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
hc.hideColumns(3, 3);
al.setHiddenColumns(hc);
Finder f = new Finder(av);
- f.findAll("aaa", false, false);
+ f.findAll("aaa", false, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
* find the visible D in seq2
*/
f = new Finder(av);
- f.findAll("D", false, false);
+ f.findAll("D", false, false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
* consecutive in the visible columns
*/
f = new Finder(av);
- f.findAll("AD", false, false);
+ f.findAll("AD", false, false, false);
searchResults = f.getSearchResults();
assertTrue(searchResults.isEmpty());
* (first run includes hidden gaps)
*/
f = new Finder(av);
- f.findAll("aaa", false, false);
+ f.findAll("aaa", false, false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
match = searchResults.getResults().get(0);
/*
* hide columns 2-5:
- * find all 'aaa' should find end of seq4 only
- * (hidden columns not all gapped)
+ * find all 'aaa' should match twice in seq4
+ * (first match partly hidden, second all visible)
*/
hc.hideColumns(2, 5);
f = new Finder(av);
- f.findAll("aaa", false, false);
+ f.findAll("aaa", false, false, false);
searchResults = f.getSearchResults();
- assertEquals(searchResults.getSize(), 1);
+ assertEquals(searchResults.getSize(), 2);
match = searchResults.getResults().get(0);
assertSame(match.getSequence(), al.getSequenceAt(3));
+ assertEquals(match.getStart(), 1);
+ assertEquals(match.getEnd(), 3);
+ match = searchResults.getResults().get(1);
+ assertSame(match.getSequence(), al.getSequenceAt(3));
assertEquals(match.getStart(), 9);
assertEquals(match.getEnd(), 11);
/*
* find all 'BE' should not match across hidden columns in seq1
*/
- f.findAll("BE", false, false);
+ f.findAll("BE", false, false, false);
assertTrue(f.getSearchResults().isEmpty());
/*
hc.revealAllHiddenColumns(new ColumnSelection());
hc.hideColumns(8, 13);
f = new Finder(av);
- f.findNext("H", false, false);
+ f.findNext("H", false, false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
* should match seq2/1, seq2/7, not seq3/6
*/
Finder f = new Finder(av);
- f.findAll("[AH]", false, false);
+ f.findAll("[AH]", false, false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
* test Match/Find works first
*/
FinderI f = new Finder(af.getViewport());
- f.findAll("M+", true, false);
+ f.findAll("M+", true, false, false);
assertEquals(
"Finder found different set of results to manually created SearchResults",
sr, f.getSearchResults());
private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
- private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<String>(
- TEST_CACHE_KEY);
+ private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<>(
+ TEST_CACHE_KEY, 20);
@BeforeClass(alwaysRun = true)
private void setUpCache()