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.SecondaryStructureCount; |
34 |
|
import jalview.datamodel.SeqCigar; |
35 |
|
import jalview.datamodel.SequenceI; |
36 |
|
import jalview.ext.android.SparseIntArray; |
37 |
|
import jalview.util.Comparison; |
38 |
|
import jalview.util.Constants; |
39 |
|
import jalview.util.Format; |
40 |
|
import jalview.util.MappingUtils; |
41 |
|
import jalview.util.QuickSort; |
42 |
|
|
43 |
|
import java.awt.Color; |
44 |
|
import java.util.Arrays; |
45 |
|
import java.util.Hashtable; |
46 |
|
import java.util.List; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@author |
55 |
|
@version |
56 |
|
|
|
|
| 74.9% |
Uncovered Elements: 119 (474) |
Complexity: 109 |
Complexity Density: 0.35 |
|
57 |
|
public class AAFrequency |
58 |
|
{ |
59 |
|
public static final String PROFILE = "P"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String[] CHARS = new String['Z' - 'A' + 1]; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
66 |
50 |
static... |
67 |
|
{ |
68 |
1350 |
for (char c = 'A'; c <= 'Z'; c++) |
69 |
|
{ |
70 |
1300 |
CHARS[c - 'A'] = String.valueOf(c); |
71 |
|
} |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
3 |
public static final ProfilesI calculate(List<SequenceI> list, int start,... |
75 |
|
int end) |
76 |
|
{ |
77 |
3 |
return calculate(list, start, end, false); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
80 |
384 |
public static final ProfilesI calculate(List<SequenceI> sequences,... |
81 |
|
int start, int end, boolean profile) |
82 |
|
{ |
83 |
384 |
SequenceI[] seqs = new SequenceI[sequences.size()]; |
84 |
384 |
int width = 0; |
85 |
384 |
synchronized (sequences) |
86 |
|
{ |
87 |
3233 |
for (int i = 0; i < sequences.size(); i++) |
88 |
|
{ |
89 |
2849 |
seqs[i] = sequences.get(i); |
90 |
2849 |
int length = seqs[i].getLength(); |
91 |
2849 |
if (length > width) |
92 |
|
{ |
93 |
383 |
width = length; |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
384 |
if (end >= width) |
98 |
|
{ |
99 |
213 |
end = width; |
100 |
|
} |
101 |
|
|
102 |
384 |
ProfilesI reply = calculate(seqs, width, start, end, profile); |
103 |
384 |
return reply; |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
@param |
112 |
|
|
113 |
|
@param |
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
@param |
118 |
|
|
119 |
|
|
|
|
| 93.3% |
Uncovered Elements: 3 (45) |
Complexity: 10 |
Complexity Density: 0.34 |
|
120 |
1369 |
public static final ProfilesI calculate(final SequenceI[] sequences,... |
121 |
|
int width, int start, int end, boolean saveFullProfile) |
122 |
|
{ |
123 |
|
|
124 |
1369 |
int seqCount = sequences.length; |
125 |
1369 |
boolean nucleotide = false; |
126 |
1369 |
int nucleotideCount = 0; |
127 |
1369 |
int peptideCount = 0; |
128 |
|
|
129 |
1369 |
ProfileI[] result = new ProfileI[width]; |
130 |
|
|
131 |
614325 |
for (int column = start; column < end; column++) |
132 |
|
{ |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
612963 |
if (nucleotideCount > 100 && column % 10 == 0) |
144 |
|
{ |
145 |
54987 |
nucleotide = (9 * peptideCount < nucleotideCount); |
146 |
|
} |
147 |
612956 |
ResidueCount residueCounts = new ResidueCount(nucleotide); |
148 |
|
|
149 |
11335667 |
for (int row = 0; row < seqCount; row++) |
150 |
|
{ |
151 |
10735459 |
if (sequences[row] == null) |
152 |
|
{ |
153 |
0 |
jalview.bin.Console.errPrintln( |
154 |
|
"WARNING: Consensus skipping null sequence - possible race condition."); |
155 |
0 |
continue; |
156 |
|
} |
157 |
10687879 |
if (sequences[row].getLength() > column) |
158 |
|
{ |
159 |
10680869 |
char c = sequences[row].getCharAt(column); |
160 |
10683452 |
residueCounts.add(c); |
161 |
10722643 |
if (Comparison.isNucleotide(c)) |
162 |
|
{ |
163 |
974520 |
nucleotideCount++; |
164 |
|
} |
165 |
9745703 |
else if (!Comparison.isGap(c)) |
166 |
|
{ |
167 |
892779 |
peptideCount++; |
168 |
|
} |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
20262 |
residueCounts.addGap(); |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
612760 |
int maxCount = residueCounts.getModalCount(); |
180 |
612744 |
String maxResidue = residueCounts.getResiduesForCount(maxCount); |
181 |
612895 |
int gapCount = residueCounts.getGapCount(); |
182 |
612916 |
ProfileI profile = new Profile(seqCount, gapCount, maxCount, |
183 |
|
maxResidue); |
184 |
|
|
185 |
612954 |
if (saveFullProfile) |
186 |
|
{ |
187 |
594611 |
profile.setCounts(residueCounts); |
188 |
|
} |
189 |
|
|
190 |
612946 |
result[column] = profile; |
191 |
|
} |
192 |
1369 |
return new Profiles(seqCount, result); |
193 |
|
|
194 |
|
|
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
197 |
0 |
public static final ProfilesI calculateSS(List<SequenceI> list, int start,... |
198 |
|
int end) |
199 |
|
{ |
200 |
0 |
return calculateSS(list, start, end, false); |
201 |
|
} |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
203 |
381 |
public static final ProfilesI calculateSS(List<SequenceI> sequences,... |
204 |
|
int start, int end, boolean profile) |
205 |
|
{ |
206 |
381 |
SequenceI[] seqs = new SequenceI[sequences.size()]; |
207 |
381 |
int width = 0; |
208 |
381 |
synchronized (sequences) |
209 |
|
{ |
210 |
3227 |
for (int i = 0; i < sequences.size(); i++) |
211 |
|
{ |
212 |
2846 |
seqs[i] = sequences.get(i); |
213 |
2846 |
int length = seqs[i].getLength(); |
214 |
2846 |
if (length > width) |
215 |
|
{ |
216 |
380 |
width = length; |
217 |
|
} |
218 |
|
} |
219 |
|
|
220 |
381 |
if (end >= width) |
221 |
|
{ |
222 |
213 |
end = width; |
223 |
|
} |
224 |
|
|
225 |
381 |
ProfilesI reply = calculateSS(seqs, width, start, end, profile); |
226 |
381 |
return reply; |
227 |
|
} |
228 |
|
} |
229 |
|
|
|
|
| 68.1% |
Uncovered Elements: 15 (47) |
Complexity: 12 |
Complexity Density: 0.39 |
|
230 |
381 |
public static final ProfilesI calculateSS(final SequenceI[] sequences,... |
231 |
|
int width, int start, int end, boolean saveFullProfile) |
232 |
|
{ |
233 |
|
|
234 |
381 |
int seqCount = sequences.length; |
235 |
|
|
236 |
381 |
ProfileI[] result = new ProfileI[width]; |
237 |
381 |
int maxSSannotcount=0; |
238 |
40439 |
for (int column = start; column < end; column++) |
239 |
|
{ |
240 |
|
|
241 |
40058 |
int ssCount = 0; |
242 |
|
|
243 |
40058 |
SecondaryStructureCount ssCounts = new SecondaryStructureCount(); |
244 |
|
|
245 |
281450 |
for (int row = 0; row < seqCount; row++) |
246 |
|
{ |
247 |
241392 |
if (sequences[row] == null) |
248 |
|
{ |
249 |
0 |
jalview.bin.Console.errPrintln( |
250 |
|
"WARNING: Consensus skipping null sequence - possible race condition."); |
251 |
0 |
continue; |
252 |
|
} |
253 |
|
|
254 |
241392 |
char c = sequences[row].getCharAt(column); |
255 |
241392 |
AlignmentAnnotation aa = AlignmentUtils |
256 |
|
.getDisplayedAlignmentAnnotation(sequences[row]); |
257 |
241392 |
if (aa != null) |
258 |
|
{ |
259 |
0 |
ssCount++; |
260 |
|
} |
261 |
|
|
262 |
241392 |
if (sequences[row].getLength() > column && !Comparison.isGap(c) |
263 |
|
&& aa != null) |
264 |
|
{ |
265 |
|
|
266 |
0 |
int seqPosition = sequences[row].findPosition(column); |
267 |
|
|
268 |
0 |
char ss = AlignmentUtils.findSSAnnotationForGivenSeqposition(aa, |
269 |
|
seqPosition); |
270 |
0 |
if (ss == '*') |
271 |
|
{ |
272 |
0 |
continue; |
273 |
|
} |
274 |
0 |
ssCounts.add(ss); |
275 |
|
} |
276 |
241392 |
else if (Comparison.isGap(c) && aa != null) |
277 |
|
{ |
278 |
0 |
ssCounts.addGap(); |
279 |
|
} |
280 |
|
} |
281 |
|
|
282 |
40058 |
int maxSSCount = ssCounts.getModalCount(); |
283 |
40058 |
String maxSS = ssCounts.getSSForCount(maxSSCount); |
284 |
40058 |
int gapCount = ssCounts.getGapCount(); |
285 |
40058 |
ProfileI profile = new Profile(maxSS, ssCount, gapCount, maxSSCount); |
286 |
|
|
287 |
40058 |
if (saveFullProfile) |
288 |
|
{ |
289 |
21744 |
profile.setSSCounts(ssCounts); |
290 |
|
} |
291 |
|
|
292 |
40058 |
result[column] = profile; |
293 |
40058 |
maxSSannotcount=Math.max(maxSSannotcount, ssCount); |
294 |
|
} |
295 |
381 |
return new Profiles(maxSSannotcount,result); |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
@param |
305 |
|
|
306 |
|
@return |
307 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
308 |
0 |
static int estimateProfileSize(SparseIntArray profileSizes)... |
309 |
|
{ |
310 |
0 |
if (profileSizes.size() == 0) |
311 |
|
{ |
312 |
0 |
return 4; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
0 |
return profileSizes.keyAt(profileSizes.size() - 1); |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
@param |
329 |
|
|
330 |
|
@param |
331 |
|
|
332 |
|
@param |
333 |
|
|
334 |
|
@param |
335 |
|
|
336 |
|
@param |
337 |
|
|
338 |
|
@param |
339 |
|
|
340 |
|
|
341 |
|
@param |
342 |
|
|
343 |
|
|
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
344 |
1115 |
public static void completeConsensus(AlignmentAnnotation consensus,... |
345 |
|
ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps, |
346 |
|
boolean showSequenceLogo, long nseq) |
347 |
|
{ |
348 |
|
|
349 |
1115 |
if (consensus == null || consensus.annotations == null |
350 |
|
|| consensus.annotations.length < endCol) |
351 |
|
{ |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
0 |
return; |
357 |
|
} |
358 |
|
|
359 |
181295 |
for (int i = startCol; i < endCol; i++) |
360 |
|
{ |
361 |
180181 |
ProfileI profile = profiles.get(i); |
362 |
180184 |
if (profile == null) |
363 |
|
{ |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
0 |
consensus.annotations[i] = null; |
369 |
0 |
return; |
370 |
|
} |
371 |
|
|
372 |
180182 |
final int dp = getPercentageDp(nseq); |
373 |
|
|
374 |
180184 |
float value = profile.getPercentageIdentity(ignoreGaps); |
375 |
|
|
376 |
180184 |
String description = getTooltip(profile, value, showSequenceLogo, |
377 |
|
ignoreGaps, dp); |
378 |
|
|
379 |
180181 |
String modalResidue = profile.getModalResidue(); |
380 |
180182 |
if ("".equals(modalResidue)) |
381 |
|
{ |
382 |
6253 |
modalResidue = "-"; |
383 |
|
} |
384 |
173929 |
else if (modalResidue.length() > 1) |
385 |
|
{ |
386 |
7853 |
modalResidue = "+"; |
387 |
|
} |
388 |
180178 |
consensus.annotations[i] = new Annotation(modalResidue, description, |
389 |
|
' ', value); |
390 |
|
} |
391 |
|
|
392 |
|
|
393 |
|
} |
394 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
395 |
0 |
public static void completeSSConsensus(AlignmentAnnotation ssConsensus,... |
396 |
|
ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps, |
397 |
|
boolean showSequenceLogo, long nseq) |
398 |
|
{ |
399 |
|
|
400 |
0 |
if (ssConsensus == null || ssConsensus.annotations == null |
401 |
|
|| ssConsensus.annotations.length < endCol) |
402 |
|
{ |
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
0 |
return; |
408 |
|
} |
409 |
|
|
410 |
0 |
for (int i = startCol; i < endCol; i++) |
411 |
|
{ |
412 |
0 |
ProfileI profile = profiles.get(i); |
413 |
0 |
if (profile == null) |
414 |
|
{ |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
0 |
ssConsensus.annotations[i] = null; |
420 |
0 |
return; |
421 |
|
} |
422 |
|
|
423 |
0 |
final int dp = getPercentageDp(nseq); |
424 |
|
|
425 |
0 |
float value = profile.getSSPercentageIdentity(ignoreGaps); |
426 |
|
|
427 |
0 |
String description = getSSTooltip(profile, value, showSequenceLogo, |
428 |
|
ignoreGaps, dp); |
429 |
|
|
430 |
0 |
String modalSS = profile.getModalSS(); |
431 |
0 |
if ("".equals(modalSS)) |
432 |
|
{ |
433 |
0 |
modalSS = "-"; |
434 |
|
} |
435 |
0 |
else if (modalSS.length() > 1) |
436 |
|
{ |
437 |
0 |
modalSS = "+"; |
438 |
|
} |
439 |
0 |
ssConsensus.annotations[i] = new Annotation(modalSS, description, ' ', |
440 |
|
value); |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
@param |
450 |
|
|
451 |
|
@param |
452 |
|
|
453 |
|
@param |
454 |
|
|
455 |
|
@param |
456 |
|
|
457 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
458 |
985 |
public static void completeGapAnnot(AlignmentAnnotation gaprow,... |
459 |
|
ProfilesI profiles, int startCol, int endCol, long nseq) |
460 |
|
{ |
461 |
985 |
if (gaprow == null || gaprow.annotations == null |
462 |
|
|| gaprow.annotations.length < endCol) |
463 |
|
{ |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
0 |
return; |
469 |
|
} |
470 |
|
|
471 |
985 |
gaprow.graphMax = nseq; |
472 |
985 |
gaprow.graphMin = 0; |
473 |
985 |
double scale = 0.8 / nseq; |
474 |
161065 |
for (int i = startCol; i < endCol; i++) |
475 |
|
{ |
476 |
160080 |
ProfileI profile = profiles.get(i); |
477 |
160080 |
if (profile == null) |
478 |
|
{ |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
0 |
gaprow.annotations[i] = null; |
484 |
0 |
return; |
485 |
|
} |
486 |
|
|
487 |
160080 |
final int gapped = profile.getNonGapped(); |
488 |
|
|
489 |
160080 |
String description = "" + gapped; |
490 |
|
|
491 |
160080 |
gaprow.annotations[i] = new Annotation("", description, '\0', gapped, |
492 |
|
jalview.util.ColorUtils.bleachColour(Color.DARK_GRAY, |
493 |
|
(float) scale * gapped)); |
494 |
|
} |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
|
508 |
|
@param |
509 |
|
@param |
510 |
|
@param |
511 |
|
@param |
512 |
|
@param |
513 |
|
|
514 |
|
@return |
515 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
516 |
180184 |
static String getTooltip(ProfileI profile, float pid,... |
517 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
518 |
|
{ |
519 |
180184 |
ResidueCount counts = profile.getCounts(); |
520 |
|
|
521 |
180182 |
String description = null; |
522 |
180186 |
if (counts != null && showSequenceLogo) |
523 |
|
{ |
524 |
65773 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
525 |
|
: profile.getHeight(); |
526 |
65773 |
description = counts.getTooltip(normaliseBy, dp); |
527 |
|
} |
528 |
|
else |
529 |
|
{ |
530 |
114413 |
StringBuilder sb = new StringBuilder(64); |
531 |
114413 |
String maxRes = profile.getModalResidue(); |
532 |
114413 |
if (maxRes.length() > 1) |
533 |
|
{ |
534 |
2526 |
sb.append("[").append(maxRes).append("]"); |
535 |
|
} |
536 |
|
else |
537 |
|
{ |
538 |
111887 |
sb.append(maxRes); |
539 |
|
} |
540 |
114413 |
if (maxRes.length() > 0) |
541 |
|
{ |
542 |
111313 |
sb.append(" "); |
543 |
111313 |
Format.appendPercentage(sb, pid, dp); |
544 |
111313 |
sb.append("%"); |
545 |
|
} |
546 |
114413 |
description = sb.toString(); |
547 |
|
} |
548 |
180181 |
return description; |
549 |
|
} |
550 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
551 |
0 |
static String getSSTooltip(ProfileI profile, float pid,... |
552 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
553 |
|
{ |
554 |
0 |
SecondaryStructureCount counts = profile.getSSCounts(); |
555 |
|
|
556 |
0 |
String description = null; |
557 |
0 |
if (counts != null && showSequenceLogo) |
558 |
|
{ |
559 |
0 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
560 |
|
: profile.getHeight(); |
561 |
0 |
description = counts.getTooltip(normaliseBy, dp); |
562 |
|
} |
563 |
|
else |
564 |
|
{ |
565 |
0 |
StringBuilder sb = new StringBuilder(64); |
566 |
0 |
String maxSS = profile.getModalSS(); |
567 |
0 |
if (maxSS.length() > 1) |
568 |
|
{ |
569 |
0 |
sb.append("[").append(maxSS).append("]"); |
570 |
|
} |
571 |
|
else |
572 |
|
{ |
573 |
0 |
sb.append(maxSS); |
574 |
|
} |
575 |
0 |
if (maxSS.length() > 0) |
576 |
|
{ |
577 |
0 |
sb.append(" "); |
578 |
0 |
Format.appendPercentage(sb, pid, dp); |
579 |
0 |
sb.append("%"); |
580 |
|
} |
581 |
0 |
description = sb.toString(); |
582 |
|
} |
583 |
0 |
return description; |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
@param |
596 |
|
|
597 |
|
@param |
598 |
|
|
599 |
|
|
600 |
|
@return |
601 |
|
|
|
|
| 81.6% |
Uncovered Elements: 9 (49) |
Complexity: 7 |
Complexity Density: 0.19 |
|
602 |
66828 |
public static int[] extractProfile(ProfileI profile, boolean ignoreGaps)... |
603 |
|
{ |
604 |
66828 |
char[] symbols; |
605 |
66828 |
int[] values; |
606 |
|
|
607 |
66828 |
if (profile.getCounts() != null) |
608 |
|
{ |
609 |
66828 |
ResidueCount counts = profile.getCounts(); |
610 |
66828 |
SymbolCounts symbolCounts = counts.getSymbolCounts(); |
611 |
66828 |
symbols = symbolCounts.symbols; |
612 |
66828 |
values = symbolCounts.values; |
613 |
|
|
614 |
|
} |
615 |
0 |
else if (profile.getSSCounts() != null) |
616 |
|
{ |
617 |
0 |
SecondaryStructureCount counts = profile.getSSCounts(); |
618 |
|
|
619 |
0 |
SecondaryStructureCount.SymbolCounts symbolCounts = counts |
620 |
|
.getSymbolCounts(); |
621 |
0 |
symbols = symbolCounts.symbols; |
622 |
0 |
values = symbolCounts.values; |
623 |
|
} |
624 |
|
else |
625 |
|
{ |
626 |
0 |
return null; |
627 |
|
} |
628 |
|
|
629 |
66828 |
QuickSort.sort(values, symbols); |
630 |
66828 |
int totalPercentage = 0; |
631 |
66828 |
final int divisor = ignoreGaps ? profile.getNonGapped() |
632 |
|
: profile.getHeight(); |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
66828 |
int[] result = new int[3 + 2 * symbols.length]; |
638 |
66828 |
int nextArrayPos = 3; |
639 |
66828 |
int nonZeroCount = 0; |
640 |
|
|
641 |
194682 |
for (int i = symbols.length - 1; i >= 0; i--) |
642 |
|
{ |
643 |
127856 |
int theChar = symbols[i]; |
644 |
127856 |
int charCount = values[i]; |
645 |
127856 |
final int percentage = (charCount * 100) / divisor; |
646 |
127856 |
if (percentage == 0) |
647 |
|
{ |
648 |
|
|
649 |
|
|
650 |
|
|
651 |
2 |
break; |
652 |
|
} |
653 |
127854 |
nonZeroCount++; |
654 |
127854 |
result[nextArrayPos++] = theChar; |
655 |
127854 |
result[nextArrayPos++] = percentage; |
656 |
127854 |
totalPercentage += percentage; |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
66828 |
if (nonZeroCount < symbols.length) |
663 |
|
{ |
664 |
2 |
int[] tmp = new int[3 + 2 * nonZeroCount]; |
665 |
2 |
System.arraycopy(result, 0, tmp, 0, tmp.length); |
666 |
2 |
result = tmp; |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
66828 |
result[0] = AlignmentAnnotation.SEQUENCE_PROFILE; |
673 |
66828 |
result[1] = nonZeroCount; |
674 |
66828 |
result[2] = totalPercentage; |
675 |
|
|
676 |
66828 |
return result; |
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
@param |
689 |
|
@return |
690 |
|
|
|
|
| 91.9% |
Uncovered Elements: 3 (37) |
Complexity: 6 |
Complexity Density: 0.22 |
|
691 |
2 |
public static int[] extractCdnaProfile(... |
692 |
|
Hashtable<String, Object> hashtable, boolean ignoreGaps) |
693 |
|
{ |
694 |
|
|
695 |
|
|
696 |
2 |
int[] codonCounts = (int[]) hashtable.get(PROFILE); |
697 |
2 |
int[] sortedCounts = new int[codonCounts.length - 2]; |
698 |
2 |
System.arraycopy(codonCounts, 2, sortedCounts, 0, |
699 |
|
codonCounts.length - 2); |
700 |
|
|
701 |
2 |
int[] result = new int[3 + 2 * sortedCounts.length]; |
702 |
|
|
703 |
2 |
result[0] = AlignmentAnnotation.CDNA_PROFILE; |
704 |
|
|
705 |
2 |
char[] codons = new char[sortedCounts.length]; |
706 |
130 |
for (int i = 0; i < codons.length; i++) |
707 |
|
{ |
708 |
128 |
codons[i] = (char) i; |
709 |
|
} |
710 |
2 |
QuickSort.sort(sortedCounts, codons); |
711 |
2 |
int totalPercentage = 0; |
712 |
2 |
int distinctValuesCount = 0; |
713 |
2 |
int j = 3; |
714 |
2 |
int divisor = ignoreGaps ? codonCounts[1] : codonCounts[0]; |
715 |
8 |
for (int i = codons.length - 1; i >= 0; i--) |
716 |
|
{ |
717 |
8 |
final int codonCount = sortedCounts[i]; |
718 |
8 |
if (codonCount == 0) |
719 |
|
{ |
720 |
0 |
break; |
721 |
|
} |
722 |
8 |
final int percentage = codonCount * 100 / divisor; |
723 |
8 |
if (percentage == 0) |
724 |
|
{ |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
2 |
break; |
729 |
|
} |
730 |
6 |
distinctValuesCount++; |
731 |
6 |
result[j++] = codons[i]; |
732 |
6 |
result[j++] = percentage; |
733 |
6 |
totalPercentage += percentage; |
734 |
|
} |
735 |
2 |
result[2] = totalPercentage; |
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
2 |
result[1] = distinctValuesCount; |
742 |
2 |
return Arrays.copyOfRange(result, 0, j); |
743 |
|
} |
744 |
|
|
745 |
|
|
746 |
|
|
747 |
|
|
748 |
|
@param |
749 |
|
|
750 |
|
|
751 |
|
@param |
752 |
|
|
753 |
|
|
|
|
| 90.3% |
Uncovered Elements: 3 (31) |
Complexity: 6 |
Complexity Density: 0.26 |
|
754 |
4 |
public static void calculateCdna(AlignmentI alignment,... |
755 |
|
Hashtable<String, Object>[] hconsensus) |
756 |
|
{ |
757 |
4 |
final char gapCharacter = alignment.getGapCharacter(); |
758 |
4 |
List<AlignedCodonFrame> mappings = alignment.getCodonFrames(); |
759 |
4 |
if (mappings == null || mappings.isEmpty()) |
760 |
|
{ |
761 |
0 |
return; |
762 |
|
} |
763 |
|
|
764 |
4 |
int cols = alignment.getWidth(); |
765 |
1928 |
for (int col = 0; col < cols; col++) |
766 |
|
{ |
767 |
|
|
768 |
1924 |
Hashtable<String, Object> columnHash = new Hashtable<>(); |
769 |
|
|
770 |
1924 |
int[] codonCounts = new int[66]; |
771 |
1924 |
codonCounts[0] = alignment.getSequences().size(); |
772 |
1924 |
int ungappedCount = 0; |
773 |
1924 |
for (SequenceI seq : alignment.getSequences()) |
774 |
|
{ |
775 |
20870 |
if (seq.getCharAt(col) == gapCharacter) |
776 |
|
{ |
777 |
10166 |
continue; |
778 |
|
} |
779 |
10704 |
List<char[]> codons = MappingUtils.findCodonsFor(seq, col, |
780 |
|
mappings); |
781 |
10704 |
for (char[] codon : codons) |
782 |
|
{ |
783 |
10657 |
int codonEncoded = CodingUtils.encodeCodon(codon); |
784 |
10657 |
if (codonEncoded >= 0) |
785 |
|
{ |
786 |
10657 |
codonCounts[codonEncoded + 2]++; |
787 |
10657 |
ungappedCount++; |
788 |
10657 |
break; |
789 |
|
} |
790 |
|
} |
791 |
|
} |
792 |
1924 |
codonCounts[1] = ungappedCount; |
793 |
|
|
794 |
1924 |
columnHash.put(PROFILE, codonCounts); |
795 |
1924 |
hconsensus[col] = columnHash; |
796 |
|
} |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
@param |
803 |
|
|
804 |
|
@param |
805 |
|
|
806 |
|
@param |
807 |
|
|
808 |
|
|
809 |
|
@param |
810 |
|
|
811 |
|
|
|
|
| 82.4% |
Uncovered Elements: 13 (74) |
Complexity: 18 |
Complexity Density: 0.36 |
|
812 |
3 |
public static void completeCdnaConsensus(... |
813 |
|
AlignmentAnnotation consensusAnnotation, |
814 |
|
Hashtable<String, Object>[] consensusData, |
815 |
|
boolean showProfileLogo, int nseqs) |
816 |
|
{ |
817 |
3 |
if (consensusAnnotation == null |
818 |
|
|| consensusAnnotation.annotations == null |
819 |
|
|| consensusAnnotation.annotations.length < consensusData.length) |
820 |
|
{ |
821 |
|
|
822 |
|
|
823 |
0 |
return; |
824 |
|
} |
825 |
|
|
826 |
|
|
827 |
3 |
consensusAnnotation.scaleColLabel = true; |
828 |
981 |
for (int col = 0; col < consensusData.length; col++) |
829 |
|
{ |
830 |
978 |
Hashtable<String, Object> hci = consensusData[col]; |
831 |
978 |
if (hci == null) |
832 |
|
{ |
833 |
|
|
834 |
0 |
continue; |
835 |
|
} |
836 |
|
|
837 |
978 |
final int[] codonCounts = (int[]) hci.get(PROFILE); |
838 |
978 |
int totalCount = 0; |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
978 |
final char[] codons = new char[codonCounts.length - 2]; |
844 |
63570 |
for (int j = 2; j < codonCounts.length; j++) |
845 |
|
{ |
846 |
62592 |
final int codonCount = codonCounts[j]; |
847 |
62592 |
codons[j - 2] = (char) (j - 2); |
848 |
62592 |
totalCount += codonCount; |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
|
|
853 |
|
|
854 |
|
|
855 |
978 |
int[] sortedCodonCounts = new int[codonCounts.length - 2]; |
856 |
978 |
System.arraycopy(codonCounts, 2, sortedCodonCounts, 0, |
857 |
|
codonCounts.length - 2); |
858 |
978 |
QuickSort.sort(sortedCodonCounts, codons); |
859 |
|
|
860 |
978 |
int modalCodonEncoded = codons[codons.length - 1]; |
861 |
978 |
int modalCodonCount = sortedCodonCounts[codons.length - 1]; |
862 |
978 |
String modalCodon = String |
863 |
|
.valueOf(CodingUtils.decodeCodon(modalCodonEncoded)); |
864 |
978 |
if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length |
865 |
|
- 2] == sortedCodonCounts[codons.length - 1]) |
866 |
|
{ |
867 |
|
|
868 |
|
|
869 |
|
|
870 |
25 |
modalCodon = "+"; |
871 |
|
} |
872 |
978 |
float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 |
873 |
|
/ (float) totalCount; |
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
878 |
|
|
879 |
|
|
880 |
|
|
881 |
|
|
882 |
|
|
883 |
|
|
884 |
978 |
StringBuilder mouseOver = new StringBuilder(32); |
885 |
978 |
StringBuilder samePercent = new StringBuilder(); |
886 |
978 |
String percent = null; |
887 |
978 |
String lastPercent = null; |
888 |
978 |
int percentDecPl = getPercentageDp(nseqs); |
889 |
|
|
890 |
1931 |
for (int j = codons.length - 1; j >= 0; j--) |
891 |
|
{ |
892 |
1931 |
int codonCount = sortedCodonCounts[j]; |
893 |
1931 |
if (codonCount == 0) |
894 |
|
{ |
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
978 |
if (samePercent.length() > 0) |
900 |
|
{ |
901 |
953 |
mouseOver.append(samePercent).append(": ").append(percent) |
902 |
|
.append("% "); |
903 |
|
} |
904 |
978 |
break; |
905 |
|
} |
906 |
953 |
int codonEncoded = codons[j]; |
907 |
953 |
final int pct = codonCount * 100 / totalCount; |
908 |
953 |
String codon = String |
909 |
|
.valueOf(CodingUtils.decodeCodon(codonEncoded)); |
910 |
953 |
StringBuilder sb = new StringBuilder(); |
911 |
953 |
Format.appendPercentage(sb, pct, percentDecPl); |
912 |
953 |
percent = sb.toString(); |
913 |
953 |
if (showProfileLogo || codonCount == modalCodonCount) |
914 |
|
{ |
915 |
953 |
if (percent.equals(lastPercent) && j > 0) |
916 |
|
{ |
917 |
0 |
samePercent.append(samePercent.length() == 0 ? "" : ", "); |
918 |
0 |
samePercent.append(codon); |
919 |
|
} |
920 |
|
else |
921 |
|
{ |
922 |
953 |
if (samePercent.length() > 0) |
923 |
|
{ |
924 |
0 |
mouseOver.append(samePercent).append(": ").append(lastPercent) |
925 |
|
.append("% "); |
926 |
|
} |
927 |
953 |
samePercent.setLength(0); |
928 |
953 |
samePercent.append(codon); |
929 |
|
} |
930 |
953 |
lastPercent = percent; |
931 |
|
} |
932 |
|
} |
933 |
|
|
934 |
978 |
consensusAnnotation.annotations[col] = new Annotation(modalCodon, |
935 |
|
mouseOver.toString(), ' ', pid); |
936 |
|
} |
937 |
|
} |
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
|
944 |
|
@param |
945 |
|
@return |
946 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
947 |
181160 |
protected static int getPercentageDp(long nseq)... |
948 |
|
{ |
949 |
181160 |
int scale = 0; |
950 |
181163 |
while (nseq >= 100) |
951 |
|
{ |
952 |
0 |
scale++; |
953 |
0 |
nseq /= 10; |
954 |
|
} |
955 |
181163 |
return scale; |
956 |
|
} |
957 |
|
} |