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 jalview.analysis.scoremodels.PIDModel; |
24 |
|
import jalview.analysis.scoremodels.ScoreMatrix; |
25 |
|
import jalview.analysis.scoremodels.ScoreModels; |
26 |
|
import jalview.analysis.scoremodels.SimilarityParams; |
27 |
|
import jalview.api.analysis.SimilarityParamsI; |
28 |
|
import jalview.datamodel.AlignmentAnnotation; |
29 |
|
import jalview.datamodel.AlignmentI; |
30 |
|
import jalview.datamodel.Mapping; |
31 |
|
import jalview.datamodel.Sequence; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.math.MiscMath; |
34 |
|
import jalview.util.Comparison; |
35 |
|
import jalview.util.Format; |
36 |
|
import jalview.util.MapList; |
37 |
|
import jalview.util.MessageManager; |
38 |
|
|
39 |
|
import java.awt.Color; |
40 |
|
import java.awt.Graphics; |
41 |
|
import java.io.PrintStream; |
42 |
|
import java.lang.IllegalArgumentException; |
43 |
|
import java.util.ArrayList; |
44 |
|
import java.util.Arrays; |
45 |
|
import java.util.HashMap; |
46 |
|
import java.util.List; |
47 |
|
import java.util.StringTokenizer; |
48 |
|
import java.util.Locale; |
49 |
|
|
50 |
|
|
51 |
|
@author |
52 |
|
@version |
53 |
|
|
|
|
| 65% |
Uncovered Elements: 273 (780) |
Complexity: 179 |
Complexity Density: 0.35 |
|
54 |
|
public class AlignSeq |
55 |
|
{ |
56 |
|
private static final int MAX_NAME_LENGTH = 30; |
57 |
|
|
58 |
|
private static final int DEFAULT_OPENCOST = 120; |
59 |
|
|
60 |
|
private static final int DEFAULT_EXTENDCOST = 20; |
61 |
|
|
62 |
|
private int GAP_OPEN_COST = DEFAULT_OPENCOST; |
63 |
|
|
64 |
|
private int GAP_EXTEND_COST = DEFAULT_EXTENDCOST; |
65 |
|
|
66 |
|
private static final int GAP_INDEX = -1; |
67 |
|
|
68 |
|
public static final String PEP = "pep"; |
69 |
|
|
70 |
|
public static final String DNA = "dna"; |
71 |
|
|
72 |
|
private static final String NEWLINE = System.lineSeparator(); |
73 |
|
|
74 |
|
float[][] score; |
75 |
|
|
76 |
|
float alignmentScore; |
77 |
|
|
78 |
|
float[][] E; |
79 |
|
|
80 |
|
float[][] F; |
81 |
|
|
82 |
|
int[][] traceback; |
83 |
|
|
84 |
|
int[] seq1; |
85 |
|
|
86 |
|
int[] seq2; |
87 |
|
|
88 |
|
SequenceI s1; |
89 |
|
|
90 |
|
SequenceI s2; |
91 |
|
|
92 |
|
public String s1str; |
93 |
|
|
94 |
|
public String s2str; |
95 |
|
|
96 |
|
int maxi; |
97 |
|
|
98 |
|
int maxj; |
99 |
|
|
100 |
|
int[] aseq1; |
101 |
|
|
102 |
|
int[] aseq2; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
int match = -1; |
108 |
|
|
109 |
|
public String astr1 = ""; |
110 |
|
|
111 |
|
public String astr2 = ""; |
112 |
|
|
113 |
|
public String indelfreeAstr1 = ""; |
114 |
|
|
115 |
|
public String indelfreeAstr2 = ""; |
116 |
|
|
117 |
|
|
118 |
|
public int seq1start; |
119 |
|
|
120 |
|
|
121 |
|
public int seq1end; |
122 |
|
|
123 |
|
|
124 |
|
public int seq2start; |
125 |
|
|
126 |
|
public int seq2end; |
127 |
|
|
128 |
|
int count; |
129 |
|
|
130 |
|
public float maxscore; |
131 |
|
|
132 |
|
public float meanScore; |
133 |
|
|
134 |
|
public int hypotheticMaxScore; |
135 |
|
|
136 |
|
int prev = 0; |
137 |
|
|
138 |
|
StringBuffer output = new StringBuffer(); |
139 |
|
|
140 |
|
String type; |
141 |
|
|
142 |
|
private ScoreMatrix scoreMatrix; |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@param |
148 |
|
|
149 |
|
@param |
150 |
|
|
151 |
|
@param |
152 |
|
|
153 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
154 |
0 |
public AlignSeq(int opencost, int extcost)... |
155 |
|
{ |
156 |
0 |
GAP_OPEN_COST = opencost; |
157 |
0 |
GAP_EXTEND_COST = extcost; |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
269 |
public AlignSeq(SequenceI s1, SequenceI s2, String type)... |
161 |
|
{ |
162 |
269 |
seqInit(s1, s1.getSequenceAsString(), s2, s2.getSequenceAsString(), |
163 |
|
type); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
|
171 |
|
@param |
172 |
|
|
173 |
|
@param |
174 |
|
|
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
2 |
public AlignSeq(SequenceI s1, String string1, SequenceI s2,... |
177 |
|
String string2, String type) |
178 |
|
{ |
179 |
2 |
seqInit(s1, string1.toUpperCase(Locale.ROOT), s2, |
180 |
|
string2.toUpperCase(Locale.ROOT), type); |
181 |
|
} |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
183 |
267 |
public AlignSeq(SequenceI s1, SequenceI s2, String type, int opencost,... |
184 |
|
int extcost) |
185 |
|
{ |
186 |
267 |
this(s1, s2, type); |
187 |
267 |
GAP_OPEN_COST = opencost; |
188 |
267 |
GAP_EXTEND_COST = extcost; |
189 |
|
} |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
191 |
2 |
public AlignSeq(SequenceI s12, String string1, SequenceI s22,... |
192 |
|
String string2, String type2, int defaultOpencost, |
193 |
|
int defaultExtendcost) |
194 |
|
{ |
195 |
2 |
this(s12, string1, s22, string2, type2); |
196 |
2 |
GAP_OPEN_COST = defaultOpencost; |
197 |
2 |
GAP_EXTEND_COST = defaultExtendcost; |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
@return |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
32 |
public float getMaxScore()... |
206 |
|
{ |
207 |
32 |
return maxscore; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
@return |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
2 |
public float getAlignmentScore()... |
216 |
|
{ |
217 |
2 |
return alignmentScore; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@return |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
623 |
public int getSeq2Start()... |
226 |
|
{ |
227 |
623 |
return seq2start; |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@return |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
201 |
public int getSeq2End()... |
236 |
|
{ |
237 |
201 |
return seq2end; |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@return |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
623 |
public int getSeq1Start()... |
246 |
|
{ |
247 |
623 |
return seq1start; |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
@return |
254 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
255 |
201 |
public int getSeq1End()... |
256 |
|
{ |
257 |
201 |
return seq1end; |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
@return |
264 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
4 |
public String getOutput()... |
266 |
|
{ |
267 |
4 |
return output.toString(); |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
@return |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
208 |
public String getAStr1()... |
276 |
|
{ |
277 |
208 |
return astr1; |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
@return |
284 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
285 |
207 |
public String getAStr2()... |
286 |
|
{ |
287 |
207 |
return astr2; |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
@return |
294 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
2 |
public int[] getASeq1()... |
296 |
|
{ |
297 |
2 |
return aseq1; |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
@return |
304 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
305 |
0 |
public int[] getASeq2()... |
306 |
|
{ |
307 |
0 |
return aseq2; |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
@return |
313 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
314 |
200 |
public SequenceI getAlignedSeq1()... |
315 |
|
{ |
316 |
200 |
SequenceI alSeq1 = new Sequence(s1.getName(), getAStr1()); |
317 |
200 |
alSeq1.setStart(s1.getStart() + getSeq1Start() - 1); |
318 |
200 |
alSeq1.setEnd(s1.getStart() + getSeq1End() - 1); |
319 |
200 |
alSeq1.setDatasetSequence( |
320 |
200 |
s1.getDatasetSequence() == null ? s1 : s1.getDatasetSequence()); |
321 |
200 |
return alSeq1; |
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
@return |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
328 |
200 |
public SequenceI getAlignedSeq2()... |
329 |
|
{ |
330 |
200 |
SequenceI alSeq2 = new Sequence(s2.getName(), getAStr2()); |
331 |
200 |
alSeq2.setStart(s2.getStart() + getSeq2Start() - 1); |
332 |
200 |
alSeq2.setEnd(s2.getStart() + getSeq2End() - 1); |
333 |
200 |
alSeq2.setDatasetSequence( |
334 |
200 |
s2.getDatasetSequence() == null ? s2 : s2.getDatasetSequence()); |
335 |
200 |
return alSeq2; |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
@return |
342 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
343 |
0 |
public double getS2Coverage()... |
344 |
|
{ |
345 |
0 |
if (match >= 0) |
346 |
|
{ |
347 |
0 |
return ((double) match) / ((double) s2.getEnd() - s2.getStart() + 1); |
348 |
|
} |
349 |
0 |
return Double.NaN; |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
@return |
356 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
357 |
0 |
public double getS1Coverage()... |
358 |
|
{ |
359 |
0 |
if (match >= 0) |
360 |
|
{ |
361 |
0 |
return ((double) match) / ((double) s1.getEnd() - s1.getStart() + 1); |
362 |
|
} |
363 |
0 |
return Double.NaN; |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
@param |
370 |
|
|
371 |
|
@param |
372 |
|
|
373 |
|
@param |
374 |
|
|
375 |
|
@param |
376 |
|
|
377 |
|
@param |
378 |
|
|
379 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
380 |
271 |
public void seqInit(SequenceI s1, String string1, SequenceI s2,... |
381 |
|
String string2, String type) |
382 |
|
{ |
383 |
271 |
seqInit(s1, string1, s2, string2, type, GAP_OPEN_COST, GAP_EXTEND_COST); |
384 |
|
} |
385 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
386 |
271 |
public void seqInit(SequenceI s1, String string1, SequenceI s2,... |
387 |
|
String string2, String type, int opening, int extension) |
388 |
|
{ |
389 |
271 |
GAP_OPEN_COST = opening; |
390 |
271 |
GAP_EXTEND_COST = extension; |
391 |
271 |
this.s1 = s1; |
392 |
271 |
this.s2 = s2; |
393 |
271 |
setDefaultParams(type); |
394 |
271 |
seqInit(string1, string2); |
395 |
|
} |
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
@param |
402 |
|
@param |
403 |
|
|
|
|
| 58.8% |
Uncovered Elements: 7 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
404 |
271 |
private void seqInit(String string1, String string2)... |
405 |
|
{ |
406 |
271 |
s1str = extractGaps(jalview.util.Comparison.GapChars, string1); |
407 |
271 |
s2str = extractGaps(jalview.util.Comparison.GapChars, string2); |
408 |
|
|
409 |
271 |
if (s1str.length() == 0 || s2str.length() == 0) |
410 |
|
{ |
411 |
0 |
output.append( |
412 |
0 |
"ALL GAPS: " + (s1str.length() == 0 ? s1.getName() : " ") |
413 |
0 |
+ (s2str.length() == 0 ? s2.getName() : "")); |
414 |
0 |
return; |
415 |
|
} |
416 |
|
|
417 |
271 |
score = new float[s1str.length()][s2str.length()]; |
418 |
|
|
419 |
271 |
E = new float[s1str.length()][s2str.length()]; |
420 |
|
|
421 |
271 |
F = new float[s1str.length()][s2str.length()]; |
422 |
271 |
traceback = new int[s1str.length()][s2str.length()]; |
423 |
|
|
424 |
271 |
seq1 = indexEncode(s1str); |
425 |
|
|
426 |
271 |
seq2 = indexEncode(s2str); |
427 |
|
} |
428 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
429 |
271 |
private void setDefaultParams(String moleculeType)... |
430 |
|
{ |
431 |
271 |
if (!PEP.equals(moleculeType) && !DNA.equals(moleculeType)) |
432 |
|
{ |
433 |
0 |
output.append("Wrong type = dna or pep only"); |
434 |
0 |
throw new Error(MessageManager |
435 |
|
.formatMessage("error.unknown_type_dna_or_pep", new String[] |
436 |
|
{ moleculeType })); |
437 |
|
} |
438 |
|
|
439 |
271 |
type = moleculeType; |
440 |
271 |
scoreMatrix = ScoreModels.getInstance() |
441 |
|
.getDefaultModel(PEP.equals(type)); |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
|
|
| 89.5% |
Uncovered Elements: 8 (76) |
Complexity: 13 |
Complexity Density: 0.24 |
|
447 |
269 |
public void traceAlignment()... |
448 |
|
{ |
449 |
|
|
450 |
269 |
float max = -Float.MAX_VALUE; |
451 |
|
|
452 |
37269 |
for (int i = 0; i < seq1.length; i++) |
453 |
|
{ |
454 |
37000 |
if (score[i][seq2.length - 1] > max) |
455 |
|
{ |
456 |
21341 |
max = score[i][seq2.length - 1]; |
457 |
21341 |
maxi = i; |
458 |
21341 |
maxj = seq2.length - 1; |
459 |
|
} |
460 |
|
} |
461 |
|
|
462 |
34590 |
for (int j = 0; j < seq2.length; j++) |
463 |
|
{ |
464 |
34321 |
if (score[seq1.length - 1][j] > max) |
465 |
|
{ |
466 |
23 |
max = score[seq1.length - 1][j]; |
467 |
23 |
maxi = seq1.length - 1; |
468 |
23 |
maxj = j; |
469 |
|
} |
470 |
|
} |
471 |
|
|
472 |
269 |
int i = maxi; |
473 |
269 |
int j = maxj; |
474 |
269 |
int trace; |
475 |
269 |
maxscore = score[i][j] / 10f; |
476 |
|
|
477 |
269 |
seq1end = maxi + 1; |
478 |
269 |
seq2end = maxj + 1; |
479 |
|
|
480 |
269 |
aseq1 = new int[seq1.length + seq2.length]; |
481 |
269 |
aseq2 = new int[seq1.length + seq2.length]; |
482 |
269 |
match = 0; |
483 |
269 |
StringBuilder sb1 = new StringBuilder(aseq1.length); |
484 |
269 |
StringBuilder sb2 = new StringBuilder(aseq2.length); |
485 |
|
|
486 |
269 |
count = (seq1.length + seq2.length) - 1; |
487 |
|
|
488 |
29400 |
while (i > 0 && j > 0) |
489 |
|
{ |
490 |
29131 |
aseq1[count] = seq1[i]; |
491 |
29131 |
sb1.append(s1str.charAt(i)); |
492 |
29131 |
aseq2[count] = seq2[j]; |
493 |
29131 |
sb2.append(s2str.charAt(j)); |
494 |
29131 |
trace = findTrace(i, j); |
495 |
|
|
496 |
29131 |
if (trace == 0) |
497 |
|
{ |
498 |
29128 |
match++; |
499 |
29128 |
i--; |
500 |
29128 |
j--; |
501 |
|
} |
502 |
3 |
else if (trace == 1) |
503 |
|
{ |
504 |
0 |
j--; |
505 |
0 |
aseq1[count] = GAP_INDEX; |
506 |
0 |
sb1.replace(sb1.length() - 1, sb1.length(), "-"); |
507 |
|
} |
508 |
3 |
else if (trace == -1) |
509 |
|
{ |
510 |
3 |
i--; |
511 |
3 |
aseq2[count] = GAP_INDEX; |
512 |
3 |
sb2.replace(sb2.length() - 1, sb2.length(), "-"); |
513 |
|
} |
514 |
|
|
515 |
29131 |
count--; |
516 |
|
} |
517 |
|
|
518 |
269 |
seq1start = i + 1; |
519 |
269 |
seq2start = j + 1; |
520 |
|
|
521 |
269 |
if (aseq1[count] != GAP_INDEX) |
522 |
|
{ |
523 |
269 |
aseq1[count] = seq1[i]; |
524 |
269 |
sb1.append(s1str.charAt(i)); |
525 |
|
} |
526 |
|
|
527 |
269 |
if (aseq2[count] != GAP_INDEX) |
528 |
|
{ |
529 |
269 |
aseq2[count] = seq2[j]; |
530 |
269 |
sb2.append(s2str.charAt(j)); |
531 |
269 |
if (aseq1[count] != GAP_INDEX) |
532 |
|
{ |
533 |
269 |
match++; |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
269 |
astr1 = sb1.reverse().toString(); |
542 |
269 |
astr2 = sb2.reverse().toString(); |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
|
|
| 0% |
Uncovered Elements: 103 (103) |
Complexity: 20 |
Complexity Density: 0.27 |
|
548 |
0 |
public void traceAlignmentWithEndGaps()... |
549 |
|
{ |
550 |
|
|
551 |
0 |
float max = -Float.MAX_VALUE; |
552 |
|
|
553 |
0 |
for (int i = 0; i < seq1.length; i++) |
554 |
|
{ |
555 |
0 |
if (score[i][seq2.length - 1] > max) |
556 |
|
{ |
557 |
0 |
max = score[i][seq2.length - 1]; |
558 |
0 |
maxi = i; |
559 |
0 |
maxj = seq2.length - 1; |
560 |
|
} |
561 |
|
} |
562 |
|
|
563 |
0 |
for (int j = 0; j < seq2.length; j++) |
564 |
|
{ |
565 |
0 |
if (score[seq1.length - 1][j] > max) |
566 |
|
{ |
567 |
0 |
max = score[seq1.length - 1][j]; |
568 |
0 |
maxi = seq1.length - 1; |
569 |
0 |
maxj = j; |
570 |
|
} |
571 |
|
} |
572 |
|
|
573 |
0 |
int i = maxi; |
574 |
0 |
int j = maxj; |
575 |
0 |
int trace; |
576 |
0 |
maxscore = score[i][j] / 10f; |
577 |
|
|
578 |
|
|
579 |
0 |
while ((i < seq1.length - 1) || (j < seq2.length - 1)) |
580 |
|
{ |
581 |
0 |
i++; |
582 |
0 |
j++; |
583 |
|
} |
584 |
0 |
seq1end = i + 1; |
585 |
0 |
seq2end = j + 1; |
586 |
|
|
587 |
0 |
aseq1 = new int[seq1.length + seq2.length]; |
588 |
0 |
aseq2 = new int[seq1.length + seq2.length]; |
589 |
|
|
590 |
0 |
StringBuilder sb1 = new StringBuilder(aseq1.length); |
591 |
0 |
StringBuilder sb2 = new StringBuilder(aseq2.length); |
592 |
|
|
593 |
0 |
count = (seq1.length + seq2.length) - 1; |
594 |
|
|
595 |
|
|
596 |
0 |
while ((i >= seq1.length) || (j >= seq2.length)) |
597 |
|
{ |
598 |
0 |
if (i >= seq1.length) |
599 |
|
{ |
600 |
0 |
aseq1[count] = GAP_INDEX; |
601 |
0 |
sb1.append("-"); |
602 |
0 |
aseq2[count] = seq2[j]; |
603 |
0 |
sb2.append(s2str.charAt(j)); |
604 |
|
} |
605 |
0 |
else if (j >= seq2.length) |
606 |
|
{ |
607 |
0 |
aseq1[count] = seq1[i]; |
608 |
0 |
sb1.append(s1str.charAt(i)); |
609 |
0 |
aseq2[count] = GAP_INDEX; |
610 |
0 |
sb2.append("-"); |
611 |
|
} |
612 |
0 |
i--; |
613 |
0 |
j--; |
614 |
|
} |
615 |
|
|
616 |
0 |
while (i > 0 && j > 0) |
617 |
|
{ |
618 |
0 |
aseq1[count] = seq1[i]; |
619 |
0 |
sb1.append(s1str.charAt(i)); |
620 |
0 |
aseq2[count] = seq2[j]; |
621 |
0 |
sb2.append(s2str.charAt(j)); |
622 |
|
|
623 |
0 |
trace = findTrace(i, j); |
624 |
|
|
625 |
0 |
if (trace == 0) |
626 |
|
{ |
627 |
0 |
i--; |
628 |
0 |
j--; |
629 |
|
} |
630 |
0 |
else if (trace == 1) |
631 |
|
{ |
632 |
0 |
j--; |
633 |
0 |
aseq1[count] = GAP_INDEX; |
634 |
0 |
sb1.replace(sb1.length() - 1, sb1.length(), "-"); |
635 |
|
} |
636 |
0 |
else if (trace == -1) |
637 |
|
{ |
638 |
0 |
i--; |
639 |
0 |
aseq2[count] = GAP_INDEX; |
640 |
0 |
sb2.replace(sb2.length() - 1, sb2.length(), "-"); |
641 |
|
} |
642 |
|
|
643 |
0 |
count--; |
644 |
|
} |
645 |
|
|
646 |
0 |
seq1start = i + 1; |
647 |
0 |
seq2start = j + 1; |
648 |
|
|
649 |
0 |
aseq1[count] = seq1[i]; |
650 |
0 |
sb1.append(s1str.charAt(i)); |
651 |
0 |
aseq2[count] = seq2[j]; |
652 |
0 |
sb2.append(s2str.charAt(j)); |
653 |
|
|
654 |
|
|
655 |
0 |
while (j > 0 || i > 0) |
656 |
|
{ |
657 |
0 |
if (j > 0) |
658 |
|
{ |
659 |
0 |
j--; |
660 |
0 |
sb1.append("-"); |
661 |
0 |
sb2.append(s2str.charAt(j)); |
662 |
|
} |
663 |
0 |
else if (i > 0) |
664 |
|
{ |
665 |
0 |
i--; |
666 |
0 |
sb1.append(s1str.charAt(i)); |
667 |
0 |
sb2.append("-"); |
668 |
|
} |
669 |
|
} |
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
0 |
astr1 = sb1.reverse().toString(); |
676 |
0 |
astr2 = sb2.reverse().toString(); |
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
|
|
| 91.7% |
Uncovered Elements: 7 (84) |
Complexity: 17 |
Complexity Density: 0.3 |
|
682 |
198 |
public void printAlignment(PrintStream os)... |
683 |
|
{ |
684 |
|
|
685 |
|
|
686 |
|
|
687 |
198 |
String s1id = getAlignedSeq1().getDisplayId(true); |
688 |
198 |
String s2id = getAlignedSeq2().getDisplayId(true); |
689 |
198 |
int nameLength = Math.max(s1id.length(), s2id.length()); |
690 |
198 |
if (nameLength > MAX_NAME_LENGTH) |
691 |
|
{ |
692 |
39 |
int truncateBy = nameLength - MAX_NAME_LENGTH; |
693 |
39 |
nameLength = MAX_NAME_LENGTH; |
694 |
|
|
695 |
39 |
if (s1id.length() > nameLength) |
696 |
|
{ |
697 |
0 |
int slashPos = s1id.lastIndexOf('/'); |
698 |
0 |
s1id = s1id.substring(0, slashPos - truncateBy) |
699 |
|
+ s1id.substring(slashPos); |
700 |
|
} |
701 |
39 |
if (s2id.length() > nameLength) |
702 |
|
{ |
703 |
39 |
int slashPos = s2id.lastIndexOf('/'); |
704 |
39 |
s2id = s2id.substring(0, slashPos - truncateBy) |
705 |
|
+ s2id.substring(slashPos); |
706 |
|
} |
707 |
|
} |
708 |
198 |
int len = 72 - nameLength - 1; |
709 |
198 |
int nochunks = ((aseq1.length - count) / len) |
710 |
198 |
+ ((aseq1.length - count) % len > 0 ? 1 : 0); |
711 |
198 |
float pid = 0f; |
712 |
|
|
713 |
198 |
output.append("Score = ").append(score[maxi][maxj]).append(NEWLINE); |
714 |
198 |
output.append("Length of alignment = ") |
715 |
|
.append(String.valueOf(aseq1.length - count)).append(NEWLINE); |
716 |
198 |
output.append("Sequence "); |
717 |
198 |
Format nameFormat = new Format("%" + nameLength + "s"); |
718 |
198 |
output.append(nameFormat.form(s1id)); |
719 |
198 |
output.append(" (Sequence length = ") |
720 |
|
.append(String.valueOf(s1str.length())).append(")") |
721 |
|
.append(NEWLINE); |
722 |
198 |
output.append("Sequence "); |
723 |
198 |
output.append(nameFormat.form(s2id)); |
724 |
198 |
output.append(" (Sequence length = ") |
725 |
|
.append(String.valueOf(s2str.length())).append(")") |
726 |
|
.append(NEWLINE).append(NEWLINE); |
727 |
|
|
728 |
198 |
ScoreMatrix pam250 = ScoreModels.getInstance().getPam250(); |
729 |
|
|
730 |
704 |
for (int j = 0; j < nochunks; j++) |
731 |
|
{ |
732 |
|
|
733 |
506 |
output.append(nameFormat.form(s1id)).append(" "); |
734 |
|
|
735 |
26671 |
for (int i = 0; i < len; i++) |
736 |
|
{ |
737 |
26165 |
if ((i + (j * len)) < astr1.length()) |
738 |
|
{ |
739 |
21418 |
output.append(astr1.charAt(i + (j * len))); |
740 |
|
} |
741 |
|
} |
742 |
|
|
743 |
506 |
output.append(NEWLINE); |
744 |
506 |
output.append(nameFormat.form(" ")).append(" "); |
745 |
|
|
746 |
|
|
747 |
|
|
748 |
|
|
749 |
|
|
750 |
|
|
751 |
|
|
752 |
26671 |
for (int i = 0; i < len; i++) |
753 |
|
{ |
754 |
26165 |
if ((i + (j * len)) < astr1.length()) |
755 |
|
{ |
756 |
21418 |
char c1 = astr1.charAt(i + (j * len)); |
757 |
21418 |
char c2 = astr2.charAt(i + (j * len)); |
758 |
21418 |
boolean sameChar = Comparison.isSameResidue(c1, c2, false); |
759 |
21418 |
if (sameChar && !Comparison.isGap(c1)) |
760 |
|
{ |
761 |
21365 |
pid++; |
762 |
21365 |
output.append("|"); |
763 |
|
} |
764 |
53 |
else if (PEP.equals(type)) |
765 |
|
{ |
766 |
53 |
if (pam250.getPairwiseScore(c1, c2) > 0) |
767 |
|
{ |
768 |
2 |
output.append("."); |
769 |
|
} |
770 |
|
else |
771 |
|
{ |
772 |
51 |
output.append(" "); |
773 |
|
} |
774 |
|
} |
775 |
|
else |
776 |
|
{ |
777 |
0 |
output.append(" "); |
778 |
|
} |
779 |
|
} |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
506 |
output = output.append(NEWLINE); |
784 |
506 |
output = output.append(nameFormat.form(s2id)).append(" "); |
785 |
|
|
786 |
26671 |
for (int i = 0; i < len; i++) |
787 |
|
{ |
788 |
26165 |
if ((i + (j * len)) < astr2.length()) |
789 |
|
{ |
790 |
21418 |
output.append(astr2.charAt(i + (j * len))); |
791 |
|
} |
792 |
|
} |
793 |
|
|
794 |
506 |
output.append(NEWLINE).append(NEWLINE); |
795 |
|
} |
796 |
|
|
797 |
198 |
pid = pid / (aseq1.length - count) * 100; |
798 |
198 |
output.append(new Format("Percentage ID = %3.2f\n").form(pid)); |
799 |
198 |
output.append(NEWLINE); |
800 |
198 |
try |
801 |
|
{ |
802 |
198 |
os.print(output.toString()); |
803 |
|
} catch (Exception ex) |
804 |
|
{ |
805 |
|
} |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
811 |
|
@param |
812 |
|
|
813 |
|
@param |
814 |
|
|
815 |
|
|
816 |
|
@return |
817 |
|
|
|
|
| 80.6% |
Uncovered Elements: 6 (31) |
Complexity: 7 |
Complexity Density: 0.37 |
|
818 |
6533024 |
public int findTrace(int i, int j)... |
819 |
|
{ |
820 |
6533024 |
int t = 0; |
821 |
6533024 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
822 |
|
s2str.charAt(j)); |
823 |
6533024 |
float max = score[i - 1][j - 1] + (pairwiseScore * 10); |
824 |
|
|
825 |
6533024 |
if (F[i][j] > max) |
826 |
|
{ |
827 |
2121557 |
max = F[i][j]; |
828 |
2121557 |
t = -1; |
829 |
|
} |
830 |
4411467 |
else if (F[i][j] == max) |
831 |
|
{ |
832 |
242511 |
if (prev == -1) |
833 |
|
{ |
834 |
144465 |
max = F[i][j]; |
835 |
144465 |
t = -1; |
836 |
|
} |
837 |
|
} |
838 |
|
|
839 |
6533024 |
if (E[i][j] >= max) |
840 |
|
{ |
841 |
2332612 |
max = E[i][j]; |
842 |
2332612 |
t = 1; |
843 |
|
} |
844 |
4200412 |
else if (E[i][j] == max) |
845 |
|
{ |
846 |
0 |
if (prev == 1) |
847 |
|
{ |
848 |
0 |
max = E[i][j]; |
849 |
0 |
t = 1; |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
6533024 |
prev = t; |
854 |
|
|
855 |
6533024 |
return t; |
856 |
|
} |
857 |
|
|
858 |
|
|
859 |
|
|
860 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 5 |
Complexity Density: 0.19 |
|
861 |
269 |
public void calcScoreMatrix()... |
862 |
|
{ |
863 |
269 |
int n = seq1.length; |
864 |
269 |
int m = seq2.length; |
865 |
269 |
final int GAP_EX_COST = GAP_EXTEND_COST; |
866 |
269 |
final int GAP_OP_COST = GAP_OPEN_COST; |
867 |
|
|
868 |
269 |
score[0][0] = scoreMatrix.getPairwiseScore(s1str.charAt(0), |
869 |
|
s2str.charAt(0)) * 10; |
870 |
269 |
E[0][0] = -GAP_EX_COST; |
871 |
269 |
F[0][0] = 0; |
872 |
|
|
873 |
|
|
874 |
34321 |
for (int j = 1; j < m; j++) |
875 |
|
{ |
876 |
|
|
877 |
34052 |
E[0][j] = max(score[0][j - 1] - GAP_OP_COST, |
878 |
|
E[0][j - 1] - GAP_EX_COST); |
879 |
34052 |
F[0][j] = -GAP_EX_COST; |
880 |
|
|
881 |
34052 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(0), |
882 |
|
s2str.charAt(j)); |
883 |
34052 |
score[0][j] = max(pairwiseScore * 10, -GAP_OP_COST, -GAP_EX_COST); |
884 |
|
|
885 |
34052 |
traceback[0][j] = 1; |
886 |
|
} |
887 |
|
|
888 |
|
|
889 |
37000 |
for (int i = 1; i < n; i++) |
890 |
|
{ |
891 |
36731 |
E[i][0] = -GAP_OP_COST; |
892 |
36731 |
F[i][0] = max(score[i - 1][0] - GAP_OP_COST, |
893 |
|
F[i - 1][0] - GAP_EX_COST); |
894 |
|
|
895 |
36731 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
896 |
|
s2str.charAt(0)); |
897 |
36731 |
score[i][0] = max(pairwiseScore * 10, E[i][0], F[i][0]); |
898 |
36731 |
traceback[i][0] = -1; |
899 |
|
} |
900 |
|
|
901 |
|
|
902 |
37000 |
for (int i = 1; i < n; i++) |
903 |
|
{ |
904 |
6540624 |
for (int j = 1; j < m; j++) |
905 |
|
{ |
906 |
6503893 |
E[i][j] = max(score[i][j - 1] - GAP_OP_COST, |
907 |
|
E[i][j - 1] - GAP_EX_COST); |
908 |
6503893 |
F[i][j] = max(score[i - 1][j] - GAP_OP_COST, |
909 |
|
F[i - 1][j] - GAP_EX_COST); |
910 |
|
|
911 |
6503893 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
912 |
|
s2str.charAt(j)); |
913 |
6503893 |
score[i][j] = max(score[i - 1][j - 1] + (pairwiseScore * 10), |
914 |
|
E[i][j], F[i][j]); |
915 |
6503893 |
traceback[i][j] = findTrace(i, j); |
916 |
|
} |
917 |
|
} |
918 |
|
} |
919 |
|
|
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
@param |
924 |
|
|
925 |
|
@param |
926 |
|
|
927 |
|
|
928 |
|
@return |
929 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
930 |
7202 |
public static String extractGaps(String gapChars, String seq)... |
931 |
|
{ |
932 |
7202 |
if (gapChars == null || seq == null) |
933 |
|
{ |
934 |
6 |
return null; |
935 |
|
} |
936 |
7196 |
StringTokenizer str = new StringTokenizer(seq, gapChars); |
937 |
7196 |
StringBuilder newString = new StringBuilder(seq.length()); |
938 |
|
|
939 |
51454 |
while (str.hasMoreTokens()) |
940 |
|
{ |
941 |
44258 |
newString.append(str.nextToken()); |
942 |
|
} |
943 |
|
|
944 |
7196 |
return newString.toString(); |
945 |
|
} |
946 |
|
|
947 |
|
|
948 |
|
|
949 |
|
|
950 |
|
@param |
951 |
|
|
952 |
|
@param |
953 |
|
|
954 |
|
@param |
955 |
|
|
956 |
|
|
957 |
|
@return |
958 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
959 |
6574676 |
private static float max(float f1, float f2, float f3)... |
960 |
|
{ |
961 |
6574676 |
float max = f1; |
962 |
|
|
963 |
6574676 |
if (f2 > f1) |
964 |
|
{ |
965 |
2125388 |
max = f2; |
966 |
|
} |
967 |
|
|
968 |
6574676 |
if (f3 > max) |
969 |
|
{ |
970 |
2106185 |
max = f3; |
971 |
|
} |
972 |
|
|
973 |
6574676 |
return max; |
974 |
|
} |
975 |
|
|
976 |
|
|
977 |
|
|
978 |
|
|
979 |
|
@param |
980 |
|
|
981 |
|
@param |
982 |
|
|
983 |
|
|
984 |
|
@return |
985 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
986 |
13078569 |
private static float max(float f1, float f2)... |
987 |
|
{ |
988 |
13078569 |
float max = f1; |
989 |
|
|
990 |
13078569 |
if (f2 > f1) |
991 |
|
{ |
992 |
6966818 |
max = f2; |
993 |
|
} |
994 |
|
|
995 |
13078569 |
return max; |
996 |
|
} |
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
|
@param |
1003 |
|
|
1004 |
|
@return |
1005 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
1006 |
544 |
int[] indexEncode(String s)... |
1007 |
|
{ |
1008 |
544 |
int[] encoded = new int[s.length()]; |
1009 |
|
|
1010 |
71918 |
for (int i = 0; i < s.length(); i++) |
1011 |
|
{ |
1012 |
71374 |
char c = s.charAt(i); |
1013 |
71374 |
encoded[i] = scoreMatrix.getMatrixIndex(c); |
1014 |
|
} |
1015 |
|
|
1016 |
544 |
return encoded; |
1017 |
|
} |
1018 |
|
|
1019 |
|
|
1020 |
|
|
1021 |
|
|
1022 |
|
@param |
1023 |
|
|
1024 |
|
@param |
1025 |
|
|
1026 |
|
@param |
1027 |
|
|
1028 |
|
@param |
1029 |
|
|
1030 |
|
@param |
1031 |
|
|
1032 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
1033 |
0 |
public static void displayMatrix(Graphics g, int[][] mat, int n, int m,... |
1034 |
|
int psize) |
1035 |
|
{ |
1036 |
|
|
1037 |
0 |
int max = -1000; |
1038 |
0 |
int min = 1000; |
1039 |
|
|
1040 |
0 |
for (int i = 0; i < n; i++) |
1041 |
|
{ |
1042 |
0 |
for (int j = 0; j < m; j++) |
1043 |
|
{ |
1044 |
0 |
if (mat[i][j] >= max) |
1045 |
|
{ |
1046 |
0 |
max = mat[i][j]; |
1047 |
|
} |
1048 |
|
|
1049 |
0 |
if (mat[i][j] <= min) |
1050 |
|
{ |
1051 |
0 |
min = mat[i][j]; |
1052 |
|
} |
1053 |
|
} |
1054 |
|
} |
1055 |
|
|
1056 |
0 |
jalview.bin.Console.outPrintln(max + " " + min); |
1057 |
|
|
1058 |
0 |
for (int i = 0; i < n; i++) |
1059 |
|
{ |
1060 |
0 |
for (int j = 0; j < m; j++) |
1061 |
|
{ |
1062 |
0 |
int x = psize * i; |
1063 |
0 |
int y = psize * j; |
1064 |
|
|
1065 |
|
|
1066 |
0 |
float score = (float) (mat[i][j] - min) / (float) (max - min); |
1067 |
0 |
g.setColor(new Color(score, 0, 0)); |
1068 |
0 |
g.fillRect(x, y, psize, psize); |
1069 |
|
|
1070 |
|
|
1071 |
|
} |
1072 |
|
} |
1073 |
|
} |
1074 |
|
|
1075 |
|
|
1076 |
|
|
1077 |
|
|
1078 |
|
|
1079 |
|
@param |
1080 |
|
@param |
1081 |
|
@param |
1082 |
|
|
1083 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1084 |
267 |
public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,... |
1085 |
|
String type) |
1086 |
|
{ |
1087 |
267 |
return doGlobalNWAlignment(s1, s2, type, DEFAULT_OPENCOST, |
1088 |
|
DEFAULT_EXTENDCOST); |
1089 |
|
} |
1090 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
1091 |
267 |
public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,... |
1092 |
|
String type, int opencost, int extcost) |
1093 |
|
{ |
1094 |
|
|
1095 |
267 |
AlignSeq as = new AlignSeq(s1, s2, type, opencost, extcost); |
1096 |
|
|
1097 |
267 |
as.calcScoreMatrix(); |
1098 |
267 |
as.traceAlignment(); |
1099 |
267 |
return as; |
1100 |
|
} |
1101 |
|
|
1102 |
|
|
1103 |
|
|
1104 |
|
@return |
1105 |
|
|
|
|
| 91.1% |
Uncovered Elements: 5 (56) |
Complexity: 13 |
Complexity Density: 0.34 |
|
1106 |
226 |
public jalview.datamodel.Mapping getMappingFromS1(boolean allowmismatch)... |
1107 |
|
{ |
1108 |
226 |
ArrayList<Integer> as1 = new ArrayList<Integer>(), |
1109 |
|
as2 = new ArrayList<Integer>(); |
1110 |
226 |
int pdbpos = s2.getStart() + getSeq2Start() - 2; |
1111 |
226 |
int alignpos = s1.getStart() + getSeq1Start() - 2; |
1112 |
226 |
int lp2 = pdbpos - 3, lp1 = alignpos - 3; |
1113 |
226 |
boolean lastmatch = false; |
1114 |
|
|
1115 |
28345 |
for (int i = 0; i < astr1.length(); i++) |
1116 |
|
{ |
1117 |
28119 |
char c1 = astr1.charAt(i), c2 = astr2.charAt(i); |
1118 |
28119 |
if (c1 != '-') |
1119 |
|
{ |
1120 |
28119 |
alignpos++; |
1121 |
|
} |
1122 |
|
|
1123 |
28119 |
if (c2 != '-') |
1124 |
|
{ |
1125 |
28119 |
pdbpos++; |
1126 |
|
} |
1127 |
|
|
1128 |
|
|
1129 |
28119 |
if (allowmismatch || (c1 == c2) || (Math.abs(c2 - c1) == ('a' - 'A'))) |
1130 |
|
{ |
1131 |
|
|
1132 |
28072 |
if (lp1 + 1 != alignpos || lp2 + 1 != pdbpos) |
1133 |
|
{ |
1134 |
268 |
as1.add(Integer.valueOf(alignpos)); |
1135 |
268 |
as2.add(Integer.valueOf(pdbpos)); |
1136 |
|
} |
1137 |
28072 |
lastmatch = true; |
1138 |
28072 |
lp1 = alignpos; |
1139 |
28072 |
lp2 = pdbpos; |
1140 |
|
} |
1141 |
|
else |
1142 |
|
{ |
1143 |
|
|
1144 |
47 |
if (lastmatch) |
1145 |
|
{ |
1146 |
42 |
as1.add(Integer.valueOf(lp1)); |
1147 |
42 |
as2.add(Integer.valueOf(lp2)); |
1148 |
|
} |
1149 |
47 |
lastmatch = false; |
1150 |
|
} |
1151 |
|
} |
1152 |
|
|
1153 |
|
|
1154 |
226 |
int[] mapseq1 = new int[as1.size() + (lastmatch ? 1 : 0)], |
1155 |
226 |
mapseq2 = new int[as2.size() + (lastmatch ? 1 : 0)]; |
1156 |
226 |
int i = 0; |
1157 |
226 |
for (Integer ip : as1) |
1158 |
|
{ |
1159 |
310 |
mapseq1[i++] = ip; |
1160 |
|
} |
1161 |
226 |
; |
1162 |
226 |
i = 0; |
1163 |
226 |
for (Integer ip : as2) |
1164 |
|
{ |
1165 |
310 |
mapseq2[i++] = ip; |
1166 |
|
} |
1167 |
226 |
; |
1168 |
226 |
if (lastmatch) |
1169 |
|
{ |
1170 |
226 |
mapseq1[mapseq1.length - 1] = alignpos; |
1171 |
226 |
mapseq2[mapseq2.length - 1] = pdbpos; |
1172 |
|
} |
1173 |
226 |
MapList map = new MapList(mapseq1, mapseq2, 1, 1); |
1174 |
|
|
1175 |
226 |
jalview.datamodel.Mapping mapping = new Mapping(map); |
1176 |
226 |
mapping.setTo(s2); |
1177 |
226 |
return mapping; |
1178 |
|
} |
1179 |
|
|
1180 |
|
|
1181 |
|
|
1182 |
|
|
1183 |
|
|
1184 |
|
@param |
1185 |
|
@param |
1186 |
|
@param |
1187 |
|
@param |
1188 |
|
|
1189 |
|
|
1190 |
|
@return |
1191 |
|
|
1192 |
|
|
|
|
| 89.2% |
Uncovered Elements: 7 (65) |
Complexity: 14 |
Complexity Density: 0.31 |
|
1193 |
5 |
public static List<List<? extends Object>> replaceMatchingSeqsWith(... |
1194 |
|
List<SequenceI> seqs, List<AlignmentAnnotation> annotations, |
1195 |
|
List<SequenceI> ochains, AlignmentI al, String dnaOrProtein, |
1196 |
|
boolean removeOldAnnots) |
1197 |
|
{ |
1198 |
5 |
List<SequenceI> orig = new ArrayList<SequenceI>(), |
1199 |
|
repl = new ArrayList<SequenceI>(); |
1200 |
5 |
List<AlignSeq> aligs = new ArrayList<AlignSeq>(); |
1201 |
5 |
if (al != null && al.getHeight() > 0) |
1202 |
|
{ |
1203 |
5 |
ArrayList<SequenceI> matches = new ArrayList<SequenceI>(); |
1204 |
5 |
ArrayList<AlignSeq> aligns = new ArrayList<AlignSeq>(); |
1205 |
|
|
1206 |
5 |
for (SequenceI sq : ochains) |
1207 |
|
{ |
1208 |
14 |
SequenceI bestm = null; |
1209 |
14 |
AlignSeq bestaseq = null; |
1210 |
14 |
float bestscore = 0; |
1211 |
14 |
for (SequenceI msq : al.getSequences()) |
1212 |
|
{ |
1213 |
30 |
AlignSeq aseq = doGlobalNWAlignment(msq, sq, dnaOrProtein); |
1214 |
30 |
if (bestm == null || aseq.getMaxScore() > bestscore) |
1215 |
|
{ |
1216 |
14 |
bestscore = aseq.getMaxScore(); |
1217 |
14 |
bestaseq = aseq; |
1218 |
14 |
bestm = msq; |
1219 |
|
} |
1220 |
|
} |
1221 |
|
|
1222 |
|
|
1223 |
|
|
1224 |
14 |
matches.add(bestm); |
1225 |
14 |
aligns.add(bestaseq); |
1226 |
14 |
al.deleteSequence(bestm); |
1227 |
|
} |
1228 |
19 |
for (int p = 0, pSize = seqs.size(); p < pSize; p++) |
1229 |
|
{ |
1230 |
14 |
SequenceI sq, sp = seqs.get(p); |
1231 |
14 |
int q; |
1232 |
? |
if ((q = ochains.indexOf(sp)) > -1) |
1233 |
|
{ |
1234 |
14 |
seqs.set(p, sq = matches.get(q)); |
1235 |
14 |
orig.add(sp); |
1236 |
14 |
repl.add(sq); |
1237 |
14 |
sq.setName(sp.getName()); |
1238 |
14 |
sq.setDescription(sp.getDescription()); |
1239 |
14 |
Mapping sp2sq; |
1240 |
14 |
sq.transferAnnotation(sp, |
1241 |
|
sp2sq = aligns.get(q).getMappingFromS1(false)); |
1242 |
14 |
aligs.add(aligns.get(q)); |
1243 |
14 |
int inspos = -1; |
1244 |
46 |
for (int ap = 0; ap < annotations.size();) |
1245 |
|
{ |
1246 |
32 |
if (annotations.get(ap).sequenceRef == sp) |
1247 |
|
{ |
1248 |
4 |
if (inspos == -1) |
1249 |
|
{ |
1250 |
4 |
inspos = ap; |
1251 |
|
} |
1252 |
4 |
if (removeOldAnnots) |
1253 |
|
{ |
1254 |
0 |
annotations.remove(ap); |
1255 |
|
} |
1256 |
|
else |
1257 |
|
{ |
1258 |
4 |
AlignmentAnnotation alan = annotations.remove(ap); |
1259 |
4 |
alan.liftOver(sq, sp2sq); |
1260 |
4 |
alan.setSequenceRef(sq); |
1261 |
4 |
sq.addAlignmentAnnotation(alan); |
1262 |
|
} |
1263 |
|
} |
1264 |
|
else |
1265 |
|
{ |
1266 |
28 |
ap++; |
1267 |
|
} |
1268 |
|
} |
1269 |
14 |
if (sq.getAnnotation() != null && sq.getAnnotation().length > 0) |
1270 |
|
{ |
1271 |
14 |
annotations.addAll(inspos == -1 ? annotations.size() : inspos, |
1272 |
|
Arrays.asList(sq.getAnnotation())); |
1273 |
|
} |
1274 |
|
} |
1275 |
|
} |
1276 |
|
} |
1277 |
5 |
return Arrays.asList(orig, repl, aligs); |
1278 |
|
} |
1279 |
|
|
1280 |
|
|
1281 |
|
|
1282 |
|
|
1283 |
|
@param |
1284 |
|
|
1285 |
|
@param |
1286 |
|
|
1287 |
|
|
1288 |
|
@param |
1289 |
|
|
1290 |
|
@param |
1291 |
|
|
1292 |
|
@param |
1293 |
|
|
1294 |
|
@return |
1295 |
|
|
1296 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 11 |
Complexity Density: 0.33 |
|
1297 |
0 |
public static float[] computeRedundancyMatrix(... |
1298 |
|
SequenceI[] originalSequences, String[] omitHidden, int start, |
1299 |
|
int end, boolean ungapped) |
1300 |
|
{ |
1301 |
0 |
int height = originalSequences.length; |
1302 |
0 |
float[] redundancy = new float[height]; |
1303 |
0 |
int[] lngth = new int[height]; |
1304 |
0 |
for (int i = 0; i < height; i++) |
1305 |
|
{ |
1306 |
0 |
redundancy[i] = 0f; |
1307 |
0 |
lngth[i] = -1; |
1308 |
|
} |
1309 |
|
|
1310 |
|
|
1311 |
|
|
1312 |
0 |
SimilarityParams pidParams = new SimilarityParams(true, true, true, |
1313 |
|
true); |
1314 |
0 |
float pid; |
1315 |
0 |
String seqi, seqj; |
1316 |
0 |
for (int i = 0; i < height; i++) |
1317 |
|
{ |
1318 |
|
|
1319 |
0 |
for (int j = 0; j < i; j++) |
1320 |
|
{ |
1321 |
0 |
if (i == j) |
1322 |
|
{ |
1323 |
0 |
continue; |
1324 |
|
} |
1325 |
|
|
1326 |
0 |
if (omitHidden == null) |
1327 |
|
{ |
1328 |
0 |
seqi = originalSequences[i].getSequenceAsString(start, end); |
1329 |
0 |
seqj = originalSequences[j].getSequenceAsString(start, end); |
1330 |
|
} |
1331 |
|
else |
1332 |
|
{ |
1333 |
0 |
seqi = omitHidden[i]; |
1334 |
0 |
seqj = omitHidden[j]; |
1335 |
|
} |
1336 |
0 |
if (lngth[i] == -1) |
1337 |
|
{ |
1338 |
0 |
String ug = AlignSeq.extractGaps(Comparison.GapChars, seqi); |
1339 |
0 |
lngth[i] = ug.length(); |
1340 |
0 |
if (ungapped) |
1341 |
|
{ |
1342 |
0 |
seqi = ug; |
1343 |
|
} |
1344 |
|
} |
1345 |
0 |
if (lngth[j] == -1) |
1346 |
|
{ |
1347 |
0 |
String ug = AlignSeq.extractGaps(Comparison.GapChars, seqj); |
1348 |
0 |
lngth[j] = ug.length(); |
1349 |
0 |
if (ungapped) |
1350 |
|
{ |
1351 |
0 |
seqj = ug; |
1352 |
|
} |
1353 |
|
} |
1354 |
0 |
pid = (float) PIDModel.computePID(seqi, seqj, pidParams); |
1355 |
|
|
1356 |
|
|
1357 |
0 |
if (lngth[j] < lngth[i]) |
1358 |
|
{ |
1359 |
0 |
redundancy[j] = Math.max(pid, redundancy[j]); |
1360 |
|
} |
1361 |
|
else |
1362 |
|
{ |
1363 |
0 |
redundancy[i] = Math.max(pid, redundancy[i]); |
1364 |
|
} |
1365 |
|
|
1366 |
|
} |
1367 |
|
} |
1368 |
0 |
return redundancy; |
1369 |
|
} |
1370 |
|
|
1371 |
|
|
1372 |
|
|
1373 |
|
|
1374 |
|
|
1375 |
|
|
1376 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
1377 |
2 |
public void meanScore()... |
1378 |
|
{ |
1379 |
2 |
int length = indelfreeAstr1.length(); |
1380 |
|
|
1381 |
2 |
HashMap<Character, Integer> seq1ResCount = new HashMap<Character, Integer>(); |
1382 |
2 |
HashMap<Character, Integer> seq2ResCount = new HashMap<Character, Integer>(); |
1383 |
|
|
1384 |
|
|
1385 |
|
|
1386 |
2 |
for (char residue : indelfreeAstr1.toCharArray()) |
1387 |
|
{ |
1388 |
8 |
seq1ResCount.putIfAbsent(residue, 0); |
1389 |
8 |
seq1ResCount.replace(residue, seq1ResCount.get(residue) + 1); |
1390 |
|
} |
1391 |
2 |
for (char residue : indelfreeAstr2.toCharArray()) |
1392 |
|
{ |
1393 |
8 |
seq2ResCount.putIfAbsent(residue, 0); |
1394 |
8 |
seq2ResCount.replace(residue, seq2ResCount.get(residue) + 1); |
1395 |
|
} |
1396 |
|
|
1397 |
|
|
1398 |
|
|
1399 |
|
|
1400 |
2 |
float _meanscore = 0; |
1401 |
2 |
for (char resA : seq1ResCount.keySet()) |
1402 |
|
{ |
1403 |
8 |
for (char resB : seq2ResCount.keySet()) |
1404 |
|
{ |
1405 |
32 |
int countA = seq1ResCount.get(resA); |
1406 |
32 |
int countB = seq2ResCount.get(resB); |
1407 |
|
|
1408 |
32 |
float scoreAB = scoreMatrix.getPairwiseScore(resA, resB); |
1409 |
|
|
1410 |
32 |
_meanscore += countA * countB * scoreAB; |
1411 |
|
} |
1412 |
|
} |
1413 |
2 |
_meanscore /= length; |
1414 |
2 |
this.meanScore = _meanscore; |
1415 |
|
} |
1416 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1417 |
0 |
public float getMeanScore()... |
1418 |
|
{ |
1419 |
0 |
return this.meanScore; |
1420 |
|
} |
1421 |
|
|
1422 |
|
|
1423 |
|
|
1424 |
|
|
1425 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
1426 |
2 |
public void hypotheticMaxScore()... |
1427 |
|
{ |
1428 |
2 |
int _hmsA = 0; |
1429 |
2 |
int _hmsB = 0; |
1430 |
2 |
for (char residue : indelfreeAstr1.toCharArray()) |
1431 |
|
{ |
1432 |
8 |
_hmsA += scoreMatrix.getPairwiseScore(residue, residue); |
1433 |
|
} |
1434 |
2 |
for (char residue : indelfreeAstr2.toCharArray()) |
1435 |
|
{ |
1436 |
8 |
_hmsB += scoreMatrix.getPairwiseScore(residue, residue); |
1437 |
|
} |
1438 |
2 |
this.hypotheticMaxScore = (_hmsA < _hmsB) ? _hmsA : _hmsB; |
1439 |
|
|
1440 |
|
|
1441 |
|
} |
1442 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1443 |
0 |
public int getHypotheticMaxScore()... |
1444 |
|
{ |
1445 |
0 |
return this.hypotheticMaxScore; |
1446 |
|
} |
1447 |
|
|
1448 |
|
|
1449 |
|
|
1450 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
1451 |
2 |
public void getIndelfreeAstr()... |
1452 |
|
{ |
1453 |
2 |
int n = astr1.length(); |
1454 |
10 |
for (int i = 0; i < n; i++) |
1455 |
|
{ |
1456 |
8 |
if (Character.isLetter(astr1.charAt(i)) |
1457 |
|
&& Character.isLetter(astr2.charAt(i))) |
1458 |
|
|
1459 |
|
|
1460 |
|
{ |
1461 |
8 |
this.indelfreeAstr1 += astr1.charAt(i); |
1462 |
8 |
this.indelfreeAstr2 += astr2.charAt(i); |
1463 |
|
} |
1464 |
|
} |
1465 |
|
} |
1466 |
|
|
1467 |
|
|
1468 |
|
|
1469 |
|
|
1470 |
|
|
1471 |
|
|
1472 |
|
|
|
|
| 68.1% |
Uncovered Elements: 15 (47) |
Complexity: 14 |
Complexity Density: 0.45 |
|
1473 |
2 |
public void scoreAlignment()... |
1474 |
|
{ |
1475 |
|
|
1476 |
2 |
getIndelfreeAstr(); |
1477 |
2 |
meanScore(); |
1478 |
2 |
hypotheticMaxScore(); |
1479 |
|
|
1480 |
2 |
if (this.hypotheticMaxScore == this.meanScore) |
1481 |
|
{ |
1482 |
0 |
this.alignmentScore = Float.NaN; |
1483 |
0 |
return; |
1484 |
|
} |
1485 |
2 |
int n = indelfreeAstr1.length(); |
1486 |
|
|
1487 |
2 |
float score = 0; |
1488 |
2 |
boolean aGapOpen = false; |
1489 |
2 |
boolean bGapOpen = false; |
1490 |
10 |
for (int i = 0; i < n; i++) |
1491 |
|
{ |
1492 |
8 |
char char1 = indelfreeAstr1.charAt(i); |
1493 |
8 |
char char2 = indelfreeAstr2.charAt(i); |
1494 |
8 |
boolean aIsLetter = Character.isLetter(char1); |
1495 |
8 |
boolean bIsLetter = Character.isLetter(char2); |
1496 |
8 |
if (aIsLetter && bIsLetter) |
1497 |
|
{ |
1498 |
8 |
score += scoreMatrix.getPairwiseScore(char1, char2); |
1499 |
|
} |
1500 |
0 |
else if (!aIsLetter && !bIsLetter) |
1501 |
|
{ |
1502 |
|
} |
1503 |
0 |
else if ((!aIsLetter && aGapOpen) || (!bIsLetter && bGapOpen)) |
1504 |
|
{ |
1505 |
0 |
score -= GAP_EXTEND_COST; |
1506 |
|
} |
1507 |
|
else |
1508 |
|
{ |
1509 |
0 |
score -= GAP_OPEN_COST; |
1510 |
|
} |
1511 |
|
|
1512 |
8 |
aGapOpen = (!aIsLetter) ? true : false; |
1513 |
8 |
bGapOpen = (!bIsLetter) ? true : false; |
1514 |
|
} |
1515 |
|
|
1516 |
2 |
float preprescore = score; |
1517 |
|
|
1518 |
2 |
score = (score - this.meanScore) |
1519 |
|
/ (this.hypotheticMaxScore - this.meanScore); |
1520 |
2 |
int[] _max = MiscMath |
1521 |
|
.findMax(new int[] |
1522 |
|
{ astr1.replace("-", "").length(), |
1523 |
|
astr2.replace("-", "").length() }); |
1524 |
2 |
float coverage = (float) n / (float) _max[1]; |
1525 |
|
|
1526 |
2 |
float prescore = score; |
1527 |
2 |
score *= coverage; |
1528 |
|
|
1529 |
|
|
1530 |
|
|
1531 |
|
|
1532 |
2 |
float minScore = 0f; |
1533 |
2 |
this.alignmentScore = (score <= minScore) ? Float.NaN : score; |
1534 |
|
} |
1535 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1536 |
0 |
public void setScoreMatrix(ScoreMatrix sm)... |
1537 |
|
{ |
1538 |
0 |
if (sm != null) |
1539 |
|
{ |
1540 |
0 |
scoreMatrix = sm; |
1541 |
|
} |
1542 |
|
} |
1543 |
|
} |