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