1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import jalview.util.Comparison; |
24 |
|
import jalview.util.Format; |
25 |
|
import jalview.util.QuickSort; |
26 |
|
import jalview.util.SparseCount; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
34 |
|
|
|
|
| 40.2% |
Uncovered Elements: 153 (256) |
Complexity: 70 |
Complexity Density: 0.49 |
|
35 |
|
public class SecondaryStructureCount |
36 |
|
{ |
37 |
|
|
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
40 |
|
public class SymbolCounts |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public final char[] symbols; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public final int[] values; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
52 |
2996 |
SymbolCounts(char[] s, int[] v)... |
53 |
|
{ |
54 |
2996 |
symbols = s; |
55 |
2996 |
values = v; |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
private static final int TOUPPERCASE = 'A' - 'a'; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String SS_SYMBOLS = "HEC"; |
65 |
|
|
66 |
|
static final int GAP_COUNT = 0; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
private static int[] SS_INDEX = new int[26]; |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
74 |
1 |
static... |
75 |
|
{ |
76 |
4 |
for (int i = 0; i < SS_SYMBOLS.length(); i++) |
77 |
|
{ |
78 |
3 |
SS_INDEX[SS_SYMBOLS.charAt(i) - 'A'] = i + 1; |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
private short[] counts; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
private int[] intCounts; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
private boolean useIntCounts; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
private SparseCount otherData; |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
int maxCount; |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
116 |
80240 |
public SecondaryStructureCount()... |
117 |
|
{ |
118 |
|
|
119 |
80240 |
int charsToCount = SS_SYMBOLS.length(); |
120 |
80240 |
counts = new short[charsToCount + 1]; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
@return |
130 |
|
|
|
|
| 53.8% |
Uncovered Elements: 6 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
131 |
19832 |
public int add(final char c)... |
132 |
|
{ |
133 |
19832 |
char u = toUpperCase(c); |
134 |
19832 |
int newValue = 0; |
135 |
19832 |
int offset = getOffset(u); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
19832 |
if (offset == 0) |
142 |
|
{ |
143 |
0 |
if (Comparison.isGap(u)) |
144 |
|
{ |
145 |
0 |
newValue = addGap(); |
146 |
|
} |
147 |
|
else |
148 |
|
{ |
149 |
0 |
newValue = addOtherCharacter(u); |
150 |
|
} |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
19832 |
newValue = increment(offset); |
155 |
|
} |
156 |
19832 |
return newValue; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@param |
164 |
|
@return |
165 |
|
|
|
|
| 63.2% |
Uncovered Elements: 7 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
166 |
24998 |
int increment(int offset)... |
167 |
|
{ |
168 |
24998 |
int newValue = 0; |
169 |
24998 |
if (useIntCounts) |
170 |
|
{ |
171 |
0 |
newValue = intCounts[offset]; |
172 |
0 |
intCounts[offset] = ++newValue; |
173 |
|
} |
174 |
|
else |
175 |
|
{ |
176 |
24998 |
if (counts[offset] == Short.MAX_VALUE) |
177 |
|
{ |
178 |
0 |
handleOverflow(); |
179 |
0 |
newValue = intCounts[offset]; |
180 |
0 |
intCounts[offset] = ++newValue; |
181 |
|
} |
182 |
|
else |
183 |
|
{ |
184 |
24998 |
newValue = counts[offset]; |
185 |
24998 |
counts[offset] = (short) ++newValue; |
186 |
|
} |
187 |
|
} |
188 |
|
|
189 |
24998 |
if (offset != GAP_COUNT) |
190 |
|
{ |
191 |
|
|
192 |
19832 |
maxCount = Math.max(maxCount, newValue); |
193 |
|
} |
194 |
24998 |
return newValue; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
200 |
0 |
synchronized void handleOverflow()... |
201 |
|
{ |
202 |
0 |
intCounts = new int[counts.length]; |
203 |
0 |
for (int i = 0; i < counts.length; i++) |
204 |
|
{ |
205 |
0 |
intCounts[i] = counts[i]; |
206 |
|
} |
207 |
0 |
counts = null; |
208 |
0 |
useIntCounts = true; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
@return |
216 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
217 |
19832 |
int getOffset(char c)... |
218 |
|
{ |
219 |
19832 |
int offset = 0; |
220 |
19832 |
if ('A' <= c && c <= 'Z') |
221 |
|
{ |
222 |
19832 |
offset = SS_INDEX[c - 'A']; |
223 |
|
} |
224 |
19832 |
return offset; |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
@param |
229 |
|
@return |
230 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
231 |
19832 |
protected char toUpperCase(final char c)... |
232 |
|
{ |
233 |
19832 |
char u = c; |
234 |
19832 |
if ('a' <= c && c <= 'z') |
235 |
|
{ |
236 |
0 |
u = (char) (c + TOUPPERCASE); |
237 |
|
} |
238 |
19832 |
return u; |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
@return |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
248 |
0 |
int addOtherCharacter(char c)... |
249 |
|
{ |
250 |
0 |
if (otherData == null) |
251 |
|
{ |
252 |
0 |
otherData = new SparseCount(); |
253 |
|
} |
254 |
0 |
int newValue = otherData.add(c, 1); |
255 |
0 |
maxCount = Math.max(maxCount, newValue); |
256 |
0 |
return newValue; |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
@param |
264 |
|
@param |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
266 |
0 |
void setOtherCharacter(char c, int value)... |
267 |
|
{ |
268 |
0 |
if (otherData == null) |
269 |
|
{ |
270 |
0 |
otherData = new SparseCount(); |
271 |
|
} |
272 |
0 |
otherData.put(c, value); |
273 |
|
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
@return |
279 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
280 |
5166 |
public int addGap()... |
281 |
|
{ |
282 |
5166 |
int newValue = increment(GAP_COUNT); |
283 |
5166 |
return newValue; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@return |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
291 |
0 |
boolean isCountingInts()... |
292 |
|
{ |
293 |
0 |
return useIntCounts; |
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@param |
301 |
|
@param |
302 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
303 |
0 |
public void put(char c, int count)... |
304 |
|
{ |
305 |
0 |
char u = toUpperCase(c); |
306 |
0 |
int offset = getOffset(u); |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
0 |
if (offset == 0) |
313 |
|
{ |
314 |
0 |
if (Comparison.isGap(u)) |
315 |
|
{ |
316 |
0 |
set(0, count); |
317 |
|
} |
318 |
|
else |
319 |
|
{ |
320 |
0 |
setOtherCharacter(u, count); |
321 |
0 |
maxCount = Math.max(maxCount, count); |
322 |
|
} |
323 |
|
} |
324 |
|
else |
325 |
|
{ |
326 |
0 |
set(offset, count); |
327 |
0 |
maxCount = Math.max(maxCount, count); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
@param |
336 |
|
@param |
337 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
338 |
0 |
void set(int offset, int value)... |
339 |
|
{ |
340 |
0 |
if (useIntCounts) |
341 |
|
{ |
342 |
0 |
intCounts[offset] = value; |
343 |
|
} |
344 |
|
else |
345 |
|
{ |
346 |
0 |
if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) |
347 |
|
{ |
348 |
0 |
handleOverflow(); |
349 |
0 |
intCounts[offset] = value; |
350 |
|
} |
351 |
|
else |
352 |
|
{ |
353 |
0 |
counts[offset] = (short) value; |
354 |
|
} |
355 |
|
} |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
@param |
362 |
|
@return |
363 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.83 |
|
364 |
0 |
public int getCount(char c)... |
365 |
|
{ |
366 |
0 |
char u = toUpperCase(c); |
367 |
0 |
int offset = getOffset(u); |
368 |
0 |
if (offset == 0) |
369 |
|
{ |
370 |
0 |
if (!Comparison.isGap(u)) |
371 |
|
{ |
372 |
|
|
373 |
0 |
return otherData == null ? 0 : otherData.get(u); |
374 |
|
} |
375 |
|
} |
376 |
0 |
return useIntCounts ? intCounts[offset] : counts[offset]; |
377 |
|
} |
378 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
379 |
80240 |
public int getGapCount()... |
380 |
|
{ |
381 |
80240 |
return useIntCounts ? intCounts[0] : counts[0]; |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
@return |
388 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
0 |
boolean isUsingOtherData()... |
390 |
|
{ |
391 |
0 |
return otherData != null; |
392 |
|
} |
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
@return |
402 |
|
|
|
|
| 51.5% |
Uncovered Elements: 16 (33) |
Complexity: 10 |
Complexity Density: 0.67 |
|
403 |
80240 |
public String getSSForCount(int count)... |
404 |
|
{ |
405 |
80240 |
if (count == 0) |
406 |
|
{ |
407 |
71286 |
return ""; |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
8954 |
StringBuilder modal = new StringBuilder(); |
415 |
8954 |
if (useIntCounts) |
416 |
|
{ |
417 |
0 |
for (int i = 1; i < intCounts.length; i++) |
418 |
|
{ |
419 |
0 |
if (intCounts[i] == count) |
420 |
|
{ |
421 |
0 |
modal.append(SS_SYMBOLS.charAt(i - 1)); |
422 |
|
} |
423 |
|
} |
424 |
|
} |
425 |
|
else |
426 |
|
{ |
427 |
35816 |
for (int i = 1; i < counts.length; i++) |
428 |
|
{ |
429 |
26862 |
if (counts[i] == count) |
430 |
|
{ |
431 |
9226 |
modal.append(SS_SYMBOLS.charAt(i - 1)); |
432 |
|
} |
433 |
|
} |
434 |
|
} |
435 |
8954 |
if (otherData != null) |
436 |
|
{ |
437 |
0 |
for (int i = 0; i < otherData.size(); i++) |
438 |
|
{ |
439 |
0 |
if (otherData.valueAt(i) == count) |
440 |
|
{ |
441 |
0 |
modal.append((char) otherData.keyAt(i)); |
442 |
|
} |
443 |
|
} |
444 |
|
} |
445 |
8954 |
return modal.toString(); |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
@return |
452 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
453 |
80240 |
public int getModalCount()... |
454 |
|
{ |
455 |
80240 |
return maxCount; |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
@return |
463 |
|
|
|
|
| 47.8% |
Uncovered Elements: 12 (23) |
Complexity: 7 |
Complexity Density: 0.64 |
|
464 |
2996 |
public int size()... |
465 |
|
{ |
466 |
2996 |
int size = 0; |
467 |
2996 |
if (useIntCounts) |
468 |
|
{ |
469 |
0 |
for (int i = 1; i < intCounts.length; i++) |
470 |
|
{ |
471 |
0 |
if (intCounts[i] > 0) |
472 |
|
{ |
473 |
0 |
size++; |
474 |
|
} |
475 |
|
} |
476 |
|
} |
477 |
|
else |
478 |
|
{ |
479 |
11984 |
for (int i = 1; i < counts.length; i++) |
480 |
|
{ |
481 |
8988 |
if (counts[i] > 0) |
482 |
|
{ |
483 |
0 |
size++; |
484 |
|
} |
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
|
492 |
2996 |
if (otherData != null) |
493 |
|
{ |
494 |
0 |
size += otherData.size(); |
495 |
|
} |
496 |
|
|
497 |
2996 |
return size; |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
@return |
505 |
|
|
|
|
| 37.8% |
Uncovered Elements: 23 (37) |
Complexity: 8 |
Complexity Density: 0.35 |
|
506 |
2996 |
public SymbolCounts getSymbolCounts()... |
507 |
|
{ |
508 |
2996 |
int size = size(); |
509 |
2996 |
char[] symbols = new char[size]; |
510 |
2996 |
int[] values = new int[size]; |
511 |
2996 |
int j = 0; |
512 |
|
|
513 |
2996 |
if (useIntCounts) |
514 |
|
{ |
515 |
0 |
for (int i = 1; i < intCounts.length; i++) |
516 |
|
{ |
517 |
0 |
if (intCounts[i] > 0) |
518 |
|
{ |
519 |
0 |
char symbol = SS_SYMBOLS.charAt(i - 1); |
520 |
0 |
symbols[j] = symbol; |
521 |
0 |
values[j] = intCounts[i]; |
522 |
0 |
j++; |
523 |
|
} |
524 |
|
} |
525 |
|
} |
526 |
|
else |
527 |
|
{ |
528 |
11984 |
for (int i = 1; i < counts.length; i++) |
529 |
|
{ |
530 |
8988 |
if (counts[i] > 0) |
531 |
|
{ |
532 |
0 |
char symbol = SS_SYMBOLS.charAt(i - 1); |
533 |
0 |
symbols[j] = symbol; |
534 |
0 |
values[j] = counts[i]; |
535 |
0 |
j++; |
536 |
|
} |
537 |
|
} |
538 |
|
} |
539 |
2996 |
if (otherData != null) |
540 |
|
{ |
541 |
0 |
for (int i = 0; i < otherData.size(); i++) |
542 |
|
{ |
543 |
0 |
symbols[j] = (char) otherData.keyAt(i); |
544 |
0 |
values[j] = otherData.valueAt(i); |
545 |
0 |
j++; |
546 |
|
} |
547 |
|
} |
548 |
|
|
549 |
2996 |
return new SymbolCounts(symbols, values); |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
|
@param |
557 |
|
|
558 |
|
|
559 |
|
@param |
560 |
|
|
561 |
|
@return |
562 |
|
|
|
|
| 50% |
Uncovered Elements: 9 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
563 |
2996 |
public String getTooltip(int normaliseBy, int percentageDecPl)... |
564 |
|
{ |
565 |
2996 |
SymbolCounts symbolCounts = getSymbolCounts(); |
566 |
2996 |
char[] ca = symbolCounts.symbols; |
567 |
2996 |
int[] vl = symbolCounts.values; |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
2996 |
QuickSort.sort(vl, ca); |
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
2996 |
boolean first = true; |
578 |
2996 |
StringBuilder sb = new StringBuilder(64); |
579 |
2996 |
for (int c = ca.length - 1; c >= 0; c--) |
580 |
|
{ |
581 |
0 |
final char residue = ca[c]; |
582 |
|
|
583 |
|
|
584 |
0 |
float tval = (vl[c] * 100f) / normaliseBy; |
585 |
0 |
sb.append(first ? "" : "; ").append(residue).append(" "); |
586 |
0 |
Format.appendPercentage(sb, tval, percentageDecPl); |
587 |
0 |
sb.append("%"); |
588 |
0 |
first = false; |
589 |
|
} |
590 |
2996 |
return sb.toString(); |
591 |
|
} |
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
596 |
0 |
@Override... |
597 |
|
public String toString() |
598 |
|
{ |
599 |
0 |
StringBuilder sb = new StringBuilder(); |
600 |
0 |
sb.append("[ "); |
601 |
0 |
SymbolCounts sc = getSymbolCounts(); |
602 |
0 |
for (int i = 0; i < sc.symbols.length; i++) |
603 |
|
{ |
604 |
0 |
sb.append(sc.symbols[i]).append(":").append(sc.values[i]).append(" "); |
605 |
|
} |
606 |
0 |
sb.append("]"); |
607 |
0 |
return sb.toString(); |
608 |
|
} |
609 |
|
} |