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.datamodel.AlignedCodonFrame; |
24 |
|
import jalview.datamodel.AlignmentAnnotation; |
25 |
|
import jalview.datamodel.AlignmentI; |
26 |
|
import jalview.datamodel.Annotation; |
27 |
|
import jalview.datamodel.Profile; |
28 |
|
import jalview.datamodel.ProfileI; |
29 |
|
import jalview.datamodel.Profiles; |
30 |
|
import jalview.datamodel.ProfilesI; |
31 |
|
import jalview.datamodel.ResidueCount; |
32 |
|
import jalview.datamodel.ResidueCount.SymbolCounts; |
33 |
|
import jalview.datamodel.SequenceI; |
34 |
|
import jalview.ext.android.SparseIntArray; |
35 |
|
import jalview.util.Comparison; |
36 |
|
import jalview.util.Format; |
37 |
|
import jalview.util.MappingUtils; |
38 |
|
import jalview.util.QuickSort; |
39 |
|
|
40 |
|
import java.awt.Color; |
41 |
|
import java.util.Arrays; |
42 |
|
import java.util.Hashtable; |
43 |
|
import java.util.List; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@author |
52 |
|
@version |
53 |
|
|
|
|
| 87.5% |
Uncovered Elements: 43 (344) |
Complexity: 77 |
Complexity Density: 0.34 |
|
54 |
|
public class AAFrequency |
55 |
|
{ |
56 |
|
public static final String PROFILE = "P"; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
private static final String[] CHARS = new String['Z' - 'A' + 1]; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
63 |
18 |
static... |
64 |
|
{ |
65 |
486 |
for (char c = 'A'; c <= 'Z'; c++) |
66 |
|
{ |
67 |
468 |
CHARS[c - 'A'] = String.valueOf(c); |
68 |
|
} |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
3 |
public static final ProfilesI calculate(List<SequenceI> list, int start,... |
72 |
|
int end) |
73 |
|
{ |
74 |
3 |
return calculate(list, start, end, false); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
77 |
357 |
public static final ProfilesI calculate(List<SequenceI> sequences,... |
78 |
|
int start, int end, boolean profile) |
79 |
|
{ |
80 |
357 |
SequenceI[] seqs = new SequenceI[sequences.size()]; |
81 |
357 |
int width = 0; |
82 |
357 |
synchronized (sequences) |
83 |
|
{ |
84 |
3031 |
for (int i = 0; i < sequences.size(); i++) |
85 |
|
{ |
86 |
2674 |
seqs[i] = sequences.get(i); |
87 |
2674 |
int length = seqs[i].getLength(); |
88 |
2674 |
if (length > width) |
89 |
|
{ |
90 |
356 |
width = length; |
91 |
|
} |
92 |
|
} |
93 |
|
|
94 |
357 |
if (end >= width) |
95 |
|
{ |
96 |
209 |
end = width; |
97 |
|
} |
98 |
|
|
99 |
357 |
ProfilesI reply = calculate(seqs, width, start, end, profile); |
100 |
357 |
return reply; |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
@param |
108 |
|
@param |
109 |
|
|
110 |
|
@param |
111 |
|
|
112 |
|
@param |
113 |
|
|
114 |
|
@param |
115 |
|
|
116 |
|
|
|
|
| 93.3% |
Uncovered Elements: 3 (45) |
Complexity: 10 |
Complexity Density: 0.34 |
|
117 |
820 |
public static final ProfilesI calculate(final SequenceI[] sequences,... |
118 |
|
int width, int start, int end, boolean saveFullProfile) |
119 |
|
{ |
120 |
|
|
121 |
820 |
int seqCount = sequences.length; |
122 |
820 |
boolean nucleotide = false; |
123 |
820 |
int nucleotideCount = 0; |
124 |
820 |
int peptideCount = 0; |
125 |
|
|
126 |
820 |
ProfileI[] result = new ProfileI[width]; |
127 |
|
|
128 |
519296 |
for (int column = start; column < end; column++) |
129 |
|
{ |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
518527 |
if (nucleotideCount > 100 && column % 10 == 0) |
141 |
|
{ |
142 |
46962 |
nucleotide = (9 * peptideCount < nucleotideCount); |
143 |
|
} |
144 |
518529 |
ResidueCount residueCounts = new ResidueCount(nucleotide); |
145 |
|
|
146 |
9887476 |
for (int row = 0; row < seqCount; row++) |
147 |
|
{ |
148 |
9339777 |
if (sequences[row] == null) |
149 |
|
{ |
150 |
0 |
System.err.println( |
151 |
|
"WARNING: Consensus skipping null sequence - possible race condition."); |
152 |
0 |
continue; |
153 |
|
} |
154 |
9201147 |
if (sequences[row].getLength() > column) |
155 |
|
{ |
156 |
9258157 |
char c = sequences[row].getCharAt(column); |
157 |
9267848 |
residueCounts.add(c); |
158 |
9507282 |
if (Comparison.isNucleotide(c)) |
159 |
|
{ |
160 |
801724 |
nucleotideCount++; |
161 |
|
} |
162 |
8647552 |
else if (!Comparison.isGap(c)) |
163 |
|
{ |
164 |
592450 |
peptideCount++; |
165 |
|
} |
166 |
|
} |
167 |
|
else |
168 |
|
{ |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
29635 |
residueCounts.addGap(); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
514252 |
int maxCount = residueCounts.getModalCount(); |
177 |
514231 |
String maxResidue = residueCounts.getResiduesForCount(maxCount); |
178 |
518407 |
int gapCount = residueCounts.getGapCount(); |
179 |
518408 |
ProfileI profile = new Profile(seqCount, gapCount, maxCount, |
180 |
|
maxResidue); |
181 |
|
|
182 |
517849 |
if (saveFullProfile) |
183 |
|
{ |
184 |
500166 |
profile.setCounts(residueCounts); |
185 |
|
} |
186 |
|
|
187 |
517570 |
result[column] = profile; |
188 |
|
} |
189 |
820 |
return new Profiles(result); |
190 |
|
|
191 |
|
|
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
@param |
201 |
|
|
202 |
|
@return |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
204 |
0 |
static int estimateProfileSize(SparseIntArray profileSizes)... |
205 |
|
{ |
206 |
0 |
if (profileSizes.size() == 0) |
207 |
|
{ |
208 |
0 |
return 4; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
0 |
return profileSizes.keyAt(profileSizes.size() - 1); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
|
226 |
|
@param |
227 |
|
|
228 |
|
@param |
229 |
|
|
230 |
|
@param |
231 |
|
|
232 |
|
@param |
233 |
|
|
234 |
|
@param |
235 |
|
|
236 |
|
|
237 |
|
@param |
238 |
|
|
239 |
|
|
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
240 |
595 |
public static void completeConsensus(AlignmentAnnotation consensus,... |
241 |
|
ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps, |
242 |
|
boolean showSequenceLogo, long nseq) |
243 |
|
{ |
244 |
|
|
245 |
595 |
if (consensus == null || consensus.annotations == null |
246 |
|
|| consensus.annotations.length < endCol) |
247 |
|
{ |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
0 |
return; |
253 |
|
} |
254 |
|
|
255 |
500773 |
for (int i = startCol; i < endCol; i++) |
256 |
|
{ |
257 |
500087 |
ProfileI profile = profiles.get(i); |
258 |
499877 |
if (profile == null) |
259 |
|
{ |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
0 |
consensus.annotations[i] = null; |
265 |
0 |
return; |
266 |
|
} |
267 |
|
|
268 |
499756 |
final int dp = getPercentageDp(nseq); |
269 |
|
|
270 |
498782 |
float value = profile.getPercentageIdentity(ignoreGaps); |
271 |
|
|
272 |
498881 |
String description = getTooltip(profile, value, showSequenceLogo, |
273 |
|
ignoreGaps, dp); |
274 |
|
|
275 |
500158 |
String modalResidue = profile.getModalResidue(); |
276 |
499632 |
if ("".equals(modalResidue)) |
277 |
|
{ |
278 |
1107 |
modalResidue = "-"; |
279 |
|
} |
280 |
498522 |
else if (modalResidue.length() > 1) |
281 |
|
{ |
282 |
5335 |
modalResidue = "+"; |
283 |
|
} |
284 |
499551 |
consensus.annotations[i] = new Annotation(modalResidue, description, |
285 |
|
' ', value); |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
@param |
295 |
|
|
296 |
|
@param |
297 |
|
|
298 |
|
@param |
299 |
|
|
300 |
|
@param |
301 |
|
|
302 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
303 |
471 |
public static void completeGapAnnot(AlignmentAnnotation gaprow,... |
304 |
|
ProfilesI profiles, int startCol, int endCol, long nseq) |
305 |
|
{ |
306 |
471 |
if (gaprow == null || gaprow.annotations == null |
307 |
|
|| gaprow.annotations.length < endCol) |
308 |
|
{ |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
0 |
return; |
314 |
|
} |
315 |
|
|
316 |
471 |
gaprow.graphMax = nseq; |
317 |
471 |
gaprow.graphMin = 0; |
318 |
471 |
double scale = 0.8 / nseq; |
319 |
481511 |
for (int i = startCol; i < endCol; i++) |
320 |
|
{ |
321 |
481040 |
ProfileI profile = profiles.get(i); |
322 |
481040 |
if (profile == null) |
323 |
|
{ |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
0 |
gaprow.annotations[i] = null; |
329 |
0 |
return; |
330 |
|
} |
331 |
|
|
332 |
481040 |
final int gapped = profile.getNonGapped(); |
333 |
|
|
334 |
481040 |
String description = "" + gapped; |
335 |
|
|
336 |
481040 |
gaprow.annotations[i] = new Annotation("", description, '\0', gapped, |
337 |
|
jalview.util.ColorUtils.bleachColour(Color.DARK_GRAY, |
338 |
|
(float) scale * gapped)); |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
@param |
354 |
|
@param |
355 |
|
@param |
356 |
|
@param |
357 |
|
@param |
358 |
|
|
359 |
|
@return |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
361 |
498855 |
static String getTooltip(ProfileI profile, float pid,... |
362 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
363 |
|
{ |
364 |
498855 |
ResidueCount counts = profile.getCounts(); |
365 |
|
|
366 |
498763 |
String description = null; |
367 |
498857 |
if (counts != null && showSequenceLogo) |
368 |
|
{ |
369 |
33760 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
370 |
|
: profile.getHeight(); |
371 |
33760 |
description = counts.getTooltip(normaliseBy, dp); |
372 |
|
} |
373 |
|
else |
374 |
|
{ |
375 |
465121 |
StringBuilder sb = new StringBuilder(64); |
376 |
466173 |
String maxRes = profile.getModalResidue(); |
377 |
465469 |
if (maxRes.length() > 1) |
378 |
|
{ |
379 |
2346 |
sb.append("[").append(maxRes).append("]"); |
380 |
|
} |
381 |
|
else |
382 |
|
{ |
383 |
463386 |
sb.append(maxRes); |
384 |
|
} |
385 |
465831 |
if (maxRes.length() > 0) |
386 |
|
{ |
387 |
465296 |
sb.append(" "); |
388 |
465559 |
Format.appendPercentage(sb, pid, dp); |
389 |
465795 |
sb.append("%"); |
390 |
|
} |
391 |
466302 |
description = sb.toString(); |
392 |
|
} |
393 |
500180 |
return description; |
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
@param |
406 |
|
|
407 |
|
@param |
408 |
|
|
409 |
|
|
410 |
|
@return |
411 |
|
|
|
|
| 95% |
Uncovered Elements: 2 (40) |
Complexity: 6 |
Complexity Density: 0.2 |
|
412 |
32922 |
public static int[] extractProfile(ProfileI profile, boolean ignoreGaps)... |
413 |
|
{ |
414 |
32922 |
ResidueCount counts = profile.getCounts(); |
415 |
32922 |
if (counts == null) |
416 |
|
{ |
417 |
0 |
return null; |
418 |
|
} |
419 |
|
|
420 |
32922 |
SymbolCounts symbolCounts = counts.getSymbolCounts(); |
421 |
32922 |
char[] symbols = symbolCounts.symbols; |
422 |
32922 |
int[] values = symbolCounts.values; |
423 |
32922 |
QuickSort.sort(values, symbols); |
424 |
32922 |
int totalPercentage = 0; |
425 |
32922 |
final int divisor = ignoreGaps ? profile.getNonGapped() |
426 |
|
: profile.getHeight(); |
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
32922 |
int[] result = new int[3 + 2 * symbols.length]; |
432 |
32922 |
int nextArrayPos = 3; |
433 |
32922 |
int nonZeroCount = 0; |
434 |
|
|
435 |
84303 |
for (int i = symbols.length - 1; i >= 0; i--) |
436 |
|
{ |
437 |
51383 |
int theChar = symbols[i]; |
438 |
51383 |
int charCount = values[i]; |
439 |
51383 |
final int percentage = (charCount * 100) / divisor; |
440 |
51383 |
if (percentage == 0) |
441 |
|
{ |
442 |
|
|
443 |
|
|
444 |
|
|
445 |
2 |
break; |
446 |
|
} |
447 |
51381 |
nonZeroCount++; |
448 |
51381 |
result[nextArrayPos++] = theChar; |
449 |
51381 |
result[nextArrayPos++] = percentage; |
450 |
51381 |
totalPercentage += percentage; |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
32922 |
if (nonZeroCount < symbols.length) |
457 |
|
{ |
458 |
2 |
int[] tmp = new int[3 + 2 * nonZeroCount]; |
459 |
2 |
System.arraycopy(result, 0, tmp, 0, tmp.length); |
460 |
2 |
result = tmp; |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
32922 |
result[0] = AlignmentAnnotation.SEQUENCE_PROFILE; |
467 |
32922 |
result[1] = nonZeroCount; |
468 |
32922 |
result[2] = totalPercentage; |
469 |
|
|
470 |
32922 |
return result; |
471 |
|
} |
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
@param |
483 |
|
@return |
484 |
|
|
|
|
| 91.9% |
Uncovered Elements: 3 (37) |
Complexity: 6 |
Complexity Density: 0.22 |
|
485 |
2 |
public static int[] extractCdnaProfile(... |
486 |
|
Hashtable<String, Object> hashtable, |
487 |
|
boolean ignoreGaps) |
488 |
|
{ |
489 |
|
|
490 |
|
|
491 |
2 |
int[] codonCounts = (int[]) hashtable.get(PROFILE); |
492 |
2 |
int[] sortedCounts = new int[codonCounts.length - 2]; |
493 |
2 |
System.arraycopy(codonCounts, 2, sortedCounts, 0, |
494 |
|
codonCounts.length - 2); |
495 |
|
|
496 |
2 |
int[] result = new int[3 + 2 * sortedCounts.length]; |
497 |
|
|
498 |
2 |
result[0] = AlignmentAnnotation.CDNA_PROFILE; |
499 |
|
|
500 |
2 |
char[] codons = new char[sortedCounts.length]; |
501 |
130 |
for (int i = 0; i < codons.length; i++) |
502 |
|
{ |
503 |
128 |
codons[i] = (char) i; |
504 |
|
} |
505 |
2 |
QuickSort.sort(sortedCounts, codons); |
506 |
2 |
int totalPercentage = 0; |
507 |
2 |
int distinctValuesCount = 0; |
508 |
2 |
int j = 3; |
509 |
2 |
int divisor = ignoreGaps ? codonCounts[1] : codonCounts[0]; |
510 |
8 |
for (int i = codons.length - 1; i >= 0; i--) |
511 |
|
{ |
512 |
8 |
final int codonCount = sortedCounts[i]; |
513 |
8 |
if (codonCount == 0) |
514 |
|
{ |
515 |
0 |
break; |
516 |
|
} |
517 |
8 |
final int percentage = codonCount * 100 / divisor; |
518 |
8 |
if (percentage == 0) |
519 |
|
{ |
520 |
|
|
521 |
|
|
522 |
|
|
523 |
2 |
break; |
524 |
|
} |
525 |
6 |
distinctValuesCount++; |
526 |
6 |
result[j++] = codons[i]; |
527 |
6 |
result[j++] = percentage; |
528 |
6 |
totalPercentage += percentage; |
529 |
|
} |
530 |
2 |
result[2] = totalPercentage; |
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
2 |
result[1] = distinctValuesCount; |
537 |
2 |
return Arrays.copyOfRange(result, 0, j); |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
@param |
544 |
|
|
545 |
|
|
546 |
|
@param |
547 |
|
|
548 |
|
|
|
|
| 90.3% |
Uncovered Elements: 3 (31) |
Complexity: 6 |
Complexity Density: 0.26 |
|
549 |
4 |
public static void calculateCdna(AlignmentI alignment,... |
550 |
|
Hashtable<String, Object>[] hconsensus) |
551 |
|
{ |
552 |
4 |
final char gapCharacter = alignment.getGapCharacter(); |
553 |
4 |
List<AlignedCodonFrame> mappings = alignment.getCodonFrames(); |
554 |
4 |
if (mappings == null || mappings.isEmpty()) |
555 |
|
{ |
556 |
0 |
return; |
557 |
|
} |
558 |
|
|
559 |
4 |
int cols = alignment.getWidth(); |
560 |
1928 |
for (int col = 0; col < cols; col++) |
561 |
|
{ |
562 |
|
|
563 |
1924 |
Hashtable<String, Object> columnHash = new Hashtable<>(); |
564 |
|
|
565 |
1924 |
int[] codonCounts = new int[66]; |
566 |
1924 |
codonCounts[0] = alignment.getSequences().size(); |
567 |
1924 |
int ungappedCount = 0; |
568 |
1924 |
for (SequenceI seq : alignment.getSequences()) |
569 |
|
{ |
570 |
20870 |
if (seq.getCharAt(col) == gapCharacter) |
571 |
|
{ |
572 |
10166 |
continue; |
573 |
|
} |
574 |
10704 |
List<char[]> codons = MappingUtils.findCodonsFor(seq, col, |
575 |
|
mappings); |
576 |
10704 |
for (char[] codon : codons) |
577 |
|
{ |
578 |
10657 |
int codonEncoded = CodingUtils.encodeCodon(codon); |
579 |
10657 |
if (codonEncoded >= 0) |
580 |
|
{ |
581 |
10657 |
codonCounts[codonEncoded + 2]++; |
582 |
10657 |
ungappedCount++; |
583 |
10657 |
break; |
584 |
|
} |
585 |
|
} |
586 |
|
} |
587 |
1924 |
codonCounts[1] = ungappedCount; |
588 |
|
|
589 |
1924 |
columnHash.put(PROFILE, codonCounts); |
590 |
1924 |
hconsensus[col] = columnHash; |
591 |
|
} |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
@param |
598 |
|
|
599 |
|
@param |
600 |
|
|
601 |
|
@param |
602 |
|
|
603 |
|
|
604 |
|
@param |
605 |
|
|
606 |
|
|
|
|
| 82.4% |
Uncovered Elements: 13 (74) |
Complexity: 18 |
Complexity Density: 0.36 |
|
607 |
4 |
public static void completeCdnaConsensus(... |
608 |
|
AlignmentAnnotation consensusAnnotation, |
609 |
|
Hashtable<String, Object>[] consensusData, boolean showProfileLogo, |
610 |
|
int nseqs) |
611 |
|
{ |
612 |
4 |
if (consensusAnnotation == null |
613 |
|
|| consensusAnnotation.annotations == null |
614 |
|
|| consensusAnnotation.annotations.length < consensusData.length) |
615 |
|
{ |
616 |
|
|
617 |
|
|
618 |
0 |
return; |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
4 |
consensusAnnotation.scaleColLabel = true; |
623 |
1928 |
for (int col = 0; col < consensusData.length; col++) |
624 |
|
{ |
625 |
1924 |
Hashtable<String, Object> hci = consensusData[col]; |
626 |
1924 |
if (hci == null) |
627 |
|
{ |
628 |
|
|
629 |
0 |
continue; |
630 |
|
} |
631 |
|
|
632 |
1924 |
final int[] codonCounts = (int[]) hci.get(PROFILE); |
633 |
1924 |
int totalCount = 0; |
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
1924 |
final char[] codons = new char[codonCounts.length - 2]; |
639 |
125060 |
for (int j = 2; j < codonCounts.length; j++) |
640 |
|
{ |
641 |
123136 |
final int codonCount = codonCounts[j]; |
642 |
123136 |
codons[j - 2] = (char) (j - 2); |
643 |
123136 |
totalCount += codonCount; |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
1924 |
int[] sortedCodonCounts = new int[codonCounts.length - 2]; |
651 |
1924 |
System.arraycopy(codonCounts, 2, sortedCodonCounts, 0, |
652 |
|
codonCounts.length - 2); |
653 |
1924 |
QuickSort.sort(sortedCodonCounts, codons); |
654 |
|
|
655 |
1924 |
int modalCodonEncoded = codons[codons.length - 1]; |
656 |
1924 |
int modalCodonCount = sortedCodonCounts[codons.length - 1]; |
657 |
1924 |
String modalCodon = String |
658 |
|
.valueOf(CodingUtils.decodeCodon(modalCodonEncoded)); |
659 |
1924 |
if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length |
660 |
|
- 2] == sortedCodonCounts[codons.length - 1]) |
661 |
|
{ |
662 |
|
|
663 |
|
|
664 |
|
|
665 |
25 |
modalCodon = "+"; |
666 |
|
} |
667 |
1924 |
float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 |
668 |
|
/ (float) totalCount; |
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
1924 |
StringBuilder mouseOver = new StringBuilder(32); |
680 |
1924 |
StringBuilder samePercent = new StringBuilder(); |
681 |
1924 |
String percent = null; |
682 |
1924 |
String lastPercent = null; |
683 |
1924 |
int percentDecPl = getPercentageDp(nseqs); |
684 |
|
|
685 |
3823 |
for (int j = codons.length - 1; j >= 0; j--) |
686 |
|
{ |
687 |
3823 |
int codonCount = sortedCodonCounts[j]; |
688 |
3823 |
if (codonCount == 0) |
689 |
|
{ |
690 |
|
|
691 |
|
|
692 |
|
|
693 |
|
|
694 |
1924 |
if (samePercent.length() > 0) |
695 |
|
{ |
696 |
1899 |
mouseOver.append(samePercent).append(": ").append(percent) |
697 |
|
.append("% "); |
698 |
|
} |
699 |
1924 |
break; |
700 |
|
} |
701 |
1899 |
int codonEncoded = codons[j]; |
702 |
1899 |
final int pct = codonCount * 100 / totalCount; |
703 |
1899 |
String codon = String |
704 |
|
.valueOf(CodingUtils.decodeCodon(codonEncoded)); |
705 |
1899 |
StringBuilder sb = new StringBuilder(); |
706 |
1899 |
Format.appendPercentage(sb, pct, percentDecPl); |
707 |
1899 |
percent = sb.toString(); |
708 |
1899 |
if (showProfileLogo || codonCount == modalCodonCount) |
709 |
|
{ |
710 |
1899 |
if (percent.equals(lastPercent) && j > 0) |
711 |
|
{ |
712 |
0 |
samePercent.append(samePercent.length() == 0 ? "" : ", "); |
713 |
0 |
samePercent.append(codon); |
714 |
|
} |
715 |
|
else |
716 |
|
{ |
717 |
1899 |
if (samePercent.length() > 0) |
718 |
|
{ |
719 |
0 |
mouseOver.append(samePercent).append(": ").append(lastPercent) |
720 |
|
.append("% "); |
721 |
|
} |
722 |
1899 |
samePercent.setLength(0); |
723 |
1899 |
samePercent.append(codon); |
724 |
|
} |
725 |
1899 |
lastPercent = percent; |
726 |
|
} |
727 |
|
} |
728 |
|
|
729 |
1924 |
consensusAnnotation.annotations[col] = new Annotation(modalCodon, |
730 |
|
mouseOver.toString(), ' ', pid); |
731 |
|
} |
732 |
|
} |
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
@param |
740 |
|
@return |
741 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
742 |
501661 |
protected static int getPercentageDp(long nseq)... |
743 |
|
{ |
744 |
501664 |
int scale = 0; |
745 |
501689 |
while (nseq >= 100) |
746 |
|
{ |
747 |
0 |
scale++; |
748 |
0 |
nseq /= 10; |
749 |
|
} |
750 |
501702 |
return scale; |
751 |
|
} |
752 |
|
} |