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 |
611831 |
for (int column = start; column < end; column++) |
130 |
|
{ |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
610488 |
if (nucleotideCount > 100 && column % 10 == 0) |
142 |
|
{ |
143 |
54923 |
nucleotide = (9 * peptideCount < nucleotideCount); |
144 |
|
} |
145 |
610480 |
ResidueCount residueCounts = new ResidueCount(nucleotide); |
146 |
|
|
147 |
11300675 |
for (int row = 0; row < seqCount; row++) |
148 |
|
{ |
149 |
10724643 |
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 |
10716594 |
if (sequences[row].getLength() > column) |
156 |
|
{ |
157 |
10690533 |
char c = sequences[row].getCharAt(column); |
158 |
10691338 |
residueCounts.add(c); |
159 |
10705756 |
if (Comparison.isNucleotide(c)) |
160 |
|
{ |
161 |
967915 |
nucleotideCount++; |
162 |
|
} |
163 |
9732442 |
else if (!Comparison.isGap(c)) |
164 |
|
{ |
165 |
877833 |
peptideCount++; |
166 |
|
} |
167 |
|
} |
168 |
|
else |
169 |
|
{ |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
30127 |
residueCounts.addGap(); |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
610017 |
int maxCount = residueCounts.getModalCount(); |
178 |
610023 |
String maxResidue = residueCounts.getResiduesForCount(maxCount); |
179 |
610345 |
int gapCount = residueCounts.getGapCount(); |
180 |
610323 |
ProfileI profile = new Profile(seqCount, gapCount, maxCount, |
181 |
|
maxResidue); |
182 |
|
|
183 |
610431 |
if (saveFullProfile) |
184 |
|
{ |
185 |
592121 |
profile.setCounts(residueCounts); |
186 |
|
} |
187 |
|
|
188 |
610470 |
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 |
1384 |
public static final ProfilesI calculateSS(final SequenceI[] sequences,... |
230 |
|
int width, int start, int end, boolean saveFullProfile, |
231 |
|
String source) |
232 |
|
{ |
233 |
|
|
234 |
1384 |
int seqCount = sequences.length; |
235 |
|
|
236 |
1384 |
int seqWithSSCount = 0; |
237 |
|
|
238 |
1384 |
ProfileI[] result = new ProfileI[width]; |
239 |
|
|
240 |
624390 |
for (int column = start; column < end; column++) |
241 |
|
{ |
242 |
|
|
243 |
623045 |
int ssCount = 0; |
244 |
|
|
245 |
623037 |
SecondaryStructureCount ssCounts = new SecondaryStructureCount(); |
246 |
|
|
247 |
11421995 |
for (int row = 0; row < seqCount; row++) |
248 |
|
{ |
249 |
10841726 |
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 |
10832732 |
char c = sequences[row].getCharAt(column); |
257 |
|
|
258 |
10826298 |
List<AlignmentAnnotation> annots = AlignmentUtils.getAlignmentAnnotationForSource(sequences[row], source); |
259 |
10842092 |
if(annots!=null) { |
260 |
99295 |
seqWithSSCount++; |
261 |
99299 |
for (AlignmentAnnotation aa : annots) |
262 |
|
{ |
263 |
108061 |
if (aa != null) |
264 |
|
{ |
265 |
108063 |
ssCount++; |
266 |
|
} |
267 |
|
|
268 |
108062 |
if (sequences[row].getLength() > column && !Comparison.isGap(c) |
269 |
|
&& aa != null) |
270 |
|
{ |
271 |
|
|
272 |
70406 |
int seqPosition = sequences[row].findPosition(column); |
273 |
|
|
274 |
70406 |
char ss = AlignmentUtils |
275 |
|
.findSSAnnotationForGivenSeqposition(aa, seqPosition); |
276 |
70404 |
if (ss == '*') |
277 |
|
{ |
278 |
0 |
continue; |
279 |
|
} |
280 |
70406 |
ssCounts.add(ss); |
281 |
|
} |
282 |
37658 |
else if (Comparison.isGap(c) && aa != null) |
283 |
|
{ |
284 |
37658 |
ssCounts.addGap(); |
285 |
|
} |
286 |
|
} |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
622997 |
int maxSSCount = ssCounts.getModalCount(); |
291 |
622880 |
String maxSS = ssCounts.getSSForCount(maxSSCount); |
292 |
622923 |
int gapCount = ssCounts.getGapCount(); |
293 |
622960 |
ProfileI profile = new Profile(maxSS, ssCount, gapCount, maxSSCount, |
294 |
|
seqWithSSCount); |
295 |
|
|
296 |
622994 |
if (saveFullProfile) |
297 |
|
{ |
298 |
604693 |
profile.setSSCounts(ssCounts); |
299 |
|
} |
300 |
|
|
301 |
622914 |
result[column] = profile; |
302 |
|
} |
303 |
1384 |
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 |
181162 |
for (int i = startCol; i < endCol; i++) |
368 |
|
{ |
369 |
180069 |
ProfileI profile = profiles.get(i); |
370 |
180069 |
if (profile == null) |
371 |
|
{ |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
0 |
consensus.annotations[i] = null; |
377 |
0 |
return; |
378 |
|
} |
379 |
|
|
380 |
180069 |
final int dp = getPercentageDp(nseq); |
381 |
|
|
382 |
180069 |
float value = profile.getPercentageIdentity(ignoreGaps); |
383 |
|
|
384 |
180069 |
String description = getTooltip(profile, value, showSequenceLogo, |
385 |
|
ignoreGaps, dp); |
386 |
|
|
387 |
180069 |
String modalResidue = profile.getModalResidue(); |
388 |
180069 |
if ("".equals(modalResidue)) |
389 |
|
{ |
390 |
6718 |
modalResidue = "-"; |
391 |
|
} |
392 |
173351 |
else if (modalResidue.length() > 1) |
393 |
|
{ |
394 |
7839 |
modalResidue = "+"; |
395 |
|
} |
396 |
180069 |
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 |
924 |
public static void completeSSConsensus(AlignmentAnnotation ssConsensus,... |
404 |
|
ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps, |
405 |
|
boolean showSequenceLogo, long nseq) |
406 |
|
{ |
407 |
|
|
408 |
924 |
if (ssConsensus == null || ssConsensus.annotations == null |
409 |
|
|| ssConsensus.annotations.length < endCol) |
410 |
|
{ |
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
3 |
return; |
416 |
|
} |
417 |
|
|
418 |
524062 |
for (int i = startCol; i < endCol; i++) |
419 |
|
{ |
420 |
523141 |
ProfileI profile = profiles.get(i); |
421 |
523141 |
if (profile == null) |
422 |
|
{ |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
0 |
ssConsensus.annotations[i] = null; |
428 |
0 |
return; |
429 |
|
} |
430 |
|
|
431 |
523141 |
if (ssConsensus.getNoOfSequencesIncluded() < 0) |
432 |
|
{ |
433 |
0 |
ssConsensus.setNoOfSequencesIncluded(profile.getSeqWithSSCount()); |
434 |
|
} |
435 |
|
|
436 |
523141 |
final int dp = getPercentageDp(nseq); |
437 |
|
|
438 |
523141 |
float value = profile.getSSPercentageIdentity(ignoreGaps); |
439 |
|
|
440 |
523141 |
String description = getSSTooltip(profile, value, showSequenceLogo, |
441 |
|
ignoreGaps, dp); |
442 |
|
|
443 |
523141 |
String modalSS = profile.getModalSS(); |
444 |
523141 |
if ("".equals(modalSS)) |
445 |
|
{ |
446 |
505657 |
modalSS = "-"; |
447 |
|
} |
448 |
17484 |
else if (modalSS.length() > 1) |
449 |
|
{ |
450 |
1082 |
modalSS = "+"; |
451 |
|
} |
452 |
523141 |
ssConsensus.annotations[i] = new Annotation(modalSS, description, |
453 |
|
' ', value); |
454 |
|
} |
455 |
|
|
456 |
|
|
457 |
921 |
if(ssConsensus.getNoOfSequencesIncluded()<1) |
458 |
844 |
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 |
1881 |
public static void completeGapAnnot(AlignmentAnnotation gaprow,... |
477 |
|
ProfilesI profiles, int startCol, int endCol, long nseq) |
478 |
|
{ |
479 |
1881 |
if (gaprow == null || gaprow.annotations == null |
480 |
|
|| gaprow.annotations.length < endCol) |
481 |
|
{ |
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
0 |
return; |
487 |
|
} |
488 |
|
|
489 |
1881 |
gaprow.graphMax = nseq; |
490 |
1881 |
gaprow.graphMin = 0; |
491 |
1881 |
double scale = 0.8 / nseq; |
492 |
684924 |
for (int i = startCol; i < endCol; i++) |
493 |
|
{ |
494 |
683060 |
ProfileI profile = profiles.get(i); |
495 |
683058 |
if (profile == null) |
496 |
|
{ |
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
0 |
gaprow.annotations[i] = null; |
502 |
0 |
return; |
503 |
|
} |
504 |
|
|
505 |
683060 |
final int gapped = profile.getNonGapped(); |
506 |
|
|
507 |
683051 |
String description = "" + gapped; |
508 |
|
|
509 |
683063 |
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 |
180069 |
static String getTooltip(ProfileI profile, float pid,... |
535 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
536 |
|
{ |
537 |
180069 |
ResidueCount counts = profile.getCounts(); |
538 |
|
|
539 |
180069 |
String description = null; |
540 |
180069 |
if (counts != null && showSequenceLogo) |
541 |
|
{ |
542 |
64337 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
543 |
|
: profile.getHeight(); |
544 |
64337 |
description = counts.getTooltip(normaliseBy, dp); |
545 |
|
} |
546 |
|
else |
547 |
|
{ |
548 |
115732 |
StringBuilder sb = new StringBuilder(64); |
549 |
115732 |
String maxRes = profile.getModalResidue(); |
550 |
115732 |
if (maxRes.length() > 1) |
551 |
|
{ |
552 |
2856 |
sb.append("[").append(maxRes).append("]"); |
553 |
|
} |
554 |
|
else |
555 |
|
{ |
556 |
112876 |
sb.append(maxRes); |
557 |
|
} |
558 |
115732 |
if (maxRes.length() > 0) |
559 |
|
{ |
560 |
112752 |
sb.append(" "); |
561 |
112752 |
Format.appendPercentage(sb, pid, dp); |
562 |
112752 |
sb.append("%"); |
563 |
|
} |
564 |
115732 |
description = sb.toString(); |
565 |
|
} |
566 |
180069 |
return description; |
567 |
|
} |
568 |
|
|
|
|
| 95.8% |
Uncovered Elements: 1 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
569 |
523141 |
static String getSSTooltip(ProfileI profile, float pid,... |
570 |
|
boolean showSequenceLogo, boolean ignoreGaps, int dp) |
571 |
|
{ |
572 |
523141 |
SecondaryStructureCount counts = profile.getSSCounts(); |
573 |
|
|
574 |
523141 |
String description = null; |
575 |
523141 |
if (counts != null && showSequenceLogo) |
576 |
|
{ |
577 |
46848 |
int normaliseBy = ignoreGaps ? profile.getNonGapped() |
578 |
|
: profile.getHeight(); |
579 |
46848 |
description = counts.getTooltip(normaliseBy, dp); |
580 |
|
} |
581 |
|
else |
582 |
|
{ |
583 |
476293 |
StringBuilder sb = new StringBuilder(64); |
584 |
476293 |
String maxSS = profile.getModalSS(); |
585 |
476293 |
if (maxSS.length() > 1) |
586 |
|
{ |
587 |
742 |
sb.append("[").append(maxSS).append("]"); |
588 |
|
} |
589 |
|
else |
590 |
|
{ |
591 |
475551 |
sb.append(maxSS); |
592 |
|
} |
593 |
476293 |
if (maxSS.length() > 0) |
594 |
|
{ |
595 |
12423 |
sb.append(" "); |
596 |
12423 |
Format.appendPercentage(sb, pid, dp); |
597 |
12423 |
sb.append("%"); |
598 |
|
} |
599 |
476293 |
description = sb.toString(); |
600 |
|
} |
601 |
523141 |
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 |
139513 |
public static int[] extractProfile(ProfileI profile, boolean ignoreGaps)... |
621 |
|
{ |
622 |
139513 |
char[] symbols; |
623 |
139513 |
int[] values; |
624 |
|
|
625 |
139513 |
if (profile.getCounts() != null) |
626 |
|
{ |
627 |
139513 |
ResidueCount counts = profile.getCounts(); |
628 |
139513 |
SymbolCounts symbolCounts = counts.getSymbolCounts(); |
629 |
139513 |
symbols = symbolCounts.symbols; |
630 |
139513 |
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 |
139513 |
QuickSort.sort(values, symbols); |
648 |
139513 |
int totalPercentage = 0; |
649 |
139513 |
final int divisor = ignoreGaps ? profile.getNonGapped() |
650 |
|
: profile.getHeight(); |
651 |
|
|
652 |
|
|
653 |
|
|
654 |
|
|
655 |
139513 |
int[] result = new int[3 + 2 * symbols.length]; |
656 |
139513 |
int nextArrayPos = 3; |
657 |
139513 |
int nonZeroCount = 0; |
658 |
|
|
659 |
389823 |
for (int i = symbols.length - 1; i >= 0; i--) |
660 |
|
{ |
661 |
250312 |
int theChar = symbols[i]; |
662 |
250312 |
int charCount = values[i]; |
663 |
250312 |
final int percentage = (charCount * 100) / divisor; |
664 |
250312 |
if (percentage == 0) |
665 |
|
{ |
666 |
|
|
667 |
|
|
668 |
|
|
669 |
2 |
break; |
670 |
|
} |
671 |
250310 |
nonZeroCount++; |
672 |
250310 |
result[nextArrayPos++] = theChar; |
673 |
250310 |
result[nextArrayPos++] = percentage; |
674 |
250310 |
totalPercentage += percentage; |
675 |
|
} |
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
|
680 |
139513 |
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 |
139513 |
result[0] = AlignmentAnnotation.SEQUENCE_PROFILE; |
691 |
139513 |
result[1] = nonZeroCount; |
692 |
139513 |
result[2] = totalPercentage; |
693 |
|
|
694 |
139513 |
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 |
3 |
public static void completeCdnaConsensus(... |
831 |
|
AlignmentAnnotation consensusAnnotation, |
832 |
|
Hashtable<String, Object>[] consensusData, |
833 |
|
boolean showProfileLogo, int nseqs) |
834 |
|
{ |
835 |
3 |
if (consensusAnnotation == null |
836 |
|
|| consensusAnnotation.annotations == null |
837 |
|
|| consensusAnnotation.annotations.length < consensusData.length) |
838 |
|
{ |
839 |
|
|
840 |
|
|
841 |
0 |
return; |
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
3 |
consensusAnnotation.scaleColLabel = true; |
846 |
981 |
for (int col = 0; col < consensusData.length; col++) |
847 |
|
{ |
848 |
978 |
Hashtable<String, Object> hci = consensusData[col]; |
849 |
978 |
if (hci == null) |
850 |
|
{ |
851 |
|
|
852 |
0 |
continue; |
853 |
|
} |
854 |
|
|
855 |
978 |
final int[] codonCounts = (int[]) hci.get(PROFILE); |
856 |
978 |
int totalCount = 0; |
857 |
|
|
858 |
|
|
859 |
|
|
860 |
|
|
861 |
978 |
final char[] codons = new char[codonCounts.length - 2]; |
862 |
63570 |
for (int j = 2; j < codonCounts.length; j++) |
863 |
|
{ |
864 |
62592 |
final int codonCount = codonCounts[j]; |
865 |
62592 |
codons[j - 2] = (char) (j - 2); |
866 |
62592 |
totalCount += codonCount; |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
|
|
871 |
|
|
872 |
|
|
873 |
978 |
int[] sortedCodonCounts = new int[codonCounts.length - 2]; |
874 |
978 |
System.arraycopy(codonCounts, 2, sortedCodonCounts, 0, |
875 |
|
codonCounts.length - 2); |
876 |
978 |
QuickSort.sort(sortedCodonCounts, codons); |
877 |
|
|
878 |
978 |
int modalCodonEncoded = codons[codons.length - 1]; |
879 |
978 |
int modalCodonCount = sortedCodonCounts[codons.length - 1]; |
880 |
978 |
String modalCodon = String |
881 |
|
.valueOf(CodingUtils.decodeCodon(modalCodonEncoded)); |
882 |
978 |
if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length |
883 |
|
- 2] == sortedCodonCounts[codons.length - 1]) |
884 |
|
{ |
885 |
|
|
886 |
|
|
887 |
|
|
888 |
25 |
modalCodon = "+"; |
889 |
|
} |
890 |
978 |
float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 |
891 |
|
/ (float) totalCount; |
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
|
|
900 |
|
|
901 |
|
|
902 |
978 |
StringBuilder mouseOver = new StringBuilder(32); |
903 |
978 |
StringBuilder samePercent = new StringBuilder(); |
904 |
978 |
String percent = null; |
905 |
978 |
String lastPercent = null; |
906 |
978 |
int percentDecPl = getPercentageDp(nseqs); |
907 |
|
|
908 |
1931 |
for (int j = codons.length - 1; j >= 0; j--) |
909 |
|
{ |
910 |
1931 |
int codonCount = sortedCodonCounts[j]; |
911 |
1931 |
if (codonCount == 0) |
912 |
|
{ |
913 |
|
|
914 |
|
|
915 |
|
|
916 |
|
|
917 |
978 |
if (samePercent.length() > 0) |
918 |
|
{ |
919 |
953 |
mouseOver.append(samePercent).append(": ").append(percent) |
920 |
|
.append("% "); |
921 |
|
} |
922 |
978 |
break; |
923 |
|
} |
924 |
953 |
int codonEncoded = codons[j]; |
925 |
953 |
final int pct = codonCount * 100 / totalCount; |
926 |
953 |
String codon = String |
927 |
|
.valueOf(CodingUtils.decodeCodon(codonEncoded)); |
928 |
953 |
StringBuilder sb = new StringBuilder(); |
929 |
953 |
Format.appendPercentage(sb, pct, percentDecPl); |
930 |
953 |
percent = sb.toString(); |
931 |
953 |
if (showProfileLogo || codonCount == modalCodonCount) |
932 |
|
{ |
933 |
953 |
if (percent.equals(lastPercent) && j > 0) |
934 |
|
{ |
935 |
0 |
samePercent.append(samePercent.length() == 0 ? "" : ", "); |
936 |
0 |
samePercent.append(codon); |
937 |
|
} |
938 |
|
else |
939 |
|
{ |
940 |
953 |
if (samePercent.length() > 0) |
941 |
|
{ |
942 |
0 |
mouseOver.append(samePercent).append(": ").append(lastPercent) |
943 |
|
.append("% "); |
944 |
|
} |
945 |
953 |
samePercent.setLength(0); |
946 |
953 |
samePercent.append(codon); |
947 |
|
} |
948 |
953 |
lastPercent = percent; |
949 |
|
} |
950 |
|
} |
951 |
|
|
952 |
978 |
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 |
704154 |
protected static int getPercentageDp(long nseq)... |
966 |
|
{ |
967 |
704159 |
int scale = 0; |
968 |
704165 |
while (nseq >= 100) |
969 |
|
{ |
970 |
0 |
scale++; |
971 |
0 |
nseq /= 10; |
972 |
|
} |
973 |
704162 |
return scale; |
974 |
|
} |
975 |
|
} |