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.AlignmentAnnotation; |
24 |
|
import jalview.datamodel.Annotation; |
25 |
|
import jalview.datamodel.SequenceFeature; |
26 |
|
import jalview.datamodel.SequenceI; |
27 |
|
import jalview.util.Comparison; |
28 |
|
import jalview.util.Format; |
29 |
|
|
30 |
|
import java.util.ArrayList; |
31 |
|
import java.util.Hashtable; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
@version |
41 |
|
|
|
|
| 56% |
Uncovered Elements: 122 (277) |
Complexity: 59 |
Complexity Density: 0.32 |
|
42 |
|
public class StructureFrequency |
43 |
|
{ |
44 |
|
public static final int STRUCTURE_PROFILE_LENGTH = 74; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String MAXCOUNT = "C"; |
49 |
|
|
50 |
|
public static final String MAXRESIDUE = "R"; |
51 |
|
|
52 |
|
public static final String PID_GAPS = "G"; |
53 |
|
|
54 |
|
public static final String PID_NOGAPS = "N"; |
55 |
|
|
56 |
|
public static final String PROFILE = "P"; |
57 |
|
|
58 |
|
public static final String PAIRPROFILE = "B"; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
@return |
68 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
69 |
90 |
public static int findPair(SequenceFeature[] pairs, int indice)... |
70 |
|
{ |
71 |
|
|
72 |
855 |
for (int i = 0; i < pairs.length; i++) |
73 |
|
{ |
74 |
855 |
if (pairs[i].getBegin() == indice) |
75 |
|
|
76 |
|
{ |
77 |
|
|
78 |
90 |
return pairs[i].getEnd(); |
79 |
|
|
80 |
|
} |
81 |
|
} |
82 |
0 |
return -1; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@param |
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
@param |
94 |
|
@param |
95 |
|
|
|
|
| 86.3% |
Uncovered Elements: 18 (131) |
Complexity: 28 |
Complexity Density: 0.32 |
|
96 |
5 |
public static final void calculate(SequenceI[] sequences, int start,... |
97 |
|
int end, Hashtable[] result, boolean profile, |
98 |
|
AlignmentAnnotation rnaStruc) |
99 |
|
{ |
100 |
|
|
101 |
5 |
Hashtable residueHash; |
102 |
5 |
String maxResidue; |
103 |
5 |
char[] struc = rnaStruc.getRNAStruc().toCharArray(); |
104 |
|
|
105 |
5 |
SequenceFeature[] rna = rnaStruc._rnasecstr; |
106 |
5 |
char c, s, cEnd; |
107 |
5 |
int bpEnd = -1; |
108 |
5 |
int jSize = sequences.length; |
109 |
5 |
int[] values; |
110 |
5 |
int[][] pairs; |
111 |
5 |
float percentage; |
112 |
|
|
113 |
470 |
for (int i = start; i < end; i++) |
114 |
|
{ |
115 |
465 |
int canonicalOrWobblePairCount = 0, canonical = 0; |
116 |
465 |
int otherPairCount = 0; |
117 |
465 |
int nongap = 0; |
118 |
465 |
maxResidue = "-"; |
119 |
465 |
values = new int[255]; |
120 |
465 |
pairs = new int[255][255]; |
121 |
465 |
bpEnd = -1; |
122 |
465 |
if (i < struc.length) |
123 |
|
{ |
124 |
465 |
s = struc[i]; |
125 |
|
} |
126 |
|
else |
127 |
|
{ |
128 |
0 |
s = '-'; |
129 |
|
} |
130 |
465 |
if (s == '.' || s == ' ') |
131 |
|
{ |
132 |
285 |
s = '-'; |
133 |
|
} |
134 |
|
|
135 |
465 |
if (!Rna.isOpeningParenthesis(s)) |
136 |
|
{ |
137 |
375 |
if (s == '-') |
138 |
|
{ |
139 |
285 |
values['-']++; |
140 |
|
} |
141 |
|
} |
142 |
|
else |
143 |
|
{ |
144 |
90 |
bpEnd = findPair(rna, i); |
145 |
|
|
146 |
90 |
if (bpEnd > -1) |
147 |
|
{ |
148 |
5580 |
for (int j = 0; j < jSize; j++) |
149 |
|
{ |
150 |
5490 |
if (sequences[j] == null) |
151 |
|
{ |
152 |
0 |
System.err.println( |
153 |
|
"WARNING: Consensus skipping null sequence - possible race condition."); |
154 |
0 |
continue; |
155 |
|
} |
156 |
|
|
157 |
5490 |
c = sequences[j].getCharAt(i); |
158 |
5490 |
cEnd = sequences[j].getCharAt(bpEnd); |
159 |
|
|
160 |
5490 |
if (Comparison.isGap(c) || Comparison.isGap(cEnd)) |
161 |
|
{ |
162 |
10 |
values['-']++; |
163 |
10 |
continue; |
164 |
|
} |
165 |
5480 |
nongap++; |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
5480 |
if ('a' <= c && 'z' >= c) |
170 |
|
{ |
171 |
0 |
c += 'A' - 'a'; |
172 |
|
} |
173 |
5480 |
if ('a' <= cEnd && 'z' >= cEnd) |
174 |
|
{ |
175 |
0 |
cEnd += 'A' - 'a'; |
176 |
|
} |
177 |
5480 |
if (Rna.isCanonicalOrWobblePair(c, cEnd)) |
178 |
|
{ |
179 |
4865 |
canonicalOrWobblePairCount++; |
180 |
4865 |
if (Rna.isCanonicalPair(c, cEnd)) |
181 |
|
{ |
182 |
4315 |
canonical++; |
183 |
|
} |
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
615 |
otherPairCount++; |
188 |
|
} |
189 |
5480 |
pairs[c][cEnd]++; |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
|
194 |
465 |
residueHash = new Hashtable(); |
195 |
465 |
if (profile) |
196 |
|
{ |
197 |
|
|
198 |
465 |
residueHash.put(PROFILE, |
199 |
|
new int[][] |
200 |
|
{ values, new int[] { jSize, (jSize - values['-']) } }); |
201 |
|
|
202 |
465 |
residueHash.put(PAIRPROFILE, pairs); |
203 |
|
} |
204 |
465 |
values['('] = canonicalOrWobblePairCount; |
205 |
465 |
values['['] = canonical; |
206 |
465 |
values['{'] = otherPairCount; |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
465 |
int count = canonicalOrWobblePairCount; |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
465 |
if (canonicalOrWobblePairCount > 0 || otherPairCount > 0) |
218 |
|
{ |
219 |
90 |
if (canonicalOrWobblePairCount >= otherPairCount) |
220 |
|
{ |
221 |
90 |
maxResidue = (canonicalOrWobblePairCount - canonical) < canonical |
222 |
|
? "(" |
223 |
|
: "["; |
224 |
|
} |
225 |
|
else |
226 |
|
{ |
227 |
0 |
maxResidue = "{"; |
228 |
|
} |
229 |
|
} |
230 |
465 |
residueHash.put(MAXCOUNT, new Integer(count)); |
231 |
465 |
residueHash.put(MAXRESIDUE, maxResidue); |
232 |
|
|
233 |
465 |
percentage = ((float) count * 100) / jSize; |
234 |
465 |
residueHash.put(PID_GAPS, new Float(percentage)); |
235 |
|
|
236 |
465 |
percentage = ((float) count * 100) / nongap; |
237 |
465 |
residueHash.put(PID_NOGAPS, new Float(percentage)); |
238 |
|
|
239 |
465 |
if (result[i] == null) |
240 |
|
{ |
241 |
375 |
result[i] = residueHash; |
242 |
|
} |
243 |
465 |
if (bpEnd > 0) |
244 |
|
{ |
245 |
90 |
values[')'] = values['(']; |
246 |
90 |
values[']'] = values['[']; |
247 |
90 |
values['}'] = values['{']; |
248 |
90 |
values['('] = 0; |
249 |
90 |
values['['] = 0; |
250 |
90 |
values['{'] = 0; |
251 |
90 |
maxResidue = maxResidue.equals("(") ? ")" |
252 |
0 |
: maxResidue.equals("[") ? "]" : "}"; |
253 |
|
|
254 |
90 |
residueHash = new Hashtable(); |
255 |
90 |
if (profile) |
256 |
|
{ |
257 |
90 |
residueHash.put(PROFILE, |
258 |
|
new int[][] |
259 |
|
{ values, new int[] { jSize, (jSize - values['-']) } }); |
260 |
|
|
261 |
90 |
residueHash.put(PAIRPROFILE, pairs); |
262 |
|
} |
263 |
|
|
264 |
90 |
residueHash.put(MAXCOUNT, new Integer(count)); |
265 |
90 |
residueHash.put(MAXRESIDUE, maxResidue); |
266 |
|
|
267 |
90 |
percentage = ((float) count * 100) / jSize; |
268 |
90 |
residueHash.put(PID_GAPS, new Float(percentage)); |
269 |
|
|
270 |
90 |
percentage = ((float) count * 100) / nongap; |
271 |
90 |
residueHash.put(PID_NOGAPS, new Float(percentage)); |
272 |
|
|
273 |
90 |
result[bpEnd] = residueHash; |
274 |
|
} |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@param |
283 |
|
|
284 |
|
@param |
285 |
|
@param |
286 |
|
@param |
287 |
|
@param |
288 |
|
@param |
289 |
|
|
|
|
| 40.2% |
Uncovered Elements: 49 (82) |
Complexity: 20 |
Complexity Density: 0.38 |
|
290 |
5 |
public static void completeConsensus(AlignmentAnnotation consensus,... |
291 |
|
Hashtable[] hconsensus, int iStart, int width, |
292 |
|
boolean ignoreGapsInConsensusCalculation, |
293 |
|
boolean includeAllConsSymbols, long nseq) |
294 |
|
{ |
295 |
5 |
float tval, value; |
296 |
5 |
if (consensus == null || consensus.annotations == null |
297 |
|
|| consensus.annotations.length < width) |
298 |
|
{ |
299 |
|
|
300 |
|
|
301 |
0 |
return; |
302 |
|
} |
303 |
5 |
String fmtstr = "%3.1f"; |
304 |
5 |
int precision = 2; |
305 |
5 |
while (nseq > 100) |
306 |
|
{ |
307 |
0 |
precision++; |
308 |
0 |
nseq /= 10; |
309 |
|
} |
310 |
5 |
if (precision > 2) |
311 |
|
{ |
312 |
0 |
fmtstr = "%" + (2 + precision) + "." + precision + "f"; |
313 |
|
} |
314 |
5 |
Format fmt = new Format(fmtstr); |
315 |
|
|
316 |
470 |
for (int i = iStart; i < width; i++) |
317 |
|
{ |
318 |
465 |
Hashtable hci; |
319 |
? |
if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) |
320 |
|
{ |
321 |
|
|
322 |
|
|
323 |
0 |
consensus.annotations[i] = null; |
324 |
0 |
continue; |
325 |
|
} |
326 |
465 |
value = 0; |
327 |
465 |
Float fv; |
328 |
465 |
if (ignoreGapsInConsensusCalculation) |
329 |
|
{ |
330 |
0 |
fv = (Float) hci.get(StructureFrequency.PID_NOGAPS); |
331 |
|
} |
332 |
|
else |
333 |
|
{ |
334 |
465 |
fv = (Float) hci.get(StructureFrequency.PID_GAPS); |
335 |
|
} |
336 |
465 |
if (fv == null) |
337 |
|
{ |
338 |
0 |
consensus.annotations[i] = null; |
339 |
|
|
340 |
0 |
continue; |
341 |
|
} |
342 |
465 |
value = fv.floatValue(); |
343 |
465 |
String maxRes = hci.get(StructureFrequency.MAXRESIDUE).toString(); |
344 |
465 |
String mouseOver = hci.get(StructureFrequency.MAXRESIDUE) + " "; |
345 |
465 |
if (maxRes.length() > 1) |
346 |
|
{ |
347 |
0 |
mouseOver = "[" + maxRes + "] "; |
348 |
0 |
maxRes = "+"; |
349 |
|
} |
350 |
465 |
int[][] profile = (int[][]) hci.get(StructureFrequency.PROFILE); |
351 |
465 |
int[][] pairs = (int[][]) hci.get(StructureFrequency.PAIRPROFILE); |
352 |
|
|
353 |
465 |
if (pairs != null && includeAllConsSymbols) |
354 |
|
|
355 |
|
|
356 |
|
{ |
357 |
0 |
mouseOver = ""; |
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
0 |
int[][] ca = new int[625][]; |
370 |
0 |
float[] vl = new float[625]; |
371 |
0 |
int x = 0; |
372 |
0 |
for (int c = 65; c < 90; c++) |
373 |
|
{ |
374 |
0 |
for (int d = 65; d < 90; d++) |
375 |
|
{ |
376 |
0 |
ca[x] = new int[] { c, d }; |
377 |
0 |
vl[x] = pairs[c][d]; |
378 |
0 |
x++; |
379 |
|
} |
380 |
|
} |
381 |
0 |
jalview.util.QuickSort.sort(vl, ca); |
382 |
0 |
int p = 0; |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
0 |
final int divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 |
388 |
|
: 0]; |
389 |
0 |
for (int c = 624; c > 0; c--) |
390 |
|
{ |
391 |
0 |
if (vl[c] > 0) |
392 |
|
{ |
393 |
0 |
tval = (vl[c] * 100f / divisor); |
394 |
0 |
mouseOver += ((p == 0) ? "" : "; ") + (char) ca[c][0] |
395 |
|
+ (char) ca[c][1] + " " + fmt.form(tval) + "%"; |
396 |
0 |
p++; |
397 |
|
|
398 |
|
} |
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
|
} |
403 |
|
else |
404 |
|
{ |
405 |
465 |
mouseOver += (fmt.form(value) + "%"); |
406 |
|
} |
407 |
465 |
consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', |
408 |
|
value); |
409 |
|
} |
410 |
|
} |
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
@param |
416 |
|
@return |
417 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 7 |
Complexity Density: 0.23 |
|
418 |
0 |
public static int[] extractProfile(Hashtable hconsensus,... |
419 |
|
boolean ignoreGapsInConsensusCalculation) |
420 |
|
{ |
421 |
0 |
int[] rtnval = new int[STRUCTURE_PROFILE_LENGTH]; |
422 |
0 |
int[][] profile = (int[][]) hconsensus.get(StructureFrequency.PROFILE); |
423 |
0 |
int[][] pairs = (int[][]) hconsensus |
424 |
|
.get(StructureFrequency.PAIRPROFILE); |
425 |
|
|
426 |
0 |
if (profile == null) |
427 |
|
{ |
428 |
0 |
return null; |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
0 |
int[][] ca = new int[625][]; |
434 |
0 |
float[] vl = new float[625]; |
435 |
0 |
int x = 0; |
436 |
0 |
for (int c = 65; c < 90; c++) |
437 |
|
{ |
438 |
0 |
for (int d = 65; d < 90; d++) |
439 |
|
{ |
440 |
0 |
ca[x] = new int[] { c, d }; |
441 |
0 |
vl[x] = pairs[c][d]; |
442 |
0 |
x++; |
443 |
|
} |
444 |
|
} |
445 |
0 |
jalview.util.QuickSort.sort(vl, ca); |
446 |
|
|
447 |
0 |
int valuesCount = 0; |
448 |
0 |
rtnval[1] = 0; |
449 |
0 |
int offset = 2; |
450 |
0 |
final int divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 |
451 |
|
: 0]; |
452 |
0 |
for (int c = 624; c > 0; c--) |
453 |
|
{ |
454 |
0 |
if (vl[c] > 0) |
455 |
|
{ |
456 |
0 |
rtnval[offset++] = ca[c][0]; |
457 |
0 |
rtnval[offset++] = ca[c][1]; |
458 |
0 |
rtnval[offset] = (int) (vl[c] * 100f / divisor); |
459 |
0 |
rtnval[1] += rtnval[offset++]; |
460 |
0 |
valuesCount++; |
461 |
|
} |
462 |
|
} |
463 |
0 |
rtnval[0] = valuesCount; |
464 |
|
|
465 |
|
|
466 |
0 |
int[] result = new int[rtnval.length + 1]; |
467 |
0 |
result[0] = AlignmentAnnotation.STRUCTURE_PROFILE; |
468 |
0 |
System.arraycopy(rtnval, 0, result, 1, rtnval.length); |
469 |
0 |
return result; |
470 |
|
} |
471 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
472 |
0 |
public static void main(String args[])... |
473 |
|
{ |
474 |
|
|
475 |
0 |
ArrayList<String> test = new ArrayList<String>(); |
476 |
0 |
test.add("A"); |
477 |
0 |
test.add("c"); |
478 |
0 |
test.add("g"); |
479 |
0 |
test.add("T"); |
480 |
0 |
test.add("U"); |
481 |
0 |
for (String i : test) |
482 |
|
{ |
483 |
0 |
for (String j : test) |
484 |
|
{ |
485 |
0 |
System.out.println(i + "-" + j + ": " |
486 |
|
+ Rna.isCanonicalOrWobblePair(i.charAt(0), j.charAt(0))); |
487 |
|
} |
488 |
|
} |
489 |
|
} |
490 |
|
} |