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