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