1 package jalview.analysis;
\r
5 import jalview.datamodel.*;
\r
10 * Implements the search algorithms for the Find dialog box.
\r
12 SearchResults searchResults;
\r
13 AlignmentI alignment;
\r
14 jalview.datamodel.SequenceGroup selection = null;
\r
15 Vector idMatch = null;
\r
16 boolean caseSensitive = false;
\r
17 boolean findAll = false;
\r
18 com.stevesoft.pat.Regex regex = null;
\r
20 * hold's last-searched position between calles to find(false)
\r
22 int seqIndex = 0, resIndex = 0;
\r
23 public Finder(AlignmentI alignment, SequenceGroup selection)
\r
25 this.alignment = alignment;
\r
26 this.selection = selection;
\r
29 public Finder(AlignmentI alignment, SequenceGroup selectionGroup,
\r
30 int seqIndex, int resIndex)
\r
32 this(alignment, selectionGroup);
\r
33 this.seqIndex = seqIndex;
\r
34 this.resIndex = resIndex;
\r
37 public boolean find(String searchString)
\r
39 boolean hasResults = false;
\r
42 searchString = searchString.toUpperCase();
\r
44 regex = new com.stevesoft.pat.Regex(searchString);
\r
45 searchResults = new SearchResults();
\r
46 idMatch = new Vector();
\r
49 boolean found = false;
\r
51 ////// is the searchString a residue number?
\r
54 int res = Integer.parseInt(searchString);
\r
56 if (selection == null || selection.getSize() < 1)
\r
58 seq = (Sequence) alignment.getSequenceAt(0);
\r
62 seq = (Sequence) (selection.getSequenceAt(0));
\r
65 searchResults.addResult(seq, res, res);
\r
68 catch (NumberFormatException ex)
\r
72 ///////////////////////////////////////////////
\r
74 int end = alignment.getHeight();
\r
76 if (selection != null)
\r
78 if ( (selection.getSize() < 1) ||
\r
79 ( (selection.getEndRes() - selection.getStartRes()) < 2))
\r
85 while (!found && (seqIndex < end))
\r
87 seq = (Sequence) alignment.getSequenceAt(seqIndex);
\r
89 if ( (selection != null) && !selection.getSequences(null).contains(seq))
\r
97 item = seq.getSequenceAsString();
\r
98 // JBPNote - check if this toUpper which is present in the application implementation makes a difference
\r
99 //if(!caseSensitive)
\r
100 // item = item.toUpperCase();
\r
102 if ( (selection != null) &&
\r
103 (selection.getEndRes() < alignment.getWidth() - 1))
\r
105 item = item.substring(0, selection.getEndRes() + 1);
\r
108 ///Shall we ignore gaps???? - JBPNote: Add Flag for forcing this or not
\r
109 StringBuffer noGapsSB = new StringBuffer();
\r
110 int insertCount = 0;
\r
111 Vector spaces = new Vector();
\r
113 for (int j = 0; j < item.length(); j++)
\r
115 if (!jalview.util.Comparison.isGap(item.charAt(j)))
\r
117 noGapsSB.append(item.charAt(j));
\r
118 spaces.addElement(new Integer(insertCount));
\r
126 String noGaps = noGapsSB.toString();
\r
128 for (int r = resIndex; r < noGaps.length(); r++)
\r
131 if (regex.searchFrom(noGaps, r))
\r
133 resIndex = regex.matchedFrom();
\r
135 if ( (selection != null) &&
\r
137 Integer.parseInt(spaces.elementAt(resIndex).toString())) <
\r
138 selection.getStartRes()))
\r
143 int sres = seq.findPosition(resIndex +
\r
144 Integer.parseInt(spaces.elementAt(
\r
147 int eres = seq.findPosition(regex.matchedTo() - 1 +
\r
148 Integer.parseInt(spaces.elementAt(regex.
\r
152 searchResults.addResult(seq, sres, eres);
\r
156 // thats enough, break and display the result
\r
178 for (int id = 0; id < alignment.getHeight(); id++)
\r
180 if (regex.search(alignment.getSequenceAt(id).getName()))
\r
182 idMatch.addElement(alignment.getSequenceAt(id));
\r
190 * @return the alignment
\r
192 public AlignmentI getAlignment()
\r
198 * @param alignment the alignment to set
\r
200 public void setAlignment(AlignmentI alignment)
\r
202 this.alignment = alignment;
\r
206 * @return the caseSensitive
\r
208 public boolean isCaseSensitive()
\r
210 return caseSensitive;
\r
214 * @param caseSensitive the caseSensitive to set
\r
216 public void setCaseSensitive(boolean caseSensitive)
\r
218 this.caseSensitive = caseSensitive;
\r
222 * @return the findAll
\r
224 public boolean isFindAll()
\r
230 * @param findAll the findAll to set
\r
232 public void setFindAll(boolean findAll)
\r
234 this.findAll = findAll;
\r
238 * @return the selection
\r
240 public jalview.datamodel.SequenceGroup getSelection()
\r
246 * @param selection the selection to set
\r
248 public void setSelection(jalview.datamodel.SequenceGroup selection)
\r
250 this.selection = selection;
\r
254 * @return the idMatch
\r
256 public Vector getIdMatch()
\r
262 * @return the regex
\r
264 public com.stevesoft.pat.Regex getRegex()
\r
270 * @return the searchResults
\r
272 public SearchResults getSearchResults()
\r
274 return searchResults;
\r
278 * @return the resIndex
\r
280 public int getResIndex()
\r
286 * @param resIndex the resIndex to set
\r
288 public void setResIndex(int resIndex)
\r
290 this.resIndex = resIndex;
\r
294 * @return the seqIndex
\r
296 public int getSeqIndex()
\r
302 * @param seqIndex the seqIndex to set
\r
304 public void setSeqIndex(int seqIndex)
\r
306 this.seqIndex = seqIndex;
\r