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 |
|
|
|
|
| 81.6% |
Uncovered Elements: 266 (1,448) |
Complexity: 352 |
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 |
59568 |
public static int getSequenceIndex(AlignmentI al, SequenceI seq)... |
250 |
|
{ |
251 |
59568 |
int result = -1; |
252 |
59568 |
int pos = 0; |
253 |
59568 |
for (SequenceI alSeq : al.getSequences()) |
254 |
|
{ |
255 |
126272048 |
if (alSeq == seq) |
256 |
|
{ |
257 |
59510 |
result = pos; |
258 |
59510 |
break; |
259 |
|
} |
260 |
126212538 |
pos++; |
261 |
|
} |
262 |
59568 |
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 |
18 |
protected static boolean mappingExists(List<AlignedCodonFrame> mappings,... |
413 |
|
SequenceI aaSeq, SequenceI cdnaSeq) |
414 |
|
{ |
415 |
18 |
if (mappings != null) |
416 |
|
{ |
417 |
18 |
for (AlignedCodonFrame acf : mappings) |
418 |
|
{ |
419 |
14 |
if (cdnaSeq == acf.getDnaForAaSeq(aaSeq)) |
420 |
|
{ |
421 |
0 |
return true; |
422 |
|
} |
423 |
|
} |
424 |
|
} |
425 |
18 |
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 |
31 |
public static MapList mapCdnaToProtein(SequenceI proteinSeq,... |
446 |
|
SequenceI cdnaSeq) |
447 |
|
{ |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
31 |
final SequenceI proteinDataset = proteinSeq.getDatasetSequence(); |
454 |
31 |
char[] aaSeqChars = proteinDataset != null |
455 |
|
? proteinDataset.getSequence() |
456 |
|
: proteinSeq.getSequence(); |
457 |
31 |
final SequenceI cdnaDataset = cdnaSeq.getDatasetSequence(); |
458 |
31 |
char[] cdnaSeqChars = cdnaDataset != null ? cdnaDataset.getSequence() |
459 |
|
: cdnaSeq.getSequence(); |
460 |
31 |
if (aaSeqChars == null || cdnaSeqChars == null) |
461 |
|
{ |
462 |
0 |
return null; |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
31 |
final int mappedLength = CODON_LENGTH * aaSeqChars.length; |
469 |
31 |
int cdnaLength = cdnaSeqChars.length; |
470 |
31 |
int cdnaStart = cdnaSeq.getStart(); |
471 |
31 |
int cdnaEnd = cdnaSeq.getEnd(); |
472 |
31 |
final int proteinStart = proteinSeq.getStart(); |
473 |
31 |
final int proteinEnd = proteinSeq.getEnd(); |
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
31 |
if (cdnaLength != mappedLength && cdnaLength > 2) |
479 |
|
{ |
480 |
16 |
String lastCodon = String.valueOf(cdnaSeqChars, |
481 |
|
cdnaLength - CODON_LENGTH, CODON_LENGTH) |
482 |
|
.toUpperCase(Locale.ROOT); |
483 |
16 |
for (String stop : ResidueProperties.STOP_CODONS) |
484 |
|
{ |
485 |
47 |
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 |
31 |
int startOffset = 0; |
498 |
31 |
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 |
31 |
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 |
16 |
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 |
51 |
protected static boolean translatesAs(char[] cdnaSeqChars, int cdnaStart,... |
536 |
|
char[] aaSeqChars) |
537 |
|
{ |
538 |
51 |
if (cdnaSeqChars == null || aaSeqChars == null) |
539 |
|
{ |
540 |
3 |
return false; |
541 |
|
} |
542 |
|
|
543 |
48 |
int aaPos = 0; |
544 |
48 |
int dnaPos = cdnaStart; |
545 |
161 |
for (; dnaPos < cdnaSeqChars.length - 2 |
546 |
|
&& aaPos < aaSeqChars.length; dnaPos += CODON_LENGTH, aaPos++) |
547 |
|
{ |
548 |
130 |
String codon = String.valueOf(cdnaSeqChars, dnaPos, CODON_LENGTH); |
549 |
130 |
final String translated = ResidueProperties.codonTranslate(codon); |
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
130 |
final char aaRes = aaSeqChars[aaPos]; |
555 |
130 |
if ((translated == null || ResidueProperties.STOP.equals(translated)) |
556 |
|
&& aaRes == '*') |
557 |
|
{ |
558 |
4 |
continue; |
559 |
|
} |
560 |
126 |
if (translated == null || !(aaRes == translated.charAt(0))) |
561 |
|
{ |
562 |
|
|
563 |
|
|
564 |
|
|
565 |
|
|
566 |
17 |
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 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
612 |
8 |
public static boolean alignSequenceAs(SequenceI seq, AlignmentI al,... |
613 |
|
String gap, boolean preserveMappedGaps, |
614 |
|
boolean preserveUnmappedGaps) |
615 |
|
{ |
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
8 |
List<AlignedCodonFrame> mappings = al.getCodonFrame(seq); |
623 |
8 |
if (mappings == null || mappings.isEmpty()) |
624 |
|
{ |
625 |
0 |
return false; |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
8 |
SequenceI alignFrom = null; |
634 |
8 |
AlignedCodonFrame mapping = null; |
635 |
8 |
for (AlignedCodonFrame mp : mappings) |
636 |
|
{ |
637 |
8 |
alignFrom = mp.findAlignedSequence(seq, al); |
638 |
8 |
if (alignFrom != null) |
639 |
|
{ |
640 |
4 |
mapping = mp; |
641 |
4 |
break; |
642 |
|
} |
643 |
|
} |
644 |
|
|
645 |
8 |
if (alignFrom == null) |
646 |
|
{ |
647 |
4 |
return false; |
648 |
|
} |
649 |
4 |
alignSequenceAs(seq, alignFrom, mapping, gap, al.getGapCharacter(), |
650 |
|
preserveMappedGaps, preserveUnmappedGaps); |
651 |
4 |
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 |
19 |
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 |
19 |
int thisSeqPos = 0; |
676 |
19 |
int sourceDsPos = 0; |
677 |
|
|
678 |
19 |
int basesWritten = 0; |
679 |
19 |
char myGapChar = myGap.charAt(0); |
680 |
19 |
int ratio = myGap.length(); |
681 |
|
|
682 |
19 |
int fromOffset = alignFrom.getStart() - 1; |
683 |
19 |
int toOffset = alignTo.getStart() - 1; |
684 |
19 |
int sourceGapMappedLength = 0; |
685 |
19 |
boolean inExon = false; |
686 |
19 |
final int toLength = alignTo.getLength(); |
687 |
19 |
final int fromLength = alignFrom.getLength(); |
688 |
19 |
StringBuilder thisAligned = new StringBuilder(2 * toLength); |
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
205 |
for (int i = 0; i < fromLength; i++) |
694 |
|
{ |
695 |
186 |
char sourceChar = alignFrom.getCharAt(i); |
696 |
186 |
if (sourceChar == sourceGap) |
697 |
|
{ |
698 |
44 |
sourceGapMappedLength += ratio; |
699 |
44 |
continue; |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
142 |
sourceDsPos++; |
706 |
|
|
707 |
142 |
int[] mappedPos = mapping.getMappedRegion(alignTo, alignFrom, |
708 |
|
sourceDsPos + fromOffset); |
709 |
142 |
if (mappedPos == null) |
710 |
|
{ |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
94 |
sourceGapMappedLength += ratio; |
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
94 |
continue; |
720 |
|
} |
721 |
|
|
722 |
48 |
int mappedCodonStart = mappedPos[0]; |
723 |
48 |
int mappedCodonEnd = mappedPos[mappedPos.length - 1]; |
724 |
48 |
StringBuilder trailingCopiedGap = new StringBuilder(); |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
48 |
int intronLength = 0; |
735 |
294 |
while (basesWritten + toOffset < mappedCodonEnd |
736 |
|
&& thisSeqPos < toLength) |
737 |
|
{ |
738 |
246 |
final char c = alignTo.getCharAt(thisSeqPos++); |
739 |
246 |
if (c != myGapChar) |
740 |
|
{ |
741 |
146 |
basesWritten++; |
742 |
146 |
int sourcePosition = basesWritten + toOffset; |
743 |
146 |
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 |
98 |
final boolean startOfCodon = sourcePosition == mappedCodonStart; |
761 |
98 |
int gapsToAdd = calculateGapsToInsert(preserveMappedGaps, |
762 |
|
preserveUnmappedGaps, sourceGapMappedLength, inExon, |
763 |
|
trailingCopiedGap.length(), intronLength, startOfCodon); |
764 |
215 |
for (int k = 0; k < gapsToAdd; k++) |
765 |
|
{ |
766 |
117 |
thisAligned.append(myGapChar); |
767 |
|
} |
768 |
98 |
sourceGapMappedLength = 0; |
769 |
98 |
inExon = true; |
770 |
|
} |
771 |
146 |
thisAligned.append(c); |
772 |
146 |
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 |
129 |
while (thisSeqPos < toLength) |
793 |
|
{ |
794 |
110 |
final char c = alignTo.getCharAt(thisSeqPos++); |
795 |
110 |
if (c != myGapChar || preserveUnmappedGaps) |
796 |
|
{ |
797 |
102 |
thisAligned.append(c); |
798 |
|
} |
799 |
110 |
sourceGapMappedLength--; |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
19 |
if (preserveUnmappedGaps) |
807 |
|
{ |
808 |
24 |
while (sourceGapMappedLength > 0) |
809 |
|
{ |
810 |
12 |
thisAligned.append(myGapChar); |
811 |
12 |
sourceGapMappedLength--; |
812 |
|
} |
813 |
|
} |
814 |
|
|
815 |
|
|
816 |
|
|
817 |
|
|
818 |
19 |
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 |
98 |
protected static int calculateGapsToInsert(boolean preserveMappedGaps,... |
834 |
|
boolean preserveUnmappedGaps, int sourceGapMappedLength, |
835 |
|
boolean inExon, int trailingGapLength, int intronLength, |
836 |
|
final boolean startOfCodon) |
837 |
|
{ |
838 |
98 |
int gapsToAdd = 0; |
839 |
98 |
if (startOfCodon) |
840 |
|
{ |
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
40 |
if (inExon && !preserveMappedGaps) |
848 |
|
{ |
849 |
4 |
trailingGapLength = 0; |
850 |
|
} |
851 |
40 |
if (!inExon && !(preserveMappedGaps && preserveUnmappedGaps)) |
852 |
|
{ |
853 |
19 |
trailingGapLength = 0; |
854 |
|
} |
855 |
40 |
if (inExon) |
856 |
|
{ |
857 |
14 |
gapsToAdd = Math.max(sourceGapMappedLength, trailingGapLength); |
858 |
|
} |
859 |
|
else |
860 |
|
{ |
861 |
26 |
if (intronLength + trailingGapLength <= sourceGapMappedLength) |
862 |
|
{ |
863 |
20 |
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 |
98 |
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 |
5 |
public static int alignProteinAsDna(AlignmentI protein, AlignmentI dna)... |
898 |
|
{ |
899 |
5 |
if (protein.isNucleotide() || !dna.isNucleotide()) |
900 |
|
{ |
901 |
0 |
jalview.bin.Console |
902 |
|
.errPrintln("Wrong alignment type in alignProteinAsDna"); |
903 |
0 |
return 0; |
904 |
|
} |
905 |
5 |
List<SequenceI> unmappedProtein = new ArrayList<>(); |
906 |
5 |
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons = buildCodonColumnsMap( |
907 |
|
protein, dna, unmappedProtein); |
908 |
5 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
1100 |
5 |
protected static Map<AlignedCodon, Map<SequenceI, AlignedCodon>> buildCodonColumnsMap(... |
1101 |
|
AlignmentI protein, AlignmentI dna, |
1102 |
|
List<SequenceI> unmappedProtein) |
1103 |
|
{ |
1104 |
|
|
1105 |
|
|
1106 |
|
|
1107 |
|
|
1108 |
5 |
unmappedProtein.addAll(protein.getSequences()); |
1109 |
|
|
1110 |
5 |
List<AlignedCodonFrame> mappings = protein.getCodonFrames(); |
1111 |
|
|
1112 |
|
|
1113 |
|
|
1114 |
|
|
1115 |
|
|
1116 |
|
|
1117 |
5 |
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons = new TreeMap<>( |
1118 |
|
new CodonComparator()); |
1119 |
|
|
1120 |
5 |
for (SequenceI dnaSeq : dna.getSequences()) |
1121 |
|
{ |
1122 |
30 |
for (AlignedCodonFrame mapping : mappings) |
1123 |
|
{ |
1124 |
516 |
SequenceI prot = mapping.findAlignedSequence(dnaSeq, protein); |
1125 |
516 |
if (prot != null) |
1126 |
|
{ |
1127 |
32 |
Mapping seqMap = mapping.getMappingForSequence(dnaSeq); |
1128 |
32 |
addCodonPositions(dnaSeq, prot, protein.getGapCharacter(), seqMap, |
1129 |
|
alignedCodons); |
1130 |
32 |
unmappedProtein.remove(prot); |
1131 |
|
} |
1132 |
|
} |
1133 |
|
} |
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
5 |
int mappedSequenceCount = protein.getHeight() - unmappedProtein.size(); |
1141 |
5 |
addUnmappedPeptideStarts(alignedCodons, mappedSequenceCount); |
1142 |
|
|
1143 |
5 |
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 |
5 |
protected static void addUnmappedPeptideStarts(... |
1157 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1158 |
|
int mappedSequenceCount) |
1159 |
|
{ |
1160 |
|
|
1161 |
|
|
1162 |
|
|
1163 |
5 |
List<SequenceI> sequencesChecked = new ArrayList<>(); |
1164 |
5 |
AlignedCodon lastCodon = null; |
1165 |
5 |
Map<SequenceI, AlignedCodon> toAdd = new HashMap<>(); |
1166 |
|
|
1167 |
5 |
for (Entry<AlignedCodon, Map<SequenceI, AlignedCodon>> entry : alignedCodons |
1168 |
|
.entrySet()) |
1169 |
|
{ |
1170 |
1913 |
for (Entry<SequenceI, AlignedCodon> sequenceCodon : entry.getValue() |
1171 |
|
.entrySet()) |
1172 |
|
{ |
1173 |
10671 |
SequenceI seq = sequenceCodon.getKey(); |
1174 |
10671 |
if (sequencesChecked.contains(seq)) |
1175 |
|
{ |
1176 |
10641 |
continue; |
1177 |
|
} |
1178 |
30 |
sequencesChecked.add(seq); |
1179 |
30 |
AlignedCodon codon = sequenceCodon.getValue(); |
1180 |
30 |
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 |
30 |
else if (codon.peptideCol == 1) |
1187 |
|
{ |
1188 |
|
|
1189 |
|
|
1190 |
|
|
1191 |
6 |
if (lastCodon != null) |
1192 |
|
{ |
1193 |
5 |
AlignedCodon firstPeptide = new AlignedCodon(lastCodon.pos1, |
1194 |
|
lastCodon.pos2, lastCodon.pos3, |
1195 |
|
String.valueOf(seq.getCharAt(0)), 0); |
1196 |
5 |
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 |
30 |
if (sequencesChecked.size() == mappedSequenceCount) |
1210 |
|
{ |
1211 |
|
|
1212 |
5 |
break; |
1213 |
|
} |
1214 |
|
} |
1215 |
1913 |
lastCodon = entry.getKey(); |
1216 |
|
} |
1217 |
|
|
1218 |
|
|
1219 |
|
|
1220 |
|
|
1221 |
5 |
for (Entry<SequenceI, AlignedCodon> startCodon : toAdd.entrySet()) |
1222 |
|
{ |
1223 |
6 |
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 |
5 |
protected static int alignProteinAs(AlignmentI protein,... |
1240 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1241 |
|
List<SequenceI> unmappedProtein) |
1242 |
|
{ |
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
5 |
int alignedWidth = alignedCodons.size(); |
1247 |
5 |
char[] gaps = new char[alignedWidth]; |
1248 |
5 |
Arrays.fill(gaps, protein.getGapCharacter()); |
1249 |
5 |
Map<SequenceI, char[]> peptides = new HashMap<>(); |
1250 |
5 |
for (SequenceI seq : protein.getSequences()) |
1251 |
|
{ |
1252 |
31 |
if (!unmappedProtein.contains(seq)) |
1253 |
|
{ |
1254 |
30 |
peptides.put(seq, Arrays.copyOf(gaps, gaps.length)); |
1255 |
|
} |
1256 |
|
} |
1257 |
|
|
1258 |
|
|
1259 |
|
|
1260 |
|
|
1261 |
|
|
1262 |
|
|
1263 |
|
|
1264 |
5 |
int column = 0; |
1265 |
5 |
for (AlignedCodon codon : alignedCodons.keySet()) |
1266 |
|
{ |
1267 |
1914 |
final Map<SequenceI, AlignedCodon> columnResidues = alignedCodons |
1268 |
|
.get(codon); |
1269 |
1914 |
for (Entry<SequenceI, AlignedCodon> entry : columnResidues.entrySet()) |
1270 |
|
{ |
1271 |
10682 |
char residue = entry.getValue().product.charAt(0); |
1272 |
10682 |
peptides.get(entry.getKey())[column] = residue; |
1273 |
|
} |
1274 |
1914 |
column++; |
1275 |
|
} |
1276 |
|
|
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
5 |
for (Entry<SequenceI, char[]> entry : peptides.entrySet()) |
1281 |
|
{ |
1282 |
30 |
entry.getKey().setSequence(new String(entry.getValue())); |
1283 |
|
} |
1284 |
|
|
1285 |
5 |
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 |
32 |
static void addCodonPositions(SequenceI dna, SequenceI protein,... |
1305 |
|
char gapChar, Mapping seqMap, |
1306 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons) |
1307 |
|
{ |
1308 |
32 |
Iterator<AlignedCodon> codons = seqMap.getCodonIterator(dna, gapChar); |
1309 |
|
|
1310 |
|
|
1311 |
|
|
1312 |
|
|
1313 |
|
|
1314 |
10716 |
while (codons.hasNext()) |
1315 |
|
{ |
1316 |
10684 |
try |
1317 |
|
{ |
1318 |
10684 |
AlignedCodon codon = codons.next(); |
1319 |
10684 |
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 |
10690 |
protected static void addCodonToMap(... |
1338 |
|
Map<AlignedCodon, Map<SequenceI, AlignedCodon>> alignedCodons, |
1339 |
|
AlignedCodon codon, SequenceI protein) |
1340 |
|
{ |
1341 |
10690 |
Map<SequenceI, AlignedCodon> seqProduct = alignedCodons.get(codon); |
1342 |
10690 |
if (seqProduct == null) |
1343 |
|
{ |
1344 |
1914 |
seqProduct = new HashMap<>(); |
1345 |
1914 |
alignedCodons.put(codon, seqProduct); |
1346 |
|
} |
1347 |
10690 |
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 (22) |
Complexity: 7 |
Complexity Density: 0.58 |
|
1367 |
28 |
public static boolean isMappable(AlignmentI al1, AlignmentI al2)... |
1368 |
|
{ |
1369 |
28 |
if (al1 == null || al2 == null) |
1370 |
|
{ |
1371 |
3 |
return false; |
1372 |
|
} |
1373 |
|
|
1374 |
|
|
1375 |
|
|
1376 |
|
|
1377 |
25 |
if (al1.isNucleotide() == al2.isNucleotide()) |
1378 |
|
{ |
1379 |
14 |
return false; |
1380 |
|
} |
1381 |
11 |
AlignmentI dna = al1.isNucleotide() ? al1 : al2; |
1382 |
11 |
AlignmentI protein = dna == al1 ? al2 : al1; |
1383 |
11 |
List<AlignedCodonFrame> mappings = protein.getCodonFrames(); |
1384 |
11 |
for (SequenceI dnaSeq : dna.getSequences()) |
1385 |
|
{ |
1386 |
12 |
for (SequenceI proteinSeq : protein.getSequences()) |
1387 |
|
{ |
1388 |
12 |
if (isMappable(dnaSeq, proteinSeq, mappings)) |
1389 |
|
{ |
1390 |
2 |
return true; |
1391 |
|
} |
1392 |
|
} |
1393 |
|
} |
1394 |
9 |
return false; |
1395 |
|
} |
1396 |
|
|
1397 |
|
|
1398 |
|
|
1399 |
|
|
1400 |
|
|
1401 |
|
@param |
1402 |
|
@param |
1403 |
|
@param |
1404 |
|
@return |
1405 |
|
|
|
|
| 62.5% |
Uncovered Elements: 6 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
1406 |
12 |
protected static boolean isMappable(SequenceI dnaSeq,... |
1407 |
|
SequenceI proteinSeq, List<AlignedCodonFrame> mappings) |
1408 |
|
{ |
1409 |
12 |
if (dnaSeq == null || proteinSeq == null) |
1410 |
|
{ |
1411 |
0 |
return false; |
1412 |
|
} |
1413 |
|
|
1414 |
12 |
SequenceI dnaDs = dnaSeq.getDatasetSequence() == null ? dnaSeq |
1415 |
|
: dnaSeq.getDatasetSequence(); |
1416 |
12 |
SequenceI proteinDs = proteinSeq.getDatasetSequence() == null |
1417 |
|
? proteinSeq |
1418 |
|
: proteinSeq.getDatasetSequence(); |
1419 |
|
|
1420 |
12 |
for (AlignedCodonFrame mapping : mappings) |
1421 |
|
{ |
1422 |
0 |
if (proteinDs == mapping.getAaForDnaSeq(dnaDs)) |
1423 |
|
{ |
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
0 |
return true; |
1428 |
|
} |
1429 |
|
} |
1430 |
|
|
1431 |
|
|
1432 |
|
|
1433 |
|
|
1434 |
|
|
1435 |
12 |
return mapCdnaToProtein(proteinDs, dnaDs) != null; |
1436 |
|
} |
1437 |
|
|
1438 |
|
|
1439 |
|
|
1440 |
|
|
1441 |
|
|
1442 |
|
|
1443 |
|
|
1444 |
|
@param |
1445 |
|
|
1446 |
|
@param |
1447 |
|
|
1448 |
|
@param |
1449 |
|
|
1450 |
|
@param |
1451 |
|
|
1452 |
|
|
|
|
| 95% |
Uncovered Elements: 2 (40) |
Complexity: 9 |
Complexity Density: 0.38 |
|
1453 |
86 |
public static void findAddableReferenceAnnotations(... |
1454 |
|
List<SequenceI> sequenceScope, Map<String, String> labelForCalcId, |
1455 |
|
final Map<SequenceI, List<AlignmentAnnotation>> candidates, |
1456 |
|
AlignmentI al) |
1457 |
|
{ |
1458 |
86 |
if (sequenceScope == null) |
1459 |
|
{ |
1460 |
1 |
return; |
1461 |
|
} |
1462 |
|
|
1463 |
|
|
1464 |
|
|
1465 |
|
|
1466 |
|
|
1467 |
|
|
1468 |
|
|
1469 |
85 |
for (SequenceI seq : sequenceScope) |
1470 |
|
{ |
1471 |
82 |
SequenceI dataset = seq.getDatasetSequence(); |
1472 |
82 |
if (dataset == null) |
1473 |
|
{ |
1474 |
0 |
continue; |
1475 |
|
} |
1476 |
82 |
AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation(); |
1477 |
82 |
if (datasetAnnotations == null) |
1478 |
|
{ |
1479 |
35 |
continue; |
1480 |
|
} |
1481 |
47 |
final List<AlignmentAnnotation> result = new ArrayList<>(); |
1482 |
47 |
for (AlignmentAnnotation dsann : datasetAnnotations) |
1483 |
|
{ |
1484 |
|
|
1485 |
|
|
1486 |
|
|
1487 |
|
|
1488 |
|
|
1489 |
155 |
final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al |
1490 |
|
.findAnnotations(seq, dsann.getCalcId(), dsann.label); |
1491 |
155 |
boolean found = false; |
1492 |
155 |
if (matchedAlignmentAnnotations != null) |
1493 |
|
{ |
1494 |
152 |
for (AlignmentAnnotation matched : matchedAlignmentAnnotations) |
1495 |
|
{ |
1496 |
135 |
if (dsann.description.equals(matched.description)) |
1497 |
|
{ |
1498 |
54 |
found = true; |
1499 |
54 |
break; |
1500 |
|
} |
1501 |
|
} |
1502 |
|
} |
1503 |
155 |
if (!found) |
1504 |
|
{ |
1505 |
101 |
result.add(dsann); |
1506 |
101 |
if (labelForCalcId != null) |
1507 |
|
{ |
1508 |
10 |
labelForCalcId.put(dsann.getCalcId(), dsann.label); |
1509 |
|
} |
1510 |
|
} |
1511 |
|
} |
1512 |
|
|
1513 |
|
|
1514 |
|
|
1515 |
47 |
if (!result.isEmpty()) |
1516 |
|
{ |
1517 |
43 |
candidates.put(seq, result); |
1518 |
|
} |
1519 |
|
} |
1520 |
|
} |
1521 |
|
|
1522 |
|
|
1523 |
|
|
1524 |
|
|
1525 |
|
|
1526 |
|
|
1527 |
|
@param |
1528 |
|
|
1529 |
|
@param |
1530 |
|
|
1531 |
|
@param |
1532 |
|
|
1533 |
|
|
1534 |
|
|
1535 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1536 |
40 |
public static void addReferenceAnnotations(... |
1537 |
|
Map<SequenceI, List<AlignmentAnnotation>> annotations, |
1538 |
|
final AlignmentI alignment, final SequenceGroup selectionGroup) |
1539 |
|
{ |
1540 |
40 |
for (SequenceI seq : annotations.keySet()) |
1541 |
|
{ |
1542 |
39 |
for (AlignmentAnnotation ann : annotations.get(seq)) |
1543 |
|
{ |
1544 |
95 |
addReferenceAnnotationTo(alignment, seq, ann, selectionGroup); |
1545 |
|
} |
1546 |
|
} |
1547 |
|
} |
1548 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
1549 |
0 |
public static boolean isSSAnnotationPresent(... |
1550 |
|
Map<SequenceI, List<AlignmentAnnotation>> annotations) |
1551 |
|
{ |
1552 |
|
|
1553 |
0 |
for (SequenceI seq : annotations.keySet()) |
1554 |
|
{ |
1555 |
0 |
if (isSecondaryStructurePresent( |
1556 |
|
annotations.get(seq).toArray(new AlignmentAnnotation[0]))) |
1557 |
|
{ |
1558 |
0 |
return true; |
1559 |
|
} |
1560 |
|
} |
1561 |
0 |
return false; |
1562 |
|
} |
1563 |
|
|
1564 |
|
|
1565 |
|
|
1566 |
|
|
1567 |
|
|
1568 |
|
|
1569 |
|
@param |
1570 |
|
@param |
1571 |
|
@param |
1572 |
|
@param |
1573 |
|
|
1574 |
|
|
1575 |
|
|
1576 |
|
@return |
1577 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
1578 |
99 |
public static AlignmentAnnotation addReferenceAnnotationTo(... |
1579 |
|
final AlignmentI alignment, final SequenceI seq, |
1580 |
|
final AlignmentAnnotation ann, final SequenceGroup selectionGroup) |
1581 |
|
{ |
1582 |
99 |
AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann); |
1583 |
99 |
int startRes = 0; |
1584 |
99 |
int endRes = ann.annotations.length; |
1585 |
99 |
if (selectionGroup != null) |
1586 |
|
{ |
1587 |
2 |
startRes = -1 + Math.min(seq.getEnd(), Math.max(seq.getStart(), |
1588 |
|
seq.findPosition(selectionGroup.getStartRes()))); |
1589 |
2 |
endRes = -1 + Math.min(seq.getEnd(), |
1590 |
|
seq.findPosition(selectionGroup.getEndRes())); |
1591 |
|
|
1592 |
|
} |
1593 |
99 |
copyAnn.restrict(startRes, endRes + 0); |
1594 |
|
|
1595 |
|
|
1596 |
|
|
1597 |
|
|
1598 |
|
|
1599 |
99 |
if (!seq.hasAnnotation(ann)) |
1600 |
|
{ |
1601 |
99 |
ContactMatrixI cm = seq.getDatasetSequence().getContactMatrixFor(ann); |
1602 |
99 |
if (cm != null) |
1603 |
|
{ |
1604 |
25 |
seq.addContactListFor(copyAnn, cm); |
1605 |
|
} |
1606 |
99 |
seq.addAlignmentAnnotation(copyAnn); |
1607 |
|
} |
1608 |
|
|
1609 |
99 |
copyAnn.adjustForAlignment(); |
1610 |
|
|
1611 |
99 |
alignment.addAnnotation(copyAnn); |
1612 |
99 |
copyAnn.visible = true; |
1613 |
|
|
1614 |
99 |
return copyAnn; |
1615 |
|
} |
1616 |
|
|
1617 |
|
|
1618 |
|
|
1619 |
|
|
1620 |
|
|
1621 |
|
|
1622 |
|
|
1623 |
|
@param |
1624 |
|
|
1625 |
|
@param |
1626 |
|
|
1627 |
|
|
1628 |
|
@param |
1629 |
|
|
1630 |
|
@param |
1631 |
|
|
1632 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 7 |
Complexity Density: 1.17 |
|
1633 |
5 |
public static void showOrHideSequenceAnnotations(AlignmentI al,... |
1634 |
|
Collection<String> types, List<SequenceI> forSequences, |
1635 |
|
boolean anyType, boolean doShow) |
1636 |
|
{ |
1637 |
5 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1638 |
5 |
if (anns != null) |
1639 |
|
{ |
1640 |
5 |
for (AlignmentAnnotation aa : anns) |
1641 |
|
{ |
1642 |
30 |
if (anyType || types.contains(aa.label)) |
1643 |
|
{ |
1644 |
21 |
if ((aa.sequenceRef != null) && (forSequences == null |
1645 |
|
|| forSequences.contains(aa.sequenceRef))) |
1646 |
|
{ |
1647 |
11 |
aa.visible = doShow; |
1648 |
|
} |
1649 |
|
} |
1650 |
|
} |
1651 |
|
} |
1652 |
|
} |
1653 |
|
|
1654 |
|
|
1655 |
|
|
1656 |
|
|
1657 |
|
@param |
1658 |
|
|
1659 |
|
@param |
1660 |
|
|
1661 |
|
@param |
1662 |
|
|
1663 |
|
|
1664 |
|
@param |
1665 |
|
|
1666 |
|
@param |
1667 |
|
|
1668 |
|
|
1669 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 7 |
Complexity Density: 1.17 |
|
1670 |
0 |
public static void showOrHideAutoCalculatedAnnotationsForGroup(... |
1671 |
|
AlignmentI al, String type, SequenceGroup selectedGroup, |
1672 |
|
boolean anyType, boolean doShow) |
1673 |
|
{ |
1674 |
|
|
1675 |
0 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1676 |
|
|
1677 |
0 |
if (anns != null) |
1678 |
|
{ |
1679 |
0 |
for (AlignmentAnnotation aa : anns) |
1680 |
|
{ |
1681 |
|
|
1682 |
|
|
1683 |
0 |
if ((anyType && aa.label |
1684 |
|
.startsWith(Constants.SECONDARY_STRUCTURE_CONSENSUS_LABEL)) |
1685 |
|
|| aa.label.startsWith(type)) |
1686 |
|
{ |
1687 |
|
|
1688 |
|
|
1689 |
0 |
if (aa.groupRef != null && selectedGroup == aa.groupRef) |
1690 |
|
{ |
1691 |
0 |
aa.visible = doShow; |
1692 |
|
} |
1693 |
|
} |
1694 |
|
} |
1695 |
|
} |
1696 |
|
} |
1697 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
1698 |
0 |
public static AlignmentAnnotation getFirstSequenceAnnotationOfType(... |
1699 |
|
AlignmentI al, int graphType) |
1700 |
|
{ |
1701 |
0 |
AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); |
1702 |
0 |
if (anns != null) |
1703 |
|
{ |
1704 |
0 |
for (AlignmentAnnotation aa : anns) |
1705 |
|
{ |
1706 |
0 |
if (aa.sequenceRef != null && aa.graph == graphType) |
1707 |
0 |
return aa; |
1708 |
|
} |
1709 |
|
} |
1710 |
0 |
return null; |
1711 |
|
} |
1712 |
|
|
1713 |
|
|
1714 |
|
|
1715 |
|
|
1716 |
|
@param |
1717 |
|
@param |
1718 |
|
@return |
1719 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1720 |
52 |
public static boolean haveCrossRef(SequenceI seq1, SequenceI seq2)... |
1721 |
|
{ |
1722 |
|
|
1723 |
|
|
1724 |
52 |
return hasCrossRef(seq1, seq2) || hasCrossRef(seq2, seq1); |
1725 |
|
} |
1726 |
|
|
1727 |
|
|
1728 |
|
|
1729 |
|
|
1730 |
|
|
1731 |
|
@param |
1732 |
|
@param |
1733 |
|
@return |
1734 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
1735 |
108 |
public static boolean hasCrossRef(SequenceI seq1, SequenceI seq2)... |
1736 |
|
{ |
1737 |
108 |
if (seq1 == null || seq2 == null) |
1738 |
|
{ |
1739 |
8 |
return false; |
1740 |
|
} |
1741 |
100 |
String name = seq2.getName(); |
1742 |
100 |
final List<DBRefEntry> xrefs = seq1.getDBRefs(); |
1743 |
100 |
if (xrefs != null) |
1744 |
|
{ |
1745 |
34 |
for (int ix = 0, nx = xrefs.size(); ix < nx; ix++) |
1746 |
|
{ |
1747 |
24 |
DBRefEntry xref = xrefs.get(ix); |
1748 |
24 |
String xrefName = xref.getSource() + "|" + xref.getAccessionId(); |
1749 |
|
|
1750 |
24 |
if (xrefName.equalsIgnoreCase(name)) |
1751 |
|
{ |
1752 |
12 |
return true; |
1753 |
|
} |
1754 |
|
} |
1755 |
|
} |
1756 |
88 |
return false; |
1757 |
|
} |
1758 |
|
|
1759 |
|
|
1760 |
|
|
1761 |
|
|
1762 |
|
|
1763 |
|
|
1764 |
|
|
1765 |
|
|
1766 |
|
@param |
1767 |
|
|
1768 |
|
@param |
1769 |
|
|
1770 |
|
@param |
1771 |
|
|
1772 |
|
|
1773 |
|
@return |
1774 |
|
|
1775 |
|
|
|
|
| 89.1% |
Uncovered Elements: 10 (92) |
Complexity: 16 |
Complexity Density: 0.24 |
|
1776 |
6 |
public static AlignmentI makeCdsAlignment(SequenceI[] dna,... |
1777 |
|
AlignmentI dataset, SequenceI[] products) |
1778 |
|
{ |
1779 |
6 |
if (dataset == null || dataset.getDataset() != null) |
1780 |
|
{ |
1781 |
0 |
throw new IllegalArgumentException( |
1782 |
|
"IMPLEMENTATION ERROR: dataset.getDataset() must be null!"); |
1783 |
|
} |
1784 |
6 |
List<SequenceI> foundSeqs = new ArrayList<>(); |
1785 |
6 |
List<SequenceI> cdsSeqs = new ArrayList<>(); |
1786 |
6 |
List<AlignedCodonFrame> mappings = dataset.getCodonFrames(); |
1787 |
6 |
HashSet<SequenceI> productSeqs = null; |
1788 |
6 |
if (products != null) |
1789 |
|
{ |
1790 |
3 |
productSeqs = new HashSet<>(); |
1791 |
3 |
for (SequenceI seq : products) |
1792 |
|
{ |
1793 |
24 |
productSeqs.add(seq.getDatasetSequence() == null ? seq |
1794 |
|
: seq.getDatasetSequence()); |
1795 |
|
} |
1796 |
|
} |
1797 |
|
|
1798 |
|
|
1799 |
|
|
1800 |
|
|
1801 |
|
|
1802 |
|
|
1803 |
|
|
1804 |
|
|
1805 |
|
|
1806 |
|
|
1807 |
|
|
1808 |
|
|
1809 |
6 |
for (SequenceI dnaSeq : dna) |
1810 |
|
{ |
1811 |
52 |
SequenceI dnaDss = dnaSeq.getDatasetSequence() == null ? dnaSeq |
1812 |
|
: dnaSeq.getDatasetSequence(); |
1813 |
|
|
1814 |
52 |
List<AlignedCodonFrame> seqMappings = MappingUtils |
1815 |
|
.findMappingsForSequence(dnaSeq, mappings); |
1816 |
52 |
for (AlignedCodonFrame mapping : seqMappings) |
1817 |
|
{ |
1818 |
42 |
List<Mapping> mappingsFromSequence = mapping |
1819 |
|
.getMappingsFromSequence(dnaSeq); |
1820 |
|
|
1821 |
42 |
for (Mapping aMapping : mappingsFromSequence) |
1822 |
|
{ |
1823 |
44 |
MapList mapList = aMapping.getMap(); |
1824 |
44 |
if (mapList.getFromRatio() == 1) |
1825 |
|
{ |
1826 |
|
|
1827 |
|
|
1828 |
|
|
1829 |
11 |
continue; |
1830 |
|
} |
1831 |
|
|
1832 |
|
|
1833 |
|
|
1834 |
|
|
1835 |
33 |
SequenceI proteinProduct = aMapping.getTo(); |
1836 |
33 |
if (productSeqs != null && !productSeqs.contains(proteinProduct)) |
1837 |
|
{ |
1838 |
2 |
continue; |
1839 |
|
} |
1840 |
|
|
1841 |
|
|
1842 |
|
|
1843 |
|
|
1844 |
|
|
1845 |
|
|
1846 |
31 |
SequenceI cdsSeq = findCdsForProtein(mappings, dnaSeq, |
1847 |
|
seqMappings, aMapping); |
1848 |
31 |
if (cdsSeq != null) |
1849 |
|
{ |
1850 |
11 |
if (!foundSeqs.contains(cdsSeq)) |
1851 |
|
{ |
1852 |
11 |
foundSeqs.add(cdsSeq); |
1853 |
11 |
SequenceI derivedSequence = cdsSeq.deriveSequence(); |
1854 |
11 |
cdsSeqs.add(derivedSequence); |
1855 |
11 |
if (!dataset.getSequences().contains(cdsSeq)) |
1856 |
|
{ |
1857 |
0 |
dataset.addSequence(cdsSeq); |
1858 |
|
} |
1859 |
|
} |
1860 |
11 |
continue; |
1861 |
|
} |
1862 |
|
|
1863 |
|
|
1864 |
|
|
1865 |
|
|
1866 |
|
|
1867 |
20 |
cdsSeq = makeCdsSequence(dnaSeq.getDatasetSequence(), aMapping, |
1868 |
|
dataset).deriveSequence(); |
1869 |
|
|
1870 |
|
|
1871 |
|
|
1872 |
|
|
1873 |
20 |
SequenceI cdsSeqDss = cdsSeq.getDatasetSequence(); |
1874 |
|
|
1875 |
20 |
cdsSeqs.add(cdsSeq); |
1876 |
|
|
1877 |
|
|
1878 |
|
|
1879 |
|
|
1880 |
20 |
List<int[]> cdsRange = Collections |
1881 |
|
.singletonList(new int[] |
1882 |
|
{ cdsSeq.getStart(), |
1883 |
|
cdsSeq.getLength() + cdsSeq.getStart() - 1 }); |
1884 |
20 |
MapList cdsToProteinMap = new MapList(cdsRange, |
1885 |
|
mapList.getToRanges(), mapList.getFromRatio(), |
1886 |
|
mapList.getToRatio()); |
1887 |
|
|
1888 |
20 |
if (!dataset.getSequences().contains(cdsSeqDss)) |
1889 |
|
{ |
1890 |
|
|
1891 |
|
|
1892 |
|
|
1893 |
|
|
1894 |
|
|
1895 |
20 |
dataset.addSequence(cdsSeqDss); |
1896 |
20 |
AlignedCodonFrame cdsToProteinMapping = new AlignedCodonFrame(); |
1897 |
20 |
cdsToProteinMapping.addMap(cdsSeqDss, proteinProduct, |
1898 |
|
cdsToProteinMap); |
1899 |
|
|
1900 |
|
|
1901 |
|
|
1902 |
|
|
1903 |
20 |
if (!mappings.contains(cdsToProteinMapping)) |
1904 |
|
{ |
1905 |
20 |
mappings.add(cdsToProteinMapping); |
1906 |
|
} |
1907 |
|
} |
1908 |
|
|
1909 |
20 |
propagateDBRefsToCDS(cdsSeqDss, dnaSeq.getDatasetSequence(), |
1910 |
|
proteinProduct, aMapping); |
1911 |
|
|
1912 |
|
|
1913 |
|
|
1914 |
20 |
AlignedCodonFrame dnaToCdsMapping = new AlignedCodonFrame(); |
1915 |
20 |
final MapList dnaToCdsMap = new MapList(mapList.getFromRanges(), |
1916 |
|
cdsRange, 1, 1); |
1917 |
20 |
dnaToCdsMapping.addMap(dnaSeq.getDatasetSequence(), cdsSeqDss, |
1918 |
|
dnaToCdsMap); |
1919 |
20 |
if (!mappings.contains(dnaToCdsMapping)) |
1920 |
|
{ |
1921 |
20 |
mappings.add(dnaToCdsMapping); |
1922 |
|
} |
1923 |
|
|
1924 |
|
|
1925 |
|
|
1926 |
|
|
1927 |
|
|
1928 |
20 |
final MapList cdsToDnaMap = dnaToCdsMap.getInverse(); |
1929 |
20 |
transferGeneLoci(dnaSeq, cdsToDnaMap, cdsSeq); |
1930 |
|
|
1931 |
|
|
1932 |
|
|
1933 |
|
|
1934 |
|
|
1935 |
|
|
1936 |
|
|
1937 |
|
|
1938 |
|
|
1939 |
|
|
1940 |
|
|
1941 |
|
|
1942 |
|
|
1943 |
|
|
1944 |
|
|
1945 |
|
|
1946 |
|
|
1947 |
|
|
1948 |
20 |
List<DBRefEntry> primrefs = dnaDss.getPrimaryDBRefs(); |
1949 |
33 |
for (int ip = 0, np = primrefs.size(); ip < np; ip++) |
1950 |
|
{ |
1951 |
13 |
DBRefEntry primRef = primrefs.get(ip); |
1952 |
|
|
1953 |
|
|
1954 |
|
|
1955 |
|
|
1956 |
13 |
String source = primRef.getSource(); |
1957 |
13 |
String version = primRef.getVersion(); |
1958 |
13 |
DBRefEntry cdsCrossRef = new DBRefEntry(source, |
1959 |
|
source + ":" + version, primRef.getAccessionId()); |
1960 |
13 |
cdsCrossRef |
1961 |
|
.setMap(new Mapping(dnaDss, new MapList(cdsToDnaMap))); |
1962 |
13 |
cdsSeqDss.addDBRef(cdsCrossRef); |
1963 |
|
|
1964 |
13 |
dnaSeq.addDBRef(new DBRefEntry(source, version, |
1965 |
|
cdsSeq.getName(), new Mapping(cdsSeqDss, dnaToCdsMap))); |
1966 |
|
|
1967 |
|
|
1968 |
|
|
1969 |
|
|
1970 |
|
|
1971 |
13 |
DBRefEntry proteinToCdsRef = new DBRefEntry(source, version, |
1972 |
|
cdsSeq.getName()); |
1973 |
|
|
1974 |
13 |
proteinToCdsRef.setMap( |
1975 |
|
new Mapping(cdsSeqDss, cdsToProteinMap.getInverse())); |
1976 |
13 |
proteinProduct.addDBRef(proteinToCdsRef); |
1977 |
|
} |
1978 |
|
|
1979 |
|
|
1980 |
|
|
1981 |
20 |
transferFeatures(dnaSeq, cdsSeq, dnaToCdsMap, null, |
1982 |
|
SequenceOntologyI.CDS); |
1983 |
|
} |
1984 |
|
} |
1985 |
|
} |
1986 |
|
|
1987 |
6 |
AlignmentI cds = new Alignment( |
1988 |
|
cdsSeqs.toArray(new SequenceI[cdsSeqs.size()])); |
1989 |
6 |
cds.setDataset(dataset); |
1990 |
|
|
1991 |
6 |
return cds; |
1992 |
|
} |
1993 |
|
|
1994 |
|
|
1995 |
|
|
1996 |
|
|
1997 |
|
|
1998 |
|
@param |
1999 |
|
@param |
2000 |
|
|
2001 |
|
@param |
2002 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
2003 |
23 |
protected static void transferGeneLoci(SequenceI fromSeq,... |
2004 |
|
MapList targetToFrom, SequenceI targetSeq) |
2005 |
|
{ |
2006 |
23 |
if (targetSeq.getGeneLoci() != null) |
2007 |
|
{ |
2008 |
|
|
2009 |
1 |
return; |
2010 |
|
} |
2011 |
22 |
GeneLociI fromLoci = fromSeq.getGeneLoci(); |
2012 |
22 |
if (fromLoci == null) |
2013 |
|
{ |
2014 |
10 |
return; |
2015 |
|
} |
2016 |
|
|
2017 |
12 |
MapList newMap = targetToFrom.traverse(fromLoci.getMapping()); |
2018 |
|
|
2019 |
12 |
if (newMap != null) |
2020 |
|
{ |
2021 |
12 |
targetSeq.setGeneLoci(fromLoci.getSpeciesId(), |
2022 |
|
fromLoci.getAssemblyId(), fromLoci.getChromosomeId(), newMap); |
2023 |
|
} |
2024 |
|
} |
2025 |
|
|
2026 |
|
|
2027 |
|
|
2028 |
|
|
2029 |
|
|
2030 |
|
|
2031 |
|
@param |
2032 |
|
|
2033 |
|
@param |
2034 |
|
|
2035 |
|
@param |
2036 |
|
|
2037 |
|
@param |
2038 |
|
|
2039 |
|
@return |
2040 |
|
|
|
|
| 93.5% |
Uncovered Elements: 2 (31) |
Complexity: 11 |
Complexity Density: 0.58 |
|
2041 |
38 |
static SequenceI findCdsForProtein(List<AlignedCodonFrame> mappings,... |
2042 |
|
SequenceI dnaSeq, List<AlignedCodonFrame> seqMappings, |
2043 |
|
Mapping aMapping) |
2044 |
|
{ |
2045 |
|
|
2046 |
|
|
2047 |
|
|
2048 |
|
|
2049 |
38 |
SequenceI seqDss = dnaSeq.getDatasetSequence() == null ? dnaSeq |
2050 |
|
: dnaSeq.getDatasetSequence(); |
2051 |
38 |
SequenceI proteinProduct = aMapping.getTo(); |
2052 |
|
|
2053 |
|
|
2054 |
|
|
2055 |
|
|
2056 |
|
|
2057 |
38 |
int mappedFromLength = MappingUtils |
2058 |
|
.getLength(aMapping.getMap().getFromRanges()); |
2059 |
38 |
int dnaLength = seqDss.getLength(); |
2060 |
38 |
if (mappedFromLength == dnaLength |
2061 |
|
|| mappedFromLength == dnaLength - CODON_LENGTH) |
2062 |
|
{ |
2063 |
|
|
2064 |
|
|
2065 |
|
|
2066 |
|
|
2067 |
4 |
if (seqDss.getFeatures().getFeaturesByOntology(SequenceOntologyI.CDS) |
2068 |
|
.isEmpty()) |
2069 |
|
{ |
2070 |
1 |
return seqDss; |
2071 |
|
} |
2072 |
|
} |
2073 |
|
|
2074 |
|
|
2075 |
|
|
2076 |
|
|
2077 |
|
|
2078 |
37 |
List<AlignedCodonFrame> mappingsToPeptide = MappingUtils |
2079 |
|
.findMappingsForSequence(proteinProduct, mappings); |
2080 |
37 |
for (AlignedCodonFrame acf : mappingsToPeptide) |
2081 |
|
{ |
2082 |
52 |
for (SequenceToSequenceMapping map : acf.getMappings()) |
2083 |
|
{ |
2084 |
276 |
Mapping mapping = map.getMapping(); |
2085 |
276 |
if (mapping != aMapping |
2086 |
|
&& mapping.getMap().getFromRatio() == CODON_LENGTH |
2087 |
|
&& proteinProduct == mapping.getTo() |
2088 |
|
&& seqDss != map.getFromSeq()) |
2089 |
|
{ |
2090 |
15 |
mappedFromLength = MappingUtils |
2091 |
|
.getLength(mapping.getMap().getFromRanges()); |
2092 |
15 |
if (mappedFromLength == map.getFromSeq().getLength()) |
2093 |
|
{ |
2094 |
|
|
2095 |
|
|
2096 |
|
|
2097 |
|
|
2098 |
|
|
2099 |
15 |
SequenceI cdsSeq = map.getFromSeq(); |
2100 |
|
|
2101 |
|
|
2102 |
15 |
List<AlignedCodonFrame> dnaToCdsMaps = MappingUtils |
2103 |
|
.findMappingsForSequence(cdsSeq, seqMappings); |
2104 |
15 |
if (!dnaToCdsMaps.isEmpty()) |
2105 |
|
{ |
2106 |
13 |
return cdsSeq; |
2107 |
|
} |
2108 |
|
} |
2109 |
|
} |
2110 |
|
} |
2111 |
|
} |
2112 |
24 |
return null; |
2113 |
|
} |
2114 |
|
|
2115 |
|
|
2116 |
|
|
2117 |
|
|
2118 |
|
|
2119 |
|
|
2120 |
|
@param |
2121 |
|
@param |
2122 |
|
@param |
2123 |
|
|
2124 |
|
|
2125 |
|
|
2126 |
|
@return |
2127 |
|
|
|
|
| 62% |
Uncovered Elements: 19 (50) |
Complexity: 10 |
Complexity Density: 0.31 |
|
2128 |
20 |
static SequenceI makeCdsSequence(SequenceI seq, Mapping mapping,... |
2129 |
|
AlignmentI dataset) |
2130 |
|
{ |
2131 |
|
|
2132 |
|
|
2133 |
|
|
2134 |
|
|
2135 |
20 |
String mapFromId = mapping.getMappedFromId(); |
2136 |
20 |
final String seqId = "CDS|" |
2137 |
20 |
+ (mapFromId != null ? mapFromId : seq.getName()); |
2138 |
|
|
2139 |
20 |
SequenceI newSeq = null; |
2140 |
|
|
2141 |
|
|
2142 |
|
|
2143 |
|
|
2144 |
20 |
char[] seqChars = seq.getSequence(); |
2145 |
20 |
List<int[]> fromRanges = mapping.getMap().getFromRanges(); |
2146 |
20 |
int cdsWidth = MappingUtils.getLength(fromRanges); |
2147 |
20 |
char[] newSeqChars = new char[cdsWidth]; |
2148 |
|
|
2149 |
20 |
int newPos = 0; |
2150 |
20 |
for (int[] range : fromRanges) |
2151 |
|
{ |
2152 |
32 |
if (range[0] <= range[1]) |
2153 |
|
{ |
2154 |
|
|
2155 |
32 |
int length = range[1] - range[0] + 1; |
2156 |
32 |
System.arraycopy(seqChars, range[0] - 1, newSeqChars, newPos, |
2157 |
|
length); |
2158 |
32 |
newPos += length; |
2159 |
|
} |
2160 |
|
else |
2161 |
|
{ |
2162 |
|
|
2163 |
0 |
for (int i = range[0]; i >= range[1]; i--) |
2164 |
|
{ |
2165 |
0 |
newSeqChars[newPos++] = Dna.getComplement(seqChars[i - 1]); |
2166 |
|
} |
2167 |
|
} |
2168 |
|
|
2169 |
32 |
newSeq = new Sequence(seqId, newSeqChars, 1, newPos); |
2170 |
|
} |
2171 |
|
|
2172 |
20 |
if (dataset != null) |
2173 |
|
{ |
2174 |
20 |
SequenceI[] matches = dataset.findSequenceMatch(newSeq.getName()); |
2175 |
20 |
if (matches != null) |
2176 |
|
{ |
2177 |
20 |
boolean matched = false; |
2178 |
20 |
for (SequenceI mtch : matches) |
2179 |
|
{ |
2180 |
3 |
if (mtch.getStart() != newSeq.getStart()) |
2181 |
|
{ |
2182 |
0 |
continue; |
2183 |
|
} |
2184 |
3 |
if (mtch.getEnd() != newSeq.getEnd()) |
2185 |
|
{ |
2186 |
0 |
continue; |
2187 |
|
} |
2188 |
3 |
if (!Arrays.equals(mtch.getSequence(), newSeq.getSequence())) |
2189 |
|
{ |
2190 |
3 |
continue; |
2191 |
|
} |
2192 |
0 |
if (!matched) |
2193 |
|
{ |
2194 |
0 |
matched = true; |
2195 |
0 |
newSeq = mtch; |
2196 |
|
} |
2197 |
|
else |
2198 |
|
{ |
2199 |
0 |
Console.error( |
2200 |
|
"JAL-2154 regression: warning - found (and ignored) a duplicate CDS sequence:" |
2201 |
|
+ mtch.toString()); |
2202 |
|
} |
2203 |
|
} |
2204 |
|
} |
2205 |
|
} |
2206 |
|
|
2207 |
|
|
2208 |
20 |
return newSeq; |
2209 |
|
} |
2210 |
|
|
2211 |
|
|
2212 |
|
|
2213 |
|
|
2214 |
|
|
2215 |
|
@param |
2216 |
|
@param |
2217 |
|
@param |
2218 |
|
@param |
2219 |
|
@return |
2220 |
|
|
|
|
| 88.6% |
Uncovered Elements: 5 (44) |
Complexity: 11 |
Complexity Density: 0.39 |
|
2221 |
20 |
protected static List<DBRefEntry> propagateDBRefsToCDS(SequenceI cdsSeq,... |
2222 |
|
SequenceI contig, SequenceI proteinProduct, Mapping mapping) |
2223 |
|
{ |
2224 |
|
|
2225 |
|
|
2226 |
20 |
List<DBRefEntry> direct = new ArrayList<>(); |
2227 |
20 |
HashSet<String> directSources = new HashSet<>(); |
2228 |
|
|
2229 |
20 |
List<DBRefEntry> refs = contig.getDBRefs(); |
2230 |
20 |
if (refs != null) |
2231 |
|
{ |
2232 |
292 |
for (int ib = 0, nb = refs.size(); ib < nb; ib++) |
2233 |
|
{ |
2234 |
279 |
DBRefEntry dbr = refs.get(ib); |
2235 |
279 |
MapList map; |
2236 |
? |
if (dbr.hasMap() && (map = dbr.getMap().getMap()).isTripletMap()) |
2237 |
|
{ |
2238 |
|
|
2239 |
24 |
if (mapping.getMap().equals(map)) |
2240 |
|
{ |
2241 |
24 |
direct.add(dbr); |
2242 |
24 |
directSources.add(dbr.getSource()); |
2243 |
|
} |
2244 |
|
} |
2245 |
|
} |
2246 |
|
} |
2247 |
20 |
List<DBRefEntry> onSource = DBRefUtils.selectRefs( |
2248 |
|
proteinProduct.getDBRefs(), |
2249 |
|
directSources.toArray(new String[0])); |
2250 |
20 |
List<DBRefEntry> propagated = new ArrayList<>(); |
2251 |
|
|
2252 |
|
|
2253 |
44 |
for (int ic = 0, nc = direct.size(); ic < nc; ic++) |
2254 |
|
{ |
2255 |
24 |
DBRefEntry cdsref = direct.get(ic); |
2256 |
24 |
Mapping m = cdsref.getMap(); |
2257 |
|
|
2258 |
24 |
MapList cdsposmap = new MapList( |
2259 |
|
Arrays.asList(new int[][] |
2260 |
|
{ new int[] { cdsSeq.getStart(), cdsSeq.getEnd() } }), |
2261 |
|
m.getMap().getToRanges(), 3, 1); |
2262 |
24 |
Mapping cdsmap = new Mapping(m.getTo(), m.getMap()); |
2263 |
|
|
2264 |
|
|
2265 |
24 |
DBRefEntry newref = new DBRefEntry(cdsref.getSource(), |
2266 |
|
cdsref.getVersion(), cdsref.getAccessionId(), |
2267 |
|
new Mapping(cdsmap.getTo(), cdsposmap)); |
2268 |
|
|
2269 |
|
|
2270 |
|
|
2271 |
|
|
2272 |
24 |
if (cdsmap.getTo() == null && onSource != null) |
2273 |
|
{ |
2274 |
2 |
List<DBRefEntry> sourceRefs = DBRefUtils.searchRefs(onSource, |
2275 |
|
cdsref.getAccessionId()); |
2276 |
2 |
if (sourceRefs != null) |
2277 |
|
{ |
2278 |
2 |
for (DBRefEntry srcref : sourceRefs) |
2279 |
|
{ |
2280 |
2 |
if (srcref.getSource().equalsIgnoreCase(cdsref.getSource())) |
2281 |
|
{ |
2282 |
|
|
2283 |
|
|
2284 |
2 |
newref.getMap().setTo(proteinProduct); |
2285 |
|
} |
2286 |
|
} |
2287 |
|
} |
2288 |
|
} |
2289 |
24 |
cdsSeq.addDBRef(newref); |
2290 |
24 |
propagated.add(newref); |
2291 |
|
} |
2292 |
20 |
return propagated; |
2293 |
|
} |
2294 |
|
|
2295 |
|
|
2296 |
|
|
2297 |
|
|
2298 |
|
|
2299 |
|
|
2300 |
|
@param |
2301 |
|
@param |
2302 |
|
@param |
2303 |
|
|
2304 |
|
@param |
2305 |
|
|
2306 |
|
|
2307 |
|
@param |
2308 |
|
|
|
|
| 88.7% |
Uncovered Elements: 6 (53) |
Complexity: 12 |
Complexity Density: 0.36 |
|
2309 |
23 |
protected static int transferFeatures(SequenceI fromSeq, SequenceI toSeq,... |
2310 |
|
MapList mapping, String select, String... omitting) |
2311 |
|
{ |
2312 |
23 |
SequenceI copyTo = toSeq; |
2313 |
43 |
while (copyTo.getDatasetSequence() != null) |
2314 |
|
{ |
2315 |
20 |
copyTo = copyTo.getDatasetSequence(); |
2316 |
|
} |
2317 |
23 |
if (fromSeq == copyTo || fromSeq.getDatasetSequence() == copyTo) |
2318 |
|
{ |
2319 |
0 |
return 0; |
2320 |
|
} |
2321 |
|
|
2322 |
|
|
2323 |
|
|
2324 |
|
|
2325 |
23 |
List<SequenceFeature> sfs = select == null |
2326 |
|
? fromSeq.getFeatures().getPositionalFeatures() |
2327 |
|
: fromSeq.getFeatures().getFeaturesByOntology(select); |
2328 |
|
|
2329 |
23 |
int count = 0; |
2330 |
23 |
for (SequenceFeature sf : sfs) |
2331 |
|
{ |
2332 |
9610 |
String type = sf.getType(); |
2333 |
9610 |
boolean omit = false; |
2334 |
9610 |
for (String toOmit : omitting) |
2335 |
|
{ |
2336 |
9603 |
if (type.equals(toOmit)) |
2337 |
|
{ |
2338 |
134 |
omit = true; |
2339 |
|
} |
2340 |
|
} |
2341 |
9610 |
if (omit) |
2342 |
|
{ |
2343 |
134 |
continue; |
2344 |
|
} |
2345 |
|
|
2346 |
|
|
2347 |
|
|
2348 |
|
|
2349 |
|
|
2350 |
9476 |
int start = sf.getBegin(); |
2351 |
9476 |
int end = sf.getEnd(); |
2352 |
9476 |
int[] mappedTo = mapping.locateInTo(start, end); |
2353 |
|
|
2354 |
|
|
2355 |
|
|
2356 |
|
|
2357 |
9476 |
if (mappedTo == null) |
2358 |
|
{ |
2359 |
4447 |
mappedTo = mapping.locateInTo(end, end); |
2360 |
4447 |
if (mappedTo != null) |
2361 |
|
{ |
2362 |
|
|
2363 |
|
|
2364 |
|
|
2365 |
|
|
2366 |
0 |
mappedTo[0] = 1; |
2367 |
|
} |
2368 |
|
} |
2369 |
9476 |
if (mappedTo == null) |
2370 |
|
{ |
2371 |
4447 |
mappedTo = mapping.locateInTo(start, start); |
2372 |
4447 |
if (mappedTo != null) |
2373 |
|
{ |
2374 |
|
|
2375 |
|
|
2376 |
|
|
2377 |
|
|
2378 |
0 |
mappedTo[1] = toSeq.getLength(); |
2379 |
|
} |
2380 |
|
} |
2381 |
9476 |
if (mappedTo != null) |
2382 |
|
{ |
2383 |
5029 |
int newBegin = Math.min(mappedTo[0], mappedTo[1]); |
2384 |
5029 |
int newEnd = Math.max(mappedTo[0], mappedTo[1]); |
2385 |
5029 |
SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, |
2386 |
|
sf.getFeatureGroup(), sf.getScore()); |
2387 |
5029 |
copyTo.addSequenceFeature(copy); |
2388 |
5029 |
count++; |
2389 |
|
} |
2390 |
|
} |
2391 |
23 |
return count; |
2392 |
|
} |
2393 |
|
|
2394 |
|
|
2395 |
|
|
2396 |
|
|
2397 |
|
|
2398 |
|
|
2399 |
|
|
2400 |
|
|
2401 |
|
@param |
2402 |
|
@param |
2403 |
|
@return |
2404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
2405 |
22 |
public static MapList mapCdsToProtein(SequenceI dnaSeq,... |
2406 |
|
SequenceI proteinSeq) |
2407 |
|
{ |
2408 |
22 |
List<int[]> ranges = findCdsPositions(dnaSeq); |
2409 |
22 |
int mappedDnaLength = MappingUtils.getLength(ranges); |
2410 |
|
|
2411 |
|
|
2412 |
|
|
2413 |
|
|
2414 |
22 |
int codonRemainder = mappedDnaLength % CODON_LENGTH; |
2415 |
22 |
if (codonRemainder > 0) |
2416 |
|
{ |
2417 |
2 |
mappedDnaLength -= codonRemainder; |
2418 |
2 |
MappingUtils.removeEndPositions(codonRemainder, ranges); |
2419 |
|
} |
2420 |
|
|
2421 |
22 |
int proteinLength = proteinSeq.getLength(); |
2422 |
22 |
int proteinStart = proteinSeq.getStart(); |
2423 |
22 |
int proteinEnd = proteinSeq.getEnd(); |
2424 |
|
|
2425 |
|
|
2426 |
|
|
2427 |
|
|
2428 |
|
|
2429 |
22 |
if (proteinSeq.getCharAt(0) == 'X') |
2430 |
|
{ |
2431 |
|
|
2432 |
1 |
proteinStart++; |
2433 |
1 |
proteinLength--; |
2434 |
|
} |
2435 |
22 |
List<int[]> proteinRange = new ArrayList<>(); |
2436 |
|
|
2437 |
|
|
2438 |
|
|
2439 |
|
|
2440 |
22 |
int codesForResidues = mappedDnaLength / CODON_LENGTH; |
2441 |
22 |
if (codesForResidues == (proteinLength + 1)) |
2442 |
|
{ |
2443 |
|
|
2444 |
|
|
2445 |
2 |
codesForResidues--; |
2446 |
2 |
mappedDnaLength -= CODON_LENGTH; |
2447 |
2 |
MappingUtils.removeEndPositions(CODON_LENGTH, ranges); |
2448 |
|
} |
2449 |
|
|
2450 |
22 |
if (codesForResidues == proteinLength) |
2451 |
|
{ |
2452 |
4 |
proteinRange.add(new int[] { proteinStart, proteinEnd }); |
2453 |
4 |
return new MapList(ranges, proteinRange, CODON_LENGTH, 1); |
2454 |
|
} |
2455 |
18 |
return null; |
2456 |
|
} |
2457 |
|
|
2458 |
|
|
2459 |
|
|
2460 |
|
|
2461 |
|
|
2462 |
|
|
2463 |
|
|
2464 |
|
|
2465 |
|
@param |
2466 |
|
@return |
2467 |
|
|
|
|
| 92.9% |
Uncovered Elements: 2 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
2468 |
24 |
protected static List<int[]> findCdsPositions(SequenceI dnaSeq)... |
2469 |
|
{ |
2470 |
24 |
List<int[]> result = new ArrayList<>(); |
2471 |
|
|
2472 |
24 |
List<SequenceFeature> sfs = dnaSeq.getFeatures() |
2473 |
|
.getFeaturesByOntology(SequenceOntologyI.CDS); |
2474 |
24 |
if (sfs.isEmpty()) |
2475 |
|
{ |
2476 |
16 |
return result; |
2477 |
|
} |
2478 |
8 |
SequenceFeatures.sortFeatures(sfs, true); |
2479 |
|
|
2480 |
8 |
for (SequenceFeature sf : sfs) |
2481 |
|
{ |
2482 |
16 |
int phase = 0; |
2483 |
16 |
try |
2484 |
|
{ |
2485 |
16 |
String s = sf.getPhase(); |
2486 |
16 |
if (s != null) |
2487 |
|
{ |
2488 |
2 |
phase = Integer.parseInt(s); |
2489 |
|
} |
2490 |
|
} catch (NumberFormatException e) |
2491 |
|
{ |
2492 |
|
|
2493 |
|
} |
2494 |
|
|
2495 |
|
|
2496 |
|
|
2497 |
|
|
2498 |
16 |
int begin = sf.getBegin(); |
2499 |
16 |
int end = sf.getEnd(); |
2500 |
16 |
if (result.isEmpty() && phase > 0) |
2501 |
|
{ |
2502 |
2 |
begin += phase; |
2503 |
2 |
if (begin > end) |
2504 |
|
{ |
2505 |
|
|
2506 |
0 |
System.err |
2507 |
|
.println("Error: start phase extends beyond start CDS in " |
2508 |
|
+ dnaSeq.getName()); |
2509 |
|
} |
2510 |
|
} |
2511 |
16 |
result.add(new int[] { begin, end }); |
2512 |
|
} |
2513 |
|
|
2514 |
|
|
2515 |
|
|
2516 |
|
|
2517 |
|
|
2518 |
|
|
2519 |
|
|
2520 |
|
|
2521 |
8 |
Collections.sort(result, IntRangeComparator.ASCENDING); |
2522 |
8 |
return result; |
2523 |
|
} |
2524 |
|
|
2525 |
|
|
2526 |
|
|
2527 |
|
|
2528 |
|
|
2529 |
|
|
2530 |
|
@param |
2531 |
|
@param |
2532 |
|
@param |
2533 |
|
|
2534 |
|
@return |
2535 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 9 |
Complexity Density: 0.43 |
|
2536 |
0 |
public static AlignmentI makeCopyAlignment(SequenceI[] seqs,... |
2537 |
|
SequenceI[] xrefs, AlignmentI dataset) |
2538 |
|
{ |
2539 |
0 |
AlignmentI copy = new Alignment(new Alignment(seqs)); |
2540 |
0 |
copy.setDataset(dataset); |
2541 |
0 |
boolean isProtein = !copy.isNucleotide(); |
2542 |
0 |
SequenceIdMatcher matcher = new SequenceIdMatcher(seqs); |
2543 |
0 |
if (xrefs != null) |
2544 |
|
{ |
2545 |
|
|
2546 |
|
|
2547 |
0 |
for (int ix = 0, nx = xrefs.length; ix < nx; ix++) |
2548 |
|
{ |
2549 |
0 |
SequenceI xref = xrefs[ix]; |
2550 |
0 |
List<DBRefEntry> dbrefs = xref.getDBRefs(); |
2551 |
0 |
if (dbrefs != null) |
2552 |
|
{ |
2553 |
0 |
for (int ir = 0, nir = dbrefs.size(); ir < nir; ir++) |
2554 |
|
{ |
2555 |
0 |
DBRefEntry dbref = dbrefs.get(ir); |
2556 |
0 |
Mapping map = dbref.getMap(); |
2557 |
0 |
SequenceI mto; |
2558 |
0 |
if (map == null || (mto = map.getTo()) == null |
2559 |
|
|| mto.isProtein() != isProtein) |
2560 |
|
{ |
2561 |
0 |
continue; |
2562 |
|
} |
2563 |
0 |
SequenceI mappedTo = mto; |
2564 |
0 |
SequenceI match = matcher.findIdMatch(mappedTo); |
2565 |
0 |
if (match == null) |
2566 |
|
{ |
2567 |
0 |
matcher.add(mappedTo); |
2568 |
0 |
copy.addSequence(mappedTo); |
2569 |
|
} |
2570 |
|
} |
2571 |
|
} |
2572 |
|
} |
2573 |
|
} |
2574 |
0 |
return copy; |
2575 |
|
} |
2576 |
|
|
2577 |
|
|
2578 |
|
|
2579 |
|
|
2580 |
|
|
2581 |
|
|
2582 |
|
|
2583 |
|
|
2584 |
|
|
2585 |
|
@param |
2586 |
|
|
2587 |
|
@param |
2588 |
|
|
2589 |
|
@return |
2590 |
|
|
|
|
| 88.2% |
Uncovered Elements: 4 (34) |
Complexity: 5 |
Complexity Density: 0.19 |
|
2591 |
4 |
public static int alignAs(AlignmentI unaligned, AlignmentI aligned)... |
2592 |
|
{ |
2593 |
|
|
2594 |
|
|
2595 |
|
|
2596 |
4 |
if (alignAsSameSequences(unaligned, aligned)) |
2597 |
|
{ |
2598 |
0 |
return unaligned.getHeight(); |
2599 |
|
} |
2600 |
|
|
2601 |
|
|
2602 |
|
|
2603 |
|
|
2604 |
4 |
List<SequenceI> unmapped = new ArrayList<>(); |
2605 |
4 |
Map<Integer, Map<SequenceI, Character>> columnMap = buildMappedColumnsMap( |
2606 |
|
unaligned, aligned, unmapped); |
2607 |
4 |
int width = columnMap.size(); |
2608 |
4 |
char gap = unaligned.getGapCharacter(); |
2609 |
4 |
int realignedCount = 0; |
2610 |
|
|
2611 |
|
|
2612 |
4 |
for (SequenceI seq : unaligned.getSequences()) |
2613 |
|
{ |
2614 |
26 |
if (!unmapped.contains(seq)) |
2615 |
|
{ |
2616 |
26 |
char[] newSeq = new char[width]; |
2617 |
26 |
Arrays.fill(newSeq, gap); |
2618 |
|
|
2619 |
26 |
int newCol = 0; |
2620 |
26 |
int lastCol = 0; |
2621 |
|
|
2622 |
|
|
2623 |
|
|
2624 |
|
|
2625 |
|
|
2626 |
26 |
for (Integer column : columnMap.keySet()) |
2627 |
|
{ |
2628 |
58976 |
Character c = columnMap.get(column).get(seq); |
2629 |
58976 |
if (c != null) |
2630 |
|
{ |
2631 |
|
|
2632 |
|
|
2633 |
|
|
2634 |
|
|
2635 |
31986 |
newSeq[newCol] = c; |
2636 |
31986 |
lastCol = newCol; |
2637 |
|
} |
2638 |
58976 |
newCol++; |
2639 |
|
} |
2640 |
|
|
2641 |
|
|
2642 |
|
|
2643 |
|
|
2644 |
26 |
if (lastCol < width) |
2645 |
|
{ |
2646 |
26 |
char[] tmp = new char[lastCol + 1]; |
2647 |
26 |
System.arraycopy(newSeq, 0, tmp, 0, lastCol + 1); |
2648 |
26 |
newSeq = tmp; |
2649 |
|
} |
2650 |
|
|
2651 |
26 |
seq.setSequence(String.valueOf(newSeq)); |
2652 |
26 |
realignedCount++; |
2653 |
|
} |
2654 |
|
} |
2655 |
4 |
return realignedCount; |
2656 |
|
} |
2657 |
|
|
2658 |
|
|
2659 |
|
|
2660 |
|
|
2661 |
|
|
2662 |
|
|
2663 |
|
@param |
2664 |
|
|
2665 |
|
@param |
2666 |
|
|
2667 |
|
|
2668 |
|
@return |
2669 |
|
|
|
|
| 88.4% |
Uncovered Elements: 5 (43) |
Complexity: 7 |
Complexity Density: 0.21 |
|
2670 |
8 |
static boolean alignAsSameSequences(AlignmentI unaligned,... |
2671 |
|
AlignmentI aligned) |
2672 |
|
{ |
2673 |
8 |
if (aligned.getDataset() == null || unaligned.getDataset() == null) |
2674 |
|
{ |
2675 |
0 |
return false; |
2676 |
|
} |
2677 |
|
|
2678 |
|
|
2679 |
8 |
Map<SequenceI, List<SequenceI>> alignedDatasets = new HashMap<>(); |
2680 |
8 |
for (SequenceI seq : aligned.getSequences()) |
2681 |
|
{ |
2682 |
59 |
SequenceI ds = seq.getDatasetSequence(); |
2683 |
59 |
if (alignedDatasets.get(ds) == null) |
2684 |
|
{ |
2685 |
58 |
alignedDatasets.put(ds, new ArrayList<SequenceI>()); |
2686 |
|
} |
2687 |
59 |
alignedDatasets.get(ds).add(seq); |
2688 |
|
} |
2689 |
|
|
2690 |
|
|
2691 |
|
|
2692 |
|
|
2693 |
|
|
2694 |
|
|
2695 |
8 |
int leftmost = Integer.MAX_VALUE; |
2696 |
8 |
for (SequenceI seq : unaligned.getSequences()) |
2697 |
|
{ |
2698 |
14 |
final SequenceI ds = seq.getDatasetSequence(); |
2699 |
14 |
if (!alignedDatasets.containsKey(ds)) |
2700 |
|
{ |
2701 |
5 |
return false; |
2702 |
|
} |
2703 |
9 |
SequenceI alignedSeq = alignedDatasets.get(ds).get(0); |
2704 |
9 |
int startCol = alignedSeq.findIndex(seq.getStart()); |
2705 |
9 |
leftmost = Math.min(leftmost, startCol); |
2706 |
|
} |
2707 |
|
|
2708 |
|
|
2709 |
|
|
2710 |
|
|
2711 |
|
|
2712 |
|
|
2713 |
3 |
final char gapCharacter = aligned.getGapCharacter(); |
2714 |
3 |
for (SequenceI seq : unaligned.getSequences()) |
2715 |
|
{ |
2716 |
7 |
List<SequenceI> alignedSequences = alignedDatasets |
2717 |
|
.get(seq.getDatasetSequence()); |
2718 |
7 |
if (alignedSequences.isEmpty()) |
2719 |
|
{ |
2720 |
|
|
2721 |
|
|
2722 |
|
|
2723 |
0 |
continue; |
2724 |
|
} |
2725 |
7 |
SequenceI alignedSeq = alignedSequences.get(0); |
2726 |
|
|
2727 |
|
|
2728 |
|
|
2729 |
|
|
2730 |
|
|
2731 |
7 |
int startCol = alignedSeq.findIndex(seq.getStart()); |
2732 |
7 |
int endCol = alignedSeq.findIndex(seq.getEnd()); |
2733 |
7 |
char[] seqchars = new char[endCol - leftmost + 1]; |
2734 |
7 |
Arrays.fill(seqchars, gapCharacter); |
2735 |
7 |
char[] toCopy = alignedSeq.getSequence(startCol - 1, endCol); |
2736 |
7 |
System.arraycopy(toCopy, 0, seqchars, startCol - leftmost, |
2737 |
|
toCopy.length); |
2738 |
7 |
seq.setSequence(String.valueOf(seqchars)); |
2739 |
7 |
if (alignedSequences.size() > 0) |
2740 |
|
{ |
2741 |
|
|
2742 |
7 |
alignedSequences.remove(0); |
2743 |
|
} |
2744 |
|
} |
2745 |
|
|
2746 |
|
|
2747 |
|
|
2748 |
|
|
2749 |
3 |
new RemoveGapColCommand("", unaligned.getSequencesArray(), 0, |
2750 |
|
unaligned.getWidth() - 1, unaligned); |
2751 |
|
|
2752 |
3 |
return true; |
2753 |
|
} |
2754 |
|
|
2755 |
|
|
2756 |
|
|
2757 |
|
|
2758 |
|
|
2759 |
|
@param |
2760 |
|
@param |
2761 |
|
@param |
2762 |
|
@return |
2763 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
2764 |
4 |
static SortedMap<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(... |
2765 |
|
AlignmentI unaligned, AlignmentI aligned, |
2766 |
|
List<SequenceI> unmapped) |
2767 |
|
{ |
2768 |
|
|
2769 |
|
|
2770 |
|
|
2771 |
|
|
2772 |
|
|
2773 |
4 |
SortedMap<Integer, Map<SequenceI, Character>> map = new TreeMap<>(); |
2774 |
|
|
2775 |
|
|
2776 |
|
|
2777 |
|
|
2778 |
4 |
unmapped.addAll(unaligned.getSequences()); |
2779 |
|
|
2780 |
4 |
List<AlignedCodonFrame> mappings = aligned.getCodonFrames(); |
2781 |
|
|
2782 |
4 |
for (SequenceI seq : unaligned.getSequences()) |
2783 |
|
{ |
2784 |
26 |
for (AlignedCodonFrame mapping : mappings) |
2785 |
|
{ |
2786 |
510 |
SequenceI fromSeq = mapping.findAlignedSequence(seq, aligned); |
2787 |
510 |
if (fromSeq != null) |
2788 |
|
{ |
2789 |
26 |
Mapping seqMap = mapping.getMappingBetween(fromSeq, seq); |
2790 |
26 |
if (addMappedPositions(seq, fromSeq, seqMap, map)) |
2791 |
|
{ |
2792 |
26 |
unmapped.remove(seq); |
2793 |
|
} |
2794 |
|
} |
2795 |
|
} |
2796 |
|
} |
2797 |
4 |
return map; |
2798 |
|
} |
2799 |
|
|
2800 |
|
|
2801 |
|
|
2802 |
|
|
2803 |
|
|
2804 |
|
|
2805 |
|
|
2806 |
|
|
2807 |
|
@param |
2808 |
|
|
2809 |
|
@param |
2810 |
|
|
2811 |
|
@param |
2812 |
|
|
2813 |
|
@param |
2814 |
|
|
2815 |
|
|
2816 |
|
@return |
2817 |
|
|
|
|
| 80% |
Uncovered Elements: 8 (40) |
Complexity: 11 |
Complexity Density: 0.46 |
|
2818 |
28 |
static boolean addMappedPositions(SequenceI seq, SequenceI fromSeq,... |
2819 |
|
Mapping seqMap, Map<Integer, Map<SequenceI, Character>> map) |
2820 |
|
{ |
2821 |
28 |
if (seqMap == null) |
2822 |
|
{ |
2823 |
0 |
return false; |
2824 |
|
} |
2825 |
|
|
2826 |
|
|
2827 |
|
|
2828 |
|
|
2829 |
28 |
if (seqMap.getTo() == fromSeq.getDatasetSequence()) |
2830 |
|
{ |
2831 |
0 |
seqMap = new Mapping(seq.getDatasetSequence(), |
2832 |
|
seqMap.getMap().getInverse()); |
2833 |
|
} |
2834 |
|
|
2835 |
28 |
int toStart = seq.getStart(); |
2836 |
|
|
2837 |
|
|
2838 |
|
|
2839 |
|
|
2840 |
28 |
for (int[] fromRange : seqMap.getMap().getFromRanges()) |
2841 |
|
{ |
2842 |
62 |
for (int i = 0; i < fromRange.length - 1; i += 2) |
2843 |
|
{ |
2844 |
31 |
boolean forward = fromRange[i + 1] >= fromRange[i]; |
2845 |
|
|
2846 |
|
|
2847 |
|
|
2848 |
|
|
2849 |
31 |
int[] range = seqMap.locateMappedRange(fromRange[i], |
2850 |
|
fromRange[i + 1]); |
2851 |
31 |
if (range == null) |
2852 |
|
{ |
2853 |
0 |
jalview.bin.Console.errPrintln("Error in mapping " + seqMap |
2854 |
|
+ " from " + fromSeq.getName()); |
2855 |
0 |
return false; |
2856 |
|
} |
2857 |
31 |
int fromCol = fromSeq.findIndex(fromRange[i]); |
2858 |
31 |
int mappedCharPos = range[0]; |
2859 |
|
|
2860 |
|
|
2861 |
|
|
2862 |
|
|
2863 |
|
|
2864 |
|
|
2865 |
|
|
2866 |
2794274 |
while (mappedCharPos <= range[1] && fromCol <= fromSeq.getLength() |
2867 |
|
&& fromCol >= 0) |
2868 |
|
{ |
2869 |
2794243 |
if (!Comparison.isGap(fromSeq.getCharAt(fromCol - 1))) |
2870 |
|
{ |
2871 |
|
|
2872 |
|
|
2873 |
|
|
2874 |
|
|
2875 |
31998 |
Map<SequenceI, Character> seqsMap = map.get(fromCol); |
2876 |
31998 |
if (seqsMap == null) |
2877 |
|
{ |
2878 |
5398 |
seqsMap = new HashMap<>(); |
2879 |
5398 |
map.put(fromCol, seqsMap); |
2880 |
|
} |
2881 |
31998 |
seqsMap.put(seq, seq.getCharAt(mappedCharPos - toStart)); |
2882 |
31998 |
mappedCharPos++; |
2883 |
|
} |
2884 |
2794243 |
fromCol += (forward ? 1 : -1); |
2885 |
|
} |
2886 |
|
} |
2887 |
|
} |
2888 |
28 |
return true; |
2889 |
|
} |
2890 |
|
|
2891 |
|
|
2892 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
2893 |
4 |
public static boolean looksLikeEnsembl(AlignmentI alignment)... |
2894 |
|
{ |
2895 |
4 |
for (SequenceI seq : alignment.getSequences()) |
2896 |
|
{ |
2897 |
88 |
String name = seq.getName(); |
2898 |
88 |
if (!name.startsWith("ENSG") && !name.startsWith("ENST")) |
2899 |
|
{ |
2900 |
0 |
return false; |
2901 |
|
} |
2902 |
|
} |
2903 |
4 |
return true; |
2904 |
|
} |
2905 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
2906 |
5 |
public static boolean isSecondaryStructurePresent(... |
2907 |
|
AlignmentAnnotation[] annotations) |
2908 |
|
{ |
2909 |
5 |
boolean ssPresent = false; |
2910 |
|
|
2911 |
5 |
for (AlignmentAnnotation aa : annotations) |
2912 |
|
{ |
2913 |
5 |
if (ssPresent) |
2914 |
|
{ |
2915 |
0 |
break; |
2916 |
|
} |
2917 |
|
|
2918 |
5 |
if (Constants.SECONDARY_STRUCTURE_LABELS.containsKey(aa.label)) |
2919 |
|
{ |
2920 |
3 |
ssPresent = true; |
2921 |
3 |
break; |
2922 |
|
} |
2923 |
|
} |
2924 |
|
|
2925 |
5 |
return ssPresent; |
2926 |
|
|
2927 |
|
} |
2928 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
2929 |
0 |
public static Color getSecondaryStructureAnnotationColour(char symbol)... |
2930 |
|
{ |
2931 |
|
|
2932 |
0 |
if (symbol == Constants.COIL) |
2933 |
|
{ |
2934 |
0 |
return Color.gray; |
2935 |
|
} |
2936 |
0 |
if (symbol == Constants.SHEET) |
2937 |
|
{ |
2938 |
0 |
return Color.green; |
2939 |
|
} |
2940 |
0 |
if (symbol == Constants.HELIX) |
2941 |
|
{ |
2942 |
0 |
return Color.red; |
2943 |
|
} |
2944 |
|
|
2945 |
0 |
return Color.white; |
2946 |
|
} |
2947 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
2948 |
70935 |
public static char findSSAnnotationForGivenSeqposition(... |
2949 |
|
AlignmentAnnotation aa, int seqPosition) |
2950 |
|
{ |
2951 |
70935 |
char ss = '*'; |
2952 |
|
|
2953 |
70936 |
if (aa != null) |
2954 |
|
{ |
2955 |
70935 |
if (aa.getAnnotationForPosition(seqPosition) != null) |
2956 |
|
{ |
2957 |
41675 |
Annotation a = aa.getAnnotationForPosition(seqPosition); |
2958 |
41674 |
ss = a.secondaryStructure; |
2959 |
|
|
2960 |
|
|
2961 |
41676 |
if (ss == ' ' || ss == '-') |
2962 |
|
{ |
2963 |
9746 |
ss = Constants.COIL; |
2964 |
|
} |
2965 |
|
} |
2966 |
|
else |
2967 |
|
{ |
2968 |
29260 |
ss = Constants.COIL; |
2969 |
|
} |
2970 |
|
} |
2971 |
|
|
2972 |
70936 |
return ss; |
2973 |
|
} |
2974 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
2975 |
1691 |
public static List<String> extractSSSourceInAlignmentAnnotation(... |
2976 |
|
AlignmentAnnotation[] annotations) |
2977 |
|
{ |
2978 |
|
|
2979 |
1691 |
List<String> ssSources = new ArrayList<>(); |
2980 |
1691 |
Set<String> addedSources = new HashSet<>(); |
2981 |
|
|
2982 |
|
|
2983 |
1691 |
if (annotations == null) |
2984 |
|
{ |
2985 |
12 |
return ssSources; |
2986 |
|
} |
2987 |
|
|
2988 |
1679 |
for (AlignmentAnnotation aa : annotations) |
2989 |
|
{ |
2990 |
|
|
2991 |
7873 |
String ssSource = extractSSSourceFromAnnotationDescription(aa); |
2992 |
|
|
2993 |
7873 |
if (ssSource != null && !addedSources.contains(ssSource)) |
2994 |
|
{ |
2995 |
68 |
ssSources.add(ssSource); |
2996 |
68 |
addedSources.add(ssSource); |
2997 |
|
} |
2998 |
|
|
2999 |
|
} |
3000 |
1679 |
Collections.sort(ssSources); |
3001 |
|
|
3002 |
1679 |
return ssSources; |
3003 |
|
|
3004 |
|
} |
3005 |
|
|
|
|
| 76.1% |
Uncovered Elements: 11 (46) |
Complexity: 15 |
Complexity Density: 0.58 |
|
3006 |
62816 |
public static String extractSSSourceFromAnnotationDescription(... |
3007 |
|
AlignmentAnnotation aa) |
3008 |
|
{ |
3009 |
|
|
3010 |
62816 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3011 |
|
{ |
3012 |
|
|
3013 |
70055 |
if (label.equals(aa.label)) |
3014 |
|
{ |
3015 |
|
|
3016 |
55577 |
if (aa.getProperty(Constants.SS_PROVIDER_PROPERTY) != null) |
3017 |
|
{ |
3018 |
|
|
3019 |
0 |
return aa.getProperty(Constants.SS_PROVIDER_PROPERTY); |
3020 |
|
|
3021 |
|
} |
3022 |
|
|
3023 |
|
|
3024 |
55576 |
if (Constants.SS_ANNOTATION_FROM_JPRED_LABEL.equals(aa.label)) |
3025 |
|
{ |
3026 |
|
|
3027 |
0 |
return (Constants.SECONDARY_STRUCTURE_LABELS.get(aa.label)); |
3028 |
|
|
3029 |
|
} |
3030 |
|
|
3031 |
|
|
3032 |
55576 |
if (Constants.SS_ANNOTATION_LABEL.equals(aa.label) |
3033 |
|
&& aa.description != null |
3034 |
|
&& Constants.SS_ANNOTATION_LABEL.equals(aa.description)) |
3035 |
|
{ |
3036 |
|
|
3037 |
17328 |
return (Constants.SECONDARY_STRUCTURE_LABELS.get(aa.label)); |
3038 |
|
|
3039 |
|
} |
3040 |
|
|
3041 |
|
|
3042 |
38248 |
if (aa.sequenceRef == null) |
3043 |
|
{ |
3044 |
174 |
return null; |
3045 |
|
} |
3046 |
38074 |
else if (aa.sequenceRef.getDatasetSequence() == null) |
3047 |
|
{ |
3048 |
0 |
return null; |
3049 |
|
} |
3050 |
38074 |
Vector<PDBEntry> pdbEntries = aa.sequenceRef.getDatasetSequence() |
3051 |
|
.getAllPDBEntries(); |
3052 |
|
|
3053 |
|
|
3054 |
38074 |
for (PDBEntry entry : pdbEntries) |
3055 |
|
{ |
3056 |
|
|
3057 |
46188 |
String entryProvider = entry.getProvider(); |
3058 |
46188 |
if (entryProvider == null) |
3059 |
|
{ |
3060 |
|
|
3061 |
|
|
3062 |
46188 |
entryProvider = "PDB"; |
3063 |
|
} |
3064 |
|
|
3065 |
|
|
3066 |
|
|
3067 |
|
|
3068 |
46188 |
String entryID = entry.getId(); |
3069 |
46188 |
int index = entryID.indexOf(':'); |
3070 |
|
|
3071 |
|
|
3072 |
46188 |
if (index != -1) |
3073 |
|
{ |
3074 |
|
|
3075 |
|
|
3076 |
0 |
entryID = entryID.substring(0, index); |
3077 |
|
|
3078 |
|
} |
3079 |
|
|
3080 |
|
|
3081 |
|
|
3082 |
46188 |
if (entryProvider == "PDB" && aa.description.toLowerCase() |
3083 |
|
.contains("secondary structure for " |
3084 |
|
+ entryID.toLowerCase())) |
3085 |
|
{ |
3086 |
|
|
3087 |
38074 |
return entryProvider; |
3088 |
|
|
3089 |
|
} |
3090 |
|
|
3091 |
8114 |
else if (entryProvider != "PDB" && aa.description.toLowerCase() |
3092 |
|
.contains(entryID.toLowerCase())) |
3093 |
|
{ |
3094 |
|
|
3095 |
0 |
return entryProvider; |
3096 |
|
|
3097 |
|
} |
3098 |
|
|
3099 |
|
} |
3100 |
|
} |
3101 |
|
} |
3102 |
|
|
3103 |
7239 |
return null; |
3104 |
|
|
3105 |
|
} |
3106 |
|
|
3107 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
3108 |
10821642 |
public static List<AlignmentAnnotation> getAlignmentAnnotationForSource(... |
3109 |
|
SequenceI seq, String ssSource) |
3110 |
|
{ |
3111 |
|
|
3112 |
10822917 |
List<AlignmentAnnotation> ssAnnots = new ArrayList<AlignmentAnnotation>(); |
3113 |
10882691 |
for (String ssLabel : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3114 |
|
{ |
3115 |
|
|
3116 |
21706654 |
AlignmentAnnotation[] aa = seq.getAnnotation(ssLabel); |
3117 |
21441485 |
if (aa != null) |
3118 |
|
{ |
3119 |
|
|
3120 |
101130 |
if (Constants.SS_ALL_PROVIDERS.equals(ssSource)) |
3121 |
|
{ |
3122 |
50571 |
ssAnnots.addAll(Arrays.asList(aa)); |
3123 |
50571 |
continue; |
3124 |
|
} |
3125 |
|
|
3126 |
50559 |
for (AlignmentAnnotation annot : aa) |
3127 |
|
{ |
3128 |
|
|
3129 |
54943 |
String ssSourceForAnnot = extractSSSourceFromAnnotationDescription( |
3130 |
|
annot); |
3131 |
54943 |
if (ssSourceForAnnot != null && ssSource.equals(ssSourceForAnnot)) |
3132 |
|
{ |
3133 |
54943 |
ssAnnots.add(annot); |
3134 |
|
} |
3135 |
|
} |
3136 |
|
} |
3137 |
|
} |
3138 |
10761489 |
if (ssAnnots.size() > 0) |
3139 |
|
{ |
3140 |
101127 |
return ssAnnots; |
3141 |
|
} |
3142 |
|
|
3143 |
10686191 |
return null; |
3144 |
|
|
3145 |
|
} |
3146 |
|
|
|
|
| 53.3% |
Uncovered Elements: 7 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
3147 |
3 |
public static Map<SequenceI, ArrayList<AlignmentAnnotation>> getSequenceAssociatedAlignmentAnnotations(... |
3148 |
|
AlignmentAnnotation[] alignAnnotList, String selectedSSSource) |
3149 |
|
{ |
3150 |
|
|
3151 |
3 |
Map<SequenceI, ArrayList<AlignmentAnnotation>> ssAlignmentAnnotationForSequences = new HashMap<SequenceI, ArrayList<AlignmentAnnotation>>(); |
3152 |
3 |
if (alignAnnotList == null || alignAnnotList.length == 0) |
3153 |
|
{ |
3154 |
0 |
return ssAlignmentAnnotationForSequences; |
3155 |
|
} |
3156 |
|
|
3157 |
3 |
for (AlignmentAnnotation aa : alignAnnotList) |
3158 |
|
{ |
3159 |
12 |
if (aa.sequenceRef == null) |
3160 |
|
{ |
3161 |
12 |
continue; |
3162 |
|
} |
3163 |
|
|
3164 |
0 |
if (isSecondaryStructureFrom(selectedSSSource, aa)) |
3165 |
|
{ |
3166 |
0 |
ssAlignmentAnnotationForSequences |
3167 |
|
.computeIfAbsent(aa.sequenceRef.getDatasetSequence(), |
3168 |
|
k -> new ArrayList<>()) |
3169 |
|
.add(aa); |
3170 |
|
} |
3171 |
|
} |
3172 |
|
|
3173 |
3 |
return ssAlignmentAnnotationForSequences; |
3174 |
|
|
3175 |
|
} |
3176 |
|
|
3177 |
|
|
3178 |
|
|
3179 |
|
@param |
3180 |
|
@param |
3181 |
|
@return |
3182 |
|
|
3183 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
3184 |
0 |
public static boolean isSecondaryStructureFrom(String selectedSSSource,... |
3185 |
|
AlignmentAnnotation aa) |
3186 |
|
{ |
3187 |
|
|
3188 |
0 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
3189 |
|
{ |
3190 |
|
|
3191 |
0 |
if (label.equals(aa.label)) |
3192 |
|
{ |
3193 |
|
|
3194 |
0 |
if (selectedSSSource.equals(Constants.SS_ALL_PROVIDERS)) |
3195 |
|
{ |
3196 |
0 |
return true; |
3197 |
|
} |
3198 |
0 |
String ssSource = AlignmentUtils |
3199 |
|
.extractSSSourceFromAnnotationDescription(aa); |
3200 |
0 |
if (ssSource != null && ssSource.equals(selectedSSSource)) |
3201 |
|
{ |
3202 |
0 |
return true; |
3203 |
|
} |
3204 |
|
} |
3205 |
|
} |
3206 |
0 |
return false; |
3207 |
|
} |
3208 |
|
|
3209 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
3210 |
0 |
public static String getSecondaryStructureProviderKey(String providerValue) {... |
3211 |
0 |
for (Map.Entry<String, String> entry : Constants.STRUCTURE_PROVIDERS.entrySet()) { |
3212 |
0 |
if (entry.getValue().equals(providerValue)) { |
3213 |
0 |
return entry.getKey(); |
3214 |
|
} |
3215 |
|
} |
3216 |
0 |
return null; |
3217 |
|
} |
3218 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
3219 |
0 |
public static String reduceLabelLength(String label) {... |
3220 |
|
|
3221 |
0 |
String[] parts = label.split(" \\| "); |
3222 |
|
|
3223 |
|
|
3224 |
0 |
String reducedLabel = Arrays.stream(parts) |
3225 |
|
.map(fullName -> Constants.STRUCTURE_PROVIDERS.entrySet().stream() |
3226 |
|
.filter(entry -> entry.getValue().equals(fullName)) |
3227 |
|
.map(Map.Entry::getKey) |
3228 |
|
.findFirst() |
3229 |
|
.orElse(fullName)) |
3230 |
|
.collect(Collectors.joining(" | ")); |
3231 |
|
|
3232 |
0 |
return reducedLabel; |
3233 |
|
} |
3234 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
3235 |
0 |
public static Color getSecondaryStructureProviderColor(String label) {... |
3236 |
|
|
3237 |
|
|
3238 |
0 |
Color c = Constants.STRUCTURE_PROVIDERS_COLOR.get(label.trim()); |
3239 |
0 |
if(c==null) |
3240 |
0 |
c = Color.BLACK; |
3241 |
0 |
return c; |
3242 |
|
} |
3243 |
|
|
3244 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
3245 |
0 |
public static void assignSecondaryStructureProviderColor(Map<String, Color> secondaryStructureProviderColorMap,... |
3246 |
|
List<String> labels) { |
3247 |
|
|
3248 |
|
|
3249 |
0 |
Set<String> uniqueLabels = new HashSet<>(labels); |
3250 |
|
|
3251 |
0 |
Color[] palette = ColorBrewer.Paired.getColorPalette(uniqueLabels.size()); |
3252 |
|
|
3253 |
|
|
3254 |
0 |
List<Color> colorList = new ArrayList<>(); |
3255 |
0 |
Collections.addAll(colorList, palette); |
3256 |
0 |
Collections.shuffle(colorList); |
3257 |
0 |
int i = 0; |
3258 |
|
|
3259 |
|
|
3260 |
0 |
for (String label : uniqueLabels) { |
3261 |
|
|
3262 |
0 |
secondaryStructureProviderColorMap.put(label.toUpperCase().trim(), colorList.get(i)); |
3263 |
0 |
i++; |
3264 |
|
} |
3265 |
|
} |
3266 |
|
} |