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