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 java.awt.Color; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.HashMap; |
29 |
|
import java.util.HashSet; |
30 |
|
import java.util.Iterator; |
31 |
|
import java.util.LinkedHashMap; |
32 |
|
import java.util.List; |
33 |
|
import java.util.Locale; |
34 |
|
import java.util.Map; |
35 |
|
import java.util.Map.Entry; |
36 |
|
import java.util.NoSuchElementException; |
37 |
|
import java.util.Set; |
38 |
|
import java.util.SortedMap; |
39 |
|
import java.util.TreeMap; |
40 |
|
import java.util.Vector; |
41 |
|
import java.util.stream.Collectors; |
42 |
|
|
43 |
|
import org.jcolorbrewer.ColorBrewer; |
44 |
|
|
45 |
|
import jalview.api.AlignCalcWorkerI; |
46 |
|
import jalview.bin.Console; |
47 |
|
import jalview.commands.RemoveGapColCommand; |
48 |
|
import jalview.datamodel.AlignedCodon; |
49 |
|
import jalview.datamodel.AlignedCodonFrame; |
50 |
|
import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; |
51 |
|
import jalview.datamodel.Alignment; |
52 |
|
import jalview.datamodel.AlignmentAnnotation; |
53 |
|
import jalview.datamodel.AlignmentI; |
54 |
|
import jalview.datamodel.Annotation; |
55 |
|
import jalview.datamodel.ContactMatrixI; |
56 |
|
import jalview.datamodel.DBRefEntry; |
57 |
|
import jalview.datamodel.GeneLociI; |
58 |
|
import jalview.datamodel.IncompleteCodonException; |
59 |
|
import jalview.datamodel.Mapping; |
60 |
|
import jalview.datamodel.PDBEntry; |
61 |
|
import jalview.datamodel.SeqCigar; |
62 |
|
import jalview.datamodel.Sequence; |
63 |
|
import jalview.datamodel.SequenceFeature; |
64 |
|
import jalview.datamodel.SequenceGroup; |
65 |
|
import jalview.datamodel.SequenceI; |
66 |
|
import jalview.datamodel.features.SequenceFeatures; |
67 |
|
import jalview.gui.AlignmentPanel; |
68 |
|
import jalview.io.gff.SequenceOntologyI; |
69 |
|
import jalview.schemes.ResidueProperties; |
70 |
|
import jalview.util.Comparison; |
71 |
|
import jalview.util.Constants; |
72 |
|
import jalview.util.DBRefUtils; |
73 |
|
import jalview.util.IntRangeComparator; |
74 |
|
import jalview.util.MapList; |
75 |
|
import jalview.util.MappingUtils; |
76 |
|
import jalview.util.MessageManager; |
77 |
|
import jalview.workers.SecondaryStructureConsensusThread; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@author |
84 |
|
|
85 |
|
|
|
|
| 78.5% |
Uncovered Elements: 327 (1,523) |
Complexity: 371 |
Complexity Density: 0.38 |
|
86 |
|
public class AlignmentUtils |
87 |
|
{ |
88 |
|
private static final int CODON_LENGTH = 3; |
89 |
|
|
90 |
|
private static final String SEQUENCE_VARIANT = "sequence_variant:"; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
public static final String VARIANT_ID = "id"; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 6 |
Complexity Density: 1 |
|
102 |
|
static final class DnaVariant |
103 |
|
{ |
104 |
|
final String base; |
105 |
|
|
106 |
|
SequenceFeature variant; |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
108 |
0 |
DnaVariant(String nuc)... |
109 |
|
{ |
110 |
0 |
base = nuc; |
111 |
0 |
variant = null; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
114 |
0 |
DnaVariant(String nuc, SequenceFeature var)... |
115 |
|
{ |
116 |
0 |
base = nuc; |
117 |
0 |
variant = var; |
118 |
|
} |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
120 |
0 |
public String getSource()... |
121 |
|
{ |
122 |
0 |
return variant == null ? null : variant.getFeatureGroup(); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
128 |
0 |
@Override... |
129 |
|
public String toString() |
130 |
|
{ |
131 |
0 |
return base + ":" + (variant == null ? "" : variant.getDescription()); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
@param |
141 |
|
@return |
142 |
|
|
|
|
| 98.4% |
Uncovered Elements: 1 (62) |
Complexity: 10 |
Complexity Density: 0.22 |
|
143 |
27 |
public static AlignmentI expandContext(AlignmentI core, int flankSize)... |
144 |
|
{ |
145 |
27 |
List<SequenceI> sq = new ArrayList<>(); |
146 |
27 |
int maxoffset = 0; |
147 |
27 |
for (SequenceI s : core.getSequences()) |
148 |
|
{ |
149 |
131 |
SequenceI newSeq = s.deriveSequence(); |
150 |
131 |
final int newSeqStart = newSeq.getStart() - 1; |
151 |
131 |
if (newSeqStart > maxoffset |
152 |
|
&& newSeq.getDatasetSequence().getStart() < s.getStart()) |
153 |
|
{ |
154 |
131 |
maxoffset = newSeqStart; |
155 |
|
} |
156 |
131 |
sq.add(newSeq); |
157 |
|
} |
158 |
27 |
if (flankSize > -1) |
159 |
|
{ |
160 |
25 |
maxoffset = Math.min(maxoffset, flankSize); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
27 |
for (SequenceI s : sq) |
167 |
|
{ |
168 |
131 |
SequenceI ds = s; |
169 |
262 |
while (ds.getDatasetSequence() != null) |
170 |
|
{ |
171 |
131 |
ds = ds.getDatasetSequence(); |
172 |
|
} |
173 |
131 |
int s_end = s.findPosition(s.getStart() + s.getLength()); |
174 |
|
|
175 |
131 |
int ustream_ds = s.getStart() - ds.getStart(); |
176 |
131 |
int dstream_ds = ds.getEnd() - s_end; |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
131 |
int offset = maxoffset - ustream_ds; |
182 |
|
|
183 |
|
|
184 |
131 |
if (flankSize >= 0) |
185 |
|
{ |
186 |
125 |
if (flankSize < ustream_ds) |
187 |
|
{ |
188 |
|
|
189 |
40 |
offset = maxoffset - flankSize; |
190 |
40 |
ustream_ds = flankSize; |
191 |
|
} |
192 |
125 |
if (flankSize <= dstream_ds) |
193 |
|
{ |
194 |
116 |
dstream_ds = flankSize - 1; |
195 |
|
} |
196 |
|
} |
197 |
|
|
198 |
131 |
char[] upstream = new String(ds |
199 |
|
.getSequence(s.getStart() - 1 - ustream_ds, s.getStart() - 1)) |
200 |
|
.toLowerCase(Locale.ROOT).toCharArray(); |
201 |
131 |
char[] downstream = new String( |
202 |
|
ds.getSequence(s_end - 1, s_end + dstream_ds)) |
203 |
|
.toLowerCase(Locale.ROOT).toCharArray(); |
204 |
131 |
char[] coreseq = s.getSequence(); |
205 |
131 |
char[] nseq = new char[offset + upstream.length + downstream.length |
206 |
|
+ coreseq.length]; |
207 |
131 |
char c = core.getGapCharacter(); |
208 |
|
|
209 |
131 |
int p = 0; |
210 |
461 |
for (; p < offset; p++) |
211 |
|
{ |
212 |
330 |
nseq[p] = c; |
213 |
|
} |
214 |
|
|
215 |
131 |
System.arraycopy(upstream, 0, nseq, p, upstream.length); |
216 |
131 |
System.arraycopy(coreseq, 0, nseq, p + upstream.length, |
217 |
|
coreseq.length); |
218 |
131 |
System.arraycopy(downstream, 0, nseq, |
219 |
|
p + coreseq.length + upstream.length, downstream.length); |
220 |
131 |
s.setSequence(new String(nseq)); |
221 |
131 |
s.setStart(s.getStart() - ustream_ds); |
222 |
131 |
s.setEnd(s_end + downstream.length); |
223 |
|
} |
224 |
27 |
AlignmentI newAl = new jalview.datamodel.Alignment( |
225 |
|
sq.toArray(new SequenceI[0])); |
226 |
27 |
for (SequenceI s : sq) |
227 |
|
{ |
228 |
131 |
if (s.getAnnotation() != null) |
229 |
|
{ |
230 |
1 |
for (AlignmentAnnotation aa : s.getAnnotation()) |
231 |
|
{ |
232 |
1 |
aa.adjustForAlignment(); |
233 |
1 |
newAl.addAnnotation(aa); |
234 |
|
} |
235 |
|
} |
236 |
|
} |
237 |
27 |
newAl.setDataset(core.getDataset()); |
238 |
27 |
return newAl; |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
@param |
247 |
|
@return |
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
249 |
56066 |
public static int getSequenceIndex(AlignmentI al, SequenceI seq)... |
250 |
|
{ |
251 |
56066 |
int result = -1; |
252 |
56066 |
int pos = 0; |
253 |
56066 |
for (SequenceI alSeq : al.getSequences()) |
254 |
|
{ |
255 |
126110737 |
if (alSeq == seq) |
256 |
|
{ |
257 |
56066 |
result = pos; |
258 |
56066 |
break; |
259 |
|
} |
260 |
126054671 |
pos++; |
261 |
|
} |
262 |
56066 |
return result; |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
@see |
271 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
272 |
1 |
public static Map<String, List<SequenceI>> getSequencesByName(... |
273 |
|
AlignmentI al) |
274 |
|
{ |
275 |
1 |
Map<String, List<SequenceI>> theMap = new LinkedHashMap<>(); |
276 |
1 |
for (SequenceI seq : al.getSequences()) |
277 |
|
{ |
278 |
3 |
String name = seq.getName(); |
279 |
3 |
if (name != null) |
280 |
|
{ |
281 |
3 |
List<SequenceI> seqs = theMap.get(name); |
282 |
3 |
if (seqs == null) |
283 |
|
{ |
284 |
2 |
seqs = new ArrayList<>(); |
285 |
2 |
theMap.put(name, seqs); |
286 |
|
} |
287 |
3 |
seqs.add(seq); |
288 |
|
} |
289 |
|
} |
290 |
1 |
return theMap; |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
@param |
300 |
|
@param |
301 |
|
@return |
302 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
303 |
4 |
public static boolean mapProteinAlignmentToCdna(... |
304 |
|
final AlignmentI proteinAlignment, final AlignmentI cdnaAlignment) |
305 |
|
{ |
306 |
4 |
if (proteinAlignment == null || cdnaAlignment == null) |
307 |
|
{ |
308 |
0 |
return false; |
309 |
|
} |
310 |
|
|
311 |
4 |
Set<SequenceI> mappedDna = new HashSet<>(); |
312 |
4 |
Set<SequenceI> mappedProtein = new HashSet<>(); |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
4 |
boolean mappingPerformed = mapProteinToCdna(proteinAlignment, |
319 |
|
cdnaAlignment, mappedDna, mappedProtein, true); |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
4 |
mappingPerformed |= mapProteinToCdna(proteinAlignment, cdnaAlignment, |
327 |
|
mappedDna, mappedProtein, false); |
328 |
4 |
return mappingPerformed; |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
@param |
336 |
|
@param |
337 |
|
@param |
338 |
|
|
339 |
|
@param |
340 |
|
|
341 |
|
@param |
342 |
|
|
343 |
|
@return |
344 |
|
|
|
|
| 93.8% |
Uncovered Elements: 2 (32) |
Complexity: 9 |
Complexity Density: 0.41 |
|
345 |
8 |
protected static boolean mapProteinToCdna(... |
346 |
|
final AlignmentI proteinAlignment, final AlignmentI cdnaAlignment, |
347 |
|
Set<SequenceI> mappedDna, Set<SequenceI> mappedProtein, |
348 |
|
boolean xrefsOnly) |
349 |
|
{ |
350 |
8 |
boolean mappingExistsOrAdded = false; |
351 |
8 |
List<SequenceI> thisSeqs = proteinAlignment.getSequences(); |
352 |
8 |
for (SequenceI aaSeq : thisSeqs) |
353 |
|
{ |
354 |
22 |
boolean proteinMapped = false; |
355 |
22 |
AlignedCodonFrame acf = new AlignedCodonFrame(); |
356 |
|
|
357 |
22 |
for (SequenceI cdnaSeq : cdnaAlignment.getSequences()) |
358 |
|
{ |
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
86 |
if (xrefsOnly && !AlignmentUtils.haveCrossRef(aaSeq, cdnaSeq)) |
369 |
|
{ |
370 |
39 |
continue; |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
47 |
if (!xrefsOnly && (mappedProtein.contains(aaSeq) |
378 |
|
|| mappedDna.contains(cdnaSeq))) |
379 |
|
{ |
380 |
29 |
continue; |
381 |
|
} |
382 |
18 |
if (mappingExists(proteinAlignment.getCodonFrames(), |
383 |
|
aaSeq.getDatasetSequence(), cdnaSeq.getDatasetSequence())) |
384 |
|
{ |
385 |
0 |
mappingExistsOrAdded = true; |
386 |
|
} |
387 |
|
else |
388 |
|
{ |
389 |
18 |
MapList map = mapCdnaToProtein(aaSeq, cdnaSeq); |
390 |
18 |
if (map != null) |
391 |
|
{ |
392 |
12 |
acf.addMap(cdnaSeq, aaSeq, map); |
393 |
12 |
mappingExistsOrAdded = true; |
394 |
12 |
proteinMapped = true; |
395 |
12 |
mappedDna.add(cdnaSeq); |
396 |
12 |
mappedProtein.add(aaSeq); |
397 |
|
} |
398 |
|
} |
399 |
|
} |
400 |
22 |
if (proteinMapped) |
401 |
|
{ |
402 |
11 |
proteinAlignment.addCodonFrame(acf); |
403 |
|
} |
404 |
|
} |
405 |
8 |
return mappingExistsOrAdded; |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
412 |
30 |
protected static boolean mappingExists(List<AlignedCodonFrame> mappings,... |
413 |
|
SequenceI aaSeq, SequenceI cdnaSeq) |
414 |
|
{ |
415 |
30 |
if (mappings != null) |
416 |
|
{ |
417 |
30 |
for (AlignedCodonFrame acf : mappings) |
418 |
|
{ |
419 |
20 |
if (cdnaSeq == acf.getDnaForAaSeq(aaSeq)) |
420 |
|
{ |
421 |
0 |
return true; |
422 |
|
} |
423 |
|
} |
424 |
|
} |
425 |
30 |
return false; |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
@param |
440 |
|
|
441 |
|
@param |
442 |
|
|
443 |
|
@return |
444 |
|
|
|
|
| 95.2% |
Uncovered Elements: 2 (42) |
Complexity: 12 |
Complexity Density: 0.43 |
|
445 |
30 |
public static MapList mapCdnaToProtein(SequenceI proteinSeq,... |
446 |
|
SequenceI cdnaSeq) |
447 |
|
{ |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
30 |
final SequenceI proteinDataset = proteinSeq.getDatasetSequence(); |
454 |
30 |
char[] aaSeqChars = proteinDataset != null |
455 |
|
? proteinDataset.getSequence() |
456 |
|
: proteinSeq.getSequence(); |
457 |
30 |
final SequenceI cdnaDataset = cdnaSeq.getDatasetSequence(); |
458 |
30 |
char[] cdnaSeqChars = cdnaDataset != null ? cdnaDataset.getSequence() |
459 |
|
: cdnaSeq.getSequence(); |
460 |
30 |
if (aaSeqChars == null || cdnaSeqChars == null) |
461 |
|
{ |
462 |
0 |
return null; |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
30 |
final int mappedLength = CODON_LENGTH * aaSeqChars.length; |
469 |
30 |
int cdnaLength = cdnaSeqChars.length; |
470 |
30 |
int cdnaStart = cdnaSeq.getStart(); |
471 |
30 |
int cdnaEnd = cdnaSeq.getEnd(); |
472 |
30 |
final int proteinStart = proteinSeq.getStart(); |
473 |
30 |
final int proteinEnd = proteinSeq.getEnd(); |
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
30 |
if (cdnaLength != mappedLength && cdnaLength > 2) |
479 |
|
{ |
480 |
14 |
String lastCodon = String.valueOf(cdnaSeqChars, |
481 |
|
cdnaLength - CODON_LENGTH, CODON_LENGTH) |
482 |
|
.toUpperCase(Locale.ROOT); |
483 |
14 |
for (String stop : ResidueProperties.STOP_CODONS) |
484 |
|
{ |
485 |
41 |
if (lastCodon.equals(stop)) |
486 |
|
{ |
487 |
2 |
cdnaEnd -= CODON_LENGTH; |
488 |
2 |
cdnaLength -= CODON_LENGTH; |
489 |
2 |
break; |
490 |
|
} |
491 |
|
} |
492 |
|
} |
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
|
497 |
30 |
int startOffset = 0; |
498 |
30 |
if (cdnaLength != mappedLength && cdnaLength > 2 |
499 |
|
&& String.valueOf(cdnaSeqChars, 0, CODON_LENGTH) |
500 |
|
.toUpperCase(Locale.ROOT) |
501 |
|
.equals(ResidueProperties.START)) |
502 |
|
{ |
503 |
5 |
startOffset += CODON_LENGTH; |
504 |
5 |
cdnaStart += CODON_LENGTH; |
505 |
5 |
cdnaLength -= CODON_LENGTH; |
506 |
|
} |
507 |
|
|
508 |
30 |
if (translatesAs(cdnaSeqChars, startOffset, aaSeqChars)) |
509 |
|
{ |
510 |
|
|
511 |
|
|
512 |
|
|
513 |
15 |
MapList map = new MapList(new int[] { cdnaStart, cdnaEnd }, |
514 |
|
new int[] |
515 |
|
{ proteinStart, proteinEnd }, CODON_LENGTH, 1); |
516 |
15 |
return map; |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
15 |
return mapCdsToProtein(cdnaSeq, proteinSeq); |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
@param |
531 |
|
@param |
532 |
|
@param |
533 |
|
@return |
534 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 14 |
Complexity Density: 0.67 |
|
535 |
50 |
protected static boolean translatesAs(char[] cdnaSeqChars, int cdnaStart,... |
536 |
|
char[] aaSeqChars) |
537 |
|
{ |
538 |
50 |
if (cdnaSeqChars == null || aaSeqChars == null) |
539 |
|
{ |
540 |
3 |
return false; |
541 |
|
} |
542 |
|
|
543 |
47 |
int aaPos = 0; |
544 |
47 |
int dnaPos = cdnaStart; |
545 |
160 |
for (; dnaPos < cdnaSeqChars.length - 2 |
546 |
|
&& aaPos < aaSeqChars.length; dnaPos += CODON_LENGTH, aaPos++) |
547 |
|
{ |
548 |
129 |
String codon = String.valueOf(cdnaSeqChars, dnaPos, CODON_LENGTH); |
549 |
129 |
final String translated = ResidueProperties.codonTranslate(codon); |
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
129 |
final char aaRes = aaSeqChars[aaPos]; |
555 |
129 |
if ((translated == null || ResidueProperties.STOP.equals(translated)) |
556 |
|
&& aaRes == '*') |
557 |
|
{ |
558 |
4 |
continue; |
559 |
|
} |
560 |
125 |
if (translated == null || !(aaRes == translated.charAt(0))) |
561 |
|
{ |
562 |
|
|
563 |
|
|
564 |
|
|
565 |
|
|
566 |
16 |
return false; |
567 |
|
} |
568 |
|
} |
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
31 |
if (aaPos != aaSeqChars.length) |
574 |
|
{ |
575 |
2 |
return false; |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
29 |
if (dnaPos == cdnaSeqChars.length) |
583 |
|
{ |
584 |
17 |
return true; |
585 |
|
} |
586 |
12 |
if (dnaPos == cdnaSeqChars.length - CODON_LENGTH) |
587 |
|
{ |
588 |
11 |
String codon = String.valueOf(cdnaSeqChars, dnaPos, CODON_LENGTH); |
589 |
11 |
if (ResidueProperties.STOP |
590 |
|
.equals(ResidueProperties.codonTranslate(codon))) |
591 |
|
{ |
592 |
9 |
return true; |
593 |
|
} |
594 |
|
} |
595 |
3 |
return false; |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
@param |
603 |
|
|
604 |
|
@param |
605 |
|
|
606 |
|
@param |
607 |
|
|
608 |
|
@param |
609 |
|
@param |
610 |
|
@return |
611 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
612 |
0 |
public static boolean alignSequenceAs(SequenceI seq, AlignmentI al,... |
613 |
|
String gap, boolean preserveMappedGaps, |
614 |
|
boolean preserveUnmappedGaps) |
615 |
|
{ |
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
0 |
List<AlignedCodonFrame> mappings = al.getCodonFrame(seq); |
623 |
0 |
if (mappings == null || mappings.isEmpty()) |
624 |
|
{ |
625 |
0 |
return false; |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
0 |
SequenceI alignFrom = null; |
634 |
0 |
AlignedCodonFrame mapping = null; |
635 |
0 |
for (AlignedCodonFrame mp : mappings) |
636 |
|
{ |
637 |
0 |
alignFrom = mp.findAlignedSequence(seq, al); |
638 |
0 |
if (alignFrom != null) |
639 |
|
{ |
640 |
0 |
mapping = mp; |
641 |
0 |
break; |
642 |
|
} |
643 |
|
} |
644 |
|
|
645 |
0 |
if (alignFrom == null) |
646 |
|
{ |
647 |
0 |
return false; |
648 |
|
} |
649 |
0 |
alignSequenceAs(seq, alignFrom, mapping, gap, al.getGapCharacter(), |
650 |
|
preserveMappedGaps, preserveUnmappedGaps); |
651 |
0 |
return true; |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
|
659 |
|
|
660 |
|
@param |
661 |
|
@param |
662 |
|
@param |
663 |
|
@param |
664 |
|
@param |
665 |
|
@param |
666 |
|
@param |
667 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (88) |
Complexity: 20 |
Complexity Density: 0.33 |
|
668 |
15 |
public static void alignSequenceAs(SequenceI alignTo, SequenceI alignFrom,... |
669 |
|
AlignedCodonFrame mapping, String myGap, char sourceGap, |
670 |
|
boolean preserveMappedGaps, boolean preserveUnmappedGaps) |
671 |
|
{ |
672 |
|
|
673 |
|
|
674 |
|
|
675 |
15 |
int thisSeqPos = 0; |
676 |
15 |
int sourceDsPos = 0; |
677 |
|
|
678 |
15 |
int basesWritten = 0; |
679 |
15 |
char myGapChar = myGap.charAt(0); |
680 |
15 |
int ratio = myGap.length(); |
681 |
|
|
682 |
15 |
int fromOffset = alignFrom.getStart() - 1; |
683 |
15 |
int toOffset = alignTo.getStart() - 1; |
684 |
15 |
int sourceGapMappedLength = 0; |
685 |
15 |
boolean inExon = false; |
686 |
15 |
final int toLength = alignTo.getLength(); |
687 |
15 |
final int fromLength = alignFrom.getLength(); |
688 |
15 |
StringBuilder thisAligned = new StringBuilder(2 * toLength); |
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
109 |
for (int i = 0; i < fromLength; i++) |
694 |
|
{ |
695 |
94 |
char sourceChar = alignFrom.getCharAt(i); |
696 |
94 |
if (sourceChar == sourceGap) |
697 |
|
{ |
698 |
44 |
sourceGapMappedLength += ratio; |
699 |
44 |
continue; |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
50 |
sourceDsPos++; |
706 |
|
|
707 |
50 |
int[] mappedPos = mapping.getMappedRegion(alignTo, alignFrom, |
708 |
|
sourceDsPos + fromOffset); |
709 |
50 |
if (mappedPos == null) |
710 |
|
{ |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
14 |
sourceGapMappedLength += ratio; |
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
14 |
continue; |
720 |
|
} |
721 |
|
|
722 |
36 |
int mappedCodonStart = mappedPos[0]; |
723 |
36 |
int mappedCodonEnd = mappedPos[mappedPos.length - 1]; |
724 |
36 |
StringBuilder trailingCopiedGap = new StringBuilder(); |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
36 |
int intronLength = 0; |
735 |
278 |
while (basesWritten + toOffset < mappedCodonEnd |
736 |
|
&& thisSeqPos < toLength) |
737 |
|
{ |
738 |
242 |
final char c = alignTo.getCharAt(thisSeqPos++); |
739 |
242 |
if (c != myGapChar) |
740 |
|
{ |
741 |
142 |
basesWritten++; |
742 |
142 |
int sourcePosition = basesWritten + toOffset; |
743 |
142 |
if (sourcePosition < mappedCodonStart) |
744 |
|
{ |
745 |
|
|
746 |
|
|
747 |
|
|
748 |
|
|
749 |
48 |
if (preserveUnmappedGaps && trailingCopiedGap.length() > 0) |
750 |
|
{ |
751 |
17 |
thisAligned.append(trailingCopiedGap.toString()); |
752 |
17 |
intronLength += trailingCopiedGap.length(); |
753 |
17 |
trailingCopiedGap = new StringBuilder(); |
754 |
|
} |
755 |
48 |
intronLength++; |
756 |
48 |
inExon = false; |
757 |
|
} |
758 |
|
else |
759 |
|
{ |
760 |
94 |
final boolean startOfCodon = sourcePosition == mappedCodonStart; |
761 |
94 |
int gapsToAdd = calculateGapsToInsert(preserveMappedGaps, |
762 |
|
preserveUnmappedGaps, sourceGapMappedLength, inExon, |
763 |
|
trailingCopiedGap.length(), intronLength, startOfCodon); |
764 |
179 |
for (int k = 0; k < gapsToAdd; k++) |
765 |
|
{ |
766 |
85 |
thisAligned.append(myGapChar); |
767 |
|
} |
768 |
94 |
sourceGapMappedLength = 0; |
769 |
94 |
inExon = true; |
770 |
|
} |
771 |
142 |
thisAligned.append(c); |
772 |
142 |
trailingCopiedGap = new StringBuilder(); |
773 |
|
} |
774 |
|
else |
775 |
|
{ |
776 |
100 |
if (inExon && preserveMappedGaps) |
777 |
|
{ |
778 |
32 |
trailingCopiedGap.append(myGapChar); |
779 |
|
} |
780 |
68 |
else if (!inExon && preserveUnmappedGaps) |
781 |
|
{ |
782 |
27 |
trailingCopiedGap.append(myGapChar); |
783 |
|
} |
784 |
|
} |
785 |
|
} |
786 |
|
} |
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
|
792 |
57 |
while (thisSeqPos < toLength) |
793 |
|
{ |
794 |
42 |
final char c = alignTo.getCharAt(thisSeqPos++); |
795 |
42 |
if (c != myGapChar || preserveUnmappedGaps) |
796 |
|
{ |
797 |
34 |
thisAligned.append(c); |
798 |
|
} |
799 |
42 |
sourceGapMappedLength--; |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
15 |
if (preserveUnmappedGaps) |
807 |
|
{ |
808 |
20 |
while (sourceGapMappedLength > 0) |
809 |
|
{ |
810 |
12 |
thisAligned.append(myGapChar); |
811 |
12 |
sourceGapMappedLength--; |
812 |
|
} |
813 |
|
} |
814 |
|
|
815 |
|
|
816 |
|
|
817 |
|
|
818 |
15 |
alignTo.setSequence(new String(thisAligned)); |
819 |
|
} |
820 |
|
|
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
@param |
825 |
|
@param |
826 |
|
@param |
827 |
|
@param |
828 |
|
@param |
829 |
|
@param |
830 |
|
@param |
831 |
|
@return |
832 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 10 |
Complexity Density: 0.67 |
|
833 |
94 |
protected static int calculateGapsToInsert(boolean preserveMappedGaps,... |
834 |
|
boolean preserveUnmappedGaps, int sourceGapMappedLength, |
835 |
|
boolean inExon, int trailingGapLength, int intronLength, |
836 |
|
final boolean startOfCodon) |
837 |
|
{ |
838 |
94 |
int gapsToAdd = 0; |
839 |
94 |
if (startOfCodon) |
840 |
|
{ |
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
36 |
if (inExon && !preserveMappedGaps) |
848 |
|
{ |
849 |
4 |
trailingGapLength = 0; |
850 |
|
} |
851 |
36 |
if (!inExon && !(preserveMappedGaps && preserveUnmappedGaps)) |
852 |
|
{ |
853 |
15 |
trailingGapLength = 0; |
854 |
|
} |
855 |
36 |
if (inExon) |
856 |
|
{ |
857 |
14 |
gapsToAdd = Math.max(sourceGapMappedLength, trailingGapLength); |
858 |
|
} |
859 |
|
else |
860 |
|
{ |
861 |
22 |
if (intronLength + trailingGapLength <= sourceGapMappedLength) |
862 |
|
{ |
863 |
16 |
gapsToAdd = sourceGapMappedLength - intronLength; |
864 |
|
} |
865 |
|
else |
866 |
|
{ |
867 |
6 |
gapsToAdd = Math.min( |
868 |
|
intronLength + trailingGapLength - sourceGapMappedLength, |
869 |
|
trailingGapLength); |
870 |
|
} |
871 |
|
} |
872 |
|
} |
873 |
|
else |
874 |
|
{ |
875 |
|
|
876 |
|
|
877 |
|
|
878 |
58 |
if (!preserveMappedGaps) |
879 |
|
{ |
880 |
32 |
trailingGapLength = 0; |
881 |
|
} |
882 |
58 |
gapsToAdd = Math.max(sourceGapMappedLength, trailingGapLength); |
883 |
|
} |
884 |
94 |
return gapsToAdd; |
885 |
|
} |
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
@param |
892 |
|
|
893 |
|
@param |
894 |
|
|
895 |
|
@return |
896 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
897 |
3 |
public static int alignProteinAsDna(AlignmentI protein, AlignmentI dna)... |
898 |
|
{ |
899 |
3 |
if (protein.isNucleotide() || !dna.isNucleotide()) |
900 |
|
{ |
901 |
0 |
jalview.bin.Console |
902 |
|
.errPrintln("Wrong alignment type in alignProteinAsDna"); |
903 |
0 |
return 0; |
904 |
|
} |
905 |
3 |
List<SequenceI> unmappedProtein = new ArrayList<>(); |
906 |
3 |
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons = buildCodonColumnsMap( |
907 |
|
protein, dna, unmappedProtein); |
908 |
3 |
return alignProteinAs(protein, alignedCodons, unmappedProtein); |
909 |
|
} |
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
|
914 |
|
|
915 |
|
|
916 |
|
|
917 |
|
@param |
918 |
|
|
919 |
|
@param |
920 |
|
|
921 |
|
@return |
922 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 5 |
Complexity Density: 0.28 |
|
923 |
4 |
public static int alignCdsAsProtein(AlignmentI dna, AlignmentI protein)... |
924 |
|
{ |
925 |
4 |
if (protein.isNucleotide() || !dna.isNucleotide()) |
926 |
|
{ |
927 |
0 |
jalview.bin.Console |
928 |
|
.errPrintln("Wrong alignment type in alignProteinAsDna"); |
929 |
0 |
return 0; |
930 |
|
} |
931 |
|
|
932 |
4 |
List<AlignedCodonFrame> mappings = protein.getCodonFrames(); |
933 |
4 |
int alignedCount = 0; |
934 |
4 |
int width = 0; |
935 |
4 |
for (SequenceI dnaSeq : dna.getSequences()) |
936 |
|
{ |
937 |
5 |
if (alignCdsSequenceAsProtein(dnaSeq, protein, mappings, |
938 |
|
dna.getGapCharacter())) |
939 |
|
{ |
940 |
5 |
alignedCount++; |
941 |
|
} |
942 |
5 |
width = Math.max(dnaSeq.getLength(), width); |
943 |
|
} |
944 |
4 |
int oldwidth; |
945 |
4 |
int diff; |
946 |
4 |
for (SequenceI dnaSeq : dna.getSequences()) |
947 |
|
{ |
948 |
5 |
oldwidth = dnaSeq.getLength(); |
949 |
5 |
diff = width - oldwidth; |
950 |
5 |
if (diff > 0) |
951 |
|
{ |
952 |
1 |
dnaSeq.insertCharAt(oldwidth, diff, dna.getGapCharacter()); |
953 |
|
} |
954 |
|
} |
955 |
4 |
return alignedCount; |
956 |
|
} |
957 |
|
|
958 |
|
|
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
|
@param |
964 |
|
@param |
965 |
|
@param |
966 |
|
@param |
967 |
|
@return |
968 |
|
|
|
|
| 67.1% |
Uncovered Elements: 25 (76) |
Complexity: 16 |
Complexity Density: 0.33 |
|
969 |
5 |
static boolean alignCdsSequenceAsProtein(SequenceI cdsSeq,... |
970 |
|
AlignmentI protein, List<AlignedCodonFrame> mappings, |
971 |
|
char gapChar) |
972 |
|
{ |
973 |
5 |
SequenceI cdsDss = cdsSeq.getDatasetSequence(); |
974 |
5 |
if (cdsDss == null) |
975 |
|
{ |
976 |
0 |
System.err |
977 |
|
.println("alignCdsSequenceAsProtein needs aligned sequence!"); |
978 |
0 |
return false; |
979 |
|
} |
980 |
|
|
981 |
5 |
List<AlignedCodonFrame> dnaMappings = MappingUtils |
982 |
|
.findMappingsForSequence(cdsSeq, mappings); |
983 |
5 |
for (AlignedCodonFrame mapping : dnaMappings) |
984 |
|
{ |
985 |
5 |
SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein); |
986 |
5 |
if (peptide != null) |
987 |
|
{ |
988 |
5 |
final int peptideLength = peptide.getLength(); |
989 |
5 |
Mapping map = mapping.getMappingBetween(cdsSeq, peptide); |
990 |
5 |
if (map != null) |
991 |
|
{ |
992 |
5 |
MapList mapList = map.getMap(); |
993 |
5 |
if (map.getTo() == peptide.getDatasetSequence()) |
994 |
|
{ |
995 |
5 |
mapList = mapList.getInverse(); |
996 |
|
} |
997 |
5 |
final int cdsLength = cdsDss.getLength(); |
998 |
5 |
int mappedFromLength = MappingUtils |
999 |
|
.getLength(mapList.getFromRanges()); |
1000 |
5 |
int mappedToLength = MappingUtils |
1001 |
|
.getLength(mapList.getToRanges()); |
1002 |
5 |
boolean addStopCodon = (cdsLength == mappedFromLength |
1003 |
|
* CODON_LENGTH + CODON_LENGTH) |
1004 |
|
|| (peptide.getDatasetSequence() |
1005 |
|
.getLength() == mappedFromLength - 1); |
1006 |
5 |
if (cdsLength != mappedToLength && !addStopCodon) |
1007 |
|
{ |
1008 |
0 |
jalview.bin.Console.errPrintln(String.format( |
1009 |
|
"Can't align cds as protein (length mismatch %d/%d): %s", |
1010 |
|
cdsLength, mappedToLength, cdsSeq.getName())); |
1011 |
|
} |
1012 |
|
|
1013 |
|
|
1014 |
|
|
1015 |
|
|
1016 |
5 |
char[] alignedCds = new char[peptideLength * CODON_LENGTH |
1017 |
5 |
+ (addStopCodon ? CODON_LENGTH : 0)]; |
1018 |
5 |
Arrays.fill(alignedCds, gapChar); |
1019 |
|
|
1020 |
|
|
1021 |
|
|
1022 |
|
|
1023 |
|
|
1024 |
5 |
int copiedBases = 0; |
1025 |
5 |
int cdsStart = cdsDss.getStart(); |
1026 |
5 |
int proteinPos = peptide.getStart() - 1; |
1027 |
5 |
int cdsCol = 0; |
1028 |
|
|
1029 |
33 |
for (int col = 0; col < peptideLength; col++) |
1030 |
|
{ |
1031 |
28 |
char residue = peptide.getCharAt(col); |
1032 |
|
|
1033 |
28 |
if (Comparison.isGap(residue)) |
1034 |
|
{ |
1035 |
13 |
cdsCol += CODON_LENGTH; |
1036 |
|
} |
1037 |
|
else |
1038 |
|
{ |
1039 |
15 |
proteinPos++; |
1040 |
15 |
int[] codon = mapList.locateInTo(proteinPos, proteinPos); |
1041 |
15 |
if (codon == null) |
1042 |
|
{ |
1043 |
|
|
1044 |
0 |
cdsCol += CODON_LENGTH; |
1045 |
|
} |
1046 |
|
else |
1047 |
|
{ |
1048 |
60 |
for (int j = codon[0]; j <= codon[1]; j++) |
1049 |
|
{ |
1050 |
45 |
char mappedBase = cdsDss.getCharAt(j - cdsStart); |
1051 |
45 |
alignedCds[cdsCol++] = mappedBase; |
1052 |
45 |
copiedBases++; |
1053 |
|
} |
1054 |
|
} |
1055 |
|
} |
1056 |
|
} |
1057 |
|
|
1058 |
|
|
1059 |
|
|
1060 |
|
|
1061 |
|
|
1062 |
5 |
if (copiedBases == cdsLength - CODON_LENGTH) |
1063 |
|
{ |
1064 |
0 |
for (int i = alignedCds.length - 1; i >= 0; i--) |
1065 |
|
{ |
1066 |
0 |
if (!Comparison.isGap(alignedCds[i])) |
1067 |
|
{ |
1068 |
0 |
cdsCol = i + 1; |
1069 |
0 |
break; |
1070 |
|
} |
1071 |
|
} |
1072 |
0 |
for (int i = cdsLength - CODON_LENGTH; i < cdsLength; i++) |
1073 |
|
{ |
1074 |
0 |
alignedCds[cdsCol++] = cdsDss.getCharAt(i); |
1075 |
|
} |
1076 |
|
} |
1077 |
5 |
cdsSeq.setSequence(new String(alignedCds)); |
1078 |
5 |
return true; |
1079 |
|
} |
1080 |
|
} |
1081 |
|
} |
1082 |
0 |
return false; |
1083 |
|
} |
1084 |
|
|
1085 |
|
|
1086 |
|
|
1087 |
|
|
1088 |
|
|
1089 |
|
|
1090 |
|
|
1091 |
|
|
1092 |
|
@param |
1093 |
|
|
1094 |
|
@param |
1095 |
|
|
1096 |
|
@param |
1097 |
|
|
1098 |
|
@return |
1099 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
1100 |
3 |
protected static Map<AlignedCodon, Map<SequenceI, AlignedCodon>> buildCodonColumnsMap(... |
1101 |
|
AlignmentI protein, AlignmentI dna, |
1102 |
|
List<SequenceI> unmappedProtein) |
1103 |
|
{ |
1104 |
|
|
1105 |
|
|
1106 |
|
|
1107 |
|
|
1108 |
3 |
unmappedProtein.addAll(protein.getSequences()); |
1109 |
|
|
1110 |
3 |
List<AlignedCodonFrame> mappings = protein.getCodonFrames(); |
1111 |
|
|
1112 |
|
|
1113 |
|
|
1114 |
|
|
1115 |
|
|
1116 |
|
|
1117 |
3 |
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons = new TreeMap<>( |
1118 |
|
new CodonComparator()); |
1119 |
|
|
1120 |
3 |
for (SequenceI dnaSeq : dna.getSequences()) |
1121 |
|
{ |
1122 |
8 |
for (AlignedCodonFrame mapping : mappings) |
1123 |
|
{ |
1124 |
10 |
SequenceI prot = mapping.findAlignedSequence(dnaSeq, protein); |
1125 |
10 |
if (prot != null) |
1126 |
|
{ |
1127 |
10 |
Mapping seqMap = mapping.getMappingForSequence(dnaSeq); |
1128 |
10 |
addCodonPositions(dnaSeq, prot, protein.getGapCharacter(), seqMap, |
1129 |
|
alignedCodons); |
1130 |
10 |
unmappedProtein.remove(prot); |
1131 |
|
} |
1132 |
|
} |
1133 |
|
} |
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
3 |
int mappedSequenceCount = protein.getHeight() - unmappedProtein.size(); |
1141 |
3 |
addUnmappedPeptideStarts(alignedCodons, mappedSequenceCount); |
1142 |
|
|
1143 |
3 |
return alignedCodons; |
1144 |
|
} |
1145 |
|
|
1146 |
|
|
1147 |
|
|
1148 |
|
|
1149 |
|
|
1150 |
|
|
1151 |
|
@param |
1152 |
|
|
1153 |
|
@param |
1154 |
|
|
1155 |
|
|
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 6 |
Complexity Density: 0.26 |
|
1156 |
3 |
protected static void addUnmappedPeptideStarts(... |
1157 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1158 |
|
int mappedSequenceCount) |
1159 |
|
{ |
1160 |
|
|
1161 |
|
|
1162 |
|
|
1163 |
3 |
List<SequenceI> sequencesChecked = new ArrayList<>(); |
1164 |
3 |
AlignedCodon lastCodon = null; |
1165 |
3 |
Map<SequenceI, AlignedCodon> toAdd = new HashMap<>(); |
1166 |
|
|
1167 |
3 |
for (Entry<AlignedCodon, Map<SequenceI, AlignedCodon>> entry : alignedCodons |
1168 |
|
.entrySet()) |
1169 |
|
{ |
1170 |
21 |
for (Entry<SequenceI, AlignedCodon> sequenceCodon : entry.getValue() |
1171 |
|
.entrySet()) |
1172 |
|
{ |
1173 |
25 |
SequenceI seq = sequenceCodon.getKey(); |
1174 |
25 |
if (sequencesChecked.contains(seq)) |
1175 |
|
{ |
1176 |
17 |
continue; |
1177 |
|
} |
1178 |
8 |
sequencesChecked.add(seq); |
1179 |
8 |
AlignedCodon codon = sequenceCodon.getValue(); |
1180 |
8 |
if (codon.peptideCol > 1) |
1181 |
|
{ |
1182 |
0 |
jalview.bin.Console.errPrintln( |
1183 |
|
"Problem mapping protein with >1 unmapped start positions: " |
1184 |
|
+ seq.getName()); |
1185 |
|
} |
1186 |
8 |
else if (codon.peptideCol == 1) |
1187 |
|
{ |
1188 |
|
|
1189 |
|
|
1190 |
|
|
1191 |
2 |
if (lastCodon != null) |
1192 |
|
{ |
1193 |
1 |
AlignedCodon firstPeptide = new AlignedCodon(lastCodon.pos1, |
1194 |
|
lastCodon.pos2, lastCodon.pos3, |
1195 |
|
String.valueOf(seq.getCharAt(0)), 0); |
1196 |
1 |
toAdd.put(seq, firstPeptide); |
1197 |
|
} |
1198 |
|
else |
1199 |
|
{ |
1200 |
|
|
1201 |
|
|
1202 |
|
|
1203 |
|
|
1204 |
1 |
AlignedCodon firstPeptide = new AlignedCodon(0, 0, 0, |
1205 |
|
String.valueOf(seq.getCharAt(0)), 0); |
1206 |
1 |
toAdd.put(seq, firstPeptide); |
1207 |
|
} |
1208 |
|
} |
1209 |
8 |
if (sequencesChecked.size() == mappedSequenceCount) |
1210 |
|
{ |
1211 |
|
|
1212 |
3 |
break; |
1213 |
|
} |
1214 |
|
} |
1215 |
21 |
lastCodon = entry.getKey(); |
1216 |
|
} |
1217 |
|
|
1218 |
|
|
1219 |
|
|
1220 |
|
|
1221 |
3 |
for (Entry<SequenceI, AlignedCodon> startCodon : toAdd.entrySet()) |
1222 |
|
{ |
1223 |
2 |
addCodonToMap(alignedCodons, startCodon.getValue(), |
1224 |
|
startCodon.getKey()); |
1225 |
|
} |
1226 |
|
} |
1227 |
|
|
1228 |
|
|
1229 |
|
|
1230 |
|
|
1231 |
|
|
1232 |
|
@param |
1233 |
|
@param |
1234 |
|
|
1235 |
|
|
1236 |
|
@param |
1237 |
|
@return |
1238 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
1239 |
3 |
protected static int alignProteinAs(AlignmentI protein,... |
1240 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1241 |
|
List<SequenceI> unmappedProtein) |
1242 |
|
{ |
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
3 |
int alignedWidth = alignedCodons.size(); |
1247 |
3 |
char[] gaps = new char[alignedWidth]; |
1248 |
3 |
Arrays.fill(gaps, protein.getGapCharacter()); |
1249 |
3 |
Map<SequenceI, char[]> peptides = new HashMap<>(); |
1250 |
3 |
for (SequenceI seq : protein.getSequences()) |
1251 |
|
{ |
1252 |
9 |
if (!unmappedProtein.contains(seq)) |
1253 |
|
{ |
1254 |
8 |
peptides.put(seq, Arrays.copyOf(gaps, gaps.length)); |
1255 |
|
} |
1256 |
|
} |
1257 |
|
|
1258 |
|
|
1259 |
|
|
1260 |
|
|
1261 |
|
|
1262 |
|
|
1263 |
|
|
1264 |
3 |
int column = 0; |
1265 |
3 |
for (AlignedCodon codon : alignedCodons.keySet()) |
1266 |
|
{ |
1267 |
22 |
final Map<SequenceI, AlignedCodon> columnResidues = alignedCodons |
1268 |
|
.get(codon); |
1269 |
22 |
for (Entry<SequenceI, AlignedCodon> entry : columnResidues.entrySet()) |
1270 |
|
{ |
1271 |
28 |
char residue = entry.getValue().product.charAt(0); |
1272 |
28 |
peptides.get(entry.getKey())[column] = residue; |
1273 |
|
} |
1274 |
22 |
column++; |
1275 |
|
} |
1276 |
|
|
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
3 |
for (Entry<SequenceI, char[]> entry : peptides.entrySet()) |
1281 |
|
{ |
1282 |
8 |
entry.getKey().setSequence(new String(entry.getValue())); |
1283 |
|
} |
1284 |
|
|
1285 |
3 |
return 0; |
1286 |
|
} |
1287 |
|
|
1288 |
|
|
1289 |
|
|
1290 |
|
|
1291 |
|
|
1292 |
|
|
1293 |
|
@param |
1294 |
|
|
1295 |
|
@param |
1296 |
|
|
1297 |
|
@param |
1298 |
|
|
1299 |
|
@param |
1300 |
|
|
1301 |
|
@param |
1302 |
|
|
1303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
1304 |
10 |
static void addCodonPositions(SequenceI dna, SequenceI protein,... |
1305 |
|
char gapChar, Mapping seqMap, |
1306 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons) |
1307 |
|
{ |
1308 |
10 |
Iterator<AlignedCodon> codons = seqMap.getCodonIterator(dna, gapChar); |
1309 |
|
|
1310 |
|
|
1311 |
|
|
1312 |
|
|
1313 |
|
|
1314 |
44 |
while (codons.hasNext()) |
1315 |
|
{ |
1316 |
34 |
try |
1317 |
|
{ |
1318 |
34 |
AlignedCodon codon = codons.next(); |
1319 |
34 |
addCodonToMap(alignedCodons, codon, protein); |
1320 |
|
} catch (IncompleteCodonException e) |
1321 |
|
{ |
1322 |
|
|
1323 |
|
} catch (NoSuchElementException e) |
1324 |
|
{ |
1325 |
|
|
1326 |
|
} |
1327 |
|
} |
1328 |
|
} |
1329 |
|
|
1330 |
|
|
1331 |
|
|
1332 |
|
|
1333 |
|
@param |
1334 |
|
@param |
1335 |
|
@param |
1336 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
1337 |
36 |
protected static void addCodonToMap(... |
1338 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1339 |
|
AlignedCodon codon, SequenceI protein) |
1340 |
|
{ |
1341 |
36 |
Map<SequenceI, AlignedCodon> seqProduct = alignedCodons.get(codon); |
1342 |
36 |
if (seqProduct == null) |
1343 |
|
{ |
1344 |
22 |
seqProduct = new HashMap<>(); |
1345 |
22 |
alignedCodons.put(codon, seqProduct); |
1346 |
|
} |
1347 |
36 |
seqProduct.put(protein, codon); |
1348 |
|
} |
1349 |
|
|
1350 |
|
|
1351 |
|
|
1352 |
|
|
1353 |
|
|
1354 |
|
|
1355 |
|
|
1356 |
|
|
1357 |
|
|
1358 |
|
|
1359 |
|
|
1360 |
|
|
1361 |
|
|
1362 |
|
|
1363 |
|
@param |
1364 |
|
@param |
1365 |
|
@return |
1366 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 9 |
Complexity Density: 0.64 |
|
1367 |
25 |
public static boolean isMappable(AlignmentI al1, AlignmentI al2)... |
1368 |
|
{ |
1369 |
25 |
if (al1 == null || al2 == null || al1 == al2) |
1370 |
|
{ |
1371 |
5 |
return false; |
1372 |
|
} |
1373 |
|
|
1374 |
|
|
1375 |
|
|
1376 |
|
|
1377 |
20 |
if (al1.isNucleotide() == al2.isNucleotide()) |
1378 |
|
{ |
1379 |
|
|
1380 |
10 |
if (al1.isNucleotide()) |
1381 |
|
{ |
1382 |
5 |
return false; |
1383 |
|
} |
1384 |
5 |
return check3diPeptideMapping(al1,al2); |
1385 |
|
} |
1386 |
10 |
AlignmentI dna = al1.isNucleotide() ? al1 : al2; |
1387 |
10 |
AlignmentI protein = dna == al1 ? al2 : al1; |
1388 |
10 |
List<AlignedCodonFrame> mappings = protein.getCodonFrames(); |
1389 |
10 |
for (SequenceI dnaSeq : dna.getSequences()) |
1390 |
|
{ |
1391 |
11 |
for (SequenceI proteinSeq : protein.getSequences()) |
1392 |
|
{ |
1393 |
11 |
if (isMappable(dnaSeq, proteinSeq, mappings)) |
1394 |
|
{ |
1395 |
2 |
return true; |
1396 |
|
} |
1397 |
|
} |
1398 |
|
} |
1399 |
8 |
return false; |
1400 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
1401 |
5 |
public static boolean check3diPeptideMapping(AlignmentI al1, AlignmentI al2)... |
1402 |
|
{ |
1403 |
5 |
if (al1.getHeight()!=al2.getHeight()) |
1404 |
1 |
{ return false; |
1405 |
|
} |
1406 |
4 |
int mappable=0; |
1407 |
4 |
for (SequenceI al1seq: al1.getSequences()) |
1408 |
|
{ |
1409 |
4 |
boolean foundMappable = false; |
1410 |
4 |
for (SequenceI al2seq:al2.getSequences()) |
1411 |
|
{ |
1412 |
4 |
if (canBuild3diMapping(al1seq,al2seq)) |
1413 |
|
{ |
1414 |
2 |
foundMappable = true; |
1415 |
2 |
break; |
1416 |
|
} |
1417 |
|
} |
1418 |
4 |
if (foundMappable) |
1419 |
|
{ |
1420 |
2 |
mappable++; |
1421 |
|
} |
1422 |
|
} |
1423 |
4 |
if (mappable>0 && mappable >= (al1.getHeight()*9/10)) |
1424 |
|
{ |
1425 |
|
|
1426 |
2 |
return true; |
1427 |
|
} |
1428 |
2 |
return false; |
1429 |
|
} |
1430 |
|
|
1431 |
|
|
1432 |
|
|
1433 |
|
@param |
1434 |
|
@param |
1435 |
|
@return |
1436 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
1437 |
16 |
public static boolean canBuild3diMapping(SequenceI al1seq,... |
1438 |
|
SequenceI al2seq) |
1439 |
|
{ |
1440 |
16 |
if (!al1seq.getDisplayId(true) |
1441 |
|
.equalsIgnoreCase(al2seq.getDisplayId(true))) { |
1442 |
8 |
return false; |
1443 |
|
} |
1444 |
8 |
String s1 = AlignSeq |
1445 |
|
.extractGaps(jalview.util.Comparison.GapChars, |
1446 |
|
al1seq.getSequenceAsString()); |
1447 |
8 |
String s2 = AlignSeq.extractGaps( |
1448 |
|
jalview.util.Comparison.GapChars, |
1449 |
|
al2seq.getSequenceAsString()); |
1450 |
8 |
return s1.length()==s2.length(); |
1451 |
|
} |
1452 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
1453 |
3 |
public static boolean map3diPeptideToProteinAligment(... |
1454 |
|
AlignmentI proteinAlignment, AlignmentI tdiAlignment) |
1455 |
|
{ |
1456 |
3 |
if (proteinAlignment==null || tdiAlignment==null) |
1457 |
|
{ |
1458 |
0 |
return false; |
1459 |
|
} |
1460 |
3 |
Set<SequenceI> mappedDna = new HashSet<>(); |
1461 |
3 |
Set<SequenceI> mappedProtein = new HashSet<>(); |
1462 |
|
|
1463 |
|
|
1464 |
|
|
1465 |
|
|
1466 |
|
|
1467 |
3 |
boolean mappingPerformed = mapProteinToTdiAlignment(proteinAlignment, |
1468 |
|
tdiAlignment, mappedDna, mappedProtein); |
1469 |
3 |
return mappingPerformed; |
1470 |
|
|
1471 |
|
|
1472 |
|
} |
1473 |
|
|
1474 |
|
|
1475 |
|
|
1476 |
|
|
1477 |
|
|
1478 |
|
@param |
1479 |
|
@param |
1480 |
|
@param |
1481 |
|
|
1482 |
|
@param |
1483 |
|
|
1484 |
|
@param |
1485 |
|
|
1486 |
|
@return |
1487 |
|
|
|
|
| 83.3% |
Uncovered Elements: 5 (30) |
Complexity: 6 |
Complexity Density: 0.3 |
|
1488 |
3 |
protected static boolean mapProteinToTdiAlignment(... |
1489 |
|
final AlignmentI proteinAlignment, final AlignmentI tdiAlignment, |
1490 |
|
Set<SequenceI> mappedTdiSeq, Set<SequenceI> mappedProtein) |
1491 |
|
{ |
1492 |
3 |
boolean mappingExistsOrAdded = false; |
1493 |
3 |
List<SequenceI> thisSeqs = proteinAlignment.getSequences(); |
1494 |
3 |
for (SequenceI aaSeq : thisSeqs) |
1495 |
|
{ |
1496 |
6 |
aaSeq = aaSeq.getDatasetSequence()!=null ? aaSeq.getDatasetSequence():null; |
1497 |
6 |
boolean proteinMapped = false; |
1498 |
6 |
AlignedCodonFrame acf = new AlignedCodonFrame(); |
1499 |
|
|
1500 |
6 |
for (SequenceI cdnaSeq : tdiAlignment.getSequences()) |
1501 |
|
{ |
1502 |
|
|
1503 |
12 |
cdnaSeq = cdnaSeq.getDatasetSequence()!=null ? cdnaSeq.getDatasetSequence():null; |
1504 |
|
|
1505 |
12 |
if (mappingExists(proteinAlignment.getCodonFrames(), |
1506 |
|
aaSeq, cdnaSeq)) |
1507 |
|
{ |
1508 |
0 |
mappingExistsOrAdded = true; |
1509 |
|
} |
1510 |
|
else |
1511 |
|
{ |
1512 |
|
|
1513 |
12 |
if (canBuild3diMapping(aaSeq, cdnaSeq)) |
1514 |
|
{ |
1515 |
6 |
MapList map = new MapList(new int[] { aaSeq.getStart(),aaSeq.getEnd()},new int[] { cdnaSeq.getStart(),cdnaSeq.getEnd()},1,1); |
1516 |
6 |
acf.addMap(cdnaSeq, aaSeq, map); |
1517 |
6 |
mappingExistsOrAdded = true; |
1518 |
6 |
proteinMapped = true; |
1519 |
6 |
mappedTdiSeq.add(cdnaSeq); |
1520 |
6 |
mappedProtein.add(aaSeq); |
1521 |
|
} |
1522 |
|
} |
1523 |
|
} |
1524 |
6 |
if (proteinMapped) |
1525 |
|
{ |
1526 |
6 |
proteinAlignment.addCodonFrame(acf); |
1527 |
|
} |
1528 |
|
} |
1529 |
3 |
return mappingExistsOrAdded; |
1530 |
|
} |
1531 |
|
|
1532 |
|
|
1533 |
|
|
1534 |
|
|
1535 |
|
|
1536 |
|
|
1537 |
|
@param |
1538 |
|
@param |
1539 |
|
@param |
1540 |
|
@return |
1541 |
|
|
|
|
| 62.5% |
Uncovered Elements: 6 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
1542 |
11 |
protected static boolean isMappable(SequenceI dnaSeq,... |
1543 |
|
SequenceI proteinSeq, List<AlignedCodonFrame> mappings) |
1544 |
|
{ |
1545 |
11 |
if (dnaSeq == null || proteinSeq == null) |
1546 |
|
{ |
1547 |
0 |
return false; |
1548 |
|
} |
1549 |
|
|
1550 |
11 |
SequenceI dnaDs = dnaSeq.getDatasetSequence() == null ? dnaSeq |
1551 |
|
: dnaSeq.getDatasetSequence(); |
1552 |
11 |
SequenceI proteinDs = proteinSeq.getDatasetSequence() == null |
1553 |
|
? proteinSeq |
1554 |
|
: proteinSeq.getDatasetSequence(); |
1555 |
|
|
1556 |
11 |
for (AlignedCodonFrame mapping : mappings) |
1557 |
|
{ |
1558 |
0 |
if (proteinDs == mapping.getAaForDnaSeq(dnaDs)) |
1559 |
|
{ |
1560 |
|
|
1561 |
|
|
1562 |
|
|
1563 |
0 |
return true; |
1564 |
|
} |
1565 |
|
} |
1566 |
|
|
1567 |
|
|
1568 |
|
|
1569 |
|
|
1570 |
|
|
1571 |
11 |
return mapCdnaToProtein(proteinDs, dnaDs) != null; |
1572 |
|
} |
1573 |
|
|
1574 |
|
|
1575 |
|
|
1576 |
|
|
1577 |
|
|
1578 |
|
|
1579 |
|
|
1580 |
|
@param |
1581 |
|
|
1582 |
|
@param |
1583 |
|
|
1584 |
|
@param |
1585 |
|
|
1586 |
|
@param |
1587 |
|
|
1588 |
|
|
|
|
| 95% |
Uncovered Elements: 2 (40) |
Complexity: 9 |
Complexity Density: 0.38 |
|
1589 |
51 |
public static void findAddableReferenceAnnotations(... |
1590 |
|
List<SequenceI> sequenceScope, Map<String, String> labelForCalcId, |
1591 |
|
final Map<SequenceI, List<AlignmentAnnotation>> candidates, |
1592 |
|
AlignmentI al) |
1593 |
|
{ |
1594 |
51 |
if (sequenceScope == null) |
1595 |
|
{ |
1596 |
1 |
return; |
1597 |
|
} |
1598 |
|
|
1599 |
|
|
1600 |
|
|
1601 |
|
|
1602 |
|
|
1603 |
|
|
1604 |
|
|
1605 |
50 |
for (SequenceI seq : sequenceScope) |
1606 |
|
{ |
1607 |
47 |
SequenceI dataset = seq.getDatasetSequence(); |
1608 |
47 |
if (dataset == null) |
1609 |
|
{ |
1610 |
0 |
continue; |
1611 |
|
} |
1612 |
47 |
AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation(); |
1613 |
47 |
if (datasetAnnotations == null) |
1614 |
|
{ |
1615 |
33 |
continue; |
1616 |
|
} |
1617 |
14 |
final List<AlignmentAnnotation> result = new ArrayList<>(); |
1618 |
14 |
for (AlignmentAnnotation dsann : datasetAnnotations) |
1619 |
|
{ |
1620 |
|
|
1621 |
|
|
1622 |
|
|
1623 |
|
|
1624 |
|
|
1625 |
26 |
final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al |
1626 |
|
.findAnnotations(seq, dsann.getCalcId(), dsann.label); |
1627 |
26 |
boolean found = false; |
1628 |
26 |
if (matchedAlignmentAnnotations != null) |
1629 |
|
{ |
1630 |
23 |
for (AlignmentAnnotation matched : matchedAlignmentAnnotations) |
1631 |
|
{ |
1632 |
5 |
if (dsann.description.equals(matched.description)) |
1633 |
|
{ |
1634 |
4 |
found = true; |
1635 |
4 |
break; |
1636 |
|
} |
1637 |
|
} |
1638 |
|
} |
1639 |
26 |
if (!found) |
1640 |
|
{ |
1641 |
22 |
result.add(dsann); |
1642 |
22 |
if (labelForCalcId != null) |
1643 |
|
{ |
1644 |
10 |
labelForCalcId.put(dsann.getCalcId(), dsann.label); |
1645 |
|
} |
1646 |
|
} |
1647 |
|
} |
1648 |
|
|
1649 |
|
|
1650 |
|
|
1651 |
14 |
if (!result.isEmpty()) |
1652 |
|
{ |
1653 |
12 |
candidates.put(seq, result); |
1654 |
|
} |
1655 |
|
} |
1656 |
|
} |
1657 |
|
|
1658 |
|
|
1659 |
|
|
1660 |
|
|
1661 |
|
|
1662 |
|
|
1663 |
|
@param |
1664 |
|
|
1665 |
|
@param |
1666 |
|
|
1667 |
|
@param |
1668 |
|
|
1669 |
|
|
1670 |
|
|
1671 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1672 |
7 |
public static void addReferenceAnnotations(... |
1673 |
|
Map<SequenceI, List<AlignmentAnnotation>> annotations, |
1674 |
|
final AlignmentI alignment, final SequenceGroup selectionGroup) |
1675 |
|
{ |
1676 |
7 |
for (SequenceI seq : annotations.keySet()) |
1677 |
|
{ |
1678 |
8 |
for (AlignmentAnnotation ann : annotations.get(seq)) |
1679 |
|
{ |
1680 |
16 |
addReferenceAnnotationTo(alignment, seq, ann, selectionGroup); |
1681 |
|
} |
1682 |
|
} |
1683 |
|
} |
1684 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
1685 |
0 |
public static boolean isSSAnnotationPresent(... |
1686 |
|
Map<SequenceI, List<AlignmentAnnotation>> annotations) |
1687 |
|
{ |
1688 |
|
|
1689 |
0 |
for (SequenceI seq : annotations.keySet()) |
1690 |
|
{ |
1691 |
0 |
if (isSecondaryStructurePresent( |
1692 |
|
annotations.get(seq).toArray(new AlignmentAnnotation[0]))) |
1693 |
|
{ |
1694 |
0 |
return true; |
1695 |
|
} |
1696 |
|
} |
1697 |
0 |
return false; |
1698 |
|
} |
1699 |
|
|
1700 |
|
|
1701 |
|
|
1702 |
|
|
1703 |
|
|
1704 |
|
|
1705 |
|
@param |
1706 |
|
@param |
1707 |
|
@param |
1708 |
|
@param |
1709 |
|
|
1710 |
|
|
1711 |
|
|
1712 |
|
@return |
1713 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
1714 |
19 |
public static AlignmentAnnotation addReferenceAnnotationTo(... |
1715 |
|
final AlignmentI alignment, final SequenceI seq, |
1716 |
|
final AlignmentAnnotation ann, final SequenceGroup selectionGroup) |
1717 |
|
{ |
1718 |
19 |
AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann); |
1719 |
19 |
int startRes = 0; |
1720 |
19 |
int endRes = ann.annotations.length; |
1721 |
19 |
if (selectionGroup != null) |
1722 |
|
{ |
1723 |
2 |
startRes = -1 + Math.min(seq.getEnd(), Math.max(seq.getStart(), |
1724 |
|
seq.findPosition(selectionGroup.getStartRes()))); |
1725 |
2 |
endRes = -1 + Math.min(seq.getEnd(), |
1726 |
|
seq.findPosition(selectionGroup.getEndRes())); |
1727 |
|
|
1728 |
|
} |
1729 |
19 |
copyAnn.restrict(startRes, endRes + 0); |
1730 |
|
|
1731 |
|
|
1732 |
|
|
1733 |
|
|
1734 |
|
|
1735 |
19 |
if (!seq.hasAnnotation(ann)) |
1736 |
|
{ |
1737 |
19 |
ContactMatrixI cm = seq.getDatasetSequence().getContactMatrixFor(ann); |
1738 |
19 |
if (cm != null) |
1739 |
|
{ |
1740 |
7 |
seq.addContactListFor(copyAnn, cm); |
1741 |
|
} |
1742 |
19 |
seq.addAlignmentAnnotation(copyAnn); |
1743 |
|
} |
1744 |
|
|
1745 |
19 |
copyAnn.adjustForAlignment(); |
1746 |
|
|
1747 |
19 |
alignment.addAnnotation(copyAnn); |
1748 |
19 |
copyAnn.visible = true; |
1749 |
|
|
1750 |
19 |
return copyAnn; |
1751 |
|
} |
1752 |
|
|
1753 |
|
|
1754 |
|
|
1755 |
|
|
1756 |
|
|
1757 |
|
|
1758 |
|
|
1759 |
|
@param |
1760 |
|
|
1761 |
|
@param |
1762 |
|
|
1763 |
|
|
1764 |
|
@param |
1765 |
|
|
1766 |
|
@param |
1767 |
|
|
1768 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 7 |
Complexity Density: 1.17 |
|
1769 |
5 |
public static void showOrHideSequenceAnnotations(AlignmentI al,... |
1770 |
|
Collection<String> types, List<SequenceI> forSequences, |
1771 |
|
boolean anyType, boolean doShow) |
1772 |
|
{ |
1773 |
5 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1774 |
5 |
if (anns != null) |
1775 |
|
{ |
1776 |
5 |
for (AlignmentAnnotation aa : anns) |
1777 |
|
{ |
1778 |
30 |
if (anyType || types.contains(aa.label)) |
1779 |
|
{ |
1780 |
21 |
if ((aa.sequenceRef != null) && (forSequences == null |
1781 |
|
|| forSequences.contains(aa.sequenceRef))) |
1782 |
|
{ |
1783 |
11 |
aa.visible = doShow; |
1784 |
|
} |
1785 |
|
} |
1786 |
|
} |
1787 |
|
} |
1788 |
|
} |
1789 |
|
|
1790 |
|
|
1791 |
|
|
1792 |
|
|
1793 |
|
@param |
1794 |
|
|
1795 |
|
@param |
1796 |
|
|
1797 |
|
@param |
1798 |
|
|
1799 |
|
|
1800 |
|
@param |
1801 |
|
|
1802 |
|
@param |
1803 |
|
|
1804 |
|
|
1805 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 7 |
Complexity Density: 1.17 |
|
1806 |
0 |
public static void showOrHideAutoCalculatedAnnotationsForGroup(... |
1807 |
|
AlignmentI al, String type, SequenceGroup selectedGroup, |
1808 |
|
boolean anyType, boolean doShow) |
1809 |
|
{ |
1810 |
|
|
1811 |
0 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1812 |
|
|
1813 |
0 |
if (anns != null) |
1814 |
|
{ |
1815 |
0 |
for (AlignmentAnnotation aa : anns) |
1816 |
|
{ |
1817 |
|
|
1818 |
|
|
1819 |
0 |
if ((anyType && aa.label |
1820 |
|
.startsWith(Constants.SECONDARY_STRUCTURE_CONSENSUS_LABEL)) |
1821 |
|
|| aa.label.startsWith(type)) |
1822 |
|
{ |
1823 |
|
|
1824 |
|
|
1825 |
0 |
if (aa.groupRef != null && selectedGroup == aa.groupRef) |
1826 |
|
{ |
1827 |
0 |
aa.visible = doShow; |
1828 |
|
} |
1829 |
|
} |
1830 |
|
} |
1831 |
|
} |
1832 |
|
} |
1833 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
1834 |
0 |
public static AlignmentAnnotation getFirstSequenceAnnotationOfType(... |
1835 |
|
AlignmentI al, int graphType) |
1836 |
|
{ |
1837 |
0 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1838 |
0 |
if (anns != null) |
1839 |
|
{ |
1840 |
0 |
for (AlignmentAnnotation aa : anns) |
1841 |
|
{ |
1842 |
0 |
if (aa.sequenceRef != null && aa.graph == graphType) |
1843 |
0 |
return aa; |
1844 |
|
} |
1845 |
|
} |
1846 |
0 |
return null; |
1847 |
|
} |
1848 |
|
|
1849 |
|
|
1850 |
|
|
1851 |
|
|
1852 |
|
@param |
1853 |
|
@param |
1854 |
|
@return |
1855 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1856 |
52 |
public static boolean haveCrossRef(SequenceI seq1, SequenceI seq2)... |
1857 |
|
{ |
1858 |
|
|
1859 |
|
|
1860 |
52 |
return hasCrossRef(seq1, seq2) || hasCrossRef(seq2, seq1); |
1861 |
|
} |
1862 |
|
|
1863 |
|
|
1864 |
|
|
1865 |
|
|
1866 |
|
|
1867 |
|
@param |
1868 |
|
@param |
1869 |
|
@return |
1870 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
1871 |
108 |
public static boolean hasCrossRef(SequenceI seq1, SequenceI seq2)... |
1872 |
|
{ |
1873 |
108 |
if (seq1 == null || seq2 == null) |
1874 |
|
{ |
1875 |
8 |
return false; |
1876 |
|
} |
1877 |
100 |
String name = seq2.getName(); |
1878 |
100 |
final List<DBRefEntry> xrefs = seq1.getDBRefs(); |
1879 |
100 |
if (xrefs != null) |
1880 |
|
{ |
1881 |
34 |
for (int ix = 0, nx = xrefs.size(); ix < nx; ix++) |
1882 |
|
{ |
1883 |
24 |
DBRefEntry xref = xrefs.get(ix); |
1884 |
24 |
String xrefName = xref.getSource() + "|" + xref.getAccessionId(); |
1885 |
|
|
1886 |
24 |
if (xrefName.equalsIgnoreCase(name)) |
1887 |
|
{ |
1888 |
12 |
return true; |
1889 |
|
} |
1890 |
|
} |
1891 |
|
} |
1892 |
88 |
return false; |
1893 |
|
} |
1894 |
|
|
1895 |
|
|
1896 |
|
|
1897 |
|
|
1898 |
|
|
1899 |
|
|
1900 |
|
|
1901 |
|
|
1902 |
|
@param |
1903 |
|
|
1904 |
|
@param |
1905 |
|
|
1906 |
|
@param |
1907 |
|
|
1908 |
|
|
1909 |
|
@return |
1910 |
|
|
1911 |
|
|
|
|
| 77.2% |
Uncovered Elements: 21 (92) |
Complexity: 16 |
Complexity Density: 0.24 |
|
1912 |
4 |
public static AlignmentI makeCdsAlignment(SequenceI[] dna,... |
1913 |
|
AlignmentI dataset, SequenceI[] products) |
1914 |
|
{ |
1915 |
4 |
if (dataset == null || dataset.getDataset() != null) |
1916 |
|
{ |
1917 |
0 |
throw new IllegalArgumentException( |
1918 |
|
"IMPLEMENTATION ERROR: dataset.getDataset() must be null!"); |
1919 |
|
} |
1920 |
4 |
List<SequenceI> foundSeqs = new ArrayList<>(); |
1921 |
4 |
List<SequenceI> cdsSeqs = new ArrayList<>(); |
1922 |
4 |
List<AlignedCodonFrame> mappings = dataset.getCodonFrames(); |
1923 |
4 |
HashSet<SequenceI> productSeqs = null; |
1924 |
4 |
if (products != null) |
1925 |
|
{ |
1926 |
1 |
productSeqs = new HashSet<>(); |
1927 |
1 |
for (SequenceI seq : products) |
1928 |
|
{ |
1929 |
2 |
productSeqs.add(seq.getDatasetSequence() == null ? seq |
1930 |
|
: seq.getDatasetSequence()); |
1931 |
|
} |
1932 |
|
} |
1933 |
|
|
1934 |
|
|
1935 |
|
|
1936 |
|
|
1937 |
|
|
1938 |
|
|
1939 |
|
|
1940 |
|
|
1941 |
|
|
1942 |
|
|
1943 |
|
|
1944 |
|
|
1945 |
4 |
for (SequenceI dnaSeq : dna) |
1946 |
|
{ |
1947 |
8 |
SequenceI dnaDss = dnaSeq.getDatasetSequence() == null ? dnaSeq |
1948 |
|
: dnaSeq.getDatasetSequence(); |
1949 |
|
|
1950 |
8 |
List<AlignedCodonFrame> seqMappings = MappingUtils |
1951 |
|
.findMappingsForSequence(dnaSeq, mappings); |
1952 |
8 |
for (AlignedCodonFrame mapping : seqMappings) |
1953 |
|
{ |
1954 |
9 |
List<Mapping> mappingsFromSequence = mapping |
1955 |
|
.getMappingsFromSequence(dnaSeq); |
1956 |
|
|
1957 |
9 |
for (Mapping aMapping : mappingsFromSequence) |
1958 |
|
{ |
1959 |
11 |
MapList mapList = aMapping.getMap(); |
1960 |
11 |
if (mapList.getFromRatio() == 1) |
1961 |
|
{ |
1962 |
|
|
1963 |
|
|
1964 |
|
|
1965 |
0 |
continue; |
1966 |
|
} |
1967 |
|
|
1968 |
|
|
1969 |
|
|
1970 |
|
|
1971 |
11 |
SequenceI proteinProduct = aMapping.getTo(); |
1972 |
11 |
if (productSeqs != null && !productSeqs.contains(proteinProduct)) |
1973 |
|
{ |
1974 |
2 |
continue; |
1975 |
|
} |
1976 |
|
|
1977 |
|
|
1978 |
|
|
1979 |
|
|
1980 |
|
|
1981 |
|
|
1982 |
9 |
SequenceI cdsSeq = findCdsForProtein(mappings, dnaSeq, |
1983 |
|
seqMappings, aMapping); |
1984 |
9 |
if (cdsSeq != null) |
1985 |
|
{ |
1986 |
0 |
if (!foundSeqs.contains(cdsSeq)) |
1987 |
|
{ |
1988 |
0 |
foundSeqs.add(cdsSeq); |
1989 |
0 |
SequenceI derivedSequence = cdsSeq.deriveSequence(); |
1990 |
0 |
cdsSeqs.add(derivedSequence); |
1991 |
0 |
if (!dataset.getSequences().contains(cdsSeq)) |
1992 |
|
{ |
1993 |
0 |
dataset.addSequence(cdsSeq); |
1994 |
|
} |
1995 |
|
} |
1996 |
0 |
continue; |
1997 |
|
} |
1998 |
|
|
1999 |
|
|
2000 |
|
|
2001 |
|
|
2002 |
|
|
2003 |
9 |
cdsSeq = makeCdsSequence(dnaSeq.getDatasetSequence(), aMapping, |
2004 |
|
dataset).deriveSequence(); |
2005 |
|
|
2006 |
|
|
2007 |
|
|
2008 |
|
|
2009 |
9 |
SequenceI cdsSeqDss = cdsSeq.getDatasetSequence(); |
2010 |
|
|
2011 |
9 |
cdsSeqs.add(cdsSeq); |
2012 |
|
|
2013 |
|
|
2014 |
|
|
2015 |
|
|
2016 |
9 |
List<int[]> cdsRange = Collections |
2017 |
|
.singletonList(new int[] |
2018 |
|
{ cdsSeq.getStart(), |
2019 |
|
cdsSeq.getLength() + cdsSeq.getStart() - 1 }); |
2020 |
9 |
MapList cdsToProteinMap = new MapList(cdsRange, |
2021 |
|
mapList.getToRanges(), mapList.getFromRatio(), |
2022 |
|
mapList.getToRatio()); |
2023 |
|
|
2024 |
9 |
if (!dataset.getSequences().contains(cdsSeqDss)) |
2025 |
|
{ |
2026 |
|
|
2027 |
|
|
2028 |
|
|
2029 |
|
|
2030 |
|
|
2031 |
9 |
dataset.addSequence(cdsSeqDss); |
2032 |
9 |
AlignedCodonFrame cdsToProteinMapping = new AlignedCodonFrame(); |
2033 |
9 |
cdsToProteinMapping.addMap(cdsSeqDss, proteinProduct, |
2034 |
|
cdsToProteinMap); |
2035 |
|
|
2036 |
|
|
2037 |
|
|
2038 |
|
|
2039 |
9 |
if (!mappings.contains(cdsToProteinMapping)) |
2040 |
|
{ |
2041 |
9 |
mappings.add(cdsToProteinMapping); |
2042 |
|
} |
2043 |
|
} |
2044 |
|
|
2045 |
9 |
propagateDBRefsToCDS(cdsSeqDss, dnaSeq.getDatasetSequence(), |
2046 |
|
proteinProduct, aMapping); |
2047 |
|
|
2048 |
|
|
2049 |
|
|
2050 |
9 |
AlignedCodonFrame dnaToCdsMapping = new AlignedCodonFrame(); |
2051 |
9 |
final MapList dnaToCdsMap = new MapList(mapList.getFromRanges(), |
2052 |
|
cdsRange, 1, 1); |
2053 |
9 |
dnaToCdsMapping.addMap(dnaSeq.getDatasetSequence(), cdsSeqDss, |
2054 |
|
dnaToCdsMap); |
2055 |
9 |
if (!mappings.contains(dnaToCdsMapping)) |
2056 |
|
{ |
2057 |
9 |
mappings.add(dnaToCdsMapping); |
2058 |
|
} |
2059 |
|
|
2060 |
|
|
2061 |
|
|
2062 |
|
|
2063 |
|
|
2064 |
9 |
final MapList cdsToDnaMap = dnaToCdsMap.getInverse(); |
2065 |
9 |
transferGeneLoci(dnaSeq, cdsToDnaMap, cdsSeq); |
2066 |
|
|
2067 |
|
|
2068 |
|
|
2069 |
|
|
2070 |
|
|
2071 |
|
|
2072 |
|
|
2073 |
|
|
2074 |
|
|
2075 |
|
|
2076 |
|
|
2077 |
|
|
2078 |
|
|
2079 |
|
|
2080 |
|
|
2081 |
|
|
2082 |
|
|
2083 |
|
|
2084 |
9 |
List<DBRefEntry> primrefs = dnaDss.getPrimaryDBRefs(); |
2085 |
11 |
for (int ip = 0, np = primrefs.size(); ip < np; ip++) |
2086 |
|
{ |
2087 |
2 |
DBRefEntry primRef = primrefs.get(ip); |
2088 |
|
|
2089 |
|
|
2090 |
|
|
2091 |
|
|
2092 |
2 |
String source = primRef.getSource(); |
2093 |
2 |
String version = primRef.getVersion(); |
2094 |
2 |
DBRefEntry cdsCrossRef = new DBRefEntry(source, |
2095 |
|
source + ":" + version, primRef.getAccessionId()); |
2096 |
2 |
cdsCrossRef |
2097 |
|
.setMap(new Mapping(dnaDss, new MapList(cdsToDnaMap))); |
2098 |
2 |
cdsSeqDss.addDBRef(cdsCrossRef); |
2099 |
|
|
2100 |
2 |
dnaSeq.addDBRef(new DBRefEntry(source, version, |
2101 |
|
cdsSeq.getName(), new Mapping(cdsSeqDss, dnaToCdsMap))); |
2102 |
|
|
2103 |
|
|
2104 |
|
|
2105 |
|
|
2106 |
|
|
2107 |
2 |
DBRefEntry proteinToCdsRef = new DBRefEntry(source, version, |
2108 |
|
cdsSeq.getName()); |
2109 |
|
|
2110 |
2 |
proteinToCdsRef.setMap( |
2111 |
|
new Mapping(cdsSeqDss, cdsToProteinMap.getInverse())); |
2112 |
2 |
proteinProduct.addDBRef(proteinToCdsRef); |
2113 |
|
} |
2114 |
|
|
2115 |
|
|
2116 |
|
|
2117 |
9 |
transferFeatures(dnaSeq, cdsSeq, dnaToCdsMap, null, |
2118 |
|
SequenceOntologyI.CDS); |
2119 |
|
} |
2120 |
|
} |
2121 |
|
} |
2122 |
|
|
2123 |
4 |
AlignmentI cds = new Alignment( |
2124 |
|
cdsSeqs.toArray(new SequenceI[cdsSeqs.size()])); |
2125 |
4 |
cds.setDataset(dataset); |
2126 |
|
|
2127 |
4 |
return cds; |
2128 |
|
} |
2129 |
|
|
2130 |
|
|
2131 |
|
|
2132 |
|
|
2133 |
|
|
2134 |
|
@param |
2135 |
|
@param |
2136 |
|
|
2137 |
|
@param |
2138 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
2139 |
12 |
protected static void transferGeneLoci(SequenceI fromSeq,... |
2140 |
|
MapList targetToFrom, SequenceI targetSeq) |
2141 |
|
{ |
2142 |
12 |
if (targetSeq.getGeneLoci() != null) |
2143 |
|
{ |
2144 |
|
|
2145 |
1 |
return; |
2146 |
|
} |
2147 |
11 |
GeneLociI fromLoci = fromSeq.getGeneLoci(); |
2148 |
11 |
if (fromLoci == null) |
2149 |
|
{ |
2150 |
10 |
return; |
2151 |
|
} |
2152 |
|
|
2153 |
1 |
MapList newMap = targetToFrom.traverse(fromLoci.getMapping()); |
2154 |
|
|
2155 |
1 |
if (newMap != null) |
2156 |
|
{ |
2157 |
1 |
targetSeq.setGeneLoci(fromLoci.getSpeciesId(), |
2158 |
|
fromLoci.getAssemblyId(), fromLoci.getChromosomeId(), newMap); |
2159 |
|
} |
2160 |
|
} |
2161 |
|
|
2162 |
|
|
2163 |
|
|
2164 |
|
|
2165 |
|
|
2166 |
|
|
2167 |
|
@param |
2168 |
|
|
2169 |
|
@param |
2170 |
|
|
2171 |
|
@param |
2172 |
|
|
2173 |
|
@param |
2174 |
|
|
2175 |
|
@return |
2176 |
|
|
|
|
| 93.5% |
Uncovered Elements: 2 (31) |
Complexity: 11 |
Complexity Density: 0.58 |
|
2177 |
16 |
static SequenceI findCdsForProtein(List<AlignedCodonFrame> mappings,... |
2178 |
|
SequenceI dnaSeq, List<AlignedCodonFrame> seqMappings, |
2179 |
|
Mapping aMapping) |
2180 |
|
{ |
2181 |
|
|
2182 |
|
|
2183 |
|
|
2184 |
|
|
2185 |
16 |
SequenceI seqDss = dnaSeq.getDatasetSequence() == null ? dnaSeq |
2186 |
|
: dnaSeq.getDatasetSequence(); |
2187 |
16 |
SequenceI proteinProduct = aMapping.getTo(); |
2188 |
|
|
2189 |
|
|
2190 |
|
|
2191 |
|
|
2192 |
|
|
2193 |
16 |
int mappedFromLength = MappingUtils |
2194 |
|
.getLength(aMapping.getMap().getFromRanges()); |
2195 |
16 |
int dnaLength = seqDss.getLength(); |
2196 |
16 |
if (mappedFromLength == dnaLength |
2197 |
|
|| mappedFromLength == dnaLength - CODON_LENGTH) |
2198 |
|
{ |
2199 |
|
|
2200 |
|
|
2201 |
|
|
2202 |
|
|
2203 |
4 |
if (seqDss.getFeatures().getFeaturesByOntology(SequenceOntologyI.CDS) |
2204 |
|
.isEmpty()) |
2205 |
|
{ |
2206 |
1 |
return seqDss; |
2207 |
|
} |
2208 |
|
} |
2209 |
|
|
2210 |
|
|
2211 |
|
|
2212 |
|
|
2213 |
|
|
2214 |
15 |
List<AlignedCodonFrame> mappingsToPeptide = MappingUtils |
2215 |
|
.findMappingsForSequence(proteinProduct, mappings); |
2216 |
15 |
for (AlignedCodonFrame acf : mappingsToPeptide) |
2217 |
|
{ |
2218 |
19 |
for (SequenceToSequenceMapping map : acf.getMappings()) |
2219 |
|
{ |
2220 |
23 |
Mapping mapping = map.getMapping(); |
2221 |
23 |
if (mapping != aMapping |
2222 |
|
&& mapping.getMap().getFromRatio() == CODON_LENGTH |
2223 |
|
&& proteinProduct == mapping.getTo() |
2224 |
|
&& seqDss != map.getFromSeq()) |
2225 |
|
{ |
2226 |
4 |
mappedFromLength = MappingUtils |
2227 |
|
.getLength(mapping.getMap().getFromRanges()); |
2228 |
4 |
if (mappedFromLength == map.getFromSeq().getLength()) |
2229 |
|
{ |
2230 |
|
|
2231 |
|
|
2232 |
|
|
2233 |
|
|
2234 |
|
|
2235 |
4 |
SequenceI cdsSeq = map.getFromSeq(); |
2236 |
|
|
2237 |
|
|
2238 |
4 |
List<AlignedCodonFrame> dnaToCdsMaps = MappingUtils |
2239 |
|
.findMappingsForSequence(cdsSeq, seqMappings); |
2240 |
4 |
if (!dnaToCdsMaps.isEmpty()) |
2241 |
|
{ |
2242 |
2 |
return cdsSeq; |
2243 |
|
} |
2244 |
|
} |
2245 |
|
} |
2246 |
|
} |
2247 |
|
} |
2248 |
13 |
return null; |
2249 |
|
} |
2250 |
|
|
2251 |
|
|
2252 |
|
|
2253 |
|
|
2254 |
|
|
2255 |
|
|
2256 |
|
@param |
2257 |
|
@param |
2258 |
|
@param |
2259 |
|
|
2260 |
|
|
2261 |
|
|
2262 |
|
@return |
2263 |
|
|
|
|
| 62% |
Uncovered Elements: 19 (50) |
Complexity: 10 |
Complexity Density: 0.31 |
|
2264 |
9 |
static SequenceI makeCdsSequence(SequenceI seq, Mapping mapping,... |
2265 |
|
AlignmentI dataset) |
2266 |
|
{ |
2267 |
|
|
2268 |
|
|
2269 |
|
|
2270 |
|
|
2271 |
9 |
String mapFromId = mapping.getMappedFromId(); |
2272 |
9 |
final String seqId = "CDS|" |
2273 |
9 |
+ (mapFromId != null ? mapFromId : seq.getName()); |
2274 |
|
|
2275 |
9 |
SequenceI newSeq = null; |
2276 |
|
|
2277 |
|
|
2278 |
|
|
2279 |
|
|
2280 |
9 |
char[] seqChars = seq.getSequence(); |
2281 |
9 |
List<int[]> fromRanges = mapping.getMap().getFromRanges(); |
2282 |
9 |
int cdsWidth = MappingUtils.getLength(fromRanges); |
2283 |
9 |
char[] newSeqChars = new char[cdsWidth]; |
2284 |
|
|
2285 |
9 |
int newPos = 0; |
2286 |
9 |
for (int[] range : fromRanges) |
2287 |
|
{ |
2288 |
21 |
if (range[0] <= range[1]) |
2289 |
|
{ |
2290 |
|
|
2291 |
21 |
int length = range[1] - range[0] + 1; |
2292 |
21 |
System.arraycopy(seqChars, range[0] - 1, newSeqChars, newPos, |
2293 |
|
length); |
2294 |
21 |
newPos += length; |
2295 |
|
} |
2296 |
|
else |
2297 |
|
{ |
2298 |
|
|
2299 |
0 |
for (int i = range[0]; i >= range[1]; i--) |
2300 |
|
{ |
2301 |
0 |
newSeqChars[newPos++] = Dna.getComplement(seqChars[i - 1]); |
2302 |
|
} |
2303 |
|
} |
2304 |
|
|
2305 |
21 |
newSeq = new Sequence(seqId, newSeqChars, 1, newPos); |
2306 |
|
} |
2307 |
|
|
2308 |
9 |
if (dataset != null) |
2309 |
|
{ |
2310 |
9 |
SequenceI[] matches = dataset.findSequenceMatch(newSeq.getName()); |
2311 |
9 |
if (matches != null) |
2312 |
|
{ |
2313 |
9 |
boolean matched = false; |
2314 |
9 |
for (SequenceI mtch : matches) |
2315 |
|
{ |
2316 |
3 |
if (mtch.getStart() != newSeq.getStart()) |
2317 |
|
{ |
2318 |
0 |
continue; |
2319 |
|
} |
2320 |
3 |
if (mtch.getEnd() != newSeq.getEnd()) |
2321 |
|
{ |
2322 |
0 |
continue; |
2323 |
|
} |
2324 |
3 |
if (!Arrays.equals(mtch.getSequence(), newSeq.getSequence())) |
2325 |
|
{ |
2326 |
3 |
continue; |
2327 |
|
} |
2328 |
0 |
if (!matched) |
2329 |
|
{ |
2330 |
0 |
matched = true; |
2331 |
0 |
newSeq = mtch; |
2332 |
|
} |
2333 |
|
else |
2334 |
|
{ |
2335 |
0 |
Console.error( |
2336 |
|
"JAL-2154 regression: warning - found (and ignored) a duplicate CDS sequence:" |
2337 |
|
+ mtch.toString()); |
2338 |
|
} |
2339 |
|
} |
2340 |
|
} |
2341 |
|
} |
2342 |
|
|
2343 |
|
|
2344 |
9 |
return newSeq; |
2345 |
|
} |
2346 |
|
|
2347 |
|
|
2348 |
|
|
2349 |
|
|
2350 |
|
|
2351 |
|
@param |
2352 |
|
@param |
2353 |
|
@param |
2354 |
|
@param |
2355 |
|
@return |
2356 |
|
|
|
|
| 86.4% |
Uncovered Elements: 6 (44) |
Complexity: 11 |
Complexity Density: 0.39 |
|
2357 |
9 |
protected static List<DBRefEntry> propagateDBRefsToCDS(SequenceI cdsSeq,... |
2358 |
|
SequenceI contig, SequenceI proteinProduct, Mapping mapping) |
2359 |
|
{ |
2360 |
|
|
2361 |
|
|
2362 |
9 |
List<DBRefEntry> direct = new ArrayList<>(); |
2363 |
9 |
HashSet<String> directSources = new HashSet<>(); |
2364 |
|
|
2365 |
9 |
List<DBRefEntry> refs = contig.getDBRefs(); |
2366 |
9 |
if (refs != null) |
2367 |
|
{ |
2368 |
6 |
for (int ib = 0, nb = refs.size(); ib < nb; ib++) |
2369 |
|
{ |
2370 |
4 |
DBRefEntry dbr = refs.get(ib); |
2371 |
4 |
MapList map; |
2372 |
? |
if (dbr.hasMap() && (map = dbr.getMap().getMap()).isTripletMap()) |
2373 |
|
{ |
2374 |
|
|
2375 |
2 |
if (mapping.getMap().equals(map)) |
2376 |
|
{ |
2377 |
2 |
direct.add(dbr); |
2378 |
2 |
directSources.add(dbr.getSource()); |
2379 |
|
} |
2380 |
|
} |
2381 |
|
} |
2382 |
|
} |
2383 |
9 |
List<DBRefEntry> onSource = DBRefUtils.selectRefs( |
2384 |
|
proteinProduct.getDBRefs(), |
2385 |
|
directSources.toArray(new String[0])); |
2386 |
9 |
List<DBRefEntry> propagated = new ArrayList<>(); |
2387 |
|
|
2388 |
|
|
2389 |
11 |
for (int ic = 0, nc = direct.size(); ic < nc; ic++) |
2390 |
|
{ |
2391 |
2 |
DBRefEntry cdsref = direct.get(ic); |
2392 |
2 |
Mapping m = cdsref.getMap(); |
2393 |
|
|
2394 |
2 |
MapList cdsposmap = new MapList( |
2395 |
|
Arrays.asList(new int[][] |
2396 |
|
{ new int[] { cdsSeq.getStart(), cdsSeq.getEnd() } }), |
2397 |
|
m.getMap().getToRanges(), 3, 1); |
2398 |
2 |
Mapping cdsmap = new Mapping(m.getTo(), m.getMap()); |
2399 |
|
|
2400 |
|
|
2401 |
2 |
DBRefEntry newref = new DBRefEntry(cdsref.getSource(), |
2402 |
|
cdsref.getVersion(), cdsref.getAccessionId(), |
2403 |
|
new Mapping(cdsmap.getTo(), cdsposmap)); |
2404 |
|
|
2405 |
|
|
2406 |
|
|
2407 |
|
|
2408 |
2 |
if (cdsmap.getTo() == null && onSource != null) |
2409 |
|
{ |
2410 |
2 |
List<DBRefEntry> sourceRefs = DBRefUtils.searchRefs(onSource, |
2411 |
|
cdsref.getAccessionId()); |
2412 |
2 |
if (sourceRefs != null) |
2413 |
|
{ |
2414 |
2 |
for (DBRefEntry srcref : sourceRefs) |
2415 |
|
{ |
2416 |
2 |
if (srcref.getSource().equalsIgnoreCase(cdsref.getSource())) |
2417 |
|
{ |
2418 |
|
|
2419 |
|
|
2420 |
2 |
newref.getMap().setTo(proteinProduct); |
2421 |
|
} |
2422 |
|
} |
2423 |
|
} |
2424 |
|
} |
2425 |
2 |
cdsSeq.addDBRef(newref); |
2426 |
2 |
propagated.add(newref); |
2427 |
|
} |
2428 |
9 |
return propagated; |
2429 |
|
} |
2430 |
|
|
2431 |
|
|
2432 |
|
|
2433 |
|
|
2434 |
|
|
2435 |
|
|
2436 |
|
@param |
2437 |
|
@param |
2438 |
|
@param |
2439 |
|
|
2440 |
|
@param |
2441 |
|
|
2442 |
|
|
2443 |
|
@param |
2444 |
|
|
|
|
| 88.7% |
Uncovered Elements: 6 (53) |
Complexity: 12 |
Complexity Density: 0.36 |
|
2445 |
12 |
protected static int transferFeatures(SequenceI fromSeq, SequenceI toSeq,... |
2446 |
|
MapList mapping, String select, String... omitting) |
2447 |
|
{ |
2448 |
12 |
SequenceI copyTo = toSeq; |
2449 |
21 |
while (copyTo.getDatasetSequence() != null) |
2450 |
|
{ |
2451 |
9 |
copyTo = copyTo.getDatasetSequence(); |
2452 |
|
} |
2453 |
12 |
if (fromSeq == copyTo || fromSeq.getDatasetSequence() == copyTo) |
2454 |
|
{ |
2455 |
0 |
return 0; |
2456 |
|
} |
2457 |
|
|
2458 |
|
|
2459 |
|
|
2460 |
|
|
2461 |
12 |
List<SequenceFeature> sfs = select == null |
2462 |
|
? fromSeq.getFeatures().getPositionalFeatures() |
2463 |
|
: fromSeq.getFeatures().getFeaturesByOntology(select); |
2464 |
|
|
2465 |
12 |
int count = 0; |
2466 |
12 |
for (SequenceFeature sf : sfs) |
2467 |
|
{ |
2468 |
14 |
String type = sf.getType(); |
2469 |
14 |
boolean omit = false; |
2470 |
14 |
for (String toOmit : omitting) |
2471 |
|
{ |
2472 |
7 |
if (type.equals(toOmit)) |
2473 |
|
{ |
2474 |
2 |
omit = true; |
2475 |
|
} |
2476 |
|
} |
2477 |
14 |
if (omit) |
2478 |
|
{ |
2479 |
2 |
continue; |
2480 |
|
} |
2481 |
|
|
2482 |
|
|
2483 |
|
|
2484 |
|
|
2485 |
|
|
2486 |
12 |
int start = sf.getBegin(); |
2487 |
12 |
int end = sf.getEnd(); |
2488 |
12 |
int[] mappedTo = mapping.locateInTo(start, end); |
2489 |
|
|
2490 |
|
|
2491 |
|
|
2492 |
|
|
2493 |
12 |
if (mappedTo == null) |
2494 |
|
{ |
2495 |
3 |
mappedTo = mapping.locateInTo(end, end); |
2496 |
3 |
if (mappedTo != null) |
2497 |
|
{ |
2498 |
|
|
2499 |
|
|
2500 |
|
|
2501 |
|
|
2502 |
0 |
mappedTo[0] = 1; |
2503 |
|
} |
2504 |
|
} |
2505 |
12 |
if (mappedTo == null) |
2506 |
|
{ |
2507 |
3 |
mappedTo = mapping.locateInTo(start, start); |
2508 |
3 |
if (mappedTo != null) |
2509 |
|
{ |
2510 |
|
|
2511 |
|
|
2512 |
|
|
2513 |
|
|
2514 |
0 |
mappedTo[1] = toSeq.getLength(); |
2515 |
|
} |
2516 |
|
} |
2517 |
12 |
if (mappedTo != null) |
2518 |
|
{ |
2519 |
9 |
int newBegin = Math.min(mappedTo[0], mappedTo[1]); |
2520 |
9 |
int newEnd = Math.max(mappedTo[0], mappedTo[1]); |
2521 |
9 |
SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, |
2522 |
|
sf.getFeatureGroup(), sf.getScore()); |
2523 |
9 |
copyTo.addSequenceFeature(copy); |
2524 |
9 |
count++; |
2525 |
|
} |
2526 |
|
} |
2527 |
12 |
return count; |
2528 |
|
} |
2529 |
|
|
2530 |
|
|
2531 |
|
|
2532 |
|
|
2533 |
|
|
2534 |
|
|
2535 |
|
|
2536 |
|
|
2537 |
|
@param |
2538 |
|
@param |
2539 |
|
@return |
2540 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
2541 |
21 |
public static MapList mapCdsToProtein(SequenceI dnaSeq,... |
2542 |
|
SequenceI proteinSeq) |
2543 |
|
{ |
2544 |
21 |
List<int[]> ranges = findCdsPositions(dnaSeq); |
2545 |
21 |
int mappedDnaLength = MappingUtils.getLength(ranges); |
2546 |
|
|
2547 |
|
|
2548 |
|
|
2549 |
|
|
2550 |
21 |
int codonRemainder = mappedDnaLength % CODON_LENGTH; |
2551 |
21 |
if (codonRemainder > 0) |
2552 |
|
{ |
2553 |
2 |
mappedDnaLength -= codonRemainder; |
2554 |
2 |
MappingUtils.removeEndPositions(codonRemainder, ranges); |
2555 |
|
} |
2556 |
|
|
2557 |
21 |
int proteinLength = proteinSeq.getLength(); |
2558 |
21 |
int proteinStart = proteinSeq.getStart(); |
2559 |
21 |
int proteinEnd = proteinSeq.getEnd(); |
2560 |
|
|
2561 |
|
|
2562 |
|
|
2563 |
|
|
2564 |
|
|
2565 |
21 |
if (proteinSeq.getCharAt(0) == 'X') |
2566 |
|
{ |
2567 |
|
|
2568 |
1 |
proteinStart++; |
2569 |
1 |
proteinLength--; |
2570 |
|
} |
2571 |
21 |
List<int[]> proteinRange = new ArrayList<>(); |
2572 |
|
|
2573 |
|
|
2574 |
|
|
2575 |
|
|
2576 |
21 |
int codesForResidues = mappedDnaLength / CODON_LENGTH; |
2577 |
21 |
if (codesForResidues == (proteinLength + 1)) |
2578 |
|
{ |
2579 |
|
|
2580 |
|
|
2581 |
2 |
codesForResidues--; |
2582 |
2 |
mappedDnaLength -= CODON_LENGTH; |
2583 |
2 |
MappingUtils.removeEndPositions(CODON_LENGTH, ranges); |
2584 |
|
} |
2585 |
|
|
2586 |
21 |
if (codesForResidues == proteinLength) |
2587 |
|
{ |
2588 |
4 |
proteinRange.add(new int[] { proteinStart, proteinEnd }); |
2589 |
4 |
return new MapList(ranges, proteinRange, CODON_LENGTH, 1); |
2590 |
|
} |
2591 |
17 |
return null; |
2592 |
|
} |
2593 |
|
|
2594 |
|
|
2595 |
|
|
2596 |
|
|
2597 |
|
|
2598 |
|
|
2599 |
|
|
2600 |
|
|
2601 |
|
@param |
2602 |
|
@return |
2603 |
|
|
|
|
| 92.9% |
Uncovered Elements: 2 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
2604 |
23 |
protected static List<int[]> findCdsPositions(SequenceI dnaSeq)... |
2605 |
|
{ |
2606 |
23 |
List<int[]> result = new ArrayList<>(); |
2607 |
|
|
2608 |
23 |
List<SequenceFeature> sfs = dnaSeq.getFeatures() |
2609 |
|
.getFeaturesByOntology(SequenceOntologyI.CDS); |
2610 |
23 |
if (sfs.isEmpty()) |
2611 |
|
{ |
2612 |
15 |
return result; |
2613 |
|
} |
2614 |
8 |
SequenceFeatures.sortFeatures(sfs, true); |
2615 |
|
|
2616 |
8 |
for (SequenceFeature sf : sfs) |
2617 |
|
{ |
2618 |
16 |
int phase = 0; |
2619 |
16 |
try |
2620 |
|
{ |
2621 |
16 |
String s = sf.getPhase(); |
2622 |
16 |
if (s != null) |
2623 |
|
{ |
2624 |
2 |
phase = Integer.parseInt(s); |
2625 |
|
} |
2626 |
|
} catch (NumberFormatException e) |
2627 |
|
{ |
2628 |
|
|
2629 |
|
} |
2630 |
|
|
2631 |
|
|
2632 |
|
|
2633 |
|
|
2634 |
16 |
int begin = sf.getBegin(); |
2635 |
16 |
int end = sf.getEnd(); |
2636 |
16 |
if (result.isEmpty() && phase > 0) |
2637 |
|
{ |
2638 |
2 |
begin += phase; |
2639 |
2 |
if (begin > end) |
2640 |
|
{ |
2641 |
|
|
2642 |
0 |
System.err |
2643 |
|
.println("Error: start phase extends beyond start CDS in " |
2644 |
|
+ dnaSeq.getName()); |
2645 |
|
} |
2646 |
|
} |
2647 |
16 |
result.add(new int[] { begin, end }); |
2648 |
|
} |
2649 |
|
|
2650 |
|
|
2651 |
|
|
2652 |
|
|
2653 |
|
|
2654 |
|
|
2655 |
|
|
2656 |
|
|
2657 |
8 |
Collections.sort(result, IntRangeComparator.ASCENDING); |
2658 |
8 |
return result; |
2659 |
|
} |
2660 |
|
|
2661 |
|
|
2662 |
|
|
2663 |
|
|
2664 |
|
|
2665 |
|
|
2666 |
|
@param |
2667 |
|
@param |
2668 |
|
@param |
2669 |
|
|
2670 |
|
@return |
2671 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 9 |
Complexity Density: 0.43 |
|
2672 |
0 |
public static AlignmentI makeCopyAlignment(SequenceI[] seqs,... |
2673 |
|
SequenceI[] xrefs, AlignmentI dataset) |
2674 |
|
{ |
2675 |
0 |
AlignmentI copy = new Alignment(new Alignment(seqs)); |
2676 |
0 |
copy.setDataset(dataset); |
2677 |
0 |
boolean isProtein = !copy.isNucleotide(); |
2678 |
0 |
SequenceIdMatcher matcher = new SequenceIdMatcher(seqs); |
2679 |
0 |
if (xrefs != null) |
2680 |
|
{ |
2681 |
|
|
2682 |
|
|
2683 |
0 |
for (int ix = 0, nx = xrefs.length; ix < nx; ix++) |
2684 |
|
{ |
2685 |
0 |
SequenceI xref = xrefs[ix]; |
2686 |
0 |
List<DBRefEntry> dbrefs = xref.getDBRefs(); |
2687 |
0 |
if (dbrefs != null) |
2688 |
|
{ |
2689 |
0 |
for (int ir = 0, nir = dbrefs.size(); ir < nir; ir++) |
2690 |
|
{ |
2691 |
0 |
DBRefEntry dbref = dbrefs.get(ir); |
2692 |
0 |
Mapping map = dbref.getMap(); |
2693 |
0 |
SequenceI mto; |
2694 |
0 |
if (map == null || (mto = map.getTo()) == null |
2695 |
|
|| mto.isProtein() != isProtein) |
2696 |
|
{ |
2697 |
0 |
continue; |
2698 |
|
} |
2699 |
0 |
SequenceI mappedTo = mto; |
2700 |
0 |
SequenceI match = matcher.findIdMatch(mappedTo); |
2701 |
0 |
if (match == null) |
2702 |
|
{ |
2703 |
0 |
matcher.add(mappedTo); |
2704 |
0 |
copy.addSequence(mappedTo); |
2705 |
|
} |
2706 |
|
} |
2707 |
|
} |
2708 |
|
} |
2709 |
|
} |
2710 |
0 |
return copy; |
2711 |
|
} |
2712 |
|
|
2713 |
|
|
2714 |
|
|
2715 |
|
|
2716 |
|
|
2717 |
|
|
2718 |
|
|
2719 |
|
|
2720 |
|
|
2721 |
|
@param |
2722 |
|
|
2723 |
|
@param |
2724 |
|
|
2725 |
|
@return |
2726 |
|
|
|
|
| 88.2% |
Uncovered Elements: 4 (34) |
Complexity: 5 |
Complexity Density: 0.19 |
|
2727 |
4 |
public static int alignAs(AlignmentI unaligned, AlignmentI aligned)... |
2728 |
|
{ |
2729 |
|
|
2730 |
|
|
2731 |
|
|
2732 |
4 |
if (alignAsSameSequences(unaligned, aligned)) |
2733 |
|
{ |
2734 |
0 |
return unaligned.getHeight(); |
2735 |
|
} |
2736 |
|
|
2737 |
|
|
2738 |
|
|
2739 |
|
|
2740 |
4 |
List<SequenceI> unmapped = new ArrayList<>(); |
2741 |
4 |
Map<Integer, Map<SequenceI, Character>> columnMap = buildMappedColumnsMap( |
2742 |
|
unaligned, aligned, unmapped); |
2743 |
4 |
int width = columnMap.size(); |
2744 |
4 |
char gap = unaligned.getGapCharacter(); |
2745 |
4 |
int realignedCount = 0; |
2746 |
|
|
2747 |
|
|
2748 |
4 |
for (SequenceI seq : unaligned.getSequences()) |
2749 |
|
{ |
2750 |
8 |
if (!unmapped.contains(seq)) |
2751 |
|
{ |
2752 |
8 |
char[] newSeq = new char[width]; |
2753 |
8 |
Arrays.fill(newSeq, gap); |
2754 |
|
|
2755 |
8 |
int newCol = 0; |
2756 |
8 |
int lastCol = 0; |
2757 |
|
|
2758 |
|
|
2759 |
|
|
2760 |
|
|
2761 |
|
|
2762 |
8 |
for (Integer column : columnMap.keySet()) |
2763 |
|
{ |
2764 |
84 |
Character c = columnMap.get(column).get(seq); |
2765 |
84 |
if (c != null) |
2766 |
|
{ |
2767 |
|
|
2768 |
|
|
2769 |
|
|
2770 |
|
|
2771 |
52 |
newSeq[newCol] = c; |
2772 |
52 |
lastCol = newCol; |
2773 |
|
} |
2774 |
84 |
newCol++; |
2775 |
|
} |
2776 |
|
|
2777 |
|
|
2778 |
|
|
2779 |
|
|
2780 |
8 |
if (lastCol < width) |
2781 |
|
{ |
2782 |
8 |
char[] tmp = new char[lastCol + 1]; |
2783 |
8 |
System.arraycopy(newSeq, 0, tmp, 0, lastCol + 1); |
2784 |
8 |
newSeq = tmp; |
2785 |
|
} |
2786 |
|
|
2787 |
8 |
seq.setSequence(String.valueOf(newSeq)); |
2788 |
8 |
realignedCount++; |
2789 |
|
} |
2790 |
|
} |
2791 |
4 |
return realignedCount; |
2792 |
|
} |
2793 |
|
|
2794 |
|
|
2795 |
|
|
2796 |
|
|
2797 |
|
|
2798 |
|
|
2799 |
|
@param |
2800 |
|
|
2801 |
|
@param |
2802 |
|
|
2803 |
|
|
2804 |
|
@return |
2805 |
|
|
|
|
| 88.4% |
Uncovered Elements: 5 (43) |
Complexity: 7 |
Complexity Density: 0.21 |
|
2806 |
8 |
static boolean alignAsSameSequences(AlignmentI unaligned,... |
2807 |
|
AlignmentI aligned) |
2808 |
|
{ |
2809 |
8 |
if (aligned.getDataset() == null || unaligned.getDataset() == null) |
2810 |
|
{ |
2811 |
0 |
return false; |
2812 |
|
} |
2813 |
|
|
2814 |
|
|
2815 |
8 |
Map<SequenceI, List<SequenceI>> alignedDatasets = new HashMap<>(); |
2816 |
8 |
for (SequenceI seq : aligned.getSequences()) |
2817 |
|
{ |
2818 |
19 |
SequenceI ds = seq.getDatasetSequence(); |
2819 |
19 |
if (alignedDatasets.get(ds) == null) |
2820 |
|
{ |
2821 |
18 |
alignedDatasets.put(ds, new ArrayList<SequenceI>()); |
2822 |
|
} |
2823 |
19 |
alignedDatasets.get(ds).add(seq); |
2824 |
|
} |
2825 |
|
|
2826 |
|
|
2827 |
|
|
2828 |
|
|
2829 |
|
|
2830 |
|
|
2831 |
8 |
int leftmost = Integer.MAX_VALUE; |
2832 |
8 |
for (SequenceI seq : unaligned.getSequences()) |
2833 |
|
{ |
2834 |
14 |
final SequenceI ds = seq.getDatasetSequence(); |
2835 |
14 |
if (!alignedDatasets.containsKey(ds)) |
2836 |
|
{ |
2837 |
5 |
return false; |
2838 |
|
} |
2839 |
9 |
SequenceI alignedSeq = alignedDatasets.get(ds).get(0); |
2840 |
9 |
int startCol = alignedSeq.findIndex(seq.getStart()); |
2841 |
9 |
leftmost = Math.min(leftmost, startCol); |
2842 |
|
} |
2843 |
|
|
2844 |
|
|
2845 |
|
|
2846 |
|
|
2847 |
|
|
2848 |
|
|
2849 |
3 |
final char gapCharacter = aligned.getGapCharacter(); |
2850 |
3 |
for (SequenceI seq : unaligned.getSequences()) |
2851 |
|
{ |
2852 |
7 |
List<SequenceI> alignedSequences = alignedDatasets |
2853 |
|
.get(seq.getDatasetSequence()); |
2854 |
7 |
if (alignedSequences.isEmpty()) |
2855 |
|
{ |
2856 |
|
|
2857 |
|
|
2858 |
|
|
2859 |
0 |
continue; |
2860 |
|
} |
2861 |
7 |
SequenceI alignedSeq = alignedSequences.get(0); |
2862 |
|
|
2863 |
|
|
2864 |
|
|
2865 |
|
|
2866 |
|
|
2867 |
7 |
int startCol = alignedSeq.findIndex(seq.getStart()); |
2868 |
7 |
int endCol = alignedSeq.findIndex(seq.getEnd()); |
2869 |
7 |
char[] seqchars = new char[endCol - leftmost + 1]; |
2870 |
7 |
Arrays.fill(seqchars, gapCharacter); |
2871 |
7 |
char[] toCopy = alignedSeq.getSequence(startCol - 1, endCol); |
2872 |
7 |
System.arraycopy(toCopy, 0, seqchars, startCol - leftmost, |
2873 |
|
toCopy.length); |
2874 |
7 |
seq.setSequence(String.valueOf(seqchars)); |
2875 |
7 |
if (alignedSequences.size() > 0) |
2876 |
|
{ |
2877 |
|
|
2878 |
7 |
alignedSequences.remove(0); |
2879 |
|
} |
2880 |
|
} |
2881 |
|
|
2882 |
|
|
2883 |
|
|
2884 |
|
|
2885 |
3 |
new RemoveGapColCommand("", unaligned.getSequencesArray(), 0, |
2886 |
|
unaligned.getWidth() - 1, unaligned); |
2887 |
|
|
2888 |
3 |
return true; |
2889 |
|
} |
2890 |
|
|
2891 |
|
|
2892 |
|
|
2893 |
|
|
2894 |
|
|
2895 |
|
@param |
2896 |
|
@param |
2897 |
|
@param |
2898 |
|
@return |
2899 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
2900 |
4 |
static SortedMap<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(... |
2901 |
|
AlignmentI unaligned, AlignmentI aligned, |
2902 |
|
List<SequenceI> unmapped) |
2903 |
|
{ |
2904 |
|
|
2905 |
|
|
2906 |
|
|
2907 |
|
|
2908 |
|
|
2909 |
4 |
SortedMap<Integer, Map<SequenceI, Character>> map = new TreeMap<>(); |
2910 |
|
|
2911 |
|
|
2912 |
|
|
2913 |
|
|
2914 |
4 |
unmapped.addAll(unaligned.getSequences()); |
2915 |
|
|
2916 |
4 |
List<AlignedCodonFrame> mappings = aligned.getCodonFrames(); |
2917 |
|
|
2918 |
4 |
for (SequenceI seq : unaligned.getSequences()) |
2919 |
|
{ |
2920 |
8 |
for (AlignedCodonFrame mapping : mappings) |
2921 |
|
{ |
2922 |
12 |
SequenceI fromSeq = mapping.findAlignedSequence(seq, aligned); |
2923 |
12 |
if (fromSeq != null) |
2924 |
|
{ |
2925 |
8 |
Mapping seqMap = mapping.getMappingBetween(fromSeq, seq); |
2926 |
8 |
if (addMappedPositions(seq, fromSeq, seqMap, map)) |
2927 |
|
{ |
2928 |
8 |
unmapped.remove(seq); |
2929 |
|
} |
2930 |
|
} |
2931 |
|
} |
2932 |
|
} |
2933 |
4 |
return map; |
2934 |
|
} |
2935 |
|
|
2936 |
|
|
2937 |
|
|
2938 |
|
|
2939 |
|
|
2940 |
|
|
2941 |
|
|
2942 |
|
|
2943 |
|
@param |
2944 |
|
|
2945 |
|
@param |
2946 |
|
|
2947 |
|
@param |
2948 |
|
|
2949 |
|
@param |
2950 |
|
|
2951 |
|
|
2952 |
|
@return |
2953 |
|
|
|
|
| 85% |
Uncovered Elements: 6 (40) |
Complexity: 11 |
Complexity Density: 0.46 |
|
2954 |
10 |
static boolean addMappedPositions(SequenceI seq, SequenceI fromSeq,... |
2955 |
|
Mapping seqMap, Map<Integer, Map<SequenceI, Character>> map) |
2956 |
|
{ |
2957 |
10 |
if (seqMap == null) |
2958 |
|
{ |
2959 |
0 |
return false; |
2960 |
|
} |
2961 |
|
|
2962 |
|
|
2963 |
|
|
2964 |
|
|
2965 |
10 |
if (seqMap.getTo() == fromSeq.getDatasetSequence()) |
2966 |
|
{ |
2967 |
2 |
seqMap = new Mapping(seq.getDatasetSequence(), |
2968 |
|
seqMap.getMap().getInverse()); |
2969 |
|
} |
2970 |
|
|
2971 |
10 |
int toStart = seq.getStart(); |
2972 |
|
|
2973 |
|
|
2974 |
|
|
2975 |
|
|
2976 |
10 |
for (int[] fromRange : seqMap.getMap().getFromRanges()) |
2977 |
|
{ |
2978 |
26 |
for (int i = 0; i < fromRange.length - 1; i += 2) |
2979 |
|
{ |
2980 |
13 |
boolean forward = fromRange[i + 1] >= fromRange[i]; |
2981 |
|
|
2982 |
|
|
2983 |
|
|
2984 |
|
|
2985 |
13 |
int[] range = seqMap.locateMappedRange(fromRange[i], |
2986 |
|
fromRange[i + 1]); |
2987 |
13 |
if (range == null) |
2988 |
|
{ |
2989 |
0 |
jalview.bin.Console.errPrintln("Error in mapping " + seqMap |
2990 |
|
+ " from " + fromSeq.getName()); |
2991 |
0 |
return false; |
2992 |
|
} |
2993 |
13 |
int fromCol = fromSeq.findIndex(fromRange[i]); |
2994 |
13 |
int mappedCharPos = range[0]; |
2995 |
|
|
2996 |
|
|
2997 |
|
|
2998 |
|
|
2999 |
|
|
3000 |
|
|
3001 |
|
|
3002 |
96 |
while (mappedCharPos <= range[1] && fromCol <= fromSeq.getLength() |
3003 |
|
&& fromCol >= 0) |
3004 |
|
{ |
3005 |
83 |
if (!Comparison.isGap(fromSeq.getCharAt(fromCol - 1))) |
3006 |
|
{ |
3007 |
|
|
3008 |
|
|
3009 |
|
|
3010 |
|
|
3011 |
64 |
Map<SequenceI, Character> seqsMap = map.get(fromCol); |
3012 |
64 |
if (seqsMap == null) |
3013 |
|
{ |
3014 |
54 |
seqsMap = new HashMap<>(); |
3015 |
54 |
map.put(fromCol, seqsMap); |
3016 |
|
} |
3017 |
64 |
seqsMap.put(seq, seq.getCharAt(mappedCharPos - toStart)); |
3018 |
64 |
mappedCharPos++; |
3019 |
|
} |
3020 |
83 |
fromCol += (forward ? 1 : -1); |
3021 |
|
} |
3022 |
|
} |
3023 |
|
} |
3024 |
10 |
return true; |
3025 |
|
} |
3026 |
|
|
3027 |
|
|
3028 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
3029 |
0 |
public static boolean looksLikeEnsembl(AlignmentI alignment)... |
3030 |
|
{ |
3031 |
0 |
for (SequenceI seq : alignment.getSequences()) |
3032 |
|
{ |
3033 |
0 |
String name = seq.getName(); |
3034 |
0 |
if (!name.startsWith("ENSG") && !name.startsWith("ENST")) |
3035 |
|
{ |
3036 |
0 |
return false; |
3037 |
|
} |
3038 |
|
} |
3039 |
0 |
return true; |
3040 |
|
} |
3041 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
3042 |
5 |
public static boolean isSecondaryStructurePresent(... |
3043 |
|
AlignmentAnnotation[] annotations) |
3044 |
|
{ |
3045 |
5 |
boolean ssPresent = false; |
3046 |
|
|
3047 |
5 |
for (AlignmentAnnotation aa : annotations) |
3048 |
|
{ |
3049 |
5 |
if (ssPresent) |
3050 |
|
{ |
3051 |
0 |
break; |
3052 |
|
} |
3053 |
|
|
3054 |
5 |
if (Constants.SECONDARY_STRUCTURE_LABELS.containsKey(aa.label)) |
3055 |
|
{ |
3056 |
3 |
ssPresent = true; |
3057 |
3 |
break; |
3058 |
|
} |
3059 |
|
} |
3060 |
|
|
3061 |
5 |
return ssPresent; |
3062 |
|
|
3063 |
|
} |
3064 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
3065 |
0 |
public static Color getSecondaryStructureAnnotationColour(char symbol)... |
3066 |
|
{ |
3067 |
|
|
3068 |
0 |
if (symbol == Constants.COIL) |
3069 |
|
{ |
3070 |
0 |
return Color.gray; |
3071 |
|
} |
3072 |
0 |
if (symbol == Constants.SHEET) |
3073 |
|
{ |
3074 |
0 |
return Color.green; |
3075 |
|
} |
3076 |
0 |
if (symbol == Constants.HELIX) |
3077 |
|
{ |
3078 |
0 |
return Color.red; |
3079 |
|
} |
3080 |
|
|
3081 |
0 |
return Color.white; |
3082 |
|
} |
3083 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
3084 |
19832 |
public static char findSSAnnotationForGivenSeqposition(... |
3085 |
|
AlignmentAnnotation aa, int seqPosition) |
3086 |
|
{ |
3087 |
19832 |
char ss = '*'; |
3088 |
|
|
3089 |
19832 |
if (aa != null) |
3090 |
|
{ |
3091 |
19832 |
if (aa.getAnnotationForPosition(seqPosition) != null) |
3092 |
|
{ |
3093 |
6340 |
Annotation a = aa.getAnnotationForPosition(seqPosition); |
3094 |
6340 |
ss = a.secondaryStructure; |
3095 |
|
|
3096 |
|
|
3097 |
6340 |
if (ss == ' ' || ss == '-') |
3098 |
|
{ |
3099 |
0 |
ss = Constants.COIL; |
3100 |
|
} |
3101 |
|
} |
3102 |
|
else |
3103 |
|
{ |
3104 |
13492 |
ss = Constants.COIL; |
3105 |
|
} |
3106 |
|
} |
3107 |
|
|
3108 |
19832 |
return ss; |
3109 |
|
} |
3110 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
3111 |
617 |
public static List<String> extractSSSourceInAlignmentAnnotation(... |
3112 |
|
AlignmentAnnotation[] annotations) |
3113 |
|
{ |
3114 |
|
|
3115 |
617 |
List<String> ssSources = new ArrayList<>(); |
3116 |
617 |
Set<String> addedSources = new HashSet<>(); |
3117 |
|
|
3118 |
|
|
3119 |
617 |
if (annotations == null) |
3120 |
|
{ |
3121 |
0 |
return ssSources; |
3122 |
|
} |
3123 |
|
|
3124 |
617 |
for (AlignmentAnnotation aa : annotations) |
3125 |
|
{ |
3126 |
|
|
3127 |
2106 |
String ssSource = extractSSSourceFromAnnotationDescription(aa); |
3128 |
|
|
3129 |
2106 |
if (ssSource != null && !addedSources.contains(ssSource)) |
3130 |
|
{ |
3131 |
26 |
ssSources.add(ssSource); |
3132 |
26 |
addedSources.add(ssSource); |
3133 |
|
} |
3134 |
|
|
3135 |
|
} |
3136 |
617 |
Collections.sort(ssSources); |
3137 |
|
|
3138 |
617 |
return ssSources; |
3139 |
|
|
3140 |
|
} |
3141 |
|
|
|
|
| 65.2% |
Uncovered Elements: 16 (46) |
Complexity: 15 |
Complexity Density: 0.58 |
|
3142 |
14605 |
public static String extractSSSourceFromAnnotationDescription(... |
3143 |
|
AlignmentAnnotation aa) |
3144 |
|
{ |
3145 |
|
|
3146 |
14605 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3147 |
|
{ |
3148 |
|
|
3149 |
16639 |
if (label.equals(aa.label)) |
3150 |
|
{ |
3151 |
|
|
3152 |
12571 |
if (aa.getProperty(Constants.SS_PROVIDER_PROPERTY) != null) |
3153 |
|
{ |
3154 |
|
|
3155 |
0 |
return aa.getProperty(Constants.SS_PROVIDER_PROPERTY); |
3156 |
|
|
3157 |
|
} |
3158 |
|
|
3159 |
|
|
3160 |
12571 |
if (Constants.SS_ANNOTATION_FROM_JPRED_LABEL.equals(aa.label)) |
3161 |
|
{ |
3162 |
|
|
3163 |
0 |
return (Constants.SECONDARY_STRUCTURE_LABELS.get(aa.label)); |
3164 |
|
|
3165 |
|
} |
3166 |
|
|
3167 |
|
|
3168 |
12571 |
if (Constants.SS_ANNOTATION_LABEL.equals(aa.label) |
3169 |
|
&& aa.description != null |
3170 |
|
&& Constants.SS_ANNOTATION_LABEL.equals(aa.description)) |
3171 |
|
{ |
3172 |
|
|
3173 |
0 |
return (Constants.SECONDARY_STRUCTURE_LABELS.get(aa.label)); |
3174 |
|
|
3175 |
|
} |
3176 |
|
|
3177 |
|
|
3178 |
12571 |
if (aa.sequenceRef == null) |
3179 |
|
{ |
3180 |
4 |
return null; |
3181 |
|
} |
3182 |
12567 |
else if (aa.sequenceRef.getDatasetSequence() == null) |
3183 |
|
{ |
3184 |
0 |
return null; |
3185 |
|
} |
3186 |
12567 |
Vector<PDBEntry> pdbEntries = aa.sequenceRef.getDatasetSequence() |
3187 |
|
.getAllPDBEntries(); |
3188 |
|
|
3189 |
|
|
3190 |
12567 |
for (PDBEntry entry : pdbEntries) |
3191 |
|
{ |
3192 |
|
|
3193 |
12567 |
String entryProvider = entry.getProvider(); |
3194 |
12567 |
if (entryProvider == null) |
3195 |
|
{ |
3196 |
|
|
3197 |
|
|
3198 |
12567 |
entryProvider = "PDB"; |
3199 |
|
} |
3200 |
|
|
3201 |
|
|
3202 |
|
|
3203 |
|
|
3204 |
12567 |
String entryID = entry.getId(); |
3205 |
12567 |
int index = entryID.indexOf(':'); |
3206 |
|
|
3207 |
|
|
3208 |
12567 |
if (index != -1) |
3209 |
|
{ |
3210 |
|
|
3211 |
|
|
3212 |
0 |
entryID = entryID.substring(0, index); |
3213 |
|
|
3214 |
|
} |
3215 |
|
|
3216 |
|
|
3217 |
|
|
3218 |
12567 |
if (entryProvider == "PDB" && aa.description.toLowerCase() |
3219 |
|
.contains("secondary structure for " |
3220 |
|
+ entryID.toLowerCase())) |
3221 |
|
{ |
3222 |
|
|
3223 |
12567 |
return entryProvider; |
3224 |
|
|
3225 |
|
} |
3226 |
|
|
3227 |
0 |
else if (entryProvider != "PDB" && aa.description.toLowerCase() |
3228 |
|
.contains(entryID.toLowerCase())) |
3229 |
|
{ |
3230 |
|
|
3231 |
0 |
return entryProvider; |
3232 |
|
|
3233 |
|
} |
3234 |
|
|
3235 |
|
} |
3236 |
|
} |
3237 |
|
} |
3238 |
|
|
3239 |
2034 |
return null; |
3240 |
|
|
3241 |
|
} |
3242 |
|
|
3243 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
3244 |
287156 |
public static List<AlignmentAnnotation> getAlignmentAnnotationForSource(... |
3245 |
|
SequenceI seq, String ssSource) |
3246 |
|
{ |
3247 |
|
|
3248 |
287156 |
List<AlignmentAnnotation> ssAnnots = new ArrayList<AlignmentAnnotation>(); |
3249 |
287156 |
for (String ssLabel : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3250 |
|
{ |
3251 |
|
|
3252 |
574312 |
AlignmentAnnotation[] aa = seq.getAnnotation(ssLabel); |
3253 |
574312 |
if (aa != null) |
3254 |
|
{ |
3255 |
|
|
3256 |
24998 |
if (Constants.SS_ALL_PROVIDERS.equals(ssSource)) |
3257 |
|
{ |
3258 |
12499 |
ssAnnots.addAll(Arrays.asList(aa)); |
3259 |
12499 |
continue; |
3260 |
|
} |
3261 |
|
|
3262 |
12499 |
for (AlignmentAnnotation annot : aa) |
3263 |
|
{ |
3264 |
|
|
3265 |
12499 |
String ssSourceForAnnot = extractSSSourceFromAnnotationDescription( |
3266 |
|
annot); |
3267 |
12499 |
if (ssSourceForAnnot != null && ssSource.equals(ssSourceForAnnot)) |
3268 |
|
{ |
3269 |
12499 |
ssAnnots.add(annot); |
3270 |
|
} |
3271 |
|
} |
3272 |
|
} |
3273 |
|
} |
3274 |
287156 |
if (ssAnnots.size() > 0) |
3275 |
|
{ |
3276 |
24998 |
return ssAnnots; |
3277 |
|
} |
3278 |
|
|
3279 |
262158 |
return null; |
3280 |
|
|
3281 |
|
} |
3282 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
3283 |
0 |
public static Map<SequenceI, ArrayList<AlignmentAnnotation>> getSequenceAssociatedAlignmentAnnotations(... |
3284 |
|
AlignmentAnnotation[] alignAnnotList, String selectedSSSource) |
3285 |
|
{ |
3286 |
|
|
3287 |
0 |
Map<SequenceI, ArrayList<AlignmentAnnotation>> ssAlignmentAnnotationForSequences = new HashMap<SequenceI, ArrayList<AlignmentAnnotation>>(); |
3288 |
0 |
if (alignAnnotList == null || alignAnnotList.length == 0) |
3289 |
|
{ |
3290 |
0 |
return ssAlignmentAnnotationForSequences; |
3291 |
|
} |
3292 |
|
|
3293 |
0 |
for (AlignmentAnnotation aa : alignAnnotList) |
3294 |
|
{ |
3295 |
0 |
if (aa.sequenceRef == null) |
3296 |
|
{ |
3297 |
0 |
continue; |
3298 |
|
} |
3299 |
|
|
3300 |
0 |
if (isSecondaryStructureFrom(selectedSSSource, aa)) |
3301 |
|
{ |
3302 |
0 |
ssAlignmentAnnotationForSequences |
3303 |
|
.computeIfAbsent(aa.sequenceRef.getDatasetSequence(), |
3304 |
|
k -> new ArrayList<>()) |
3305 |
|
.add(aa); |
3306 |
|
} |
3307 |
|
} |
3308 |
|
|
3309 |
0 |
return ssAlignmentAnnotationForSequences; |
3310 |
|
|
3311 |
|
} |
3312 |
|
|
3313 |
|
|
3314 |
|
|
3315 |
|
@param |
3316 |
|
@param |
3317 |
|
@return |
3318 |
|
|
3319 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
3320 |
0 |
public static boolean isSecondaryStructureFrom(String selectedSSSource,... |
3321 |
|
AlignmentAnnotation aa) |
3322 |
|
{ |
3323 |
|
|
3324 |
0 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3325 |
|
{ |
3326 |
|
|
3327 |
0 |
if (label.equals(aa.label)) |
3328 |
|
{ |
3329 |
|
|
3330 |
0 |
if (selectedSSSource.equals(Constants.SS_ALL_PROVIDERS)) |
3331 |
|
{ |
3332 |
0 |
return true; |
3333 |
|
} |
3334 |
0 |
String ssSource = AlignmentUtils |
3335 |
|
.extractSSSourceFromAnnotationDescription(aa); |
3336 |
0 |
if (ssSource != null && ssSource.equals(selectedSSSource)) |
3337 |
|
{ |
3338 |
0 |
return true; |
3339 |
|
} |
3340 |
|
} |
3341 |
|
} |
3342 |
0 |
return false; |
3343 |
|
} |
3344 |
|
|
3345 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
3346 |
0 |
public static String getSecondaryStructureProviderKey(String providerValue) {... |
3347 |
0 |
for (Map.Entry<String, String> entry : Constants.STRUCTURE_PROVIDERS.entrySet()) { |
3348 |
0 |
if (entry.getValue().equals(providerValue)) { |
3349 |
0 |
return entry.getKey(); |
3350 |
|
} |
3351 |
|
} |
3352 |
0 |
return null; |
3353 |
|
} |
3354 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
3355 |
0 |
public static String reduceLabelLength(String label) {... |
3356 |
|
|
3357 |
0 |
String[] parts = label.split(" \\| "); |
3358 |
|
|
3359 |
|
|
3360 |
0 |
String reducedLabel = Arrays.stream(parts) |
3361 |
|
.map(fullName -> Constants.STRUCTURE_PROVIDERS.entrySet().stream() |
3362 |
|
.filter(entry -> entry.getValue().equals(fullName)) |
3363 |
|
.map(Map.Entry::getKey) |
3364 |
|
.findFirst() |
3365 |
|
.orElse(fullName)) |
3366 |
|
.collect(Collectors.joining(" | ")); |
3367 |
|
|
3368 |
0 |
return reducedLabel; |
3369 |
|
} |
3370 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
3371 |
0 |
public static Color getSecondaryStructureProviderColor(String label) {... |
3372 |
|
|
3373 |
|
|
3374 |
0 |
Color c = Constants.STRUCTURE_PROVIDERS_COLOR.get(label.trim()); |
3375 |
0 |
if(c==null) |
3376 |
0 |
c = Color.BLACK; |
3377 |
0 |
return c; |
3378 |
|
} |
3379 |
|
|
3380 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
3381 |
0 |
public static void assignSecondaryStructureProviderColor(Map<String, Color> secondaryStructureProviderColorMap,... |
3382 |
|
List<String> labels) { |
3383 |
|
|
3384 |
|
|
3385 |
0 |
Set<String> uniqueLabels = new HashSet<>(labels); |
3386 |
|
|
3387 |
0 |
Color[] palette = ColorBrewer.Paired.getColorPalette(uniqueLabels.size()); |
3388 |
|
|
3389 |
|
|
3390 |
0 |
List<Color> colorList = new ArrayList<>(); |
3391 |
0 |
Collections.addAll(colorList, palette); |
3392 |
0 |
Collections.shuffle(colorList); |
3393 |
0 |
int i = 0; |
3394 |
|
|
3395 |
|
|
3396 |
0 |
for (String label : uniqueLabels) { |
3397 |
|
|
3398 |
0 |
secondaryStructureProviderColorMap.put(label.toUpperCase().trim(), colorList.get(i)); |
3399 |
0 |
i++; |
3400 |
|
} |
3401 |
|
} |
3402 |
|
} |