1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import jalview.analysis.AlignmentSorter; |
24 |
|
import jalview.api.AlignViewportI; |
25 |
|
import jalview.commands.CommandI; |
26 |
|
import jalview.commands.EditCommand; |
27 |
|
import jalview.commands.EditCommand.Action; |
28 |
|
import jalview.commands.EditCommand.Edit; |
29 |
|
import jalview.commands.OrderCommand; |
30 |
|
import jalview.datamodel.AlignedCodonFrame; |
31 |
|
import jalview.datamodel.AlignmentI; |
32 |
|
import jalview.datamodel.AlignmentOrder; |
33 |
|
import jalview.datamodel.ColumnSelection; |
34 |
|
import jalview.datamodel.HiddenColumns; |
35 |
|
import jalview.datamodel.SearchResultMatchI; |
36 |
|
import jalview.datamodel.SearchResults; |
37 |
|
import jalview.datamodel.SearchResultsI; |
38 |
|
import jalview.datamodel.Sequence; |
39 |
|
import jalview.datamodel.SequenceGroup; |
40 |
|
import jalview.datamodel.SequenceI; |
41 |
|
|
42 |
|
import java.util.ArrayList; |
43 |
|
import java.util.Arrays; |
44 |
|
import java.util.HashMap; |
45 |
|
import java.util.Iterator; |
46 |
|
import java.util.List; |
47 |
|
import java.util.Map; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@author |
53 |
|
|
54 |
|
|
|
|
| 79.9% |
Uncovered Elements: 87 (432) |
Complexity: 110 |
Complexity Density: 0.41 |
|
55 |
|
public final class MappingUtils |
56 |
|
{ |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
@param |
68 |
|
|
69 |
|
@param |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
71 |
0 |
protected static void mapCutOrPaste(Edit edit, boolean undo,... |
72 |
|
List<SequenceI> targetSeqs, EditCommand result, |
73 |
|
List<AlignedCodonFrame> mappings) |
74 |
|
{ |
75 |
0 |
Action action = edit.getAction(); |
76 |
0 |
if (undo) |
77 |
|
{ |
78 |
0 |
action = action.getUndoAction(); |
79 |
|
} |
80 |
|
|
81 |
0 |
System.err.println("MappingUtils.mapCutOrPaste not yet implemented"); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@param |
89 |
|
@param |
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
@return |
94 |
|
|
|
|
| 77.4% |
Uncovered Elements: 7 (31) |
Complexity: 9 |
Complexity Density: 0.47 |
|
95 |
1 |
public static EditCommand mapEditCommand(EditCommand command,... |
96 |
|
boolean undo, final AlignmentI mapTo, char gapChar, |
97 |
|
List<AlignedCodonFrame> mappings) |
98 |
|
{ |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
1 |
if (!mapTo.isNucleotide()) |
103 |
|
{ |
104 |
0 |
return null; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
1 |
Map<SequenceI, SequenceI> targetCopies = new HashMap<>(); |
112 |
1 |
for (SequenceI seq : mapTo.getSequences()) |
113 |
|
{ |
114 |
1 |
SequenceI ds = seq.getDatasetSequence(); |
115 |
1 |
if (ds != null) |
116 |
|
{ |
117 |
1 |
final SequenceI copy = new Sequence(seq); |
118 |
1 |
copy.setDatasetSequence(ds); |
119 |
1 |
targetCopies.put(ds, copy); |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
1 |
Map<SequenceI, SequenceI> originalSequences = command.priorState(undo); |
127 |
|
|
128 |
1 |
EditCommand result = new EditCommand(); |
129 |
1 |
Iterator<Edit> edits = command.getEditIterator(!undo); |
130 |
2 |
while (edits.hasNext()) |
131 |
|
{ |
132 |
1 |
Edit edit = edits.next(); |
133 |
1 |
if (edit.getAction() == Action.CUT |
134 |
|
|| edit.getAction() == Action.PASTE) |
135 |
|
{ |
136 |
0 |
mapCutOrPaste(edit, undo, mapTo.getSequences(), result, mappings); |
137 |
|
} |
138 |
1 |
else if (edit.getAction() == Action.INSERT_GAP |
139 |
|
|| edit.getAction() == Action.DELETE_GAP) |
140 |
|
{ |
141 |
1 |
mapInsertOrDelete(edit, undo, originalSequences, |
142 |
|
mapTo.getSequences(), targetCopies, gapChar, result, |
143 |
|
mappings); |
144 |
|
} |
145 |
|
} |
146 |
1 |
return result.getSize() > 0 ? result : null; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
|
154 |
|
@param |
155 |
|
|
156 |
|
@param |
157 |
|
|
158 |
|
@param |
159 |
|
@param |
160 |
|
@param |
161 |
|
@param |
162 |
|
|
163 |
|
@param |
164 |
|
|
|
|
| 64.2% |
Uncovered Elements: 19 (53) |
Complexity: 11 |
Complexity Density: 0.33 |
|
165 |
1 |
protected static void mapInsertOrDelete(Edit edit, boolean undo,... |
166 |
|
Map<SequenceI, SequenceI> originalSequences, |
167 |
|
final List<SequenceI> targetSeqs, |
168 |
|
Map<SequenceI, SequenceI> targetCopies, char gapChar, |
169 |
|
EditCommand result, List<AlignedCodonFrame> mappings) |
170 |
|
{ |
171 |
1 |
Action action = edit.getAction(); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
1 |
if (undo) |
177 |
|
{ |
178 |
0 |
action = action.getUndoAction(); |
179 |
|
} |
180 |
1 |
final int count = edit.getNumber(); |
181 |
1 |
final int editPos = edit.getPosition(); |
182 |
1 |
for (SequenceI seq : edit.getSequences()) |
183 |
|
{ |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
1 |
SequenceI ds = seq.getDatasetSequence(); |
189 |
1 |
if (ds == null) |
190 |
|
{ |
191 |
0 |
continue; |
192 |
|
} |
193 |
1 |
final SequenceI actedOn = originalSequences.get(ds); |
194 |
1 |
final int seqpos = actedOn.findPosition(editPos); |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
1 |
SearchResultsI sr = buildSearchResults(seq, seqpos, mappings); |
200 |
|
|
201 |
1 |
if (!sr.isEmpty()) |
202 |
|
{ |
203 |
1 |
for (SequenceI targetSeq : targetSeqs) |
204 |
|
{ |
205 |
1 |
ds = targetSeq.getDatasetSequence(); |
206 |
1 |
if (ds == null) |
207 |
|
{ |
208 |
0 |
continue; |
209 |
|
} |
210 |
1 |
SequenceI copyTarget = targetCopies.get(ds); |
211 |
1 |
final int[] match = sr.getResults(copyTarget, 0, |
212 |
|
copyTarget.getLength()); |
213 |
1 |
if (match != null) |
214 |
|
{ |
215 |
1 |
final int ratio = 3; |
216 |
1 |
final int mappedCount = count * ratio; |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
1 |
int mappedEditPos = action == Action.DELETE_GAP |
223 |
|
? match[0] - mappedCount |
224 |
|
: match[0]; |
225 |
1 |
Edit e = result.new Edit(action, new SequenceI[] { targetSeq }, |
226 |
|
mappedEditPos, mappedCount, gapChar); |
227 |
1 |
result.addEdit(e); |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
1 |
if (action == Action.INSERT_GAP) |
233 |
|
{ |
234 |
1 |
copyTarget.setSequence(new String( |
235 |
|
StringUtils.insertCharAt(copyTarget.getSequence(), |
236 |
|
mappedEditPos, mappedCount, gapChar))); |
237 |
|
} |
238 |
0 |
else if (action == Action.DELETE_GAP) |
239 |
|
{ |
240 |
0 |
copyTarget.setSequence(new String( |
241 |
|
StringUtils.deleteChars(copyTarget.getSequence(), |
242 |
|
mappedEditPos, mappedEditPos + mappedCount))); |
243 |
|
} |
244 |
|
} |
245 |
|
} |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
1 |
if (action == Action.INSERT_GAP) |
251 |
|
{ |
252 |
1 |
actedOn.setSequence(new String(StringUtils.insertCharAt( |
253 |
|
actedOn.getSequence(), editPos, count, gapChar))); |
254 |
|
} |
255 |
0 |
else if (action == Action.DELETE_GAP) |
256 |
|
{ |
257 |
0 |
actedOn.setSequence(new String(StringUtils.deleteChars( |
258 |
|
actedOn.getSequence(), editPos, editPos + count))); |
259 |
|
} |
260 |
|
} |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
@param |
268 |
|
@param |
269 |
|
@param |
270 |
|
@return |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
272 |
113 |
public static SearchResultsI buildSearchResults(SequenceI seq, int index,... |
273 |
|
List<AlignedCodonFrame> seqmappings) |
274 |
|
{ |
275 |
113 |
SearchResultsI results = new SearchResults(); |
276 |
113 |
addSearchResults(results, seq, index, seqmappings); |
277 |
113 |
return results; |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@param |
285 |
|
@param |
286 |
|
@param |
287 |
|
@param |
288 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
289 |
113 |
public static void addSearchResults(SearchResultsI results, SequenceI seq,... |
290 |
|
int index, List<AlignedCodonFrame> seqmappings) |
291 |
|
{ |
292 |
113 |
if (index >= seq.getStart() && index <= seq.getEnd()) |
293 |
|
{ |
294 |
113 |
for (AlignedCodonFrame acf : seqmappings) |
295 |
|
{ |
296 |
113 |
acf.markMappedRegion(seq, index, results); |
297 |
|
} |
298 |
|
} |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
@param |
306 |
|
@param |
307 |
|
@param |
308 |
|
@return |
309 |
|
|
|
|
| 92.6% |
Uncovered Elements: 5 (68) |
Complexity: 14 |
Complexity Density: 0.3 |
|
310 |
9 |
public static SequenceGroup mapSequenceGroup(final SequenceGroup sg,... |
311 |
|
final AlignViewportI mapFrom, final AlignViewportI mapTo) |
312 |
|
{ |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
9 |
boolean targetIsNucleotide = mapTo.isNucleotide(); |
318 |
9 |
AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo; |
319 |
9 |
List<AlignedCodonFrame> codonFrames = protein.getAlignment() |
320 |
|
.getCodonFrames(); |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
9 |
SequenceGroup mappedGroup = new SequenceGroup(sg); |
325 |
9 |
mappedGroup.setColourScheme(mapTo.getGlobalColourScheme()); |
326 |
9 |
mappedGroup.clear(); |
327 |
|
|
328 |
9 |
int minStartCol = -1; |
329 |
9 |
int maxEndCol = -1; |
330 |
9 |
final int selectionStartRes = sg.getStartRes(); |
331 |
9 |
final int selectionEndRes = sg.getEndRes(); |
332 |
9 |
for (SequenceI selected : sg.getSequences()) |
333 |
|
{ |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
20 |
int firstUngappedPos = selectionStartRes; |
338 |
24 |
while (firstUngappedPos <= selectionEndRes |
339 |
|
&& Comparison.isGap(selected.getCharAt(firstUngappedPos))) |
340 |
|
{ |
341 |
4 |
firstUngappedPos++; |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
20 |
if (firstUngappedPos > selectionEndRes) |
348 |
|
{ |
349 |
1 |
continue; |
350 |
|
} |
351 |
|
|
352 |
19 |
int lastUngappedPos = selectionEndRes; |
353 |
19 |
while (lastUngappedPos >= selectionStartRes |
354 |
|
&& Comparison.isGap(selected.getCharAt(lastUngappedPos))) |
355 |
|
{ |
356 |
0 |
lastUngappedPos--; |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
19 |
int startResiduePos = selected.findPosition(firstUngappedPos); |
363 |
19 |
int endResiduePos = selected.findPosition(lastUngappedPos); |
364 |
|
|
365 |
19 |
for (AlignedCodonFrame acf : codonFrames) |
366 |
|
{ |
367 |
19 |
SequenceI mappedSequence = targetIsNucleotide |
368 |
|
? acf.getDnaForAaSeq(selected) |
369 |
|
: acf.getAaForDnaSeq(selected); |
370 |
19 |
if (mappedSequence != null) |
371 |
|
{ |
372 |
19 |
for (SequenceI seq : mapTo.getAlignment().getSequences()) |
373 |
|
{ |
374 |
33 |
int mappedStartResidue = 0; |
375 |
33 |
int mappedEndResidue = 0; |
376 |
33 |
if (seq.getDatasetSequence() == mappedSequence) |
377 |
|
{ |
378 |
|
|
379 |
|
|
380 |
|
|
381 |
19 |
List<AlignedCodonFrame> mapping = Arrays |
382 |
|
.asList(new AlignedCodonFrame[] |
383 |
|
{ acf }); |
384 |
19 |
SearchResultsI sr = buildSearchResults(selected, |
385 |
|
startResiduePos, mapping); |
386 |
19 |
for (SearchResultMatchI m : sr.getResults()) |
387 |
|
{ |
388 |
19 |
mappedStartResidue = m.getStart(); |
389 |
19 |
mappedEndResidue = m.getEnd(); |
390 |
|
} |
391 |
19 |
sr = buildSearchResults(selected, endResiduePos, mapping); |
392 |
19 |
for (SearchResultMatchI m : sr.getResults()) |
393 |
|
{ |
394 |
19 |
mappedStartResidue = Math.min(mappedStartResidue, |
395 |
|
m.getStart()); |
396 |
19 |
mappedEndResidue = Math.max(mappedEndResidue, m.getEnd()); |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
19 |
int mappedStartCol = seq.findIndex(mappedStartResidue) - 1; |
404 |
19 |
minStartCol = minStartCol == -1 ? mappedStartCol |
405 |
|
: Math.min(minStartCol, mappedStartCol); |
406 |
19 |
int mappedEndCol = seq.findIndex(mappedEndResidue) - 1; |
407 |
19 |
maxEndCol = maxEndCol == -1 ? mappedEndCol |
408 |
|
: Math.max(maxEndCol, mappedEndCol); |
409 |
19 |
mappedGroup.addSequence(seq, false); |
410 |
19 |
break; |
411 |
|
} |
412 |
|
} |
413 |
|
} |
414 |
|
} |
415 |
|
} |
416 |
9 |
mappedGroup.setStartRes(minStartCol < 0 ? 0 : minStartCol); |
417 |
9 |
mappedGroup.setEndRes(maxEndCol < 0 ? 0 : maxEndCol); |
418 |
9 |
return mappedGroup; |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
@param |
426 |
|
|
427 |
|
@param |
428 |
|
|
429 |
|
@param |
430 |
|
|
431 |
|
@param |
432 |
|
|
433 |
|
@return |
434 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 7 |
Complexity Density: 0.29 |
|
435 |
0 |
public static CommandI mapOrderCommand(OrderCommand command, boolean undo,... |
436 |
|
AlignmentI mapTo, List<AlignedCodonFrame> mappings) |
437 |
|
{ |
438 |
0 |
SequenceI[] sortOrder = command.getSequenceOrder(undo); |
439 |
0 |
List<SequenceI> mappedOrder = new ArrayList<>(); |
440 |
0 |
int j = 0; |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
0 |
boolean mappingToNucleotide = mapTo.isNucleotide(); |
448 |
0 |
for (SequenceI seq : sortOrder) |
449 |
|
{ |
450 |
0 |
for (AlignedCodonFrame acf : mappings) |
451 |
|
{ |
452 |
0 |
SequenceI mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq(seq) |
453 |
|
: acf.getAaForDnaSeq(seq); |
454 |
0 |
if (mappedSeq != null) |
455 |
|
{ |
456 |
0 |
for (SequenceI seq2 : mapTo.getSequences()) |
457 |
|
{ |
458 |
0 |
if (seq2.getDatasetSequence() == mappedSeq) |
459 |
|
{ |
460 |
0 |
mappedOrder.add(seq2); |
461 |
0 |
j++; |
462 |
0 |
break; |
463 |
|
} |
464 |
|
} |
465 |
|
} |
466 |
|
} |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
0 |
if (j == 0) |
473 |
|
{ |
474 |
0 |
return null; |
475 |
|
} |
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
0 |
if (j < mapTo.getHeight()) |
482 |
|
{ |
483 |
0 |
for (SequenceI seq : mapTo.getSequences()) |
484 |
|
{ |
485 |
0 |
if (!mappedOrder.contains(seq)) |
486 |
|
{ |
487 |
0 |
mappedOrder.add(seq); |
488 |
|
} |
489 |
|
} |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
0 |
final SequenceI[] mappedOrderArray = mappedOrder |
497 |
|
.toArray(new SequenceI[mappedOrder.size()]); |
498 |
0 |
SequenceI[] oldOrder = mapTo.getSequencesArray(); |
499 |
0 |
AlignmentSorter.sortBy(mapTo, new AlignmentOrder(mappedOrderArray)); |
500 |
0 |
final OrderCommand result = new OrderCommand(command.getDescription(), |
501 |
|
oldOrder, mapTo); |
502 |
0 |
return result; |
503 |
|
} |
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
|
508 |
|
|
509 |
|
|
510 |
|
@param |
511 |
|
@param |
512 |
|
@param |
513 |
|
@return |
514 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
515 |
13 |
public static void mapColumnSelection(ColumnSelection colsel,... |
516 |
|
HiddenColumns hiddencols, AlignViewportI mapFrom, |
517 |
|
AlignViewportI mapTo, ColumnSelection newColSel, |
518 |
|
HiddenColumns newHidden) |
519 |
|
{ |
520 |
13 |
boolean targetIsNucleotide = mapTo.isNucleotide(); |
521 |
13 |
AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo; |
522 |
13 |
List<AlignedCodonFrame> codonFrames = protein.getAlignment() |
523 |
|
.getCodonFrames(); |
524 |
|
|
525 |
13 |
if (colsel == null) |
526 |
|
{ |
527 |
1 |
return; |
528 |
|
} |
529 |
|
|
530 |
12 |
char fromGapChar = mapFrom.getAlignment().getGapCharacter(); |
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
12 |
List<SequenceI> fromSequences = mapFrom.getAlignment().getSequences(); |
537 |
12 |
List<SequenceI> toSequences = mapTo.getAlignment().getSequences(); |
538 |
|
|
539 |
12 |
for (Integer sel : colsel.getSelected()) |
540 |
|
{ |
541 |
12 |
mapColumn(sel.intValue(), codonFrames, newColSel, fromSequences, |
542 |
|
toSequences, fromGapChar); |
543 |
|
} |
544 |
|
|
545 |
12 |
Iterator<int[]> regions = hiddencols.iterator(); |
546 |
18 |
while (regions.hasNext()) |
547 |
|
{ |
548 |
6 |
mapHiddenColumns(regions.next(), codonFrames, newHidden, |
549 |
|
fromSequences, |
550 |
|
toSequences, fromGapChar); |
551 |
|
} |
552 |
12 |
return; |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
@param |
560 |
|
@param |
561 |
|
@param |
562 |
|
@param |
563 |
|
@param |
564 |
|
@param |
565 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
566 |
6 |
protected static void mapHiddenColumns(int[] hidden,... |
567 |
|
List<AlignedCodonFrame> mappings, HiddenColumns mappedColumns, |
568 |
|
List<SequenceI> fromSequences, List<SequenceI> toSequences, |
569 |
|
char fromGapChar) |
570 |
|
{ |
571 |
12 |
for (int col = hidden[0]; col <= hidden[1]; col++) |
572 |
|
{ |
573 |
6 |
int[] mappedTo = findMappedColumns(col, mappings, fromSequences, |
574 |
|
toSequences, fromGapChar); |
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
6 |
if (mappedTo != null) |
581 |
|
{ |
582 |
5 |
mappedColumns.hideColumns(mappedTo[0] - 1, mappedTo[1] - 1); |
583 |
|
} |
584 |
|
} |
585 |
|
} |
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
@param |
591 |
|
|
592 |
|
@param |
593 |
|
|
594 |
|
@param |
595 |
|
|
596 |
|
@param |
597 |
|
@param |
598 |
|
@param |
599 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
600 |
12 |
protected static void mapColumn(int col, List<AlignedCodonFrame> mappings,... |
601 |
|
ColumnSelection mappedColumns, List<SequenceI> fromSequences, |
602 |
|
List<SequenceI> toSequences, char fromGapChar) |
603 |
|
{ |
604 |
12 |
int[] mappedTo = findMappedColumns(col, mappings, fromSequences, |
605 |
|
toSequences, fromGapChar); |
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
12 |
if (mappedTo != null) |
613 |
|
{ |
614 |
48 |
for (int i = mappedTo[0]; i <= mappedTo[1]; i++) |
615 |
|
{ |
616 |
37 |
mappedColumns.addElement(i - 1); |
617 |
|
} |
618 |
|
} |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
@param |
627 |
|
@param |
628 |
|
@param |
629 |
|
@param |
630 |
|
@param |
631 |
|
@return |
632 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 4 |
Complexity Density: 0.2 |
|
633 |
18 |
protected static int[] findMappedColumns(int col,... |
634 |
|
List<AlignedCodonFrame> mappings, List<SequenceI> fromSequences, |
635 |
|
List<SequenceI> toSequences, char fromGapChar) |
636 |
|
{ |
637 |
18 |
int[] mappedTo = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE }; |
638 |
18 |
boolean found = false; |
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
18 |
for (SequenceI fromSeq : fromSequences) |
644 |
|
{ |
645 |
|
|
646 |
|
|
647 |
|
|
648 |
54 |
if (fromSeq.getCharAt(col) == fromGapChar) |
649 |
|
{ |
650 |
20 |
continue; |
651 |
|
} |
652 |
|
|
653 |
|
|
654 |
|
|
655 |
|
|
656 |
34 |
int residuePos = fromSeq.findPosition(col); |
657 |
34 |
SearchResultsI sr = buildSearchResults(fromSeq, residuePos, mappings); |
658 |
34 |
for (SearchResultMatchI m : sr.getResults()) |
659 |
|
{ |
660 |
44 |
int mappedStartResidue = m.getStart(); |
661 |
44 |
int mappedEndResidue = m.getEnd(); |
662 |
44 |
SequenceI mappedSeq = m.getSequence(); |
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
|
667 |
|
|
668 |
44 |
for (SequenceI toSeq : toSequences) |
669 |
|
{ |
670 |
88 |
if (toSeq.getDatasetSequence() == mappedSeq) |
671 |
|
{ |
672 |
44 |
int mappedStartCol = toSeq.findIndex(mappedStartResidue); |
673 |
44 |
int mappedEndCol = toSeq.findIndex(mappedEndResidue); |
674 |
44 |
mappedTo[0] = Math.min(mappedTo[0], mappedStartCol); |
675 |
44 |
mappedTo[1] = Math.max(mappedTo[1], mappedEndCol); |
676 |
44 |
found = true; |
677 |
44 |
break; |
678 |
|
|
679 |
|
} |
680 |
|
} |
681 |
|
} |
682 |
|
} |
683 |
18 |
return found ? mappedTo : null; |
684 |
|
} |
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
@param |
691 |
|
|
692 |
|
@param |
693 |
|
|
694 |
|
@param |
695 |
|
|
696 |
|
@return |
697 |
|
|
698 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
699 |
44 |
public static List<char[]> findCodonsFor(SequenceI seq, int col,... |
700 |
|
List<AlignedCodonFrame> mappings) |
701 |
|
{ |
702 |
44 |
List<char[]> result = new ArrayList<>(); |
703 |
44 |
int dsPos = seq.findPosition(col); |
704 |
44 |
for (AlignedCodonFrame mapping : mappings) |
705 |
|
{ |
706 |
44 |
if (mapping.involvesSequence(seq)) |
707 |
|
{ |
708 |
44 |
List<char[]> codons = mapping |
709 |
|
.getMappedCodons(seq.getDatasetSequence(), dsPos); |
710 |
44 |
if (codons != null) |
711 |
|
{ |
712 |
1 |
result.addAll(codons); |
713 |
|
} |
714 |
|
} |
715 |
|
} |
716 |
44 |
return result; |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
@param |
724 |
|
@return |
725 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
726 |
34 |
public static int[] flattenRanges(int[] ranges)... |
727 |
|
{ |
728 |
|
|
729 |
|
|
730 |
|
|
731 |
34 |
int count = 0; |
732 |
90 |
for (int i = 0; i < ranges.length - 1; i += 2) |
733 |
|
{ |
734 |
56 |
count += Math.abs(ranges[i + 1] - ranges[i]) + 1; |
735 |
|
} |
736 |
|
|
737 |
34 |
int[] result = new int[count]; |
738 |
34 |
int k = 0; |
739 |
90 |
for (int i = 0; i < ranges.length - 1; i += 2) |
740 |
|
{ |
741 |
56 |
int from = ranges[i]; |
742 |
56 |
final int to = ranges[i + 1]; |
743 |
56 |
int step = from <= to ? 1 : -1; |
744 |
56 |
do |
745 |
|
{ |
746 |
133 |
result[k++] = from; |
747 |
133 |
from += step; |
748 |
133 |
} while (from != to + step); |
749 |
|
} |
750 |
34 |
return result; |
751 |
|
} |
752 |
|
|
753 |
|
|
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
@param |
758 |
|
@param |
759 |
|
@return |
760 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
761 |
48 |
public static List<AlignedCodonFrame> findMappingsForSequence(... |
762 |
|
SequenceI sequence, List<AlignedCodonFrame> mappings) |
763 |
|
{ |
764 |
48 |
return findMappingsForSequenceAndOthers(sequence, mappings, null); |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
|
|
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
@param |
773 |
|
@param |
774 |
|
@param |
775 |
|
@return |
776 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 11 |
Complexity Density: 0.73 |
|
777 |
52 |
public static List<AlignedCodonFrame> findMappingsForSequenceAndOthers(... |
778 |
|
SequenceI sequence, List<AlignedCodonFrame> mappings, |
779 |
|
List<SequenceI> filterList) |
780 |
|
{ |
781 |
52 |
List<AlignedCodonFrame> result = new ArrayList<>(); |
782 |
52 |
if (sequence == null || mappings == null) |
783 |
|
{ |
784 |
5 |
return result; |
785 |
|
} |
786 |
47 |
for (AlignedCodonFrame mapping : mappings) |
787 |
|
{ |
788 |
178 |
if (mapping.involvesSequence(sequence)) |
789 |
|
{ |
790 |
65 |
if (filterList != null) |
791 |
|
{ |
792 |
3 |
for (SequenceI otherseq : filterList) |
793 |
|
{ |
794 |
7 |
SequenceI otherDataset = otherseq.getDatasetSequence(); |
795 |
7 |
if (otherseq == sequence |
796 |
|
|| otherseq == sequence.getDatasetSequence() |
797 |
|
|| (otherDataset != null && (otherDataset == sequence |
798 |
|
|| otherDataset == sequence |
799 |
|
.getDatasetSequence()))) |
800 |
|
{ |
801 |
|
|
802 |
4 |
continue; |
803 |
|
} |
804 |
3 |
if (mapping.involvesSequence(otherseq)) |
805 |
|
{ |
806 |
|
|
807 |
2 |
result.add(mapping); |
808 |
2 |
break; |
809 |
|
} |
810 |
|
} |
811 |
|
} |
812 |
|
else |
813 |
|
{ |
814 |
62 |
result.add(mapping); |
815 |
|
} |
816 |
|
} |
817 |
|
} |
818 |
47 |
return result; |
819 |
|
} |
820 |
|
|
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
@param |
826 |
|
@return |
827 |
|
|
|
|
| 81.2% |
Uncovered Elements: 3 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
828 |
61 |
public static int getLength(List<int[]> ranges)... |
829 |
|
{ |
830 |
61 |
if (ranges == null) |
831 |
|
{ |
832 |
1 |
return 0; |
833 |
|
} |
834 |
60 |
int length = 0; |
835 |
60 |
for (int[] range : ranges) |
836 |
|
{ |
837 |
89 |
if (range.length % 2 != 0) |
838 |
|
{ |
839 |
0 |
System.err.println( |
840 |
|
"Error unbalance start/end ranges: " + ranges.toString()); |
841 |
0 |
return 0; |
842 |
|
} |
843 |
192 |
for (int i = 0; i < range.length - 1; i += 2) |
844 |
|
{ |
845 |
103 |
length += Math.abs(range[i + 1] - range[i]) + 1; |
846 |
|
} |
847 |
|
} |
848 |
60 |
return length; |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
|
|
853 |
|
|
854 |
|
@param |
855 |
|
@param |
856 |
|
@return |
857 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 8 |
Complexity Density: 1 |
|
858 |
22 |
public static boolean contains(List<int[]> ranges, int value)... |
859 |
|
{ |
860 |
22 |
if (ranges == null) |
861 |
|
{ |
862 |
1 |
return false; |
863 |
|
} |
864 |
21 |
for (int[] range : ranges) |
865 |
|
{ |
866 |
72 |
if (range[1] >= range[0] && value >= range[0] && value <= range[1]) |
867 |
|
{ |
868 |
|
|
869 |
|
|
870 |
|
|
871 |
8 |
return true; |
872 |
|
} |
873 |
64 |
if (range[1] < range[0] && value <= range[0] && value >= range[1]) |
874 |
|
{ |
875 |
|
|
876 |
|
|
877 |
|
|
878 |
5 |
return true; |
879 |
|
} |
880 |
|
} |
881 |
8 |
return false; |
882 |
|
} |
883 |
|
|
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
@param |
893 |
|
@param |
894 |
|
|
895 |
|
@return |
896 |
|
|
|
|
| 96.4% |
Uncovered Elements: 1 (28) |
Complexity: 7 |
Complexity Density: 0.39 |
|
897 |
21 |
public static int[] removeStartPositions(int removeCount,... |
898 |
|
final int[] ranges) |
899 |
|
{ |
900 |
21 |
if (removeCount <= 0) |
901 |
|
{ |
902 |
5 |
return ranges; |
903 |
|
} |
904 |
|
|
905 |
16 |
int[] copy = Arrays.copyOf(ranges, ranges.length); |
906 |
16 |
int sxpos = -1; |
907 |
16 |
int cdspos = 0; |
908 |
28 |
for (int x = 0; x < copy.length && sxpos == -1; x += 2) |
909 |
|
{ |
910 |
28 |
cdspos += Math.abs(copy[x + 1] - copy[x]) + 1; |
911 |
28 |
if (removeCount < cdspos) |
912 |
|
{ |
913 |
|
|
914 |
|
|
915 |
|
|
916 |
16 |
sxpos = x; |
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
|
921 |
16 |
if (copy[x] <= copy[x + 1]) |
922 |
|
{ |
923 |
9 |
copy[x] = copy[x + 1] - cdspos + removeCount + 1; |
924 |
|
} |
925 |
|
else |
926 |
|
{ |
927 |
7 |
copy[x] = copy[x + 1] + cdspos - removeCount - 1; |
928 |
|
} |
929 |
16 |
break; |
930 |
|
} |
931 |
|
} |
932 |
|
|
933 |
16 |
if (sxpos > 0) |
934 |
|
{ |
935 |
|
|
936 |
|
|
937 |
|
|
938 |
10 |
int[] nxon = new int[copy.length - sxpos]; |
939 |
10 |
System.arraycopy(copy, sxpos, nxon, 0, copy.length - sxpos); |
940 |
10 |
return nxon; |
941 |
|
} |
942 |
6 |
return copy; |
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
|
|
947 |
|
|
948 |
|
|
949 |
|
@param |
950 |
|
|
951 |
|
@param |
952 |
|
|
953 |
|
@return |
954 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 5 |
Complexity Density: 1 |
|
955 |
33 |
public static boolean rangeContains(int[] range, int[] queryRange)... |
956 |
|
{ |
957 |
33 |
if (range == null || queryRange == null || range.length != 2 |
958 |
|
|| queryRange.length != 2) |
959 |
|
{ |
960 |
|
|
961 |
|
|
962 |
|
|
963 |
4 |
return false; |
964 |
|
} |
965 |
|
|
966 |
29 |
int min = Math.min(range[0], range[1]); |
967 |
29 |
int max = Math.max(range[0], range[1]); |
968 |
|
|
969 |
29 |
return (min <= queryRange[0] && max >= queryRange[0] |
970 |
|
&& min <= queryRange[1] && max >= queryRange[1]); |
971 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
|
|
978 |
|
@param |
979 |
|
@param |
980 |
|
|
981 |
|
@return |
982 |
|
|
|
|
| 75% |
Uncovered Elements: 6 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
983 |
8 |
public static void removeEndPositions(int positions,... |
984 |
|
List<int[]> ranges) |
985 |
|
{ |
986 |
8 |
int toRemove = positions; |
987 |
8 |
Iterator<int[]> it = new ReverseListIterator<>(ranges); |
988 |
19 |
while (toRemove > 0) |
989 |
|
{ |
990 |
11 |
int[] endRange = it.next(); |
991 |
11 |
if (endRange.length != 2) |
992 |
|
{ |
993 |
|
|
994 |
|
|
995 |
|
|
996 |
0 |
System.err |
997 |
|
.println("MappingUtils.removeEndPositions doesn't handle multiple ranges"); |
998 |
0 |
return; |
999 |
|
} |
1000 |
|
|
1001 |
11 |
int length = endRange[1] - endRange[0] + 1; |
1002 |
11 |
if (length <= 0) |
1003 |
|
{ |
1004 |
|
|
1005 |
|
|
1006 |
|
|
1007 |
0 |
System.err |
1008 |
|
.println("MappingUtils.removeEndPositions doesn't handle reverse strand"); |
1009 |
0 |
return; |
1010 |
|
} |
1011 |
11 |
if (length > toRemove) |
1012 |
|
{ |
1013 |
7 |
endRange[1] -= toRemove; |
1014 |
7 |
toRemove = 0; |
1015 |
|
} |
1016 |
|
else |
1017 |
|
{ |
1018 |
4 |
toRemove -= length; |
1019 |
4 |
it.remove(); |
1020 |
|
} |
1021 |
|
} |
1022 |
|
} |
1023 |
|
} |