1 package jalview.analysis;
5 import jalview.datamodel.*;
10 * Implements the search algorithms for the Find dialog box.
12 SearchResults searchResults;
14 jalview.datamodel.SequenceGroup selection = null;
15 Vector idMatch = null;
16 boolean caseSensitive = false;
17 boolean findAll = false;
18 com.stevesoft.pat.Regex regex = null;
20 * hold's last-searched position between calles to find(false)
22 int seqIndex = 0, resIndex = 0;
23 public Finder(AlignmentI alignment, SequenceGroup selection)
25 this.alignment = alignment;
26 this.selection = selection;
29 public Finder(AlignmentI alignment, SequenceGroup selectionGroup,
30 int seqIndex, int resIndex)
32 this(alignment, selectionGroup);
33 this.seqIndex = seqIndex;
34 this.resIndex = resIndex;
37 public boolean find(String searchString)
39 boolean hasResults = false;
42 searchString = searchString.toUpperCase();
44 regex = new com.stevesoft.pat.Regex(searchString);
45 searchResults = new SearchResults();
46 idMatch = new Vector();
49 boolean found = false;
51 ////// is the searchString a residue number?
54 int res = Integer.parseInt(searchString);
56 if (selection == null || selection.getSize() < 1)
58 seq = (Sequence) alignment.getSequenceAt(0);
62 seq = (Sequence) (selection.getSequenceAt(0));
65 searchResults.addResult(seq, res, res);
68 catch (NumberFormatException ex)
72 ///////////////////////////////////////////////
74 int end = alignment.getHeight();
76 if (selection != null)
78 if ( (selection.getSize() < 1) ||
79 ( (selection.getEndRes() - selection.getStartRes()) < 2))
85 while (!found && (seqIndex < end))
87 seq = (Sequence) alignment.getSequenceAt(seqIndex);
89 if ( (selection != null) && !selection.getSequences(null).contains(seq))
97 item = seq.getSequenceAsString();
99 item = item.toUpperCase();
101 if ( (selection != null) &&
102 (selection.getEndRes() < alignment.getWidth() - 1))
104 item = item.substring(0, selection.getEndRes() + 1);
107 ///Shall we ignore gaps???? - JBPNote: Add Flag for forcing this or not
108 StringBuffer noGapsSB = new StringBuffer();
110 Vector spaces = new Vector();
112 for (int j = 0; j < item.length(); j++)
114 if (!jalview.util.Comparison.isGap(item.charAt(j)))
116 noGapsSB.append(item.charAt(j));
117 spaces.addElement(new Integer(insertCount));
125 String noGaps = noGapsSB.toString();
127 for (int r = resIndex; r < noGaps.length(); r++)
130 if (regex.searchFrom(noGaps, r))
132 resIndex = regex.matchedFrom();
134 if ( (selection != null) &&
136 Integer.parseInt(spaces.elementAt(resIndex).toString())) <
137 selection.getStartRes()))
142 int sres = seq.findPosition(resIndex +
143 Integer.parseInt(spaces.elementAt(
146 int eres = seq.findPosition(regex.matchedTo() - 1 +
147 Integer.parseInt(spaces.elementAt(regex.
151 searchResults.addResult(seq, sres, eres);
155 // thats enough, break and display the result
177 for (int id = 0; id < alignment.getHeight(); id++)
179 if (regex.search(alignment.getSequenceAt(id).getName()))
181 idMatch.addElement(alignment.getSequenceAt(id));
189 * @return the alignment
191 public AlignmentI getAlignment()
197 * @param alignment the alignment to set
199 public void setAlignment(AlignmentI alignment)
201 this.alignment = alignment;
205 * @return the caseSensitive
207 public boolean isCaseSensitive()
209 return caseSensitive;
213 * @param caseSensitive the caseSensitive to set
215 public void setCaseSensitive(boolean caseSensitive)
217 this.caseSensitive = caseSensitive;
221 * @return the findAll
223 public boolean isFindAll()
229 * @param findAll the findAll to set
231 public void setFindAll(boolean findAll)
233 this.findAll = findAll;
237 * @return the selection
239 public jalview.datamodel.SequenceGroup getSelection()
245 * @param selection the selection to set
247 public void setSelection(jalview.datamodel.SequenceGroup selection)
249 this.selection = selection;
253 * @return the idMatch
255 public Vector getIdMatch()
263 public com.stevesoft.pat.Regex getRegex()
269 * @return the searchResults
271 public SearchResults getSearchResults()
273 return searchResults;
277 * @return the resIndex
279 public int getResIndex()
285 * @param resIndex the resIndex to set
287 public void setResIndex(int resIndex)
289 this.resIndex = resIndex;
293 * @return the seqIndex
295 public int getSeqIndex()
301 * @param seqIndex the seqIndex to set
303 public void setSeqIndex(int seqIndex)
305 this.seqIndex = seqIndex;