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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (277) |
Complexity: 78 |
Complexity Density: 0.52 |
|
35 |
|
public class ResidueCount |
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 |
139345 |
SymbolCounts(char[] s, int[] v)... |
53 |
|
{ |
54 |
139347 |
symbols = s; |
55 |
139350 |
values = v; |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
private static final int TOUPPERCASE = 'A' - 'a'; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String NUCS = "ACGNTU"; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private static final String AAS = "ACDEFGHIKLMNPQRSTUVWXY"; |
72 |
|
|
73 |
|
private static final int GAP_COUNT = 0; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
private static int[] NUC_INDEX = new int[26]; |
80 |
|
|
81 |
|
private static int[] AA_INDEX = new int[26]; |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
82 |
18 |
static... |
83 |
|
{ |
84 |
126 |
for (int i = 0; i < NUCS.length(); i++) |
85 |
|
{ |
86 |
108 |
NUC_INDEX[NUCS.charAt(i) - 'A'] = i + 1; |
87 |
|
} |
88 |
414 |
for (int i = 0; i < AAS.length(); i++) |
89 |
|
{ |
90 |
396 |
AA_INDEX[AAS.charAt(i) - 'A'] = i + 1; |
91 |
|
} |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
private short[] counts; |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
private int[] intCounts; |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
private boolean useIntCounts; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
private SparseCount otherData; |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
int maxCount; |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
private boolean isNucleotide; |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
10 |
public ResidueCount()... |
135 |
|
{ |
136 |
10 |
this(false); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
143 |
591051 |
public ResidueCount(boolean nucleotide)... |
144 |
|
{ |
145 |
591081 |
isNucleotide = nucleotide; |
146 |
591038 |
int charsToCount = nucleotide ? NUCS.length() : AAS.length(); |
147 |
591041 |
counts = new short[charsToCount + 1]; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
@return |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
158 |
9954585 |
public int add(final char c)... |
159 |
|
{ |
160 |
9957535 |
char u = toUpperCase(c); |
161 |
10048355 |
int newValue = 0; |
162 |
10055597 |
int offset = getOffset(u); |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
10165719 |
if (offset == 0) |
169 |
|
{ |
170 |
7964435 |
if (Comparison.isGap(u)) |
171 |
|
{ |
172 |
8110497 |
newValue = addGap(); |
173 |
|
} |
174 |
|
else |
175 |
|
{ |
176 |
86 |
newValue = addOtherCharacter(u); |
177 |
|
} |
178 |
|
} |
179 |
|
else |
180 |
|
{ |
181 |
2080587 |
newValue = increment(offset); |
182 |
|
} |
183 |
10115454 |
return newValue; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@param |
191 |
|
@return |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
193 |
2080475 |
int increment(int offset)... |
194 |
|
{ |
195 |
2080618 |
int newValue = 0; |
196 |
2081152 |
if (useIntCounts) |
197 |
|
{ |
198 |
1 |
newValue = intCounts[offset]; |
199 |
1 |
intCounts[offset] = ++newValue; |
200 |
|
} |
201 |
|
else |
202 |
|
{ |
203 |
2084023 |
if (counts[offset] == Short.MAX_VALUE) |
204 |
|
{ |
205 |
7 |
handleOverflow(); |
206 |
7 |
newValue = intCounts[offset]; |
207 |
7 |
intCounts[offset] = ++newValue; |
208 |
|
} |
209 |
|
else |
210 |
|
{ |
211 |
2085878 |
newValue = counts[offset]; |
212 |
2085770 |
counts[offset] = (short) ++newValue; |
213 |
|
} |
214 |
|
} |
215 |
2089257 |
maxCount = Math.max(maxCount, newValue); |
216 |
2090170 |
return newValue; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
222 |
9 |
synchronized void handleOverflow()... |
223 |
|
{ |
224 |
9 |
intCounts = new int[counts.length]; |
225 |
136 |
for (int i = 0; i < counts.length; i++) |
226 |
|
{ |
227 |
127 |
intCounts[i] = counts[i]; |
228 |
|
} |
229 |
9 |
counts = null; |
230 |
9 |
useIntCounts = true; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
@param |
237 |
|
@return |
238 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
239 |
10058505 |
int getOffset(char c)... |
240 |
|
{ |
241 |
10064775 |
int offset = 0; |
242 |
10179473 |
if ('A' <= c && c <= 'Z') |
243 |
|
{ |
244 |
2082477 |
offset = isNucleotide ? NUC_INDEX[c - 'A'] : AA_INDEX[c - 'A']; |
245 |
|
} |
246 |
10085467 |
return offset; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
@param |
251 |
|
@return |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
253 |
9975140 |
protected char toUpperCase(final char c)... |
254 |
|
{ |
255 |
9993853 |
char u = c; |
256 |
10019880 |
if ('a' <= c && c <= 'z') |
257 |
|
{ |
258 |
315 |
u = (char) (c + TOUPPERCASE); |
259 |
|
} |
260 |
10025007 |
return u; |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
@param |
268 |
|
@return |
269 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
270 |
86 |
int addOtherCharacter(char c)... |
271 |
|
{ |
272 |
86 |
if (otherData == null) |
273 |
|
{ |
274 |
67 |
otherData = new SparseCount(); |
275 |
|
} |
276 |
86 |
int newValue = otherData.add(c, 1); |
277 |
86 |
maxCount = Math.max(maxCount, newValue); |
278 |
86 |
return newValue; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@param |
286 |
|
@param |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
288 |
5 |
void setOtherCharacter(char c, int value)... |
289 |
|
{ |
290 |
5 |
if (otherData == null) |
291 |
|
{ |
292 |
2 |
otherData = new SparseCount(); |
293 |
|
} |
294 |
5 |
otherData.put(c, value); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@return |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
302 |
8248046 |
public int addGap()... |
303 |
|
{ |
304 |
8266541 |
int newValue; |
305 |
8246969 |
if (useIntCounts) |
306 |
|
{ |
307 |
1 |
newValue = ++intCounts[GAP_COUNT]; |
308 |
|
} |
309 |
|
else |
310 |
|
{ |
311 |
8288140 |
newValue = ++counts[GAP_COUNT]; |
312 |
|
} |
313 |
8287959 |
return newValue; |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
@return |
320 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
321 |
10 |
boolean isCountingInts()... |
322 |
|
{ |
323 |
10 |
return useIntCounts; |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
@param |
331 |
|
@param |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
333 |
66 |
public void put(char c, int count)... |
334 |
|
{ |
335 |
66 |
char u = toUpperCase(c); |
336 |
66 |
int offset = getOffset(u); |
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
66 |
if (offset == 0) |
343 |
|
{ |
344 |
8 |
if (Comparison.isGap(u)) |
345 |
|
{ |
346 |
3 |
set(0, count); |
347 |
|
} |
348 |
|
else |
349 |
|
{ |
350 |
5 |
setOtherCharacter(u, count); |
351 |
5 |
maxCount = Math.max(maxCount, count); |
352 |
|
} |
353 |
|
} |
354 |
|
else |
355 |
|
{ |
356 |
58 |
set(offset, count); |
357 |
58 |
maxCount = Math.max(maxCount, count); |
358 |
|
} |
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
@param |
366 |
|
@param |
367 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
368 |
61 |
void set(int offset, int value)... |
369 |
|
{ |
370 |
61 |
if (useIntCounts) |
371 |
|
{ |
372 |
1 |
intCounts[offset] = value; |
373 |
|
} |
374 |
|
else |
375 |
|
{ |
376 |
60 |
if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) |
377 |
|
{ |
378 |
2 |
handleOverflow(); |
379 |
2 |
intCounts[offset] = value; |
380 |
|
} |
381 |
|
else |
382 |
|
{ |
383 |
58 |
counts[offset] = (short) value; |
384 |
|
} |
385 |
|
} |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
@param |
392 |
|
@return |
393 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.83 |
|
394 |
62 |
public int getCount(char c)... |
395 |
|
{ |
396 |
62 |
char u = toUpperCase(c); |
397 |
62 |
int offset = getOffset(u); |
398 |
62 |
if (offset == 0) |
399 |
|
{ |
400 |
11 |
if (!Comparison.isGap(u)) |
401 |
|
{ |
402 |
|
|
403 |
6 |
return otherData == null ? 0 : otherData.get(u); |
404 |
|
} |
405 |
|
} |
406 |
56 |
return useIntCounts ? intCounts[offset] : counts[offset]; |
407 |
|
} |
408 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
409 |
590980 |
public int getGapCount()... |
410 |
|
{ |
411 |
590940 |
return useIntCounts ? intCounts[0] : counts[0]; |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
@return |
418 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
419 |
7 |
boolean isUsingOtherData()... |
420 |
|
{ |
421 |
7 |
return otherData != null; |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
@return |
432 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 12 |
Complexity Density: 0.8 |
|
433 |
514234 |
public String getResiduesForCount(int count)... |
434 |
|
{ |
435 |
514231 |
if (count == 0) |
436 |
|
{ |
437 |
1569 |
return ""; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
512669 |
StringBuilder modal = new StringBuilder(); |
445 |
515925 |
if (useIntCounts) |
446 |
|
{ |
447 |
60 |
for (int i = 1; i < intCounts.length; i++) |
448 |
|
{ |
449 |
56 |
if (intCounts[i] == count) |
450 |
|
{ |
451 |
4 |
modal.append( |
452 |
4 |
isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); |
453 |
|
} |
454 |
|
} |
455 |
|
} |
456 |
|
else |
457 |
|
{ |
458 |
5208242 |
for (int i = 1; i < counts.length; i++) |
459 |
|
{ |
460 |
4697548 |
if (counts[i] == count) |
461 |
|
{ |
462 |
523932 |
modal.append( |
463 |
523968 |
isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); |
464 |
|
} |
465 |
|
} |
466 |
|
} |
467 |
516848 |
if (otherData != null) |
468 |
|
{ |
469 |
94 |
for (int i = 0; i < otherData.size(); i++) |
470 |
|
{ |
471 |
47 |
if (otherData.valueAt(i) == count) |
472 |
|
{ |
473 |
45 |
modal.append((char) otherData.keyAt(i)); |
474 |
|
} |
475 |
|
} |
476 |
|
} |
477 |
516797 |
return modal.toString(); |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
@return |
484 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
485 |
514252 |
public int getModalCount()... |
486 |
|
{ |
487 |
514252 |
return maxCount; |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
@return |
495 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 7 |
Complexity Density: 0.64 |
|
496 |
139332 |
public int size()... |
497 |
|
{ |
498 |
139334 |
int size = 0; |
499 |
139335 |
if (useIntCounts) |
500 |
|
{ |
501 |
53 |
for (int i = 1; i < intCounts.length; i++) |
502 |
|
{ |
503 |
50 |
if (intCounts[i] > 0) |
504 |
|
{ |
505 |
10 |
size++; |
506 |
|
} |
507 |
|
} |
508 |
|
} |
509 |
|
else |
510 |
|
{ |
511 |
3198975 |
for (int i = 1; i < counts.length; i++) |
512 |
|
{ |
513 |
3060605 |
if (counts[i] > 0) |
514 |
|
{ |
515 |
270844 |
size++; |
516 |
|
} |
517 |
|
} |
518 |
|
} |
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
139347 |
if (otherData != null) |
525 |
|
{ |
526 |
23 |
size += otherData.size(); |
527 |
|
} |
528 |
|
|
529 |
139334 |
return size; |
530 |
|
} |
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
|
@return |
537 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 10 |
Complexity Density: 0.43 |
|
538 |
139337 |
public SymbolCounts getSymbolCounts()... |
539 |
|
{ |
540 |
139335 |
int size = size(); |
541 |
139337 |
char[] symbols = new char[size]; |
542 |
139330 |
int[] values = new int[size]; |
543 |
139340 |
int j = 0; |
544 |
|
|
545 |
139352 |
if (useIntCounts) |
546 |
|
{ |
547 |
53 |
for (int i = 1; i < intCounts.length; i++) |
548 |
|
{ |
549 |
50 |
if (intCounts[i] > 0) |
550 |
|
{ |
551 |
10 |
char symbol = isNucleotide ? NUCS.charAt(i - 1) |
552 |
|
: AAS.charAt(i - 1); |
553 |
10 |
symbols[j] = symbol; |
554 |
10 |
values[j] = intCounts[i]; |
555 |
10 |
j++; |
556 |
|
} |
557 |
|
} |
558 |
|
} |
559 |
|
else |
560 |
|
{ |
561 |
3199026 |
for (int i = 1; i < counts.length; i++) |
562 |
|
{ |
563 |
3060672 |
if (counts[i] > 0) |
564 |
|
{ |
565 |
270836 |
char symbol = isNucleotide ? NUCS.charAt(i - 1) |
566 |
|
: AAS.charAt(i - 1); |
567 |
270835 |
symbols[j] = symbol; |
568 |
270833 |
values[j] = counts[i]; |
569 |
270782 |
j++; |
570 |
|
} |
571 |
|
} |
572 |
|
} |
573 |
139340 |
if (otherData != null) |
574 |
|
{ |
575 |
48 |
for (int i = 0; i < otherData.size(); i++) |
576 |
|
{ |
577 |
25 |
symbols[j] = (char) otherData.keyAt(i); |
578 |
25 |
values[j] = otherData.valueAt(i); |
579 |
25 |
j++; |
580 |
|
} |
581 |
|
} |
582 |
|
|
583 |
139344 |
return new SymbolCounts(symbols, values); |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
@param |
591 |
|
|
592 |
|
|
593 |
|
@param |
594 |
|
|
595 |
|
@return |
596 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
597 |
33763 |
public String getTooltip(int normaliseBy, int percentageDecPl)... |
598 |
|
{ |
599 |
33763 |
SymbolCounts symbolCounts = getSymbolCounts(); |
600 |
33762 |
char[] ca = symbolCounts.symbols; |
601 |
33762 |
int[] vl = symbolCounts.values; |
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
33762 |
QuickSort.sort(vl, ca); |
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
33759 |
boolean first = true; |
612 |
33759 |
StringBuilder sb = new StringBuilder(64); |
613 |
96171 |
for (int c = ca.length - 1; c >= 0; c--) |
614 |
|
{ |
615 |
62409 |
final char residue = ca[c]; |
616 |
|
|
617 |
|
|
618 |
62408 |
float tval = (vl[c] * 100f) / normaliseBy; |
619 |
62416 |
sb.append(first ? "" : "; ").append(residue).append(" "); |
620 |
62409 |
Format.appendPercentage(sb, tval, percentageDecPl); |
621 |
62418 |
sb.append("%"); |
622 |
62418 |
first = false; |
623 |
|
} |
624 |
33762 |
return sb.toString(); |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
630 |
3 |
@Override... |
631 |
|
public String toString() |
632 |
|
{ |
633 |
3 |
StringBuilder sb = new StringBuilder(); |
634 |
3 |
sb.append("[ "); |
635 |
3 |
SymbolCounts sc = getSymbolCounts(); |
636 |
12 |
for (int i = 0; i < sc.symbols.length; i++) |
637 |
|
{ |
638 |
9 |
sb.append(sc.symbols[i]).append(":").append(sc.values[i]).append(" "); |
639 |
|
} |
640 |
3 |
sb.append("]"); |
641 |
3 |
return sb.toString(); |
642 |
|
} |
643 |
|
} |