1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel.features; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.Map.Entry; |
29 |
|
import java.util.Set; |
30 |
|
import java.util.TreeMap; |
31 |
|
|
32 |
|
import intervalstore.api.IntervalI; |
33 |
|
import jalview.datamodel.SequenceFeature; |
34 |
|
import jalview.io.gff.SequenceOntologyFactory; |
35 |
|
import jalview.io.gff.SequenceOntologyI; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@author |
43 |
|
|
44 |
|
|
|
|
| 0% |
Uncovered Elements: 157 (157) |
Complexity: 47 |
Complexity Density: 0.47 |
|
45 |
|
public class SequenceFeatures implements SequenceFeaturesI |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private Map<String, FeatureStore> featureStore; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
public SequenceFeatures()... |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
0 |
featureStore = new TreeMap<>(); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
70 |
0 |
public SequenceFeatures(List<SequenceFeature> features)... |
71 |
|
{ |
72 |
0 |
this(); |
73 |
0 |
if (features != null) |
74 |
|
{ |
75 |
0 |
for (SequenceFeature feature : features) |
76 |
|
{ |
77 |
0 |
add(feature); |
78 |
|
} |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
@inheritDoc |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
85 |
0 |
@Override... |
86 |
|
public boolean add(SequenceFeature sf) |
87 |
|
{ |
88 |
0 |
String type = sf.getType(); |
89 |
0 |
if (type == null) |
90 |
|
{ |
91 |
0 |
jalview.bin.Console |
92 |
|
.errPrintln("Feature type may not be null: " + sf.toString()); |
93 |
0 |
return false; |
94 |
|
} |
95 |
|
|
96 |
0 |
if (featureStore.get(type) == null) |
97 |
|
{ |
98 |
0 |
featureStore.put(type, new FeatureStore()); |
99 |
|
} |
100 |
0 |
return featureStore.get(type).addFeature(sf); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
@inheritDoc |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
106 |
0 |
@Override... |
107 |
|
public List<SequenceFeature> findFeatures(int from, int to, |
108 |
|
String... type) |
109 |
|
{ |
110 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
111 |
|
|
112 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
113 |
|
{ |
114 |
0 |
result.addAll(featureSet.findOverlappingFeatures(from, to)); |
115 |
|
} |
116 |
|
|
117 |
0 |
return result; |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
@inheritDoc |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
123 |
0 |
@Override... |
124 |
|
public List<SequenceFeature> getAllFeatures(String... type) |
125 |
|
{ |
126 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
127 |
|
|
128 |
0 |
result.addAll(getPositionalFeatures(type)); |
129 |
|
|
130 |
0 |
result.addAll(getNonPositionalFeatures()); |
131 |
|
|
132 |
0 |
return result; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
@inheritDoc |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
138 |
0 |
@Override... |
139 |
|
public List<SequenceFeature> getFeaturesByOntology(String... ontologyTerm) |
140 |
|
{ |
141 |
0 |
if (ontologyTerm == null || ontologyTerm.length == 0) |
142 |
|
{ |
143 |
0 |
return new ArrayList<>(); |
144 |
|
} |
145 |
|
|
146 |
0 |
Set<String> featureTypes = getFeatureTypes(ontologyTerm); |
147 |
0 |
if (featureTypes.isEmpty()) |
148 |
|
{ |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
0 |
return new ArrayList<>(); |
153 |
|
} |
154 |
|
|
155 |
0 |
return getAllFeatures( |
156 |
|
featureTypes.toArray(new String[featureTypes.size()])); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
@inheritDoc |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
162 |
0 |
@Override... |
163 |
|
public int getFeatureCount(boolean positional, String... type) |
164 |
|
{ |
165 |
0 |
int result = 0; |
166 |
|
|
167 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
168 |
|
{ |
169 |
0 |
result += featureSet.getFeatureCount(positional); |
170 |
|
} |
171 |
0 |
return result; |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
@inheritDoc |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
177 |
0 |
@Override... |
178 |
|
public int getTotalFeatureLength(String... type) |
179 |
|
{ |
180 |
0 |
int result = 0; |
181 |
|
|
182 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
183 |
|
{ |
184 |
0 |
result += featureSet.getTotalFeatureLength(); |
185 |
|
} |
186 |
0 |
return result; |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
@inheritDoc |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
192 |
0 |
@Override... |
193 |
|
public List<SequenceFeature> getPositionalFeatures(String... type) |
194 |
|
{ |
195 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
196 |
|
|
197 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
198 |
|
{ |
199 |
0 |
result.addAll(featureSet.getPositionalFeatures()); |
200 |
|
} |
201 |
0 |
return result; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@param |
211 |
|
@return |
212 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
213 |
0 |
protected Iterable<FeatureStore> varargToTypes(String... type)... |
214 |
|
{ |
215 |
0 |
if (type == null || type.length == 0) |
216 |
|
{ |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
0 |
return featureStore.values(); |
221 |
|
} |
222 |
|
|
223 |
0 |
List<FeatureStore> types = new ArrayList<>(); |
224 |
0 |
for (String theType : type) |
225 |
|
{ |
226 |
0 |
if (theType != null && featureStore.containsKey(theType)) |
227 |
|
{ |
228 |
0 |
types.add(featureStore.get(theType)); |
229 |
|
} |
230 |
|
} |
231 |
0 |
return types; |
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
|
@inheritDoc |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
237 |
0 |
@Override... |
238 |
|
public List<SequenceFeature> getContactFeatures(String... type) |
239 |
|
{ |
240 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
241 |
|
|
242 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
243 |
|
{ |
244 |
0 |
result.addAll(featureSet.getContactFeatures()); |
245 |
|
} |
246 |
0 |
return result; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
@inheritDoc |
251 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
252 |
0 |
@Override... |
253 |
|
public List<SequenceFeature> getNonPositionalFeatures(String... type) |
254 |
|
{ |
255 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
256 |
|
|
257 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
258 |
|
{ |
259 |
0 |
result.addAll(featureSet.getNonPositionalFeatures()); |
260 |
|
} |
261 |
0 |
return result; |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
@inheritDoc |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
267 |
0 |
@Override... |
268 |
|
public boolean delete(SequenceFeature sf) |
269 |
|
{ |
270 |
0 |
for (FeatureStore featureSet : featureStore.values()) |
271 |
|
{ |
272 |
0 |
if (featureSet.delete(sf)) |
273 |
|
{ |
274 |
0 |
return true; |
275 |
|
} |
276 |
|
} |
277 |
0 |
return false; |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
@inheritDoc |
282 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
283 |
0 |
@Override... |
284 |
|
public boolean hasFeatures() |
285 |
|
{ |
286 |
0 |
for (FeatureStore featureSet : featureStore.values()) |
287 |
|
{ |
288 |
0 |
if (!featureSet.isEmpty()) |
289 |
|
{ |
290 |
0 |
return true; |
291 |
|
} |
292 |
|
} |
293 |
0 |
return false; |
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
|
@inheritDoc |
298 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
299 |
0 |
@Override... |
300 |
|
public Set<String> getFeatureGroups(boolean positionalFeatures, |
301 |
|
String... type) |
302 |
|
{ |
303 |
0 |
Set<String> groups = new HashSet<>(); |
304 |
|
|
305 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
306 |
|
{ |
307 |
0 |
groups.addAll(featureSet.getFeatureGroups(positionalFeatures)); |
308 |
|
} |
309 |
|
|
310 |
0 |
return groups; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
|
@inheritDoc |
315 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
316 |
0 |
@Override... |
317 |
|
public Set<String> getFeatureTypesForGroups(boolean positionalFeatures, |
318 |
|
String... groups) |
319 |
|
{ |
320 |
0 |
Set<String> result = new HashSet<>(); |
321 |
|
|
322 |
0 |
for (Entry<String, FeatureStore> featureType : featureStore.entrySet()) |
323 |
|
{ |
324 |
0 |
Set<String> featureGroups = featureType.getValue() |
325 |
|
.getFeatureGroups(positionalFeatures); |
326 |
0 |
for (String group : groups) |
327 |
|
{ |
328 |
0 |
if (featureGroups.contains(group)) |
329 |
|
{ |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
0 |
result.add(featureType.getKey()); |
334 |
0 |
break; |
335 |
|
} |
336 |
|
} |
337 |
|
} |
338 |
|
|
339 |
0 |
return result; |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
@inheritDoc |
344 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
345 |
0 |
@Override... |
346 |
|
public Set<String> getFeatureTypes(String... soTerm) |
347 |
|
{ |
348 |
0 |
Set<String> types = new HashSet<>(); |
349 |
0 |
for (Entry<String, FeatureStore> entry : featureStore.entrySet()) |
350 |
|
{ |
351 |
0 |
String type = entry.getKey(); |
352 |
0 |
if (!entry.getValue().isEmpty() && isOntologyTerm(type, soTerm)) |
353 |
|
{ |
354 |
0 |
types.add(type); |
355 |
|
} |
356 |
|
} |
357 |
0 |
return types; |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
@param |
367 |
|
@param |
368 |
|
@return |
369 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
370 |
0 |
protected boolean isOntologyTerm(String type, String... soTerm)... |
371 |
|
{ |
372 |
0 |
if (soTerm == null || soTerm.length == 0) |
373 |
|
{ |
374 |
0 |
return true; |
375 |
|
} |
376 |
0 |
SequenceOntologyI so = SequenceOntologyFactory.getInstance(); |
377 |
0 |
for (String term : soTerm) |
378 |
|
{ |
379 |
0 |
if (type.equals(term) || so.isA(type, term)) |
380 |
|
{ |
381 |
0 |
return true; |
382 |
|
} |
383 |
|
} |
384 |
0 |
return false; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
@inheritDoc |
389 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
390 |
0 |
@Override... |
391 |
|
public float getMinimumScore(String type, boolean positional) |
392 |
|
{ |
393 |
0 |
return featureStore.containsKey(type) |
394 |
|
? featureStore.get(type).getMinimumScore(positional) |
395 |
|
: Float.NaN; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
|
@inheritDoc |
400 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
401 |
0 |
@Override... |
402 |
|
public float getMaximumScore(String type, boolean positional) |
403 |
|
{ |
404 |
0 |
return featureStore.containsKey(type) |
405 |
|
? featureStore.get(type).getMaximumScore(positional) |
406 |
|
: Float.NaN; |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
@param |
414 |
|
@param |
415 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
416 |
0 |
public static void sortFeatures(List<? extends IntervalI> features,... |
417 |
|
final boolean forwardStrand) |
418 |
|
{ |
419 |
0 |
Collections.sort(features, |
420 |
0 |
forwardStrand ? IntervalI.COMPARE_BEGIN_ASC_END_DESC |
421 |
|
: IntervalI.COMPARE_END_DESC); |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
|
@inheritDoc |
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
435 |
0 |
@Override... |
436 |
|
public List<SequenceFeature> getFeaturesForGroup(boolean positional, |
437 |
|
String group, String... type) |
438 |
|
{ |
439 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
440 |
0 |
for (FeatureStore featureSet : varargToTypes(type)) |
441 |
|
{ |
442 |
0 |
if (featureSet.getFeatureGroups(positional).contains(group)) |
443 |
|
{ |
444 |
0 |
result.addAll(featureSet.getFeaturesForGroup(positional, group)); |
445 |
|
} |
446 |
|
} |
447 |
0 |
return result; |
448 |
|
} |
449 |
|
|
450 |
|
|
451 |
|
@inheritDoc |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
453 |
0 |
@Override... |
454 |
|
public boolean shiftFeatures(int fromPosition, int shiftBy) |
455 |
|
{ |
456 |
0 |
boolean modified = false; |
457 |
0 |
for (FeatureStore fs : featureStore.values()) |
458 |
|
{ |
459 |
0 |
modified |= fs.shiftFeatures(fromPosition, shiftBy); |
460 |
|
} |
461 |
0 |
return modified; |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
|
@inheritDoc |
466 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
467 |
0 |
@Override... |
468 |
|
public void deleteAll() |
469 |
|
{ |
470 |
0 |
featureStore.clear(); |
471 |
|
} |
472 |
|
} |