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 |
1365 |
public static final ProfilesI calculate(final SequenceI[] sequences,... |
121 |
|
int width, int start, int end, boolean saveFullProfile) |
122 |
|
{ |
123 |
|
|
124 |
1365 |
int seqCount = sequences.length; |
125 |
1365 |
boolean nucleotide = false; |
126 |
1365 |
int nucleotideCount = 0; |
127 |
1365 |
int peptideCount = 0; |
128 |
|
|
129 |
1365 |
ProfileI[] result = new ProfileI[width]; |
130 |
|
|
131 |
613829 |
for (int column = start; column < end; column++) |
132 |
|
{ |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
612470 |
if (nucleotideCount > 100 && column % 10 == 0) |
144 |
|
{ |
145 |
55011 |
nucleotide = (9 * peptideCount < nucleotideCount); |
146 |
|
} |
147 |
612478 |
ResidueCount residueCounts = new ResidueCount(nucleotide); |
148 |
|
|
149 |
11336630 |
for (int row = 0; row < seqCount; row++) |
150 |
|
{ |
151 |
10736609 |
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 |
10708677 |
if (sequences[row].getLength() > column) |
158 |
|
{ |
159 |
10679071 |
char c = sequences[row].getCharAt(column); |
160 |
10677780 |
residueCounts.add(c); |
161 |
10718833 |
if (Comparison.isNucleotide(c)) |
162 |
|
{ |
163 |
975183 |
nucleotideCount++; |
164 |
|
} |
165 |
9741168 |
else if (!Comparison.isGap(c)) |
166 |
|
{ |
167 |
894502 |
peptideCount++; |
168 |
|
} |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
30133 |
residueCounts.addGap(); |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
612397 |
int maxCount = residueCounts.getModalCount(); |
180 |
612371 |
String maxResidue = residueCounts.getResiduesForCount(maxCount); |
181 |
612459 |
int gapCount = residueCounts.getGapCount(); |
182 |
612447 |
ProfileI profile = new Profile(seqCount, gapCount, maxCount, |
183 |
|
maxResidue); |
184 |
|
|
185 |
612486 |
if (saveFullProfile) |
186 |
|
{ |
187 |
594147 |
profile.setCounts(residueCounts); |
188 |
|
} |
189 |
|
|
190 |
612456 |
result[column] = profile; |
191 |
|
} |
192 |
1365 |
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 |
1114 |
public static void completeConsensus(AlignmentAnnotation consensus,... |
345 |
|
ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps, |
346 |
|
boolean showSequenceLogo, long nseq) |
347 |
|
{ |
348 |
|
|
349 |
1114 |
if (consensus == null || consensus.annotations == null |
350 |
|
|| consensus.annotations.length < endCol) |
351 |
|
{ |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
0 |
return; |
357 |
|
} |
358 |
|
|
359 |
183813 |
for (int i = startCol; i < endCol; i++) |
360 |
|
{ |
361 |
182699 |
ProfileI profile = profiles.get(i); |
362 |
182702 |
if (profile == null) |
363 |
|
{ |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
0 |
consensus.annotations[i] = null; |
369 |
0 |
return; |
370 |
|
} |
371 |
|
|
372 |
182702 |
final int dp = getPercentageDp(nseq); |
373 |
|
|
374 |
182701 |
float value = profile.getPercentageIdentity(ignoreGaps); |
375 |
|
|
376 |
182703 |
String description = getTooltip(profile, value, showSequenceLogo, |
377 |
|
ignoreGaps, dp); |
378 |
|
|
379 |
182698 |
String modalResidue = profile.getModalResidue(); |
380 |
182697 |
if ("".equals(modalResidue)) |
381 |
|
{ |
382 |
6203 |
modalResidue = "-"; |
383 |
|
} |
384 |
176498 |
else if (modalResidue.length() > 1) |
385 |
|
{ |
386 |
7887 |
modalResidue = "+"; |
387 |
|
} |
388 |
182699 |
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 |
986 |
public static void completeGapAnnot(AlignmentAnnotation gaprow,... |
459 |
|
ProfilesI profiles, int startCol, int endCol, long nseq) |
460 |
|
{ |
461 |
986 |
if (gaprow == null || gaprow.annotations == null |
462 |
|
|| gaprow.annotations.length < endCol) |
463 |
|
{ |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
0 |
return; |
469 |
|
} |
470 |
|
|
471 |
986 |
gaprow.graphMax = nseq; |
472 |
986 |
gaprow.graphMin = 0; |
473 |
986 |
double scale = 0.8 / nseq; |
474 |
163898 |
for (int i = startCol; i < endCol; i++) |
475 |
|
{ |
476 |
162912 |
ProfileI profile = profiles.get(i); |
477 |
162912 |
if (profile == null) |
478 |
|
{ |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
0 |
gaprow.annotations[i] = null; |
484 |
0 |
return; |
485 |
|
} |
486 |
|
|
487 |
162912 |
final int gapped = profile.getNonGapped(); |
488 |
|
|
489 |
162912 |
String description = "" + gapped; |
490 |
|
|
491 |
162912 |
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 |
182701 |
static String getTooltip(ProfileI profile, float pid,... |
517 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
518 |
|
{ |
519 |
182704 |
ResidueCount counts = profile.getCounts(); |
520 |
|
|
521 |
182704 |
String description = null; |
522 |
182704 |
if (counts != null && showSequenceLogo) |
523 |
|
{ |
524 |
64157 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
525 |
|
: profile.getHeight(); |
526 |
64157 |
description = counts.getTooltip(normaliseBy, dp); |
527 |
|
} |
528 |
|
else |
529 |
|
{ |
530 |
118547 |
StringBuilder sb = new StringBuilder(64); |
531 |
118547 |
String maxRes = profile.getModalResidue(); |
532 |
118547 |
if (maxRes.length() > 1) |
533 |
|
{ |
534 |
2930 |
sb.append("[").append(maxRes).append("]"); |
535 |
|
} |
536 |
|
else |
537 |
|
{ |
538 |
115617 |
sb.append(maxRes); |
539 |
|
} |
540 |
118547 |
if (maxRes.length() > 0) |
541 |
|
{ |
542 |
115497 |
sb.append(" "); |
543 |
115497 |
Format.appendPercentage(sb, pid, dp); |
544 |
115497 |
sb.append("%"); |
545 |
|
} |
546 |
118547 |
description = sb.toString(); |
547 |
|
} |
548 |
182698 |
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 |
101848 |
public static int[] extractProfile(ProfileI profile, boolean ignoreGaps)... |
603 |
|
{ |
604 |
101848 |
char[] symbols; |
605 |
101848 |
int[] values; |
606 |
|
|
607 |
101848 |
if (profile.getCounts() != null) |
608 |
|
{ |
609 |
101848 |
ResidueCount counts = profile.getCounts(); |
610 |
101848 |
SymbolCounts symbolCounts = counts.getSymbolCounts(); |
611 |
101848 |
symbols = symbolCounts.symbols; |
612 |
101848 |
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 |
101848 |
QuickSort.sort(values, symbols); |
630 |
101848 |
int totalPercentage = 0; |
631 |
101848 |
final int divisor = ignoreGaps ? profile.getNonGapped() |
632 |
|
: profile.getHeight(); |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
101848 |
int[] result = new int[3 + 2 * symbols.length]; |
638 |
101848 |
int nextArrayPos = 3; |
639 |
101848 |
int nonZeroCount = 0; |
640 |
|
|
641 |
295945 |
for (int i = symbols.length - 1; i >= 0; i--) |
642 |
|
{ |
643 |
194099 |
int theChar = symbols[i]; |
644 |
194099 |
int charCount = values[i]; |
645 |
194099 |
final int percentage = (charCount * 100) / divisor; |
646 |
194099 |
if (percentage == 0) |
647 |
|
{ |
648 |
|
|
649 |
|
|
650 |
|
|
651 |
2 |
break; |
652 |
|
} |
653 |
194097 |
nonZeroCount++; |
654 |
194097 |
result[nextArrayPos++] = theChar; |
655 |
194097 |
result[nextArrayPos++] = percentage; |
656 |
194097 |
totalPercentage += percentage; |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
101848 |
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 |
101848 |
result[0] = AlignmentAnnotation.SEQUENCE_PROFILE; |
673 |
101848 |
result[1] = nonZeroCount; |
674 |
101848 |
result[2] = totalPercentage; |
675 |
|
|
676 |
101848 |
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 |
4 |
public static void completeCdnaConsensus(... |
813 |
|
AlignmentAnnotation consensusAnnotation, |
814 |
|
Hashtable<String, Object>[] consensusData, |
815 |
|
boolean showProfileLogo, int nseqs) |
816 |
|
{ |
817 |
4 |
if (consensusAnnotation == null |
818 |
|
|| consensusAnnotation.annotations == null |
819 |
|
|| consensusAnnotation.annotations.length < consensusData.length) |
820 |
|
{ |
821 |
|
|
822 |
|
|
823 |
0 |
return; |
824 |
|
} |
825 |
|
|
826 |
|
|
827 |
4 |
consensusAnnotation.scaleColLabel = true; |
828 |
1928 |
for (int col = 0; col < consensusData.length; col++) |
829 |
|
{ |
830 |
1924 |
Hashtable<String, Object> hci = consensusData[col]; |
831 |
1924 |
if (hci == null) |
832 |
|
{ |
833 |
|
|
834 |
0 |
continue; |
835 |
|
} |
836 |
|
|
837 |
1924 |
final int[] codonCounts = (int[]) hci.get(PROFILE); |
838 |
1924 |
int totalCount = 0; |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
1924 |
final char[] codons = new char[codonCounts.length - 2]; |
844 |
125060 |
for (int j = 2; j < codonCounts.length; j++) |
845 |
|
{ |
846 |
123136 |
final int codonCount = codonCounts[j]; |
847 |
123136 |
codons[j - 2] = (char) (j - 2); |
848 |
123136 |
totalCount += codonCount; |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
|
|
853 |
|
|
854 |
|
|
855 |
1924 |
int[] sortedCodonCounts = new int[codonCounts.length - 2]; |
856 |
1924 |
System.arraycopy(codonCounts, 2, sortedCodonCounts, 0, |
857 |
|
codonCounts.length - 2); |
858 |
1924 |
QuickSort.sort(sortedCodonCounts, codons); |
859 |
|
|
860 |
1924 |
int modalCodonEncoded = codons[codons.length - 1]; |
861 |
1924 |
int modalCodonCount = sortedCodonCounts[codons.length - 1]; |
862 |
1924 |
String modalCodon = String |
863 |
|
.valueOf(CodingUtils.decodeCodon(modalCodonEncoded)); |
864 |
1924 |
if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length |
865 |
|
- 2] == sortedCodonCounts[codons.length - 1]) |
866 |
|
{ |
867 |
|
|
868 |
|
|
869 |
|
|
870 |
25 |
modalCodon = "+"; |
871 |
|
} |
872 |
1924 |
float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 |
873 |
|
/ (float) totalCount; |
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
878 |
|
|
879 |
|
|
880 |
|
|
881 |
|
|
882 |
|
|
883 |
|
|
884 |
1924 |
StringBuilder mouseOver = new StringBuilder(32); |
885 |
1924 |
StringBuilder samePercent = new StringBuilder(); |
886 |
1924 |
String percent = null; |
887 |
1924 |
String lastPercent = null; |
888 |
1924 |
int percentDecPl = getPercentageDp(nseqs); |
889 |
|
|
890 |
3823 |
for (int j = codons.length - 1; j >= 0; j--) |
891 |
|
{ |
892 |
3823 |
int codonCount = sortedCodonCounts[j]; |
893 |
3823 |
if (codonCount == 0) |
894 |
|
{ |
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
1924 |
if (samePercent.length() > 0) |
900 |
|
{ |
901 |
1899 |
mouseOver.append(samePercent).append(": ").append(percent) |
902 |
|
.append("% "); |
903 |
|
} |
904 |
1924 |
break; |
905 |
|
} |
906 |
1899 |
int codonEncoded = codons[j]; |
907 |
1899 |
final int pct = codonCount * 100 / totalCount; |
908 |
1899 |
String codon = String |
909 |
|
.valueOf(CodingUtils.decodeCodon(codonEncoded)); |
910 |
1899 |
StringBuilder sb = new StringBuilder(); |
911 |
1899 |
Format.appendPercentage(sb, pct, percentDecPl); |
912 |
1899 |
percent = sb.toString(); |
913 |
1899 |
if (showProfileLogo || codonCount == modalCodonCount) |
914 |
|
{ |
915 |
1899 |
if (percent.equals(lastPercent) && j > 0) |
916 |
|
{ |
917 |
0 |
samePercent.append(samePercent.length() == 0 ? "" : ", "); |
918 |
0 |
samePercent.append(codon); |
919 |
|
} |
920 |
|
else |
921 |
|
{ |
922 |
1899 |
if (samePercent.length() > 0) |
923 |
|
{ |
924 |
0 |
mouseOver.append(samePercent).append(": ").append(lastPercent) |
925 |
|
.append("% "); |
926 |
|
} |
927 |
1899 |
samePercent.setLength(0); |
928 |
1899 |
samePercent.append(codon); |
929 |
|
} |
930 |
1899 |
lastPercent = percent; |
931 |
|
} |
932 |
|
} |
933 |
|
|
934 |
1924 |
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 |
184625 |
protected static int getPercentageDp(long nseq)... |
948 |
|
{ |
949 |
184625 |
int scale = 0; |
950 |
184626 |
while (nseq >= 100) |
951 |
|
{ |
952 |
0 |
scale++; |
953 |
0 |
nseq /= 10; |
954 |
|
} |
955 |
184626 |
return scale; |
956 |
|
} |
957 |
|
} |