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