1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis; |
22 |
|
|
23 |
|
import jalview.api.AlignViewportI; |
24 |
|
import jalview.api.FinderI; |
25 |
|
import jalview.datamodel.AlignmentI; |
26 |
|
import jalview.datamodel.Range; |
27 |
|
import jalview.datamodel.SearchResultMatchI; |
28 |
|
import jalview.datamodel.SearchResults; |
29 |
|
import jalview.datamodel.SearchResultsI; |
30 |
|
import jalview.datamodel.SequenceGroup; |
31 |
|
import jalview.datamodel.SequenceI; |
32 |
|
import jalview.datamodel.VisibleContigsIterator; |
33 |
|
import jalview.util.Comparison; |
34 |
|
|
35 |
|
import java.util.List; |
36 |
|
import java.util.Vector; |
37 |
|
|
38 |
|
import com.stevesoft.pat.Regex; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
|
|
| 98.8% |
Uncovered Elements: 2 (171) |
Complexity: 51 |
Complexity Density: 0.48 |
|
43 |
|
public class Finder implements FinderI |
44 |
|
{ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private SearchResultsI searchResults; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private Vector<SequenceI> idMatches; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private AlignViewportI viewport; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private int sequenceIndex; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private int columnIndex; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@param |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
77 |
31 |
public Finder(AlignViewportI av)... |
78 |
|
{ |
79 |
31 |
this.viewport = av; |
80 |
31 |
this.sequenceIndex = 0; |
81 |
31 |
this.columnIndex = -1; |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
84 |
22 |
@Override... |
85 |
|
public void findAll(String theSearchString, boolean matchCase, |
86 |
|
boolean searchDescription) |
87 |
|
{ |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
22 |
sequenceIndex = 0; |
92 |
22 |
columnIndex = -1; |
93 |
|
|
94 |
22 |
doFind(theSearchString, matchCase, searchDescription, true); |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
22 |
sequenceIndex = 0; |
100 |
22 |
columnIndex = -1; |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
103 |
18 |
@Override... |
104 |
|
public void findNext(String theSearchString, boolean matchCase, |
105 |
|
boolean searchDescription) |
106 |
|
{ |
107 |
18 |
doFind(theSearchString, matchCase, searchDescription, false); |
108 |
|
|
109 |
18 |
if (searchResults.isEmpty() && idMatches.isEmpty()) |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
3 |
sequenceIndex = 0; |
115 |
3 |
columnIndex = -1; |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
@param |
124 |
|
@param |
125 |
|
@param |
126 |
|
|
|
|
| 92.9% |
Uncovered Elements: 2 (28) |
Complexity: 8 |
Complexity Density: 0.44 |
|
127 |
40 |
protected void doFind(String theSearchString, boolean matchCase,... |
128 |
|
boolean searchDescription, boolean findAll) |
129 |
|
{ |
130 |
40 |
String searchString = matchCase ? theSearchString |
131 |
|
: theSearchString.toUpperCase(); |
132 |
40 |
Regex searchPattern = new Regex(searchString); |
133 |
40 |
searchPattern.setIgnoreCase(!matchCase); |
134 |
|
|
135 |
40 |
searchResults = new SearchResults(); |
136 |
40 |
idMatches = new Vector<>(); |
137 |
|
|
138 |
40 |
SequenceGroup selection = viewport.getSelectionGroup(); |
139 |
40 |
if (selection != null && selection.getSize() < 1) |
140 |
|
{ |
141 |
0 |
selection = null; |
142 |
|
} |
143 |
|
|
144 |
40 |
AlignmentI alignment = viewport.getAlignment(); |
145 |
40 |
int end = alignment.getHeight(); |
146 |
|
|
147 |
202 |
while (sequenceIndex < end) |
148 |
|
{ |
149 |
177 |
SequenceI seq = alignment.getSequenceAt(sequenceIndex); |
150 |
177 |
boolean found = findNextMatch(seq, searchString, searchPattern, |
151 |
|
searchDescription); |
152 |
177 |
if (found && !findAll) |
153 |
|
{ |
154 |
15 |
return; |
155 |
|
} |
156 |
162 |
if (!found) |
157 |
|
{ |
158 |
108 |
sequenceIndex++; |
159 |
108 |
columnIndex = -1; |
160 |
|
} |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 6 |
Complexity Density: 0.3 |
|
172 |
170 |
protected Range getNextVisibleSequenceRegion(SequenceI sequence,... |
173 |
|
int column) |
174 |
|
{ |
175 |
170 |
int seqColStart = column; |
176 |
170 |
int seqColEnd = sequence.getLength() - 1; |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
170 |
AlignmentI alignment = viewport.getAlignment(); |
183 |
170 |
VisibleContigsIterator visibleRegions = alignment.getHiddenColumns() |
184 |
|
.getVisContigsIterator(column, alignment.getWidth(), |
185 |
|
false); |
186 |
170 |
int[] visible = visibleRegions.hasNext() ? visibleRegions.next() : null; |
187 |
170 |
if (visible == null) |
188 |
|
{ |
189 |
2 |
columnIndex = seqColEnd + 1; |
190 |
2 |
return null; |
191 |
|
} |
192 |
168 |
seqColStart = Math.max(seqColStart, visible[0]); |
193 |
168 |
seqColEnd = Math.min(seqColEnd, visible[1]); |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
168 |
SequenceGroup selection = viewport.getSelectionGroup(); |
199 |
168 |
if (selection != null) |
200 |
|
{ |
201 |
30 |
int selectionStart = selection.getStartRes(); |
202 |
30 |
int selectionEnd = selection.getEndRes(); |
203 |
30 |
if (selectionStart > seqColEnd || selectionEnd < seqColStart) |
204 |
|
{ |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
10 |
columnIndex = seqColEnd + 1; |
209 |
10 |
return null; |
210 |
|
} |
211 |
20 |
seqColStart = Math.max(seqColStart, selectionStart); |
212 |
20 |
seqColEnd = Math.min(seqColEnd, selectionEnd); |
213 |
|
} |
214 |
|
|
215 |
158 |
return new Range(seqColStart, seqColEnd); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
@param |
226 |
|
@param |
227 |
|
@param |
228 |
|
@return |
229 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 7 |
Complexity Density: 0.64 |
|
230 |
177 |
protected boolean findNextMatch(SequenceI seq, String searchString,... |
231 |
|
Regex searchPattern, boolean matchDescription) |
232 |
|
{ |
233 |
177 |
SequenceGroup selection = viewport.getSelectionGroup(); |
234 |
177 |
if (selection != null && !selection.contains(seq)) |
235 |
|
{ |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
9 |
return false; |
240 |
|
} |
241 |
|
|
242 |
168 |
if (columnIndex < 0) |
243 |
|
{ |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
107 |
if (doNonMotifSearches(seq, searchString, searchPattern, |
249 |
|
matchDescription)) |
250 |
|
{ |
251 |
17 |
return true; |
252 |
|
} |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
151 |
int end = seq.getLength(); |
259 |
269 |
while (columnIndex < end) |
260 |
|
{ |
261 |
170 |
if (searchNextVisibleRegion(seq, searchPattern)) |
262 |
|
{ |
263 |
52 |
return true; |
264 |
|
} |
265 |
|
} |
266 |
99 |
return false; |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
@param |
276 |
|
@param |
277 |
|
@return |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
279 |
170 |
protected boolean searchNextVisibleRegion(SequenceI seq, Regex searchPattern)... |
280 |
|
{ |
281 |
170 |
Range visible = getNextVisibleSequenceRegion(seq, columnIndex); |
282 |
170 |
if (visible == null) |
283 |
|
{ |
284 |
12 |
return false; |
285 |
|
} |
286 |
158 |
String seqString = seq.getSequenceAsString(visible.start, visible.end + 1); |
287 |
158 |
String noGaps = AlignSeq.extractGaps(Comparison.GapChars, seqString); |
288 |
|
|
289 |
158 |
if (searchPattern.search(noGaps)) |
290 |
|
{ |
291 |
52 |
int sequenceStartPosition = seq.findPosition(visible.start); |
292 |
52 |
recordMatch(seq, searchPattern, sequenceStartPosition); |
293 |
52 |
return true; |
294 |
|
} |
295 |
|
else |
296 |
|
{ |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
106 |
columnIndex = visible.end + 1; |
302 |
|
} |
303 |
|
|
304 |
106 |
return false; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
@param |
315 |
|
@param |
316 |
|
@param |
317 |
|
@return |
318 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
319 |
52 |
protected boolean recordMatch(SequenceI seq, Regex searchPattern,... |
320 |
|
int firstResiduePosition) |
321 |
|
{ |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
52 |
int offset = searchPattern.matchedFrom(); |
326 |
52 |
int matchStartPosition = firstResiduePosition + offset; |
327 |
52 |
int matchEndPosition = matchStartPosition |
328 |
|
+ searchPattern.charsMatched() - 1; |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
52 |
columnIndex = seq.findIndex(matchStartPosition); |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
52 |
List<SearchResultMatchI> matches = searchResults.getResults(); |
340 |
52 |
SearchResultMatchI lastMatch = matches.isEmpty() ? null |
341 |
|
: matches.get(matches.size() - 1); |
342 |
|
|
343 |
52 |
if (lastMatch == null || !lastMatch.contains(seq, matchStartPosition, |
344 |
|
matchEndPosition)) |
345 |
|
{ |
346 |
36 |
searchResults.addResult(seq, matchStartPosition, matchEndPosition); |
347 |
36 |
return true; |
348 |
|
} |
349 |
|
|
350 |
16 |
return false; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@param |
363 |
|
@param |
364 |
|
@param |
365 |
|
@param |
366 |
|
@return |
367 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
368 |
107 |
protected boolean doNonMotifSearches(SequenceI seq, String searchString,... |
369 |
|
Regex searchPattern, boolean includeDescription) |
370 |
|
{ |
371 |
|
|
372 |
|
|
373 |
|
|
374 |
107 |
columnIndex = 0; |
375 |
|
|
376 |
107 |
if (searchForResidueNumber(seq, searchString)) |
377 |
|
{ |
378 |
3 |
return true; |
379 |
|
} |
380 |
104 |
if (searchSequenceName(seq, searchPattern)) |
381 |
|
{ |
382 |
10 |
return true; |
383 |
|
} |
384 |
94 |
if (includeDescription && searchSequenceDescription(seq, searchPattern)) |
385 |
|
{ |
386 |
4 |
return true; |
387 |
|
} |
388 |
90 |
return false; |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
@param |
397 |
|
@param |
398 |
|
@return |
399 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
400 |
11 |
protected boolean searchSequenceDescription(SequenceI seq, Regex searchPattern)... |
401 |
|
{ |
402 |
11 |
String desc = seq.getDescription(); |
403 |
11 |
if (desc != null && searchPattern.search(desc) && !idMatches.contains(seq)) |
404 |
|
{ |
405 |
4 |
idMatches.addElement(seq); |
406 |
4 |
return true; |
407 |
|
} |
408 |
7 |
return false; |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
@param |
417 |
|
@param |
418 |
|
@return |
419 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
420 |
104 |
protected boolean searchSequenceName(SequenceI seq, Regex searchPattern)... |
421 |
|
{ |
422 |
104 |
if (searchPattern.search(seq.getName()) && !idMatches.contains(seq)) |
423 |
|
{ |
424 |
10 |
idMatches.addElement(seq); |
425 |
10 |
return true; |
426 |
|
} |
427 |
94 |
return false; |
428 |
|
} |
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
435 |
107 |
protected boolean searchForResidueNumber(SequenceI seq, String searchString)... |
436 |
|
{ |
437 |
107 |
try |
438 |
|
{ |
439 |
107 |
int res = Integer.parseInt(searchString); |
440 |
5 |
if (seq.getStart() <= res && seq.getEnd() >= res) |
441 |
|
{ |
442 |
3 |
searchResults.addResult(seq, res, res); |
443 |
3 |
return true; |
444 |
|
} |
445 |
|
} catch (NumberFormatException ex) |
446 |
|
{ |
447 |
|
} |
448 |
104 |
return false; |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
@see |
453 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
454 |
30 |
@Override... |
455 |
|
public Vector<SequenceI> getIdMatches() |
456 |
|
{ |
457 |
30 |
return idMatches; |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
@see |
462 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
463 |
43 |
@Override... |
464 |
|
public SearchResultsI getSearchResults() |
465 |
|
{ |
466 |
43 |
return searchResults; |
467 |
|
} |
468 |
|
} |