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.analysis.scoremodels.PIDModel; |
24 |
|
import jalview.analysis.scoremodels.SimilarityParams; |
25 |
|
import jalview.datamodel.AlignmentAnnotation; |
26 |
|
import jalview.datamodel.AlignmentI; |
27 |
|
import jalview.datamodel.AlignmentOrder; |
28 |
|
import jalview.datamodel.SequenceFeature; |
29 |
|
import jalview.datamodel.SequenceGroup; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
import jalview.datamodel.SequenceNode; |
32 |
|
import jalview.util.QuickSort; |
33 |
|
|
34 |
|
import java.util.ArrayList; |
35 |
|
import java.util.Collections; |
36 |
|
import java.util.Iterator; |
37 |
|
import java.util.List; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
|
|
| 46.5% |
Uncovered Elements: 214 (400) |
Complexity: 99 |
Complexity Density: 0.41 |
|
54 |
|
public class AlignmentSorter |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
static boolean sortIdAscending = true; |
61 |
|
|
62 |
|
static int lastGroupHash = 0; |
63 |
|
|
64 |
|
static boolean sortGroupAscending = true; |
65 |
|
|
66 |
|
static AlignmentOrder lastOrder = null; |
67 |
|
|
68 |
|
static boolean sortOrderAscending = true; |
69 |
|
|
70 |
|
static TreeModel lastTree = null; |
71 |
|
|
72 |
|
static boolean sortTreeAscending = true; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
private static String lastSortByAnnotation; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
private static String sortByFeatureCriteria; |
84 |
|
|
85 |
|
private static boolean sortByFeatureAscending = true; |
86 |
|
|
87 |
|
private static boolean sortLengthAscending; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
@param |
94 |
|
|
95 |
|
@param |
96 |
|
|
97 |
|
@param |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
99 |
0 |
public static void sortByPID(AlignmentI align, SequenceI s)... |
100 |
|
{ |
101 |
0 |
int nSeq = align.getHeight(); |
102 |
|
|
103 |
0 |
float[] scores = new float[nSeq]; |
104 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
105 |
0 |
String refSeq = s.getSequenceAsString(); |
106 |
|
|
107 |
0 |
SimilarityParams pidParams = new SimilarityParams(true, true, true, |
108 |
|
true); |
109 |
0 |
for (int i = 0; i < nSeq; i++) |
110 |
|
{ |
111 |
0 |
scores[i] = (float) PIDModel.computePID( |
112 |
|
align.getSequenceAt(i).getSequenceAsString(), refSeq, |
113 |
|
pidParams); |
114 |
0 |
seqs[i] = align.getSequenceAt(i); |
115 |
|
} |
116 |
|
|
117 |
0 |
QuickSort.sort(scores, seqs); |
118 |
|
|
119 |
0 |
setReverseOrder(align, seqs); |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
130 |
2 |
private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)... |
131 |
|
{ |
132 |
2 |
int nSeq = seqs.length; |
133 |
|
|
134 |
2 |
int len = 0; |
135 |
|
|
136 |
2 |
if ((nSeq % 2) == 0) |
137 |
|
{ |
138 |
0 |
len = nSeq / 2; |
139 |
|
} |
140 |
|
else |
141 |
|
{ |
142 |
2 |
len = (nSeq + 1) / 2; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
2 |
List<SequenceI> asq = align.getSequences(); |
147 |
2 |
synchronized (asq) |
148 |
|
{ |
149 |
36 |
for (int i = 0; i < len; i++) |
150 |
|
{ |
151 |
|
|
152 |
34 |
asq.set(i, seqs[nSeq - i - 1]); |
153 |
34 |
asq.set(nSeq - i - 1, seqs[i]); |
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@param |
162 |
|
|
163 |
|
@param |
164 |
|
|
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
2 |
private static void setOrder(AlignmentI align, List<SequenceI> tmp)... |
167 |
|
{ |
168 |
2 |
setOrder(align, vectorSubsetToArray(tmp, align.getSequences())); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
|
176 |
|
@param |
177 |
|
|
178 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
179 |
7 |
public static void setOrder(AlignmentI align, SequenceI[] seqs)... |
180 |
|
{ |
181 |
|
|
182 |
7 |
List<SequenceI> algn = align.getSequences(); |
183 |
7 |
synchronized (algn) |
184 |
|
{ |
185 |
7 |
List<SequenceI> tmp = new ArrayList<>(); |
186 |
|
|
187 |
93 |
for (int i = 0; i < seqs.length; i++) |
188 |
|
{ |
189 |
86 |
if (algn.contains(seqs[i])) |
190 |
|
{ |
191 |
86 |
tmp.add(seqs[i]); |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
7 |
algn.clear(); |
196 |
|
|
197 |
93 |
for (int i = 0; i < tmp.size(); i++) |
198 |
|
{ |
199 |
86 |
algn.add(tmp.get(i)); |
200 |
|
} |
201 |
|
} |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@param |
208 |
|
|
209 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
210 |
0 |
public static void sortByID(AlignmentI align)... |
211 |
|
{ |
212 |
0 |
int nSeq = align.getHeight(); |
213 |
|
|
214 |
0 |
String[] ids = new String[nSeq]; |
215 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
216 |
|
|
217 |
0 |
for (int i = 0; i < nSeq; i++) |
218 |
|
{ |
219 |
0 |
ids[i] = align.getSequenceAt(i).getName(); |
220 |
0 |
seqs[i] = align.getSequenceAt(i); |
221 |
|
} |
222 |
|
|
223 |
0 |
QuickSort.sort(ids, seqs); |
224 |
|
|
225 |
0 |
if (sortIdAscending) |
226 |
|
{ |
227 |
0 |
setReverseOrder(align, seqs); |
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
0 |
setOrder(align, seqs); |
232 |
|
} |
233 |
|
|
234 |
0 |
sortIdAscending = !sortIdAscending; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
@param |
241 |
|
|
242 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
243 |
0 |
public static void sortByLength(AlignmentI align)... |
244 |
|
{ |
245 |
0 |
int nSeq = align.getHeight(); |
246 |
|
|
247 |
0 |
float[] length = new float[nSeq]; |
248 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
249 |
|
|
250 |
0 |
for (int i = 0; i < nSeq; i++) |
251 |
|
{ |
252 |
0 |
seqs[i] = align.getSequenceAt(i); |
253 |
0 |
length[i] = (seqs[i].getEnd() - seqs[i].getStart()); |
254 |
|
} |
255 |
|
|
256 |
0 |
QuickSort.sort(length, seqs); |
257 |
|
|
258 |
0 |
if (sortLengthAscending) |
259 |
|
{ |
260 |
0 |
setReverseOrder(align, seqs); |
261 |
|
} |
262 |
|
else |
263 |
|
{ |
264 |
0 |
setOrder(align, seqs); |
265 |
|
} |
266 |
|
|
267 |
0 |
sortLengthAscending = !sortLengthAscending; |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
@param |
276 |
|
|
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 8 |
Complexity Density: 0.36 |
|
278 |
4 |
public static void sortByGroup(AlignmentI align)... |
279 |
|
{ |
280 |
|
|
281 |
|
|
282 |
4 |
List<SequenceGroup> groups = new ArrayList<>(); |
283 |
|
|
284 |
4 |
if (groups.hashCode() != lastGroupHash) |
285 |
|
{ |
286 |
1 |
sortGroupAscending = true; |
287 |
1 |
lastGroupHash = groups.hashCode(); |
288 |
|
} |
289 |
|
else |
290 |
|
{ |
291 |
3 |
sortGroupAscending = !sortGroupAscending; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
4 |
for (SequenceGroup sg : align.getGroups()) |
297 |
|
{ |
298 |
44 |
for (int j = 0; j < groups.size(); j++) |
299 |
|
{ |
300 |
32 |
SequenceGroup sg2 = groups.get(j); |
301 |
|
|
302 |
32 |
if (sg.getSize() > sg2.getSize()) |
303 |
|
{ |
304 |
8 |
groups.add(j, sg); |
305 |
|
|
306 |
8 |
break; |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
20 |
if (!groups.contains(sg)) |
311 |
|
{ |
312 |
12 |
groups.add(sg); |
313 |
|
} |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
|
318 |
4 |
List<SequenceI> seqs = new ArrayList<>(); |
319 |
|
|
320 |
24 |
for (int i = 0; i < groups.size(); i++) |
321 |
|
{ |
322 |
20 |
SequenceGroup sg = groups.get(i); |
323 |
20 |
SequenceI[] orderedseqs = sg.getSequencesInOrder(align); |
324 |
|
|
325 |
152 |
for (int j = 0; j < orderedseqs.length; j++) |
326 |
|
{ |
327 |
132 |
seqs.add(orderedseqs[j]); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
4 |
if (sortGroupAscending) |
332 |
|
{ |
333 |
2 |
setOrder(align, seqs); |
334 |
|
} |
335 |
|
else |
336 |
|
{ |
337 |
2 |
setReverseOrder(align, |
338 |
|
vectorSubsetToArray(seqs, align.getSequences())); |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
@param |
347 |
|
|
348 |
|
@param |
349 |
|
|
350 |
|
|
351 |
|
@return |
352 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
353 |
4 |
private static SequenceI[] vectorSubsetToArray(List<SequenceI> tmp,... |
354 |
|
List<SequenceI> mask) |
355 |
|
{ |
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
4 |
ArrayList<SequenceI> seqs = new ArrayList<>(); |
361 |
4 |
int i, idx; |
362 |
4 |
boolean[] tmask = new boolean[mask.size()]; |
363 |
|
|
364 |
136 |
for (i = 0; i < mask.size(); i++) |
365 |
|
{ |
366 |
132 |
tmask[i] = true; |
367 |
|
} |
368 |
|
|
369 |
136 |
for (i = 0; i < tmp.size(); i++) |
370 |
|
{ |
371 |
132 |
SequenceI sq = tmp.get(i); |
372 |
132 |
idx = mask.indexOf(sq); |
373 |
132 |
if (idx > -1 && tmask[idx]) |
374 |
|
{ |
375 |
132 |
tmask[idx] = false; |
376 |
132 |
seqs.add(sq); |
377 |
|
} |
378 |
|
} |
379 |
|
|
380 |
136 |
for (i = 0; i < tmask.length; i++) |
381 |
|
{ |
382 |
132 |
if (tmask[i]) |
383 |
|
{ |
384 |
0 |
seqs.add(mask.get(i)); |
385 |
|
} |
386 |
|
} |
387 |
|
|
388 |
4 |
return seqs.toArray(new SequenceI[seqs.size()]); |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
@param |
395 |
|
|
396 |
|
@param |
397 |
|
|
398 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
399 |
0 |
public static void sortBy(AlignmentI align, AlignmentOrder order)... |
400 |
|
{ |
401 |
|
|
402 |
0 |
List<SequenceI> tmp = order.getOrder(); |
403 |
|
|
404 |
0 |
if (lastOrder == order) |
405 |
|
{ |
406 |
0 |
sortOrderAscending = !sortOrderAscending; |
407 |
|
} |
408 |
|
else |
409 |
|
{ |
410 |
0 |
sortOrderAscending = true; |
411 |
|
} |
412 |
|
|
413 |
0 |
if (sortOrderAscending) |
414 |
|
{ |
415 |
0 |
setOrder(align, tmp); |
416 |
|
} |
417 |
|
else |
418 |
|
{ |
419 |
0 |
setReverseOrder(align, |
420 |
|
vectorSubsetToArray(tmp, align.getSequences())); |
421 |
|
} |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
@param |
428 |
|
|
429 |
|
@param |
430 |
|
|
431 |
|
|
432 |
|
@return |
433 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
434 |
0 |
private static List<SequenceI> getOrderByTree(AlignmentI align,... |
435 |
|
TreeModel tree) |
436 |
|
{ |
437 |
0 |
int nSeq = align.getHeight(); |
438 |
|
|
439 |
0 |
List<SequenceI> tmp = new ArrayList<>(); |
440 |
|
|
441 |
0 |
tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences()); |
442 |
|
|
443 |
0 |
if (tmp.size() != nSeq) |
444 |
|
{ |
445 |
|
|
446 |
|
|
447 |
|
|
448 |
0 |
if (tmp.size() != nSeq) |
449 |
|
{ |
450 |
0 |
addStrays(align, tmp); |
451 |
|
} |
452 |
|
|
453 |
0 |
if (tmp.size() != nSeq) |
454 |
|
{ |
455 |
0 |
System.err.println("WARNING: tmp.size()=" + tmp.size() + " != nseq=" |
456 |
|
+ nSeq |
457 |
|
+ " in getOrderByTree - tree contains sequences not in alignment"); |
458 |
|
} |
459 |
|
} |
460 |
|
|
461 |
0 |
return tmp; |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
@param |
468 |
|
|
469 |
|
@param |
470 |
|
|
471 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
472 |
0 |
public static void sortByTree(AlignmentI align, TreeModel tree)... |
473 |
|
{ |
474 |
0 |
List<SequenceI> tmp = getOrderByTree(align, tree); |
475 |
|
|
476 |
|
|
477 |
0 |
if (lastTree != tree) |
478 |
|
{ |
479 |
0 |
sortTreeAscending = true; |
480 |
0 |
lastTree = tree; |
481 |
|
} |
482 |
|
else |
483 |
|
{ |
484 |
0 |
sortTreeAscending = !sortTreeAscending; |
485 |
|
} |
486 |
|
|
487 |
0 |
if (sortTreeAscending) |
488 |
|
{ |
489 |
0 |
setOrder(align, tmp); |
490 |
|
} |
491 |
|
else |
492 |
|
{ |
493 |
0 |
setReverseOrder(align, |
494 |
|
vectorSubsetToArray(tmp, align.getSequences())); |
495 |
|
} |
496 |
|
} |
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@param |
502 |
|
|
503 |
|
@param |
504 |
|
|
505 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
506 |
0 |
private static void addStrays(AlignmentI align, List<SequenceI> tmp)... |
507 |
|
{ |
508 |
0 |
int nSeq = align.getHeight(); |
509 |
|
|
510 |
0 |
for (int i = 0; i < nSeq; i++) |
511 |
|
{ |
512 |
0 |
if (!tmp.contains(align.getSequenceAt(i))) |
513 |
|
{ |
514 |
0 |
tmp.add(align.getSequenceAt(i)); |
515 |
|
} |
516 |
|
} |
517 |
|
|
518 |
0 |
if (nSeq != tmp.size()) |
519 |
|
{ |
520 |
0 |
System.err |
521 |
|
.println("ERROR: Size still not right even after addStrays"); |
522 |
|
} |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
@param |
529 |
|
|
530 |
|
@param |
531 |
|
|
532 |
|
@param |
533 |
|
|
534 |
|
|
535 |
|
@return |
536 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 8 |
Complexity Density: 0.62 |
|
537 |
0 |
private static List<SequenceI> _sortByTree(SequenceNode node,... |
538 |
|
List<SequenceI> tmp, List<SequenceI> seqset) |
539 |
|
{ |
540 |
0 |
if (node == null) |
541 |
|
{ |
542 |
0 |
return tmp; |
543 |
|
} |
544 |
|
|
545 |
0 |
SequenceNode left = (SequenceNode) node.left(); |
546 |
0 |
SequenceNode right = (SequenceNode) node.right(); |
547 |
|
|
548 |
0 |
if ((left == null) && (right == null)) |
549 |
|
{ |
550 |
0 |
if (!node.isPlaceholder() && (node.element() != null)) |
551 |
|
{ |
552 |
0 |
if (node.element() instanceof SequenceI) |
553 |
|
{ |
554 |
0 |
if (!tmp.contains(node.element())) |
555 |
|
|
556 |
|
|
557 |
|
{ |
558 |
0 |
tmp.add((SequenceI) node.element()); |
559 |
|
} |
560 |
|
} |
561 |
|
} |
562 |
|
|
563 |
0 |
return tmp; |
564 |
|
} |
565 |
|
else |
566 |
|
{ |
567 |
0 |
_sortByTree(left, tmp, seqset); |
568 |
0 |
_sortByTree(right, tmp, seqset); |
569 |
|
} |
570 |
|
|
571 |
0 |
return tmp; |
572 |
|
} |
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
583 |
0 |
public static void recoverOrder(SequenceI[] alignment)... |
584 |
|
{ |
585 |
0 |
float[] ids = new float[alignment.length]; |
586 |
|
|
587 |
0 |
for (int i = 0; i < alignment.length; i++) |
588 |
|
{ |
589 |
0 |
ids[i] = (new Float(alignment[i].getName().substring(8))) |
590 |
|
.floatValue(); |
591 |
|
} |
592 |
|
|
593 |
0 |
jalview.util.QuickSort.sort(ids, alignment); |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
@param |
601 |
|
|
602 |
|
|
603 |
|
@param |
604 |
|
|
605 |
|
|
|
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 11 |
Complexity Density: 0.38 |
|
606 |
0 |
public static void sortByAnnotationScore(String scoreLabel,... |
607 |
|
AlignmentI alignment) |
608 |
|
{ |
609 |
0 |
SequenceI[] seqs = alignment.getSequencesArray(); |
610 |
0 |
boolean[] hasScore = new boolean[seqs.length]; |
611 |
|
|
612 |
0 |
int hasScores = 0; |
613 |
0 |
double[] scores = new double[seqs.length]; |
614 |
0 |
double min = 0, max = 0; |
615 |
0 |
for (int i = 0; i < seqs.length; i++) |
616 |
|
{ |
617 |
0 |
AlignmentAnnotation[] scoreAnn = seqs[i].getAnnotation(scoreLabel); |
618 |
0 |
if (scoreAnn != null) |
619 |
|
{ |
620 |
0 |
hasScores++; |
621 |
0 |
hasScore[i] = true; |
622 |
0 |
scores[i] = scoreAnn[0].getScore(); |
623 |
|
|
624 |
0 |
if (hasScores == 1) |
625 |
|
{ |
626 |
0 |
max = min = scores[i]; |
627 |
|
} |
628 |
|
else |
629 |
|
{ |
630 |
0 |
if (max < scores[i]) |
631 |
|
{ |
632 |
0 |
max = scores[i]; |
633 |
|
} |
634 |
0 |
if (min > scores[i]) |
635 |
|
{ |
636 |
0 |
min = scores[i]; |
637 |
|
} |
638 |
|
} |
639 |
|
} |
640 |
|
else |
641 |
|
{ |
642 |
0 |
hasScore[i] = false; |
643 |
|
} |
644 |
|
} |
645 |
0 |
if (hasScores == 0) |
646 |
|
{ |
647 |
0 |
return; |
648 |
|
} |
649 |
0 |
if (hasScores < seqs.length) |
650 |
|
{ |
651 |
0 |
for (int i = 0; i < seqs.length; i++) |
652 |
|
{ |
653 |
0 |
if (!hasScore[i]) |
654 |
|
{ |
655 |
0 |
scores[i] = (max + i + 1.0); |
656 |
|
} |
657 |
|
} |
658 |
|
} |
659 |
|
|
660 |
0 |
jalview.util.QuickSort.sort(scores, seqs); |
661 |
0 |
if (lastSortByAnnotation != scoreLabel) |
662 |
|
{ |
663 |
0 |
lastSortByAnnotation = scoreLabel; |
664 |
0 |
setOrder(alignment, seqs); |
665 |
|
} |
666 |
|
else |
667 |
|
{ |
668 |
0 |
setReverseOrder(alignment, seqs); |
669 |
|
} |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
public static String FEATURE_SCORE = "average_score"; |
679 |
|
|
680 |
|
public static String FEATURE_LABEL = "text"; |
681 |
|
|
682 |
|
public static String FEATURE_DENSITY = "density"; |
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
@param |
692 |
|
|
693 |
|
@param |
694 |
|
|
695 |
|
@param |
696 |
|
|
697 |
|
@param |
698 |
|
|
699 |
|
@param |
700 |
|
|
701 |
|
@param |
702 |
|
|
703 |
|
|
|
|
| 72.8% |
Uncovered Elements: 28 (103) |
Complexity: 28 |
Complexity Density: 0.46 |
|
704 |
6 |
public static void sortByFeature(List<String> featureTypes,... |
705 |
|
List<String> groups, final int startCol, final int endCol, |
706 |
|
AlignmentI alignment, String method) |
707 |
|
{ |
708 |
6 |
if (method != FEATURE_SCORE && method != FEATURE_LABEL |
709 |
|
&& method != FEATURE_DENSITY) |
710 |
|
{ |
711 |
0 |
String msg = String |
712 |
|
.format("Implementation Error - sortByFeature method must be either '%s' or '%s'", |
713 |
|
FEATURE_SCORE, FEATURE_DENSITY); |
714 |
0 |
System.err.println(msg); |
715 |
0 |
return; |
716 |
|
} |
717 |
|
|
718 |
6 |
flipFeatureSortIfUnchanged(method, featureTypes, groups, startCol, endCol); |
719 |
|
|
720 |
6 |
SequenceI[] seqs = alignment.getSequencesArray(); |
721 |
|
|
722 |
6 |
boolean[] hasScore = new boolean[seqs.length]; |
723 |
|
|
724 |
6 |
int hasScores = 0; |
725 |
6 |
double[] scores = new double[seqs.length]; |
726 |
6 |
int[] seqScores = new int[seqs.length]; |
727 |
6 |
Object[][] feats = new Object[seqs.length][]; |
728 |
6 |
double min = 0d; |
729 |
6 |
double max = 0d; |
730 |
|
|
731 |
30 |
for (int i = 0; i < seqs.length; i++) |
732 |
|
{ |
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
24 |
String[] types = featureTypes == null ? null : featureTypes |
738 |
|
.toArray(new String[featureTypes.size()]); |
739 |
24 |
List<SequenceFeature> sfs = seqs[i].findFeatures(startCol + 1, |
740 |
|
endCol + 1, types); |
741 |
|
|
742 |
24 |
seqScores[i] = 0; |
743 |
24 |
scores[i] = 0.0; |
744 |
|
|
745 |
24 |
Iterator<SequenceFeature> it = sfs.listIterator(); |
746 |
52 |
while (it.hasNext()) |
747 |
|
{ |
748 |
28 |
SequenceFeature sf = it.next(); |
749 |
|
|
750 |
|
|
751 |
|
|
752 |
|
|
753 |
|
|
754 |
28 |
String featureGroup = sf.getFeatureGroup(); |
755 |
28 |
if (groups != null && featureGroup != null |
756 |
|
&& !"".equals(featureGroup) |
757 |
|
&& !groups.contains(featureGroup)) |
758 |
|
{ |
759 |
1 |
it.remove(); |
760 |
|
} |
761 |
|
else |
762 |
|
{ |
763 |
27 |
float score = sf.getScore(); |
764 |
27 |
if (FEATURE_SCORE.equals(method) && !Float.isNaN(score)) |
765 |
|
{ |
766 |
21 |
if (seqScores[i] == 0) |
767 |
|
{ |
768 |
15 |
hasScores++; |
769 |
|
} |
770 |
21 |
seqScores[i]++; |
771 |
21 |
hasScore[i] = true; |
772 |
21 |
scores[i] += score; |
773 |
|
|
774 |
|
} |
775 |
|
} |
776 |
|
} |
777 |
|
|
778 |
24 |
feats[i] = sfs.toArray(new SequenceFeature[sfs.size()]); |
779 |
24 |
if (!sfs.isEmpty()) |
780 |
|
{ |
781 |
18 |
if (method == FEATURE_LABEL) |
782 |
|
{ |
783 |
|
|
784 |
0 |
String[] labs = new String[sfs.size()]; |
785 |
0 |
for (int l = 0; l < sfs.size(); l++) |
786 |
|
{ |
787 |
0 |
SequenceFeature sf = sfs.get(l); |
788 |
0 |
String description = sf.getDescription(); |
789 |
0 |
labs[l] = (description != null ? description : sf.getType()); |
790 |
|
} |
791 |
0 |
QuickSort.sort(labs, feats[i]); |
792 |
|
} |
793 |
|
} |
794 |
24 |
if (hasScore[i]) |
795 |
|
{ |
796 |
|
|
797 |
15 |
scores[i] /= seqScores[i]; |
798 |
|
|
799 |
15 |
if (hasScores == 1) |
800 |
|
{ |
801 |
5 |
min = scores[i]; |
802 |
5 |
max = min; |
803 |
|
} |
804 |
|
else |
805 |
|
{ |
806 |
10 |
max = Math.max(max, scores[i]); |
807 |
10 |
min = Math.min(min, scores[i]); |
808 |
|
} |
809 |
|
} |
810 |
|
} |
811 |
|
|
812 |
6 |
if (FEATURE_SCORE.equals(method)) |
813 |
|
{ |
814 |
6 |
if (hasScores == 0) |
815 |
|
{ |
816 |
1 |
return; |
817 |
|
} |
818 |
|
|
819 |
5 |
if (hasScores < seqs.length) |
820 |
|
{ |
821 |
25 |
for (int i = 0; i < seqs.length; i++) |
822 |
|
{ |
823 |
20 |
if (!hasScore[i]) |
824 |
|
{ |
825 |
5 |
scores[i] = (max + 1 + i); |
826 |
|
} |
827 |
|
else |
828 |
|
{ |
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
} |
835 |
|
} |
836 |
|
} |
837 |
5 |
QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); |
838 |
|
} |
839 |
0 |
else if (FEATURE_DENSITY.equals(method)) |
840 |
|
{ |
841 |
0 |
for (int i = 0; i < seqs.length; i++) |
842 |
|
{ |
843 |
0 |
int featureCount = feats[i] == null ? 0 |
844 |
|
: ((SequenceFeature[]) feats[i]).length; |
845 |
0 |
scores[i] = featureCount; |
846 |
|
|
847 |
|
|
848 |
|
} |
849 |
0 |
QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); |
850 |
|
} |
851 |
|
|
852 |
5 |
setOrder(alignment, seqs); |
853 |
|
} |
854 |
|
|
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
@param |
860 |
|
@param |
861 |
|
@param |
862 |
|
@param |
863 |
|
@param |
864 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
865 |
6 |
protected static void flipFeatureSortIfUnchanged(String method,... |
866 |
|
List<String> featureTypes, List<String> groups, |
867 |
|
final int startCol, final int endCol) |
868 |
|
{ |
869 |
6 |
StringBuilder sb = new StringBuilder(64); |
870 |
6 |
sb.append(startCol).append(method).append(endCol); |
871 |
6 |
if (featureTypes != null) |
872 |
|
{ |
873 |
2 |
Collections.sort(featureTypes); |
874 |
2 |
sb.append(featureTypes.toString()); |
875 |
|
} |
876 |
6 |
if (groups != null) |
877 |
|
{ |
878 |
1 |
Collections.sort(groups); |
879 |
1 |
sb.append(groups.toString()); |
880 |
|
} |
881 |
6 |
String scoreCriteria = sb.toString(); |
882 |
|
|
883 |
|
|
884 |
|
|
885 |
|
|
886 |
6 |
if (sortByFeatureCriteria == null |
887 |
|
|| !scoreCriteria.equals(sortByFeatureCriteria)) |
888 |
|
{ |
889 |
4 |
sortByFeatureAscending = true; |
890 |
|
} |
891 |
|
else |
892 |
|
{ |
893 |
2 |
sortByFeatureAscending = !sortByFeatureAscending; |
894 |
|
} |
895 |
6 |
sortByFeatureCriteria = scoreCriteria; |
896 |
|
} |
897 |
|
|
898 |
|
} |