1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import jalview.util.MessageManager; |
24 |
|
|
25 |
|
import java.util.Vector; |
26 |
|
|
|
|
| 82% |
Uncovered Elements: 61 (339) |
Complexity: 99 |
Complexity Density: 0.45 |
|
27 |
|
public abstract class CigarBase |
28 |
|
{ |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
34 |
173 |
public CigarBase()... |
35 |
|
{ |
36 |
|
|
37 |
|
} |
38 |
|
|
39 |
|
protected int length = 0; |
40 |
|
|
41 |
|
protected int _inc_length = 10; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
protected char[] operation = null; |
46 |
|
|
47 |
|
protected int[] range = null; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
public static final char D = 'D'; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public static final char I = 'I'; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
public static final char M = 'M'; |
63 |
|
|
64 |
|
static protected final char _case_shift = 'a' - 'A'; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@param |
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
|
76 |
|
@return |
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 80.8% |
Uncovered Elements: 14 (73) |
Complexity: 15 |
Complexity Density: 0.29 |
|
80 |
208 |
public Object[] getSequenceAndDeletions(String reference, char GapChar)... |
81 |
|
{ |
82 |
208 |
int rlength = 0; |
83 |
208 |
int[][] deletions = new int[length][]; |
84 |
208 |
int[][] trunc_deletions = null; |
85 |
208 |
StringBuffer sq = new StringBuffer(); |
86 |
208 |
int cursor = 0, alcursor = 0, start = 0, startpos = 0, end = 0, |
87 |
|
endpos = 0, delcount = -1; |
88 |
208 |
boolean consecutive_del = false; |
89 |
208 |
if (length == 0) |
90 |
|
{ |
91 |
0 |
return null; |
92 |
|
} |
93 |
208 |
if (reference != null) |
94 |
|
{ |
95 |
208 |
rlength = reference.length(); |
96 |
|
} |
97 |
208 |
boolean modstart = true; |
98 |
1328 |
for (int i = 0; i < length; i++) |
99 |
|
{ |
100 |
1120 |
switch (operation[i]) |
101 |
|
{ |
102 |
106 |
case D: |
103 |
106 |
if (!consecutive_del) |
104 |
|
{ |
105 |
106 |
deletions[++delcount] = new int[] { cursor, 0, alcursor }; |
106 |
|
} |
107 |
106 |
cursor += range[i]; |
108 |
106 |
deletions[delcount][1] = cursor - 1; |
109 |
106 |
consecutive_del = true; |
110 |
106 |
break; |
111 |
410 |
case I: |
112 |
410 |
consecutive_del = false; |
113 |
1846 |
for (int r = 0; r < range[i]; r++) |
114 |
|
{ |
115 |
1436 |
sq.append(GapChar); |
116 |
1436 |
alcursor++; |
117 |
|
} |
118 |
410 |
break; |
119 |
604 |
case M: |
120 |
604 |
consecutive_del = false; |
121 |
604 |
if (modstart) |
122 |
|
{ |
123 |
206 |
start = cursor; |
124 |
206 |
startpos = alcursor; |
125 |
206 |
modstart = false; |
126 |
|
} |
127 |
604 |
if (reference != null) |
128 |
|
{ |
129 |
604 |
int sbend = cursor + range[i]; |
130 |
604 |
if (sbend > rlength) |
131 |
|
{ |
132 |
0 |
sq.append(reference.substring(cursor, rlength)); |
133 |
0 |
while (sbend-- >= rlength) |
134 |
|
{ |
135 |
0 |
sq.append(GapChar); |
136 |
|
} |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
604 |
sq.append(reference.substring(cursor, sbend)); |
141 |
|
} |
142 |
|
} |
143 |
604 |
alcursor += range[i]; |
144 |
604 |
cursor += range[i]; |
145 |
604 |
end = cursor - 1; |
146 |
604 |
endpos = alcursor; |
147 |
604 |
break; |
148 |
0 |
default: |
149 |
0 |
throw new Error(MessageManager.formatMessage( |
150 |
|
"error.unknown_seq_cigar_operation", new String[] |
151 |
|
{ new StringBuffer(operation[i]).toString() })); |
152 |
|
} |
153 |
|
} |
154 |
208 |
if (++delcount > 0) |
155 |
|
{ |
156 |
96 |
trunc_deletions = new int[delcount][]; |
157 |
96 |
System.arraycopy(deletions, 0, trunc_deletions, 0, delcount); |
158 |
|
} |
159 |
208 |
deletions = null; |
160 |
208 |
return new Object[] { ((reference != null) ? sq.toString() : null), |
161 |
|
new int[] |
162 |
|
{ start, startpos, end, endpos }, trunc_deletions }; |
163 |
|
} |
164 |
|
|
|
|
| 19% |
Uncovered Elements: 17 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
165 |
101 |
protected void compact_operations()... |
166 |
|
{ |
167 |
101 |
int i = 1; |
168 |
101 |
if (operation == null) |
169 |
|
{ |
170 |
101 |
return; |
171 |
|
} |
172 |
0 |
char last = operation[0]; |
173 |
0 |
while (i < length) |
174 |
|
{ |
175 |
0 |
if (last == operation[i]) |
176 |
|
{ |
177 |
0 |
range[i - 1] += range[i]; |
178 |
0 |
int r = length - i; |
179 |
0 |
if (r > 0) |
180 |
|
{ |
181 |
0 |
System.arraycopy(range, i + 1, range, i, r); |
182 |
0 |
System.arraycopy(operation, i + 1, operation, i, r); |
183 |
|
} |
184 |
0 |
length--; |
185 |
|
} |
186 |
|
else |
187 |
|
{ |
188 |
0 |
last = operation[i++]; |
189 |
|
} |
190 |
|
} |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
@param |
197 |
|
|
198 |
|
@return |
199 |
|
@throws |
200 |
|
|
201 |
|
|
202 |
|
|
|
|
| 82.9% |
Uncovered Elements: 7 (41) |
Complexity: 21 |
Complexity Density: 0.78 |
|
203 |
1 |
public static Object[] parseCigarString(String cigarString)... |
204 |
|
throws Exception |
205 |
|
{ |
206 |
1 |
int ops = 0; |
207 |
23 |
for (int i = 0, l = cigarString.length(); i < l; i++) |
208 |
|
{ |
209 |
22 |
char c = cigarString.charAt(i); |
210 |
22 |
if (c == M || c == (M - _case_shift) || c == I |
211 |
|
|| c == (I - _case_shift) || c == D || c == (D - _case_shift)) |
212 |
|
{ |
213 |
10 |
ops++; |
214 |
|
} |
215 |
|
} |
216 |
1 |
char[] operation = new char[ops]; |
217 |
1 |
int[] range = new int[ops]; |
218 |
1 |
int op = 0; |
219 |
1 |
int i = 0, l = cigarString.length(); |
220 |
11 |
while (i < l) |
221 |
|
{ |
222 |
10 |
char c; |
223 |
10 |
int j = i; |
224 |
10 |
do |
225 |
|
{ |
226 |
22 |
c = cigarString.charAt(j++); |
227 |
22 |
} while (c >= '0' && c <= '9' && j < l); |
228 |
10 |
if (j >= l && c >= '0' && c <= '9') |
229 |
|
{ |
230 |
0 |
throw new Exception(MessageManager |
231 |
|
.getString("exception.unterminated_cigar_string")); |
232 |
|
} |
233 |
10 |
try |
234 |
|
{ |
235 |
10 |
String rangeint = cigarString.substring(i, j - 1); |
236 |
10 |
range[op] = Integer.parseInt(rangeint); |
237 |
10 |
i = j; |
238 |
|
} catch (Exception e) |
239 |
|
{ |
240 |
0 |
throw new Error(MessageManager |
241 |
|
.getString("error.implementation_bug_parse_cigar_string")); |
242 |
|
} |
243 |
10 |
if (c >= 'a' && c <= 'z') |
244 |
|
{ |
245 |
0 |
c -= _case_shift; |
246 |
|
} |
247 |
10 |
if ((c == M || c == I || c == D)) |
248 |
|
{ |
249 |
10 |
operation[op++] = c; |
250 |
|
} |
251 |
|
else |
252 |
|
{ |
253 |
0 |
throw new Exception(MessageManager.formatMessage( |
254 |
|
"exception.unexpected_operation_cigar_string_pos", |
255 |
|
new String[] |
256 |
|
{ new StringBuffer(c).toString(), |
257 |
|
Integer.valueOf(i).toString(), cigarString })); |
258 |
|
} |
259 |
|
} |
260 |
1 |
return new Object[] { operation, range }; |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
@param |
267 |
|
|
268 |
|
@param |
269 |
|
|
270 |
|
|
|
|
| 80% |
Uncovered Elements: 8 (40) |
Complexity: 12 |
Complexity Density: 0.46 |
|
271 |
1403 |
public void addOperation(char op, int range)... |
272 |
|
{ |
273 |
1403 |
if (op >= 'a' && op <= 'z') |
274 |
|
{ |
275 |
0 |
op -= _case_shift; |
276 |
|
} |
277 |
1403 |
if (op != M && op != D && op != I) |
278 |
|
{ |
279 |
0 |
throw new Error(MessageManager.getString( |
280 |
|
"error.implementation_error_invalid_operation_string")); |
281 |
|
} |
282 |
1403 |
if (range == 0) |
283 |
|
{ |
284 |
0 |
return; |
285 |
|
} |
286 |
1403 |
if (range < 0) |
287 |
|
{ |
288 |
0 |
throw new Error( |
289 |
|
MessageManager.getString("error.invalid_range_string")); |
290 |
|
} |
291 |
1403 |
int lngth = 0; |
292 |
1403 |
if (operation == null) |
293 |
|
{ |
294 |
272 |
this.operation = new char[_inc_length]; |
295 |
272 |
this.range = new int[_inc_length]; |
296 |
|
} |
297 |
1403 |
if (length + 1 == operation.length) |
298 |
|
{ |
299 |
23 |
char[] ops = this.operation; |
300 |
23 |
this.operation = new char[length + 1 + _inc_length]; |
301 |
23 |
System.arraycopy(ops, 0, this.operation, 0, length); |
302 |
23 |
ops = null; |
303 |
23 |
int[] rng = this.range; |
304 |
23 |
this.range = new int[length + 1 + _inc_length]; |
305 |
23 |
System.arraycopy(rng, 0, this.range, 0, length); |
306 |
23 |
rng = null; |
307 |
|
} |
308 |
1403 |
if ((length > 0) && (operation[length - 1] == op)) |
309 |
|
{ |
310 |
98 |
length--; |
311 |
|
} |
312 |
|
else |
313 |
|
{ |
314 |
1305 |
this.range[length] = 0; |
315 |
|
} |
316 |
1403 |
this.operation[length] = op; |
317 |
1403 |
this.range[length++] += range; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
@param |
340 |
|
|
341 |
|
|
342 |
|
@param |
343 |
|
|
344 |
|
@param |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
@param |
386 |
|
|
387 |
|
@param |
388 |
|
|
389 |
|
@return |
390 |
|
|
|
|
| 88.9% |
Uncovered Elements: 9 (81) |
Complexity: 22 |
Complexity Density: 0.39 |
|
391 |
101 |
public int deleteRange(int start, int end)... |
392 |
|
{ |
393 |
101 |
int deleted = 0; |
394 |
101 |
if (length == 0) |
395 |
|
{ |
396 |
|
|
397 |
0 |
return deleted; |
398 |
|
} |
399 |
101 |
if (start < 0 || start > end) |
400 |
|
{ |
401 |
0 |
throw new Error(MessageManager.getString( |
402 |
|
"error.implementation_error_delete_range_out_of_bounds")); |
403 |
|
} |
404 |
|
|
405 |
101 |
int cursor = 0; |
406 |
101 |
int rlength = 1 + end - start; |
407 |
101 |
int oldlen = length; |
408 |
101 |
int o = 0; |
409 |
101 |
boolean editing = false; |
410 |
101 |
char[] oldops = operation; |
411 |
101 |
int[] oldrange = range; |
412 |
101 |
length = 0; |
413 |
101 |
operation = null; |
414 |
101 |
range = null; |
415 |
101 |
compact_operations(); |
416 |
655 |
while (o < oldlen && cursor <= end && rlength > 0) |
417 |
|
{ |
418 |
554 |
if (oldops[o] == D) |
419 |
|
{ |
420 |
|
|
421 |
70 |
addDeleted(oldrange[o++]); |
422 |
70 |
continue; |
423 |
|
} |
424 |
|
|
425 |
484 |
int remain = oldrange[o]; |
426 |
484 |
if (!editing) |
427 |
|
{ |
428 |
430 |
if ((cursor + remain) <= start) |
429 |
|
{ |
430 |
329 |
addOperation(oldops[o], oldrange[o]); |
431 |
329 |
cursor += oldrange[o++]; |
432 |
329 |
continue; |
433 |
|
} |
434 |
101 |
editing = true; |
435 |
|
|
436 |
101 |
if (start - cursor > 0) |
437 |
|
{ |
438 |
87 |
addOperation(oldops[o], start - cursor); |
439 |
87 |
remain -= start - cursor; |
440 |
|
} |
441 |
|
} |
442 |
|
|
443 |
155 |
if (o < oldlen && editing && rlength > 0 && remain > 0) |
444 |
|
{ |
445 |
155 |
switch (oldops[o]) |
446 |
|
{ |
447 |
106 |
case M: |
448 |
106 |
if (rlength > remain) |
449 |
|
{ |
450 |
72 |
addDeleted(remain); |
451 |
72 |
deleted += remain; |
452 |
|
} |
453 |
|
else |
454 |
|
{ |
455 |
34 |
deleted += rlength; |
456 |
34 |
addDeleted(rlength); |
457 |
34 |
if (remain - rlength > 0) |
458 |
|
{ |
459 |
14 |
this.addOperation(M, remain - rlength); |
460 |
|
} |
461 |
34 |
rlength = 0; |
462 |
34 |
remain = 0; |
463 |
|
} |
464 |
106 |
break; |
465 |
49 |
case I: |
466 |
49 |
if (remain - rlength > 0) |
467 |
|
{ |
468 |
|
|
469 |
13 |
addInsertion(remain - rlength); |
470 |
13 |
rlength = 0; |
471 |
|
} |
472 |
49 |
break; |
473 |
0 |
case D: |
474 |
0 |
throw new Error( |
475 |
|
MessageManager.getString("error.implementation_error")); |
476 |
|
|
477 |
0 |
default: |
478 |
0 |
throw new Error(MessageManager.formatMessage( |
479 |
|
"error.implementation_error_unknown_operation", |
480 |
|
new String[] |
481 |
|
{ new StringBuffer(oldops[o]).toString() })); |
482 |
|
} |
483 |
155 |
rlength -= remain; |
484 |
155 |
remain = oldrange[++o]; |
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
200 |
while (o < oldlen) |
489 |
|
{ |
490 |
99 |
addOperation(oldops[o], oldrange[o++]); |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
101 |
return deleted; |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
@return |
504 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
505 |
1 |
public boolean hasDeletedRegions()... |
506 |
|
{ |
507 |
9 |
for (int i = 0; i < length; i++) |
508 |
|
{ |
509 |
8 |
if (operation[i] == D) |
510 |
|
{ |
511 |
0 |
return true; |
512 |
|
} |
513 |
|
} |
514 |
1 |
return false; |
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
@return |
521 |
|
|
|
|
| 90.6% |
Uncovered Elements: 3 (32) |
Complexity: 8 |
Complexity Density: 0.33 |
|
522 |
25 |
public int[] getDeletedRegions()... |
523 |
|
{ |
524 |
25 |
if (length == 0) |
525 |
|
{ |
526 |
1 |
return null; |
527 |
|
} |
528 |
24 |
Vector dr = new Vector(); |
529 |
24 |
int cursor = 0, vcursor = 0; |
530 |
68 |
for (int i = 0; i < length; i++) |
531 |
|
{ |
532 |
44 |
switch (operation[i]) |
533 |
|
{ |
534 |
28 |
case M: |
535 |
28 |
cursor += range[i]; |
536 |
28 |
break; |
537 |
0 |
case I: |
538 |
0 |
vcursor += range[i]; |
539 |
0 |
break; |
540 |
16 |
case D: |
541 |
16 |
dr.addElement(new int[] { vcursor, cursor, range[i] }); |
542 |
16 |
cursor += range[i]; |
543 |
|
} |
544 |
|
} |
545 |
24 |
if (dr.size() == 0) |
546 |
|
{ |
547 |
14 |
return null; |
548 |
|
} |
549 |
10 |
int[] delregions = new int[dr.size() * 3]; |
550 |
26 |
for (int i = 0, l = dr.size(); i < l; i++) |
551 |
|
{ |
552 |
16 |
int[] reg = (int[]) dr.elementAt(i); |
553 |
16 |
delregions[i * 3] = reg[0]; |
554 |
16 |
delregions[i * 3 + 1] = reg[1]; |
555 |
16 |
delregions[i * 3 + 2] = reg[2]; |
556 |
|
} |
557 |
10 |
return delregions; |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
@return |
564 |
|
|
565 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
566 |
1 |
public int getFullWidth()... |
567 |
|
{ |
568 |
1 |
int w = 0; |
569 |
1 |
if (range != null) |
570 |
|
{ |
571 |
9 |
for (int i = 0; i < length; i++) |
572 |
|
{ |
573 |
8 |
w += range[i]; |
574 |
|
} |
575 |
|
} |
576 |
1 |
return w; |
577 |
|
} |
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
@return |
583 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 5 |
Complexity Density: 0.83 |
|
584 |
37 |
public int getWidth()... |
585 |
|
{ |
586 |
37 |
int w = 0; |
587 |
37 |
if (range != null) |
588 |
|
{ |
589 |
165 |
for (int i = 0; i < length; i++) |
590 |
|
{ |
591 |
129 |
if (operation[i] == M || operation[i] == I) |
592 |
|
{ |
593 |
113 |
w += range[i]; |
594 |
|
} |
595 |
|
} |
596 |
|
} |
597 |
37 |
return w; |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
@param |
604 |
|
|
605 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
606 |
13 |
public void addInsertion(int range)... |
607 |
|
{ |
608 |
13 |
this.addOperation(I, range); |
609 |
|
} |
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
@param |
615 |
|
|
616 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
617 |
176 |
public void addDeleted(int range)... |
618 |
|
{ |
619 |
176 |
this.addOperation(D, range); |
620 |
|
} |
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
@param |
627 |
|
|
628 |
|
@param |
629 |
|
|
630 |
|
@return |
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
@return |
650 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
651 |
16 |
public String getCigarstring()... |
652 |
|
{ |
653 |
16 |
StringBuffer cigarString = new StringBuffer(); |
654 |
84 |
for (int i = 0; i < length; i++) |
655 |
|
{ |
656 |
68 |
cigarString.append("" + range[i]); |
657 |
68 |
cigarString.append(operation[i]); |
658 |
|
} |
659 |
16 |
return cigarString.toString(); |
660 |
|
} |
661 |
|
} |