1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
package jalview.analysis; |
28 |
|
|
29 |
|
import jalview.analysis.SecStrConsensus.SimpleBP; |
30 |
|
import jalview.datamodel.SequenceFeature; |
31 |
|
import jalview.util.MessageManager; |
32 |
|
|
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.HashMap; |
35 |
|
import java.util.Hashtable; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
import java.util.Stack; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 200 (200) |
Complexity: 68 |
Complexity Density: 0.46 |
|
40 |
|
public class Rna |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
@return |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0 |
public static boolean isOpeningParenthesis(char c)... |
51 |
|
{ |
52 |
0 |
return ('A' <= c && c <= 'Z' || c == '(' || c == '[' || c == '{' |
53 |
|
|| c == '<'); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@return |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0 |
public static boolean isOpeningParenthesis(String s)... |
64 |
|
{ |
65 |
0 |
return s != null && s.length() == 1 |
66 |
|
&& isOpeningParenthesis(s.charAt(0)); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@return |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
public static boolean isClosingParenthesis(char c)... |
77 |
|
{ |
78 |
0 |
return ('a' <= c && c <= 'z' || c == ')' || c == ']' || c == '}' |
79 |
|
|| c == '>'); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@return |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
0 |
public static boolean isClosingParenthesis(String s)... |
90 |
|
{ |
91 |
0 |
return s != null && s.length() == 1 |
92 |
|
&& isClosingParenthesis(s.charAt(0)); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
@return |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 7 |
Complexity Density: 0.54 |
|
103 |
0 |
public static char getMatchingOpeningParenthesis(char c)... |
104 |
|
{ |
105 |
0 |
if ('a' <= c && c <= 'z') |
106 |
|
{ |
107 |
0 |
return (char) (c + 'A' - 'a'); |
108 |
|
} |
109 |
0 |
switch (c) |
110 |
|
{ |
111 |
0 |
case ')': |
112 |
0 |
return '('; |
113 |
0 |
case ']': |
114 |
0 |
return '['; |
115 |
0 |
case '}': |
116 |
0 |
return '{'; |
117 |
0 |
case '>': |
118 |
0 |
return '<'; |
119 |
0 |
default: |
120 |
0 |
return c; |
121 |
|
} |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
|
135 |
|
@return |
136 |
|
@link |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 8 |
Complexity Density: 0.33 |
|
138 |
0 |
protected static List<SimpleBP> getSimpleBPs(CharSequence line)... |
139 |
|
throws WUSSParseException |
140 |
|
{ |
141 |
0 |
Hashtable<Character, Stack<Integer>> stacks = new Hashtable<Character, Stack<Integer>>(); |
142 |
0 |
List<SimpleBP> pairs = new ArrayList<SimpleBP>(); |
143 |
0 |
int i = 0; |
144 |
0 |
while (i < line.length()) |
145 |
|
{ |
146 |
0 |
char base = line.charAt(i); |
147 |
|
|
148 |
0 |
if (isOpeningParenthesis(base)) |
149 |
|
{ |
150 |
0 |
if (!stacks.containsKey(base)) |
151 |
|
{ |
152 |
0 |
stacks.put(base, new Stack<Integer>()); |
153 |
|
} |
154 |
0 |
stacks.get(base).push(i); |
155 |
|
|
156 |
|
} |
157 |
0 |
else if (isClosingParenthesis(base)) |
158 |
|
{ |
159 |
|
|
160 |
0 |
char opening = getMatchingOpeningParenthesis(base); |
161 |
|
|
162 |
0 |
if (!stacks.containsKey(opening)) |
163 |
|
{ |
164 |
0 |
throw new WUSSParseException(MessageManager.formatMessage( |
165 |
|
"exception.mismatched_unseen_closing_char", new String[] |
166 |
|
{ String.valueOf(base) }), i); |
167 |
|
} |
168 |
|
|
169 |
0 |
Stack<Integer> stack = stacks.get(opening); |
170 |
0 |
if (stack.isEmpty()) |
171 |
|
{ |
172 |
|
|
173 |
0 |
throw new WUSSParseException(MessageManager.formatMessage( |
174 |
|
"exception.mismatched_closing_char", new String[] |
175 |
|
{ String.valueOf(base) }), i); |
176 |
|
} |
177 |
0 |
int temp = stack.pop(); |
178 |
|
|
179 |
0 |
pairs.add(new SimpleBP(temp, i)); |
180 |
|
} |
181 |
0 |
i++; |
182 |
|
} |
183 |
0 |
for (char opening : stacks.keySet()) |
184 |
|
{ |
185 |
0 |
Stack<Integer> stack = stacks.get(opening); |
186 |
0 |
if (!stack.empty()) |
187 |
|
{ |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
0 |
throw new WUSSParseException(MessageManager.formatMessage( |
193 |
|
"exception.mismatched_opening_char", new String[] |
194 |
|
{ String.valueOf(opening), String.valueOf(stack.pop()) }), |
195 |
|
i); |
196 |
|
} |
197 |
|
} |
198 |
0 |
return pairs; |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
206 |
|
@return |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
@param |
220 |
|
@return |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
222 |
0 |
public static boolean isRnaSecondaryStructureSymbol(char c)... |
223 |
|
{ |
224 |
0 |
return isOpeningParenthesis(c) || isClosingParenthesis(c); |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
@param |
232 |
|
@return |
233 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
234 |
0 |
public static boolean isRnaSecondaryStructureSymbol(String s)... |
235 |
|
{ |
236 |
0 |
return isOpeningParenthesis(s) || isClosingParenthesis(s); |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
@return |
246 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
247 |
0 |
public static String getRNASecStrucState(String ssString)... |
248 |
|
{ |
249 |
0 |
if (ssString == null) |
250 |
|
{ |
251 |
0 |
return null; |
252 |
|
} |
253 |
0 |
StringBuilder result = new StringBuilder(ssString.length()); |
254 |
0 |
for (int i = 0; i < ssString.length(); i++) |
255 |
|
{ |
256 |
0 |
char c = ssString.charAt(i); |
257 |
0 |
result.append(isRnaSecondaryStructureSymbol(c) ? c : " "); |
258 |
|
} |
259 |
0 |
return result.toString(); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
@param |
267 |
|
@param |
268 |
|
@return |
269 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 16 |
Complexity Density: 0.52 |
|
270 |
0 |
public static boolean isCanonicalOrWobblePair(char first, char second)... |
271 |
|
{ |
272 |
0 |
if (first > 'Z') |
273 |
|
{ |
274 |
0 |
first -= 32; |
275 |
|
} |
276 |
0 |
if (second > 'Z') |
277 |
|
{ |
278 |
0 |
second -= 32; |
279 |
|
} |
280 |
|
|
281 |
0 |
switch (first) |
282 |
|
{ |
283 |
0 |
case 'A': |
284 |
0 |
switch (second) |
285 |
|
{ |
286 |
0 |
case 'T': |
287 |
0 |
case 'U': |
288 |
0 |
return true; |
289 |
|
} |
290 |
0 |
break; |
291 |
0 |
case 'C': |
292 |
0 |
switch (second) |
293 |
|
{ |
294 |
0 |
case 'G': |
295 |
0 |
return true; |
296 |
|
} |
297 |
0 |
break; |
298 |
0 |
case 'T': |
299 |
0 |
case 'U': |
300 |
0 |
switch (second) |
301 |
|
{ |
302 |
0 |
case 'A': |
303 |
0 |
case 'G': |
304 |
0 |
return true; |
305 |
|
} |
306 |
0 |
break; |
307 |
0 |
case 'G': |
308 |
0 |
switch (second) |
309 |
|
{ |
310 |
0 |
case 'C': |
311 |
0 |
case 'T': |
312 |
0 |
case 'U': |
313 |
0 |
return true; |
314 |
|
} |
315 |
0 |
break; |
316 |
|
} |
317 |
0 |
return false; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
@param |
325 |
|
@param |
326 |
|
@return |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 13 |
Complexity Density: 0.46 |
|
328 |
0 |
public static boolean isCanonicalPair(char first, char second)... |
329 |
|
{ |
330 |
|
|
331 |
0 |
if (first > 'Z') |
332 |
|
{ |
333 |
0 |
first -= 32; |
334 |
|
} |
335 |
0 |
if (second > 'Z') |
336 |
|
{ |
337 |
0 |
second -= 32; |
338 |
|
} |
339 |
|
|
340 |
0 |
switch (first) |
341 |
|
{ |
342 |
0 |
case 'A': |
343 |
0 |
switch (second) |
344 |
|
{ |
345 |
0 |
case 'T': |
346 |
0 |
case 'U': |
347 |
0 |
return true; |
348 |
|
} |
349 |
0 |
break; |
350 |
0 |
case 'G': |
351 |
0 |
switch (second) |
352 |
|
{ |
353 |
0 |
case 'C': |
354 |
0 |
return true; |
355 |
|
} |
356 |
0 |
break; |
357 |
0 |
case 'C': |
358 |
0 |
switch (second) |
359 |
|
{ |
360 |
0 |
case 'G': |
361 |
0 |
return true; |
362 |
|
} |
363 |
0 |
break; |
364 |
0 |
case 'T': |
365 |
0 |
case 'U': |
366 |
0 |
switch (second) |
367 |
|
{ |
368 |
0 |
case 'A': |
369 |
0 |
return true; |
370 |
|
} |
371 |
0 |
break; |
372 |
|
} |
373 |
0 |
return false; |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
@param |
382 |
|
@return |
383 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 7 |
Complexity Density: 0.54 |
|
384 |
0 |
public static char getMatchingClosingParenthesis(char c)... |
385 |
|
{ |
386 |
0 |
if ('A' <= c && c <= 'Z') |
387 |
|
{ |
388 |
0 |
return (char) (c + 'a' - 'A'); |
389 |
|
} |
390 |
0 |
switch (c) |
391 |
|
{ |
392 |
0 |
case '(': |
393 |
0 |
return ')'; |
394 |
0 |
case '[': |
395 |
0 |
return ']'; |
396 |
0 |
case '{': |
397 |
0 |
return '}'; |
398 |
0 |
case '<': |
399 |
0 |
return '>'; |
400 |
0 |
default: |
401 |
0 |
return c; |
402 |
|
} |
403 |
|
} |
404 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 7 |
Complexity Density: 0.28 |
|
405 |
0 |
public static SequenceFeature[] getHelixMap(CharSequence rnaAnnotation)... |
406 |
|
throws WUSSParseException |
407 |
|
{ |
408 |
0 |
List<SequenceFeature> result = new ArrayList<SequenceFeature>(); |
409 |
|
|
410 |
0 |
int helix = 0; |
411 |
0 |
int lastopen = 0; |
412 |
0 |
int lastclose = 9999999; |
413 |
|
|
414 |
0 |
Map<Integer, Integer> helices = new HashMap<Integer, Integer>(); |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
0 |
List<SimpleBP> bps = getSimpleBPs(rnaAnnotation); |
419 |
0 |
for (SimpleBP basePair : bps) |
420 |
|
{ |
421 |
0 |
final int open = basePair.getBP5(); |
422 |
0 |
final int close = basePair.getBP3(); |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
0 |
if (open > lastclose) |
433 |
|
{ |
434 |
0 |
helix++; |
435 |
|
} |
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
0 |
int j = bps.size(); |
441 |
0 |
while (--j >= 0) |
442 |
|
{ |
443 |
0 |
int popen = bps.get(j).getBP5(); |
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
0 |
if ((popen < lastopen) && (popen > open)) |
449 |
|
{ |
450 |
0 |
if (helices.containsValue(popen) |
451 |
|
&& ((helices.get(popen)) == helix)) |
452 |
|
{ |
453 |
0 |
continue; |
454 |
|
} |
455 |
|
else |
456 |
|
{ |
457 |
0 |
helix++; |
458 |
0 |
break; |
459 |
|
} |
460 |
|
} |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
0 |
helices.put(open, helix); |
465 |
0 |
helices.put(close, helix); |
466 |
|
|
467 |
|
|
468 |
0 |
result.add(new SequenceFeature("RNA helix", "", open, close, |
469 |
|
String.valueOf(helix))); |
470 |
|
|
471 |
0 |
lastopen = open; |
472 |
0 |
lastclose = close; |
473 |
|
} |
474 |
|
|
475 |
0 |
return result.toArray(new SequenceFeature[result.size()]); |
476 |
|
} |
477 |
|
} |