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.datamodel.AlignmentI; |
24 |
|
import jalview.datamodel.SearchResultMatchI; |
25 |
|
import jalview.datamodel.SearchResults; |
26 |
|
import jalview.datamodel.SearchResultsI; |
27 |
|
import jalview.datamodel.SequenceGroup; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.util.Comparison; |
30 |
|
|
31 |
|
import java.util.ArrayList; |
32 |
|
import java.util.List; |
33 |
|
import java.util.Vector; |
34 |
|
|
35 |
|
import com.stevesoft.pat.Regex; |
36 |
|
|
|
|
| 75.9% |
Uncovered Elements: 38 (158) |
Complexity: 56 |
Complexity Density: 0.58 |
|
37 |
|
public class Finder |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
SearchResultsI searchResults; |
43 |
|
|
44 |
|
AlignmentI alignment; |
45 |
|
|
46 |
|
SequenceGroup selection = null; |
47 |
|
|
48 |
|
Vector<SequenceI> idMatch = null; |
49 |
|
|
50 |
|
boolean caseSensitive = false; |
51 |
|
|
52 |
|
private boolean includeDescription = false; |
53 |
|
|
54 |
|
boolean findAll = false; |
55 |
|
|
56 |
|
Regex regex = null; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
int seqIndex = 0, resIndex = -1; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
15 |
public Finder(AlignmentI alignment, SequenceGroup selection)... |
64 |
|
{ |
65 |
15 |
this.alignment = alignment; |
66 |
15 |
this.selection = selection; |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@param |
75 |
|
@param |
76 |
|
@param |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
78 |
3 |
public Finder(AlignmentI alignment, SequenceGroup selectionGroup,... |
79 |
|
int seqIndex, int resIndex) |
80 |
|
{ |
81 |
3 |
this(alignment, selectionGroup); |
82 |
3 |
this.seqIndex = seqIndex; |
83 |
3 |
this.resIndex = resIndex; |
84 |
|
} |
85 |
|
|
|
|
| 82.8% |
Uncovered Elements: 20 (116) |
Complexity: 37 |
Complexity Density: 0.5 |
|
86 |
15 |
public boolean find(String searchString)... |
87 |
|
{ |
88 |
15 |
boolean hasResults = false; |
89 |
15 |
if (!caseSensitive) |
90 |
|
{ |
91 |
11 |
searchString = searchString.toUpperCase(); |
92 |
|
} |
93 |
15 |
regex = new Regex(searchString); |
94 |
15 |
regex.setIgnoreCase(!caseSensitive); |
95 |
15 |
searchResults = new SearchResults(); |
96 |
15 |
idMatch = new Vector<SequenceI>(); |
97 |
15 |
String item = null; |
98 |
15 |
boolean found = false; |
99 |
15 |
int end = alignment.getHeight(); |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
15 |
if (selection != null) |
104 |
|
{ |
105 |
0 |
if ((selection.getSize() < 1) |
106 |
|
|| ((selection.getEndRes() - selection.getStartRes()) < 2)) |
107 |
|
{ |
108 |
0 |
selection = null; |
109 |
|
} |
110 |
|
} |
111 |
15 |
SearchResultMatchI lastm = null; |
112 |
|
|
113 |
66 |
while (!found && (seqIndex < end)) |
114 |
|
{ |
115 |
53 |
SequenceI seq = alignment.getSequenceAt(seqIndex); |
116 |
|
|
117 |
53 |
if ((selection != null && selection.getSize() > 0) |
118 |
|
&& !selection.getSequences(null).contains(seq)) |
119 |
|
{ |
120 |
0 |
seqIndex++; |
121 |
0 |
resIndex = -1; |
122 |
|
|
123 |
0 |
continue; |
124 |
|
} |
125 |
53 |
if (resIndex < 0) |
126 |
|
{ |
127 |
51 |
resIndex = 0; |
128 |
|
|
129 |
|
|
130 |
51 |
try |
131 |
|
{ |
132 |
51 |
int res = Integer.parseInt(searchString); |
133 |
|
|
134 |
4 |
if (seq.getEnd() >= res) |
135 |
|
{ |
136 |
2 |
searchResults.addResult(seq, res, res); |
137 |
2 |
hasResults = true; |
138 |
|
|
139 |
|
|
140 |
2 |
if (!findAll) |
141 |
|
{ |
142 |
0 |
found = true; |
143 |
0 |
break; |
144 |
|
} |
145 |
|
} |
146 |
|
} catch (NumberFormatException ex) |
147 |
|
{ |
148 |
|
} |
149 |
|
|
150 |
51 |
if (regex.search(seq.getName()) && !idMatch.contains(seq)) |
151 |
|
{ |
152 |
6 |
idMatch.addElement(seq); |
153 |
6 |
hasResults = true; |
154 |
6 |
if (!findAll) |
155 |
|
{ |
156 |
|
|
157 |
2 |
found = true; |
158 |
2 |
break; |
159 |
|
} |
160 |
|
} |
161 |
|
|
162 |
49 |
if (isIncludeDescription() && seq.getDescription() != null |
163 |
|
&& regex.search(seq.getDescription()) |
164 |
|
&& !idMatch.contains(seq)) |
165 |
|
{ |
166 |
3 |
idMatch.addElement(seq); |
167 |
3 |
hasResults = true; |
168 |
3 |
if (!findAll) |
169 |
|
{ |
170 |
|
|
171 |
0 |
found = true; |
172 |
0 |
break; |
173 |
|
} |
174 |
|
} |
175 |
|
} |
176 |
51 |
item = seq.getSequenceAsString(); |
177 |
|
|
178 |
51 |
if ((selection != null) |
179 |
|
&& (selection.getEndRes() < alignment.getWidth() - 1)) |
180 |
|
{ |
181 |
0 |
item = item.substring(0, selection.getEndRes() + 1); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
51 |
StringBuilder noGapsSB = new StringBuilder(); |
186 |
51 |
int insertCount = 0; |
187 |
51 |
List<Integer> spaces = new ArrayList<Integer>(); |
188 |
|
|
189 |
647 |
for (int j = 0; j < item.length(); j++) |
190 |
|
{ |
191 |
596 |
if (!Comparison.isGap(item.charAt(j))) |
192 |
|
{ |
193 |
482 |
noGapsSB.append(item.charAt(j)); |
194 |
482 |
spaces.add(Integer.valueOf(insertCount)); |
195 |
|
} |
196 |
|
else |
197 |
|
{ |
198 |
114 |
insertCount++; |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
51 |
String noGaps = noGapsSB.toString(); |
203 |
81 |
for (int r = resIndex; r < noGaps.length(); r++) |
204 |
|
{ |
205 |
|
|
206 |
81 |
if (regex.searchFrom(noGaps, r)) |
207 |
|
{ |
208 |
31 |
resIndex = regex.matchedFrom(); |
209 |
|
|
210 |
31 |
if ((selection != null && selection.getSize() > 0) && (resIndex |
211 |
|
+ spaces.get(resIndex) < selection.getStartRes())) |
212 |
|
{ |
213 |
0 |
continue; |
214 |
|
} |
215 |
|
|
216 |
31 |
int sres = seq.findPosition(resIndex + spaces.get(resIndex)); |
217 |
31 |
int eres = seq.findPosition(regex.matchedTo() - 1 |
218 |
|
+ (spaces.get(regex.matchedTo() - 1))); |
219 |
|
|
220 |
31 |
if (lastm == null || (lastm.getSequence() != seq |
221 |
|
|| (!(lastm.getStart() <= sres |
222 |
|
&& lastm.getEnd() >= eres)))) |
223 |
|
{ |
224 |
15 |
lastm = searchResults.addResult(seq, sres, eres); |
225 |
|
} |
226 |
31 |
hasResults = true; |
227 |
31 |
if (!findAll) |
228 |
|
{ |
229 |
|
|
230 |
1 |
found = true; |
231 |
1 |
resIndex++; |
232 |
|
|
233 |
1 |
break; |
234 |
|
} |
235 |
|
|
236 |
30 |
r = resIndex; |
237 |
|
} |
238 |
|
else |
239 |
|
{ |
240 |
50 |
break; |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
51 |
if (!found) |
245 |
|
{ |
246 |
50 |
seqIndex++; |
247 |
50 |
resIndex = -1; |
248 |
|
} |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
15 |
return hasResults; |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
@return |
262 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
0 |
public AlignmentI getAlignment()... |
264 |
|
{ |
265 |
0 |
return alignment; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
@param |
270 |
|
|
271 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
272 |
0 |
public void setAlignment(AlignmentI alignment)... |
273 |
|
{ |
274 |
0 |
this.alignment = alignment; |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
@return |
279 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
280 |
0 |
public boolean isCaseSensitive()... |
281 |
|
{ |
282 |
0 |
return caseSensitive; |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
@param |
287 |
|
|
288 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
289 |
4 |
public void setCaseSensitive(boolean caseSensitive)... |
290 |
|
{ |
291 |
4 |
this.caseSensitive = caseSensitive; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
@return |
296 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
297 |
0 |
public boolean isFindAll()... |
298 |
|
{ |
299 |
0 |
return findAll; |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
@param |
304 |
|
|
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
12 |
public void setFindAll(boolean findAll)... |
307 |
|
{ |
308 |
12 |
this.findAll = findAll; |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
@return |
313 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
314 |
0 |
public jalview.datamodel.SequenceGroup getSelection()... |
315 |
|
{ |
316 |
0 |
return selection; |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
@param |
321 |
|
|
322 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
323 |
0 |
public void setSelection(jalview.datamodel.SequenceGroup selection)... |
324 |
|
{ |
325 |
0 |
this.selection = selection; |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
@return |
333 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
334 |
17 |
public Vector<SequenceI> getIdMatch()... |
335 |
|
{ |
336 |
17 |
return idMatch; |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
|
@return |
341 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
342 |
0 |
public com.stevesoft.pat.Regex getRegex()... |
343 |
|
{ |
344 |
0 |
return regex; |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
|
@return |
349 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
19 |
public SearchResultsI getSearchResults()... |
351 |
|
{ |
352 |
19 |
return searchResults; |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
@return |
357 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
358 |
2 |
public int getResIndex()... |
359 |
|
{ |
360 |
2 |
return resIndex; |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
@param |
365 |
|
|
366 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
367 |
0 |
public void setResIndex(int resIndex)... |
368 |
|
{ |
369 |
0 |
this.resIndex = resIndex; |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
|
@return |
374 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
375 |
1 |
public int getSeqIndex()... |
376 |
|
{ |
377 |
1 |
return seqIndex; |
378 |
|
} |
379 |
|
|
380 |
|
|
381 |
|
@param |
382 |
|
|
383 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
384 |
0 |
public void setSeqIndex(int seqIndex)... |
385 |
|
{ |
386 |
0 |
this.seqIndex = seqIndex; |
387 |
|
} |
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
49 |
public boolean isIncludeDescription()... |
390 |
|
{ |
391 |
49 |
return includeDescription; |
392 |
|
} |
393 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
394 |
3 |
public void setIncludeDescription(boolean includeDescription)... |
395 |
|
{ |
396 |
3 |
this.includeDescription = includeDescription; |
397 |
|
} |
398 |
|
} |