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