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 (275) |
Complexity: 78 |
Complexity Density: 0.53 |
|
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 |
25762 |
SymbolCounts(char[] s, int[] v)... |
53 |
|
{ |
54 |
25763 |
symbols = s; |
55 |
25766 |
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 |
|
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 |
1 |
static... |
83 |
|
{ |
84 |
7 |
for (int i = 0; i < NUCS.length(); i++) |
85 |
|
{ |
86 |
6 |
NUC_INDEX[NUCS.charAt(i) - 'A'] = i + 1; |
87 |
|
} |
88 |
23 |
for (int i = 0; i < AAS.length(); i++) |
89 |
|
{ |
90 |
22 |
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 |
93516 |
public ResidueCount(boolean nucleotide)... |
144 |
|
{ |
145 |
93519 |
isNucleotide = nucleotide; |
146 |
93515 |
int charsToCount = nucleotide ? NUCS.length() : AAS.length(); |
147 |
93526 |
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 |
432459 |
public int add(final char c)... |
159 |
|
{ |
160 |
433056 |
char u = toUpperCase(c); |
161 |
433171 |
int newValue = 0; |
162 |
434491 |
int offset = getOffset(u); |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
435921 |
if (offset == 0) |
169 |
|
{ |
170 |
22286 |
if (Comparison.isGap(u)) |
171 |
|
{ |
172 |
22206 |
newValue = addGap(); |
173 |
|
} |
174 |
|
else |
175 |
|
{ |
176 |
80 |
newValue = addOtherCharacter(u); |
177 |
|
} |
178 |
|
} |
179 |
|
else |
180 |
|
{ |
181 |
414006 |
newValue = increment(offset); |
182 |
|
} |
183 |
435894 |
return newValue; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@param |
191 |
|
@return |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
193 |
465719 |
int increment(int offset)... |
194 |
|
{ |
195 |
465863 |
int newValue = 0; |
196 |
466205 |
if (useIntCounts) |
197 |
|
{ |
198 |
2 |
newValue = intCounts[offset]; |
199 |
2 |
intCounts[offset] = ++newValue; |
200 |
|
} |
201 |
|
else |
202 |
|
{ |
203 |
466107 |
if (counts[offset] == Short.MAX_VALUE) |
204 |
|
{ |
205 |
8 |
handleOverflow(); |
206 |
8 |
newValue = intCounts[offset]; |
207 |
8 |
intCounts[offset] = ++newValue; |
208 |
|
} |
209 |
|
else |
210 |
|
{ |
211 |
466562 |
newValue = counts[offset]; |
212 |
466547 |
counts[offset] = (short) ++newValue; |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
466964 |
if (offset != GAP_COUNT) |
217 |
|
{ |
218 |
|
|
219 |
413989 |
maxCount = Math.max(maxCount, newValue); |
220 |
|
} |
221 |
466495 |
return newValue; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
227 |
10 |
synchronized void handleOverflow()... |
228 |
|
{ |
229 |
10 |
intCounts = new int[counts.length]; |
230 |
144 |
for (int i = 0; i < counts.length; i++) |
231 |
|
{ |
232 |
134 |
intCounts[i] = counts[i]; |
233 |
|
} |
234 |
10 |
counts = null; |
235 |
10 |
useIntCounts = true; |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
@param |
242 |
|
@return |
243 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
244 |
433207 |
int getOffset(char c)... |
245 |
|
{ |
246 |
433839 |
int offset = 0; |
247 |
434987 |
if ('A' <= c && c <= 'Z') |
248 |
|
{ |
249 |
413647 |
offset = isNucleotide ? NUC_INDEX[c - 'A'] : AA_INDEX[c - 'A']; |
250 |
|
} |
251 |
435933 |
return offset; |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
@param |
256 |
|
@return |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
258 |
433096 |
protected char toUpperCase(final char c)... |
259 |
|
{ |
260 |
433123 |
char u = c; |
261 |
433700 |
if ('a' <= c && c <= 'z') |
262 |
|
{ |
263 |
504 |
u = (char) (c + TOUPPERCASE); |
264 |
|
} |
265 |
433837 |
return u; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
@param |
273 |
|
@return |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
275 |
80 |
int addOtherCharacter(char c)... |
276 |
|
{ |
277 |
80 |
if (otherData == null) |
278 |
|
{ |
279 |
63 |
otherData = new SparseCount(); |
280 |
|
} |
281 |
80 |
int newValue = otherData.add(c, 1); |
282 |
80 |
maxCount = Math.max(maxCount, newValue); |
283 |
80 |
return newValue; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
@param |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
293 |
5 |
void setOtherCharacter(char c, int value)... |
294 |
|
{ |
295 |
5 |
if (otherData == null) |
296 |
|
{ |
297 |
2 |
otherData = new SparseCount(); |
298 |
|
} |
299 |
5 |
otherData.put(c, value); |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
@return |
306 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
307 |
52857 |
public int addGap()... |
308 |
|
{ |
309 |
52870 |
int newValue = increment(GAP_COUNT); |
310 |
52921 |
return newValue; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
@return |
317 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
318 |
13 |
boolean isCountingInts()... |
319 |
|
{ |
320 |
13 |
return useIntCounts; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
@param |
328 |
|
@param |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
330 |
66 |
public void put(char c, int count)... |
331 |
|
{ |
332 |
66 |
char u = toUpperCase(c); |
333 |
66 |
int offset = getOffset(u); |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
66 |
if (offset == 0) |
340 |
|
{ |
341 |
8 |
if (Comparison.isGap(u)) |
342 |
|
{ |
343 |
3 |
set(0, count); |
344 |
|
} |
345 |
|
else |
346 |
|
{ |
347 |
5 |
setOtherCharacter(u, count); |
348 |
5 |
maxCount = Math.max(maxCount, count); |
349 |
|
} |
350 |
|
} |
351 |
|
else |
352 |
|
{ |
353 |
58 |
set(offset, count); |
354 |
58 |
maxCount = Math.max(maxCount, count); |
355 |
|
} |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@param |
363 |
|
@param |
364 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
365 |
62 |
void set(int offset, int value)... |
366 |
|
{ |
367 |
62 |
if (useIntCounts) |
368 |
|
{ |
369 |
1 |
intCounts[offset] = value; |
370 |
|
} |
371 |
|
else |
372 |
|
{ |
373 |
61 |
if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) |
374 |
|
{ |
375 |
2 |
handleOverflow(); |
376 |
2 |
intCounts[offset] = value; |
377 |
|
} |
378 |
|
else |
379 |
|
{ |
380 |
59 |
counts[offset] = (short) value; |
381 |
|
} |
382 |
|
} |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
@param |
389 |
|
@return |
390 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.83 |
|
391 |
62 |
public int getCount(char c)... |
392 |
|
{ |
393 |
62 |
char u = toUpperCase(c); |
394 |
62 |
int offset = getOffset(u); |
395 |
62 |
if (offset == 0) |
396 |
|
{ |
397 |
11 |
if (!Comparison.isGap(u)) |
398 |
|
{ |
399 |
|
|
400 |
6 |
return otherData == null ? 0 : otherData.get(u); |
401 |
|
} |
402 |
|
} |
403 |
56 |
return useIntCounts ? intCounts[offset] : counts[offset]; |
404 |
|
} |
405 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
406 |
93489 |
public int getGapCount()... |
407 |
|
{ |
408 |
93503 |
return useIntCounts ? intCounts[0] : counts[0]; |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
@return |
415 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
416 |
7 |
boolean isUsingOtherData()... |
417 |
|
{ |
418 |
7 |
return otherData != null; |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
@return |
429 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 12 |
Complexity Density: 0.8 |
|
430 |
75670 |
public String getResiduesForCount(int count)... |
431 |
|
{ |
432 |
75670 |
if (count == 0) |
433 |
|
{ |
434 |
237 |
return ""; |
435 |
|
} |
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
75433 |
StringBuilder modal = new StringBuilder(); |
442 |
75433 |
if (useIntCounts) |
443 |
|
{ |
444 |
60 |
for (int i = 1; i < intCounts.length; i++) |
445 |
|
{ |
446 |
56 |
if (intCounts[i] == count) |
447 |
|
{ |
448 |
4 |
modal.append( |
449 |
4 |
isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); |
450 |
|
} |
451 |
|
} |
452 |
|
} |
453 |
|
else |
454 |
|
{ |
455 |
917363 |
for (int i = 1; i < counts.length; i++) |
456 |
|
{ |
457 |
841934 |
if (counts[i] == count) |
458 |
|
{ |
459 |
76349 |
modal.append( |
460 |
76349 |
isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); |
461 |
|
} |
462 |
|
} |
463 |
|
} |
464 |
75433 |
if (otherData != null) |
465 |
|
{ |
466 |
90 |
for (int i = 0; i < otherData.size(); i++) |
467 |
|
{ |
468 |
45 |
if (otherData.valueAt(i) == count) |
469 |
|
{ |
470 |
43 |
modal.append((char) otherData.keyAt(i)); |
471 |
|
} |
472 |
|
} |
473 |
|
} |
474 |
75433 |
return modal.toString(); |
475 |
|
} |
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
@return |
481 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
482 |
75659 |
public int getModalCount()... |
483 |
|
{ |
484 |
75659 |
return maxCount; |
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
@return |
492 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 7 |
Complexity Density: 0.64 |
|
493 |
25763 |
public int size()... |
494 |
|
{ |
495 |
25763 |
int size = 0; |
496 |
25764 |
if (useIntCounts) |
497 |
|
{ |
498 |
53 |
for (int i = 1; i < intCounts.length; i++) |
499 |
|
{ |
500 |
50 |
if (intCounts[i] > 0) |
501 |
|
{ |
502 |
10 |
size++; |
503 |
|
} |
504 |
|
} |
505 |
|
} |
506 |
|
else |
507 |
|
{ |
508 |
591007 |
for (int i = 1; i < counts.length; i++) |
509 |
|
{ |
510 |
565467 |
if (counts[i] > 0) |
511 |
|
{ |
512 |
54816 |
size++; |
513 |
|
} |
514 |
|
} |
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
25756 |
if (otherData != null) |
522 |
|
{ |
523 |
25 |
size += otherData.size(); |
524 |
|
} |
525 |
|
|
526 |
25756 |
return size; |
527 |
|
} |
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
@return |
534 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 10 |
Complexity Density: 0.43 |
|
535 |
25764 |
public SymbolCounts getSymbolCounts()... |
536 |
|
{ |
537 |
25763 |
int size = size(); |
538 |
25759 |
char[] symbols = new char[size]; |
539 |
25762 |
int[] values = new int[size]; |
540 |
25763 |
int j = 0; |
541 |
|
|
542 |
25764 |
if (useIntCounts) |
543 |
|
{ |
544 |
53 |
for (int i = 1; i < intCounts.length; i++) |
545 |
|
{ |
546 |
50 |
if (intCounts[i] > 0) |
547 |
|
{ |
548 |
10 |
char symbol = isNucleotide ? NUCS.charAt(i - 1) |
549 |
|
: AAS.charAt(i - 1); |
550 |
10 |
symbols[j] = symbol; |
551 |
10 |
values[j] = intCounts[i]; |
552 |
10 |
j++; |
553 |
|
} |
554 |
|
} |
555 |
|
} |
556 |
|
else |
557 |
|
{ |
558 |
591283 |
for (int i = 1; i < counts.length; i++) |
559 |
|
{ |
560 |
565746 |
if (counts[i] > 0) |
561 |
|
{ |
562 |
54838 |
char symbol = isNucleotide ? NUCS.charAt(i - 1) |
563 |
|
: AAS.charAt(i - 1); |
564 |
54841 |
symbols[j] = symbol; |
565 |
54841 |
values[j] = counts[i]; |
566 |
54835 |
j++; |
567 |
|
} |
568 |
|
} |
569 |
|
} |
570 |
25760 |
if (otherData != null) |
571 |
|
{ |
572 |
52 |
for (int i = 0; i < otherData.size(); i++) |
573 |
|
{ |
574 |
27 |
symbols[j] = (char) otherData.keyAt(i); |
575 |
27 |
values[j] = otherData.valueAt(i); |
576 |
27 |
j++; |
577 |
|
} |
578 |
|
} |
579 |
|
|
580 |
25760 |
return new SymbolCounts(symbols, values); |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
@param |
588 |
|
|
589 |
|
|
590 |
|
@param |
591 |
|
|
592 |
|
@return |
593 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
594 |
3058 |
public String getTooltip(int normaliseBy, int percentageDecPl)... |
595 |
|
{ |
596 |
3058 |
SymbolCounts symbolCounts = getSymbolCounts(); |
597 |
3058 |
char[] ca = symbolCounts.symbols; |
598 |
3058 |
int[] vl = symbolCounts.values; |
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
3058 |
QuickSort.sort(vl, ca); |
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
3058 |
boolean first = true; |
609 |
3058 |
StringBuilder sb = new StringBuilder(64); |
610 |
9404 |
for (int c = ca.length - 1; c >= 0; c--) |
611 |
|
{ |
612 |
6346 |
final char residue = ca[c]; |
613 |
|
|
614 |
|
|
615 |
6346 |
float tval = (vl[c] * 100f) / normaliseBy; |
616 |
6346 |
sb.append(first ? "" : "; ").append(residue).append(" "); |
617 |
6346 |
Format.appendPercentage(sb, tval, percentageDecPl); |
618 |
6346 |
sb.append("%"); |
619 |
6346 |
first = false; |
620 |
|
} |
621 |
3058 |
return sb.toString(); |
622 |
|
} |
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
627 |
3 |
@Override... |
628 |
|
public String toString() |
629 |
|
{ |
630 |
3 |
StringBuilder sb = new StringBuilder(); |
631 |
3 |
sb.append("[ "); |
632 |
3 |
SymbolCounts sc = getSymbolCounts(); |
633 |
12 |
for (int i = 0; i < sc.symbols.length; i++) |
634 |
|
{ |
635 |
9 |
sb.append(sc.symbols[i]).append(":").append(sc.values[i]).append(" "); |
636 |
|
} |
637 |
3 |
sb.append("]"); |
638 |
3 |
return sb.toString(); |
639 |
|
} |
640 |
|
} |