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.datamodel.AlignmentAnnotation; |
28 |
|
import jalview.datamodel.AlignmentI; |
29 |
|
import jalview.datamodel.Mapping; |
30 |
|
import jalview.datamodel.Sequence; |
31 |
|
import jalview.datamodel.SequenceI; |
32 |
|
import jalview.util.Comparison; |
33 |
|
import jalview.util.Format; |
34 |
|
import jalview.util.MapList; |
35 |
|
import jalview.util.MessageManager; |
36 |
|
|
37 |
|
import java.awt.Color; |
38 |
|
import java.awt.Graphics; |
39 |
|
import java.io.PrintStream; |
40 |
|
import java.util.ArrayList; |
41 |
|
import java.util.Arrays; |
42 |
|
import java.util.List; |
43 |
|
import java.util.StringTokenizer; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@author |
49 |
|
@version |
50 |
|
|
|
|
| 73.4% |
Uncovered Elements: 144 (541) |
Complexity: 122 |
Complexity Density: 0.35 |
|
51 |
|
public class AlignSeq |
52 |
|
{ |
53 |
|
private static final int MAX_NAME_LENGTH = 30; |
54 |
|
|
55 |
|
private static final int GAP_OPEN_COST = 120; |
56 |
|
|
57 |
|
private static final int GAP_EXTEND_COST = 20; |
58 |
|
|
59 |
|
private static final int GAP_INDEX = -1; |
60 |
|
|
61 |
|
public static final String PEP = "pep"; |
62 |
|
|
63 |
|
public static final String DNA = "dna"; |
64 |
|
|
65 |
|
private static final String NEWLINE = System.lineSeparator(); |
66 |
|
|
67 |
|
float[][] score; |
68 |
|
|
69 |
|
float[][] E; |
70 |
|
|
71 |
|
float[][] F; |
72 |
|
|
73 |
|
int[][] traceback; |
74 |
|
|
75 |
|
int[] seq1; |
76 |
|
|
77 |
|
int[] seq2; |
78 |
|
|
79 |
|
SequenceI s1; |
80 |
|
|
81 |
|
SequenceI s2; |
82 |
|
|
83 |
|
public String s1str; |
84 |
|
|
85 |
|
public String s2str; |
86 |
|
|
87 |
|
int maxi; |
88 |
|
|
89 |
|
int maxj; |
90 |
|
|
91 |
|
int[] aseq1; |
92 |
|
|
93 |
|
int[] aseq2; |
94 |
|
|
95 |
|
public String astr1 = ""; |
96 |
|
|
97 |
|
public String astr2 = ""; |
98 |
|
|
99 |
|
|
100 |
|
public int seq1start; |
101 |
|
|
102 |
|
|
103 |
|
public int seq1end; |
104 |
|
|
105 |
|
|
106 |
|
public int seq2start; |
107 |
|
|
108 |
|
public int seq2end; |
109 |
|
|
110 |
|
int count; |
111 |
|
|
112 |
|
public float maxscore; |
113 |
|
|
114 |
|
int prev = 0; |
115 |
|
|
116 |
|
StringBuffer output = new StringBuffer(); |
117 |
|
|
118 |
|
String type; |
119 |
|
|
120 |
|
private ScoreMatrix scoreMatrix; |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
@param |
130 |
|
|
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
151 |
public AlignSeq(SequenceI s1, SequenceI s2, String type)... |
133 |
|
{ |
134 |
151 |
seqInit(s1, s1.getSequenceAsString(), s2, s2.getSequenceAsString(), |
135 |
|
type); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
|
143 |
|
@param |
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
2 |
public AlignSeq(SequenceI s1, String string1, SequenceI s2,... |
149 |
|
String string2, String type) |
150 |
|
{ |
151 |
2 |
seqInit(s1, string1.toUpperCase(), s2, string2.toUpperCase(), type); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
@return |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
32 |
public float getMaxScore()... |
160 |
|
{ |
161 |
32 |
return maxscore; |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
@return |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
334 |
public int getSeq2Start()... |
170 |
|
{ |
171 |
334 |
return seq2start; |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@return |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
105 |
public int getSeq2End()... |
180 |
|
{ |
181 |
105 |
return seq2end; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@return |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
334 |
public int getSeq1Start()... |
190 |
|
{ |
191 |
334 |
return seq1start; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
@return |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
105 |
public int getSeq1End()... |
200 |
|
{ |
201 |
105 |
return seq1end; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
209 |
2 |
public String getOutput()... |
210 |
|
{ |
211 |
2 |
return output.toString(); |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
@return |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
108 |
public String getAStr1()... |
220 |
|
{ |
221 |
108 |
return astr1; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
@return |
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
107 |
public String getAStr2()... |
230 |
|
{ |
231 |
107 |
return astr2; |
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
@return |
238 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
239 |
2 |
public int[] getASeq1()... |
240 |
|
{ |
241 |
2 |
return aseq1; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
@return |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
249 |
0 |
public int[] getASeq2()... |
250 |
|
{ |
251 |
0 |
return aseq2; |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@return |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
258 |
104 |
public SequenceI getAlignedSeq1()... |
259 |
|
{ |
260 |
104 |
SequenceI alSeq1 = new Sequence(s1.getName(), getAStr1()); |
261 |
104 |
alSeq1.setStart(s1.getStart() + getSeq1Start() - 1); |
262 |
104 |
alSeq1.setEnd(s1.getStart() + getSeq1End() - 1); |
263 |
104 |
alSeq1.setDatasetSequence( |
264 |
104 |
s1.getDatasetSequence() == null ? s1 : s1.getDatasetSequence()); |
265 |
104 |
return alSeq1; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
@return |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
272 |
104 |
public SequenceI getAlignedSeq2()... |
273 |
|
{ |
274 |
104 |
SequenceI alSeq2 = new Sequence(s2.getName(), getAStr2()); |
275 |
104 |
alSeq2.setStart(s2.getStart() + getSeq2Start() - 1); |
276 |
104 |
alSeq2.setEnd(s2.getStart() + getSeq2End() - 1); |
277 |
104 |
alSeq2.setDatasetSequence( |
278 |
104 |
s2.getDatasetSequence() == null ? s2 : s2.getDatasetSequence()); |
279 |
104 |
return alSeq2; |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@param |
286 |
|
|
287 |
|
@param |
288 |
|
|
289 |
|
@param |
290 |
|
|
291 |
|
@param |
292 |
|
|
293 |
|
@param |
294 |
|
|
295 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
296 |
153 |
public void seqInit(SequenceI s1, String string1, SequenceI s2,... |
297 |
|
String string2, String type) |
298 |
|
{ |
299 |
153 |
this.s1 = s1; |
300 |
153 |
this.s2 = s2; |
301 |
153 |
setDefaultParams(type); |
302 |
153 |
seqInit(string1, string2); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
@param |
310 |
|
@param |
311 |
|
|
|
|
| 58.8% |
Uncovered Elements: 7 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
312 |
153 |
private void seqInit(String string1, String string2)... |
313 |
|
{ |
314 |
153 |
s1str = extractGaps(jalview.util.Comparison.GapChars, string1); |
315 |
153 |
s2str = extractGaps(jalview.util.Comparison.GapChars, string2); |
316 |
|
|
317 |
153 |
if (s1str.length() == 0 || s2str.length() == 0) |
318 |
|
{ |
319 |
0 |
output.append( |
320 |
0 |
"ALL GAPS: " + (s1str.length() == 0 ? s1.getName() : " ") |
321 |
0 |
+ (s2str.length() == 0 ? s2.getName() : "")); |
322 |
0 |
return; |
323 |
|
} |
324 |
|
|
325 |
153 |
score = new float[s1str.length()][s2str.length()]; |
326 |
|
|
327 |
153 |
E = new float[s1str.length()][s2str.length()]; |
328 |
|
|
329 |
153 |
F = new float[s1str.length()][s2str.length()]; |
330 |
153 |
traceback = new int[s1str.length()][s2str.length()]; |
331 |
|
|
332 |
153 |
seq1 = indexEncode(s1str); |
333 |
|
|
334 |
153 |
seq2 = indexEncode(s2str); |
335 |
|
} |
336 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
337 |
153 |
private void setDefaultParams(String moleculeType)... |
338 |
|
{ |
339 |
153 |
if (!PEP.equals(moleculeType) && !DNA.equals(moleculeType)) |
340 |
|
{ |
341 |
0 |
output.append("Wrong type = dna or pep only"); |
342 |
0 |
throw new Error(MessageManager |
343 |
|
.formatMessage("error.unknown_type_dna_or_pep", new String[] |
344 |
|
{ moleculeType })); |
345 |
|
} |
346 |
|
|
347 |
153 |
type = moleculeType; |
348 |
153 |
scoreMatrix = ScoreModels.getInstance() |
349 |
|
.getDefaultModel(PEP.equals(type)); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
|
|
| 78.6% |
Uncovered Elements: 15 (70) |
Complexity: 12 |
Complexity Density: 0.24 |
|
355 |
151 |
public void traceAlignment()... |
356 |
|
{ |
357 |
|
|
358 |
151 |
float max = -Float.MAX_VALUE; |
359 |
|
|
360 |
19335 |
for (int i = 0; i < seq1.length; i++) |
361 |
|
{ |
362 |
19184 |
if (score[i][seq2.length - 1] > max) |
363 |
|
{ |
364 |
10701 |
max = score[i][seq2.length - 1]; |
365 |
10701 |
maxi = i; |
366 |
10701 |
maxj = seq2.length - 1; |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
18402 |
for (int j = 0; j < seq2.length; j++) |
371 |
|
{ |
372 |
18251 |
if (score[seq1.length - 1][j] > max) |
373 |
|
{ |
374 |
18 |
max = score[seq1.length - 1][j]; |
375 |
18 |
maxi = seq1.length - 1; |
376 |
18 |
maxj = j; |
377 |
|
} |
378 |
|
} |
379 |
|
|
380 |
151 |
int i = maxi; |
381 |
151 |
int j = maxj; |
382 |
151 |
int trace; |
383 |
151 |
maxscore = score[i][j] / 10f; |
384 |
|
|
385 |
151 |
seq1end = maxi + 1; |
386 |
151 |
seq2end = maxj + 1; |
387 |
|
|
388 |
151 |
aseq1 = new int[seq1.length + seq2.length]; |
389 |
151 |
aseq2 = new int[seq1.length + seq2.length]; |
390 |
|
|
391 |
151 |
StringBuilder sb1 = new StringBuilder(aseq1.length); |
392 |
151 |
StringBuilder sb2 = new StringBuilder(aseq2.length); |
393 |
|
|
394 |
151 |
count = (seq1.length + seq2.length) - 1; |
395 |
|
|
396 |
14775 |
while (i > 0 && j > 0) |
397 |
|
{ |
398 |
14624 |
aseq1[count] = seq1[i]; |
399 |
14624 |
sb1.append(s1str.charAt(i)); |
400 |
14624 |
aseq2[count] = seq2[j]; |
401 |
14624 |
sb2.append(s2str.charAt(j)); |
402 |
|
|
403 |
14624 |
trace = findTrace(i, j); |
404 |
|
|
405 |
14624 |
if (trace == 0) |
406 |
|
{ |
407 |
14624 |
i--; |
408 |
14624 |
j--; |
409 |
|
} |
410 |
0 |
else if (trace == 1) |
411 |
|
{ |
412 |
0 |
j--; |
413 |
0 |
aseq1[count] = GAP_INDEX; |
414 |
0 |
sb1.replace(sb1.length() - 1, sb1.length(), "-"); |
415 |
|
} |
416 |
0 |
else if (trace == -1) |
417 |
|
{ |
418 |
0 |
i--; |
419 |
0 |
aseq2[count] = GAP_INDEX; |
420 |
0 |
sb2.replace(sb2.length() - 1, sb2.length(), "-"); |
421 |
|
} |
422 |
|
|
423 |
14624 |
count--; |
424 |
|
} |
425 |
|
|
426 |
151 |
seq1start = i + 1; |
427 |
151 |
seq2start = j + 1; |
428 |
|
|
429 |
151 |
if (aseq1[count] != GAP_INDEX) |
430 |
|
{ |
431 |
151 |
aseq1[count] = seq1[i]; |
432 |
151 |
sb1.append(s1str.charAt(i)); |
433 |
|
} |
434 |
|
|
435 |
151 |
if (aseq2[count] != GAP_INDEX) |
436 |
|
{ |
437 |
151 |
aseq2[count] = seq2[j]; |
438 |
151 |
sb2.append(s2str.charAt(j)); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
151 |
astr1 = sb1.reverse().toString(); |
446 |
151 |
astr2 = sb2.reverse().toString(); |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
|
|
| 81% |
Uncovered Elements: 16 (84) |
Complexity: 17 |
Complexity Density: 0.3 |
|
452 |
102 |
public void printAlignment(PrintStream os)... |
453 |
|
{ |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
102 |
String s1id = getAlignedSeq1().getDisplayId(true); |
458 |
102 |
String s2id = getAlignedSeq2().getDisplayId(true); |
459 |
102 |
int nameLength = Math.max(s1id.length(), s2id.length()); |
460 |
102 |
if (nameLength > MAX_NAME_LENGTH) |
461 |
|
{ |
462 |
0 |
int truncateBy = nameLength - MAX_NAME_LENGTH; |
463 |
0 |
nameLength = MAX_NAME_LENGTH; |
464 |
|
|
465 |
0 |
if (s1id.length() > nameLength) |
466 |
|
{ |
467 |
0 |
int slashPos = s1id.lastIndexOf('/'); |
468 |
0 |
s1id = s1id.substring(0, slashPos - truncateBy) |
469 |
|
+ s1id.substring(slashPos); |
470 |
|
} |
471 |
0 |
if (s2id.length() > nameLength) |
472 |
|
{ |
473 |
0 |
int slashPos = s2id.lastIndexOf('/'); |
474 |
0 |
s2id = s2id.substring(0, slashPos - truncateBy) |
475 |
|
+ s2id.substring(slashPos); |
476 |
|
} |
477 |
|
} |
478 |
102 |
int len = 72 - nameLength - 1; |
479 |
102 |
int nochunks = ((aseq1.length - count) / len) |
480 |
102 |
+ ((aseq1.length - count) % len > 0 ? 1 : 0); |
481 |
102 |
float pid = 0f; |
482 |
|
|
483 |
102 |
output.append("Score = ").append(score[maxi][maxj]).append(NEWLINE); |
484 |
102 |
output.append("Length of alignment = ") |
485 |
|
.append(String.valueOf(aseq1.length - count)).append(NEWLINE); |
486 |
102 |
output.append("Sequence "); |
487 |
102 |
Format nameFormat = new Format("%" + nameLength + "s"); |
488 |
102 |
output.append(nameFormat.form(s1id)); |
489 |
102 |
output.append(" (Sequence length = ") |
490 |
|
.append(String.valueOf(s1str.length())).append(")") |
491 |
|
.append(NEWLINE); |
492 |
102 |
output.append("Sequence "); |
493 |
102 |
output.append(nameFormat.form(s2id)); |
494 |
102 |
output.append(" (Sequence length = ") |
495 |
|
.append(String.valueOf(s2str.length())).append(")") |
496 |
|
.append(NEWLINE).append(NEWLINE); |
497 |
|
|
498 |
102 |
ScoreMatrix pam250 = ScoreModels.getInstance().getPam250(); |
499 |
|
|
500 |
310 |
for (int j = 0; j < nochunks; j++) |
501 |
|
{ |
502 |
|
|
503 |
208 |
output.append(nameFormat.form(s1id)).append(" "); |
504 |
|
|
505 |
12081 |
for (int i = 0; i < len; i++) |
506 |
|
{ |
507 |
11873 |
if ((i + (j * len)) < astr1.length()) |
508 |
|
{ |
509 |
9299 |
output.append(astr1.charAt(i + (j * len))); |
510 |
|
} |
511 |
|
} |
512 |
|
|
513 |
208 |
output.append(NEWLINE); |
514 |
208 |
output.append(nameFormat.form(" ")).append(" "); |
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
12081 |
for (int i = 0; i < len; i++) |
523 |
|
{ |
524 |
11873 |
if ((i + (j * len)) < astr1.length()) |
525 |
|
{ |
526 |
9299 |
char c1 = astr1.charAt(i + (j * len)); |
527 |
9299 |
char c2 = astr2.charAt(i + (j * len)); |
528 |
9299 |
boolean sameChar = Comparison.isSameResidue(c1, c2, false); |
529 |
9299 |
if (sameChar && !Comparison.isGap(c1)) |
530 |
|
{ |
531 |
9253 |
pid++; |
532 |
9253 |
output.append("|"); |
533 |
|
} |
534 |
46 |
else if (PEP.equals(type)) |
535 |
|
{ |
536 |
46 |
if (pam250.getPairwiseScore(c1, c2) > 0) |
537 |
|
{ |
538 |
2 |
output.append("."); |
539 |
|
} |
540 |
|
else |
541 |
|
{ |
542 |
44 |
output.append(" "); |
543 |
|
} |
544 |
|
} |
545 |
|
else |
546 |
|
{ |
547 |
0 |
output.append(" "); |
548 |
|
} |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
208 |
output = output.append(NEWLINE); |
554 |
208 |
output = output.append(nameFormat.form(s2id)).append(" "); |
555 |
|
|
556 |
12081 |
for (int i = 0; i < len; i++) |
557 |
|
{ |
558 |
11873 |
if ((i + (j * len)) < astr2.length()) |
559 |
|
{ |
560 |
9299 |
output.append(astr2.charAt(i + (j * len))); |
561 |
|
} |
562 |
|
} |
563 |
|
|
564 |
208 |
output.append(NEWLINE).append(NEWLINE); |
565 |
|
} |
566 |
|
|
567 |
102 |
pid = pid / (aseq1.length - count) * 100; |
568 |
102 |
output.append(new Format("Percentage ID = %3.2f\n").form(pid)); |
569 |
102 |
output.append(NEWLINE); |
570 |
102 |
try |
571 |
|
{ |
572 |
102 |
os.print(output.toString()); |
573 |
|
} catch (Exception ex) |
574 |
|
{ |
575 |
|
} |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
@param |
582 |
|
|
583 |
|
@param |
584 |
|
|
585 |
|
|
586 |
|
@return |
587 |
|
|
|
|
| 80.6% |
Uncovered Elements: 6 (31) |
Complexity: 7 |
Complexity Density: 0.37 |
|
588 |
3414810 |
public int findTrace(int i, int j)... |
589 |
|
{ |
590 |
3414810 |
int t = 0; |
591 |
3414810 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
592 |
|
s2str.charAt(j)); |
593 |
3414810 |
float max = score[i - 1][j - 1] + (pairwiseScore * 10); |
594 |
|
|
595 |
3414810 |
if (F[i][j] > max) |
596 |
|
{ |
597 |
1079010 |
max = F[i][j]; |
598 |
1079010 |
t = -1; |
599 |
|
} |
600 |
2335800 |
else if (F[i][j] == max) |
601 |
|
{ |
602 |
131389 |
if (prev == -1) |
603 |
|
{ |
604 |
74710 |
max = F[i][j]; |
605 |
74710 |
t = -1; |
606 |
|
} |
607 |
|
} |
608 |
|
|
609 |
3414810 |
if (E[i][j] >= max) |
610 |
|
{ |
611 |
1189211 |
max = E[i][j]; |
612 |
1189211 |
t = 1; |
613 |
|
} |
614 |
2225599 |
else if (E[i][j] == max) |
615 |
|
{ |
616 |
0 |
if (prev == 1) |
617 |
|
{ |
618 |
0 |
max = E[i][j]; |
619 |
0 |
t = 1; |
620 |
|
} |
621 |
|
} |
622 |
|
|
623 |
3414810 |
prev = t; |
624 |
|
|
625 |
3414810 |
return t; |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 5 |
Complexity Density: 0.21 |
|
631 |
151 |
public void calcScoreMatrix()... |
632 |
|
{ |
633 |
151 |
int n = seq1.length; |
634 |
151 |
int m = seq2.length; |
635 |
|
|
636 |
|
|
637 |
151 |
score[0][0] = scoreMatrix.getPairwiseScore(s1str.charAt(0), |
638 |
|
s2str.charAt(0)) * 10; |
639 |
151 |
E[0][0] = -GAP_EXTEND_COST; |
640 |
151 |
F[0][0] = 0; |
641 |
|
|
642 |
|
|
643 |
18251 |
for (int j = 1; j < m; j++) |
644 |
|
{ |
645 |
|
|
646 |
18100 |
E[0][j] = max(score[0][j - 1] - GAP_OPEN_COST, E[0][j - 1] - GAP_EXTEND_COST); |
647 |
18100 |
F[0][j] = -GAP_EXTEND_COST; |
648 |
|
|
649 |
18100 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(0), |
650 |
|
s2str.charAt(j)); |
651 |
18100 |
score[0][j] = max(pairwiseScore * 10, -GAP_OPEN_COST, -GAP_EXTEND_COST); |
652 |
|
|
653 |
18100 |
traceback[0][j] = 1; |
654 |
|
} |
655 |
|
|
656 |
|
|
657 |
19184 |
for (int i = 1; i < n; i++) |
658 |
|
{ |
659 |
19033 |
E[i][0] = -GAP_OPEN_COST; |
660 |
19033 |
F[i][0] = max(score[i - 1][0] - GAP_OPEN_COST, F[i - 1][0] - GAP_EXTEND_COST); |
661 |
|
|
662 |
19033 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
663 |
|
s2str.charAt(0)); |
664 |
19033 |
score[i][0] = max(pairwiseScore * 10, E[i][0], F[i][0]); |
665 |
19033 |
traceback[i][0] = -1; |
666 |
|
} |
667 |
|
|
668 |
|
|
669 |
19184 |
for (int i = 1; i < n; i++) |
670 |
|
{ |
671 |
3419219 |
for (int j = 1; j < m; j++) |
672 |
|
{ |
673 |
3400186 |
E[i][j] = max(score[i][j - 1] - GAP_OPEN_COST, E[i][j - 1] - GAP_EXTEND_COST); |
674 |
3400186 |
F[i][j] = max(score[i - 1][j] - GAP_OPEN_COST, F[i - 1][j] - GAP_EXTEND_COST); |
675 |
|
|
676 |
3400186 |
float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), |
677 |
|
s2str.charAt(j)); |
678 |
3400186 |
score[i][j] = max(score[i - 1][j - 1] + (pairwiseScore * 10), |
679 |
|
E[i][j], F[i][j]); |
680 |
3400186 |
traceback[i][j] = findTrace(i, j); |
681 |
|
} |
682 |
|
} |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
@param |
689 |
|
|
690 |
|
@param |
691 |
|
|
692 |
|
|
693 |
|
@return |
694 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
695 |
4909 |
public static String extractGaps(String gapChars, String seq)... |
696 |
|
{ |
697 |
4909 |
if (gapChars == null || seq == null) |
698 |
|
{ |
699 |
6 |
return null; |
700 |
|
} |
701 |
4903 |
StringTokenizer str = new StringTokenizer(seq, gapChars); |
702 |
4903 |
StringBuilder newString = new StringBuilder(seq.length()); |
703 |
|
|
704 |
28243 |
while (str.hasMoreTokens()) |
705 |
|
{ |
706 |
23340 |
newString.append(str.nextToken()); |
707 |
|
} |
708 |
|
|
709 |
4903 |
return newString.toString(); |
710 |
|
} |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
@param |
716 |
|
|
717 |
|
@param |
718 |
|
|
719 |
|
@param |
720 |
|
|
721 |
|
|
722 |
|
@return |
723 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
724 |
3437319 |
private static float max(float f1, float f2, float f3)... |
725 |
|
{ |
726 |
3437319 |
float max = f1; |
727 |
|
|
728 |
3437319 |
if (f2 > f1) |
729 |
|
{ |
730 |
1080568 |
max = f2; |
731 |
|
} |
732 |
|
|
733 |
3437319 |
if (f3 > max) |
734 |
|
{ |
735 |
1069391 |
max = f3; |
736 |
|
} |
737 |
|
|
738 |
3437319 |
return max; |
739 |
|
} |
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
@param |
745 |
|
|
746 |
|
@param |
747 |
|
|
748 |
|
|
749 |
|
@return |
750 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
751 |
6837505 |
private static float max(float f1, float f2)... |
752 |
|
{ |
753 |
6837505 |
float max = f1; |
754 |
|
|
755 |
6837505 |
if (f2 > f1) |
756 |
|
{ |
757 |
3665772 |
max = f2; |
758 |
|
} |
759 |
|
|
760 |
6837505 |
return max; |
761 |
|
} |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
@param |
768 |
|
|
769 |
|
@return |
770 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
771 |
308 |
int[] indexEncode(String s)... |
772 |
|
{ |
773 |
308 |
int[] encoded = new int[s.length()]; |
774 |
|
|
775 |
37796 |
for (int i = 0; i < s.length(); i++) |
776 |
|
{ |
777 |
37488 |
char c = s.charAt(i); |
778 |
37488 |
encoded[i] = scoreMatrix.getMatrixIndex(c); |
779 |
|
} |
780 |
|
|
781 |
308 |
return encoded; |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
@param |
788 |
|
|
789 |
|
@param |
790 |
|
|
791 |
|
@param |
792 |
|
|
793 |
|
@param |
794 |
|
|
795 |
|
@param |
796 |
|
|
797 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
798 |
0 |
public static void displayMatrix(Graphics g, int[][] mat, int n, int m,... |
799 |
|
int psize) |
800 |
|
{ |
801 |
|
|
802 |
0 |
int max = -1000; |
803 |
0 |
int min = 1000; |
804 |
|
|
805 |
0 |
for (int i = 0; i < n; i++) |
806 |
|
{ |
807 |
0 |
for (int j = 0; j < m; j++) |
808 |
|
{ |
809 |
0 |
if (mat[i][j] >= max) |
810 |
|
{ |
811 |
0 |
max = mat[i][j]; |
812 |
|
} |
813 |
|
|
814 |
0 |
if (mat[i][j] <= min) |
815 |
|
{ |
816 |
0 |
min = mat[i][j]; |
817 |
|
} |
818 |
|
} |
819 |
|
} |
820 |
|
|
821 |
0 |
System.out.println(max + " " + min); |
822 |
|
|
823 |
0 |
for (int i = 0; i < n; i++) |
824 |
|
{ |
825 |
0 |
for (int j = 0; j < m; j++) |
826 |
|
{ |
827 |
0 |
int x = psize * i; |
828 |
0 |
int y = psize * j; |
829 |
|
|
830 |
|
|
831 |
0 |
float score = (float) (mat[i][j] - min) / (float) (max - min); |
832 |
0 |
g.setColor(new Color(score, 0, 0)); |
833 |
0 |
g.fillRect(x, y, psize, psize); |
834 |
|
|
835 |
|
|
836 |
|
} |
837 |
|
} |
838 |
|
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
@param |
845 |
|
@param |
846 |
|
@param |
847 |
|
|
848 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
849 |
149 |
public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,... |
850 |
|
String type) |
851 |
|
{ |
852 |
149 |
AlignSeq as = new AlignSeq(s1, s2, type); |
853 |
|
|
854 |
149 |
as.calcScoreMatrix(); |
855 |
149 |
as.traceAlignment(); |
856 |
149 |
return as; |
857 |
|
} |
858 |
|
|
859 |
|
|
860 |
|
|
861 |
|
@return |
862 |
|
|
|
|
| 91.1% |
Uncovered Elements: 5 (56) |
Complexity: 12 |
Complexity Density: 0.32 |
|
863 |
129 |
public jalview.datamodel.Mapping getMappingFromS1(boolean allowmismatch)... |
864 |
|
{ |
865 |
129 |
ArrayList<Integer> as1 = new ArrayList<Integer>(), |
866 |
|
as2 = new ArrayList<Integer>(); |
867 |
129 |
int pdbpos = s2.getStart() + getSeq2Start() - 2; |
868 |
129 |
int alignpos = s1.getStart() + getSeq1Start() - 2; |
869 |
129 |
int lp2 = pdbpos - 3, lp1 = alignpos - 3; |
870 |
129 |
boolean lastmatch = false; |
871 |
|
|
872 |
16124 |
for (int i = 0; i < astr1.length(); i++) |
873 |
|
{ |
874 |
15995 |
char c1 = astr1.charAt(i), c2 = astr2.charAt(i); |
875 |
15995 |
if (c1 != '-') |
876 |
|
{ |
877 |
15995 |
alignpos++; |
878 |
|
} |
879 |
|
|
880 |
15995 |
if (c2 != '-') |
881 |
|
{ |
882 |
15995 |
pdbpos++; |
883 |
|
} |
884 |
|
|
885 |
15995 |
if (allowmismatch || c1 == c2) |
886 |
|
{ |
887 |
|
|
888 |
15955 |
if (lp1 + 1 != alignpos || lp2 + 1 != pdbpos) |
889 |
|
{ |
890 |
168 |
as1.add(Integer.valueOf(alignpos)); |
891 |
168 |
as2.add(Integer.valueOf(pdbpos)); |
892 |
|
} |
893 |
15955 |
lastmatch = true; |
894 |
15955 |
lp1 = alignpos; |
895 |
15955 |
lp2 = pdbpos; |
896 |
|
} |
897 |
|
else |
898 |
|
{ |
899 |
|
|
900 |
40 |
if (lastmatch) |
901 |
|
{ |
902 |
39 |
as1.add(Integer.valueOf(lp1)); |
903 |
39 |
as2.add(Integer.valueOf(lp2)); |
904 |
|
} |
905 |
40 |
lastmatch = false; |
906 |
|
} |
907 |
|
} |
908 |
|
|
909 |
|
|
910 |
129 |
int[] mapseq1 = new int[as1.size() + (lastmatch ? 1 : 0)], |
911 |
129 |
mapseq2 = new int[as2.size() + (lastmatch ? 1 : 0)]; |
912 |
129 |
int i = 0; |
913 |
129 |
for (Integer ip : as1) |
914 |
|
{ |
915 |
207 |
mapseq1[i++] = ip; |
916 |
|
} |
917 |
129 |
; |
918 |
129 |
i = 0; |
919 |
129 |
for (Integer ip : as2) |
920 |
|
{ |
921 |
207 |
mapseq2[i++] = ip; |
922 |
|
} |
923 |
129 |
; |
924 |
129 |
if (lastmatch) |
925 |
|
{ |
926 |
129 |
mapseq1[mapseq1.length - 1] = alignpos; |
927 |
129 |
mapseq2[mapseq2.length - 1] = pdbpos; |
928 |
|
} |
929 |
129 |
MapList map = new MapList(mapseq1, mapseq2, 1, 1); |
930 |
|
|
931 |
129 |
jalview.datamodel.Mapping mapping = new Mapping(map); |
932 |
129 |
mapping.setTo(s2); |
933 |
129 |
return mapping; |
934 |
|
} |
935 |
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
@param |
941 |
|
@param |
942 |
|
@param |
943 |
|
@param |
944 |
|
|
945 |
|
|
946 |
|
@return |
947 |
|
|
948 |
|
|
|
|
| 89.2% |
Uncovered Elements: 7 (65) |
Complexity: 14 |
Complexity Density: 0.31 |
|
949 |
5 |
public static List<List<? extends Object>> replaceMatchingSeqsWith(... |
950 |
|
List<SequenceI> seqs, List<AlignmentAnnotation> annotations, |
951 |
|
List<SequenceI> ochains, AlignmentI al, String dnaOrProtein, |
952 |
|
boolean removeOldAnnots) |
953 |
|
{ |
954 |
5 |
List<SequenceI> orig = new ArrayList<SequenceI>(), |
955 |
|
repl = new ArrayList<SequenceI>(); |
956 |
5 |
List<AlignSeq> aligs = new ArrayList<AlignSeq>(); |
957 |
5 |
if (al != null && al.getHeight() > 0) |
958 |
|
{ |
959 |
5 |
ArrayList<SequenceI> matches = new ArrayList<SequenceI>(); |
960 |
5 |
ArrayList<AlignSeq> aligns = new ArrayList<AlignSeq>(); |
961 |
|
|
962 |
5 |
for (SequenceI sq : ochains) |
963 |
|
{ |
964 |
14 |
SequenceI bestm = null; |
965 |
14 |
AlignSeq bestaseq = null; |
966 |
14 |
float bestscore = 0; |
967 |
14 |
for (SequenceI msq : al.getSequences()) |
968 |
|
{ |
969 |
30 |
AlignSeq aseq = doGlobalNWAlignment(msq, sq, dnaOrProtein); |
970 |
30 |
if (bestm == null || aseq.getMaxScore() > bestscore) |
971 |
|
{ |
972 |
14 |
bestscore = aseq.getMaxScore(); |
973 |
14 |
bestaseq = aseq; |
974 |
14 |
bestm = msq; |
975 |
|
} |
976 |
|
} |
977 |
|
|
978 |
|
|
979 |
14 |
matches.add(bestm); |
980 |
14 |
aligns.add(bestaseq); |
981 |
14 |
al.deleteSequence(bestm); |
982 |
|
} |
983 |
19 |
for (int p = 0, pSize = seqs.size(); p < pSize; p++) |
984 |
|
{ |
985 |
14 |
SequenceI sq, sp = seqs.get(p); |
986 |
14 |
int q; |
987 |
? |
if ((q = ochains.indexOf(sp)) > -1) |
988 |
|
{ |
989 |
14 |
seqs.set(p, sq = matches.get(q)); |
990 |
14 |
orig.add(sp); |
991 |
14 |
repl.add(sq); |
992 |
14 |
sq.setName(sp.getName()); |
993 |
14 |
sq.setDescription(sp.getDescription()); |
994 |
14 |
Mapping sp2sq; |
995 |
14 |
sq.transferAnnotation(sp, |
996 |
|
sp2sq = aligns.get(q).getMappingFromS1(false)); |
997 |
14 |
aligs.add(aligns.get(q)); |
998 |
14 |
int inspos = -1; |
999 |
46 |
for (int ap = 0; ap < annotations.size();) |
1000 |
|
{ |
1001 |
32 |
if (annotations.get(ap).sequenceRef == sp) |
1002 |
|
{ |
1003 |
4 |
if (inspos == -1) |
1004 |
|
{ |
1005 |
4 |
inspos = ap; |
1006 |
|
} |
1007 |
4 |
if (removeOldAnnots) |
1008 |
|
{ |
1009 |
0 |
annotations.remove(ap); |
1010 |
|
} |
1011 |
|
else |
1012 |
|
{ |
1013 |
4 |
AlignmentAnnotation alan = annotations.remove(ap); |
1014 |
4 |
alan.liftOver(sq, sp2sq); |
1015 |
4 |
alan.setSequenceRef(sq); |
1016 |
4 |
sq.addAlignmentAnnotation(alan); |
1017 |
|
} |
1018 |
|
} |
1019 |
|
else |
1020 |
|
{ |
1021 |
28 |
ap++; |
1022 |
|
} |
1023 |
|
} |
1024 |
14 |
if (sq.getAnnotation() != null && sq.getAnnotation().length > 0) |
1025 |
|
{ |
1026 |
14 |
annotations.addAll(inspos == -1 ? annotations.size() : inspos, |
1027 |
|
Arrays.asList(sq.getAnnotation())); |
1028 |
|
} |
1029 |
|
} |
1030 |
|
} |
1031 |
|
} |
1032 |
5 |
return Arrays.asList(orig, repl, aligs); |
1033 |
|
} |
1034 |
|
|
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
|
@param |
1039 |
|
|
1040 |
|
@param |
1041 |
|
|
1042 |
|
|
1043 |
|
@param |
1044 |
|
|
1045 |
|
@param |
1046 |
|
|
1047 |
|
@param |
1048 |
|
|
1049 |
|
@return |
1050 |
|
|
1051 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 11 |
Complexity Density: 0.33 |
|
1052 |
0 |
public static float[] computeRedundancyMatrix(... |
1053 |
|
SequenceI[] originalSequences, String[] omitHidden, int start, |
1054 |
|
int end, boolean ungapped) |
1055 |
|
{ |
1056 |
0 |
int height = originalSequences.length; |
1057 |
0 |
float[] redundancy = new float[height]; |
1058 |
0 |
int[] lngth = new int[height]; |
1059 |
0 |
for (int i = 0; i < height; i++) |
1060 |
|
{ |
1061 |
0 |
redundancy[i] = 0f; |
1062 |
0 |
lngth[i] = -1; |
1063 |
|
} |
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
0 |
SimilarityParams pidParams = new SimilarityParams(true, true, true, |
1068 |
|
true); |
1069 |
0 |
float pid; |
1070 |
0 |
String seqi, seqj; |
1071 |
0 |
for (int i = 0; i < height; i++) |
1072 |
|
{ |
1073 |
|
|
1074 |
0 |
for (int j = 0; j < i; j++) |
1075 |
|
{ |
1076 |
0 |
if (i == j) |
1077 |
|
{ |
1078 |
0 |
continue; |
1079 |
|
} |
1080 |
|
|
1081 |
0 |
if (omitHidden == null) |
1082 |
|
{ |
1083 |
0 |
seqi = originalSequences[i].getSequenceAsString(start, end); |
1084 |
0 |
seqj = originalSequences[j].getSequenceAsString(start, end); |
1085 |
|
} |
1086 |
|
else |
1087 |
|
{ |
1088 |
0 |
seqi = omitHidden[i]; |
1089 |
0 |
seqj = omitHidden[j]; |
1090 |
|
} |
1091 |
0 |
if (lngth[i] == -1) |
1092 |
|
{ |
1093 |
0 |
String ug = AlignSeq.extractGaps(Comparison.GapChars, seqi); |
1094 |
0 |
lngth[i] = ug.length(); |
1095 |
0 |
if (ungapped) |
1096 |
|
{ |
1097 |
0 |
seqi = ug; |
1098 |
|
} |
1099 |
|
} |
1100 |
0 |
if (lngth[j] == -1) |
1101 |
|
{ |
1102 |
0 |
String ug = AlignSeq.extractGaps(Comparison.GapChars, seqj); |
1103 |
0 |
lngth[j] = ug.length(); |
1104 |
0 |
if (ungapped) |
1105 |
|
{ |
1106 |
0 |
seqj = ug; |
1107 |
|
} |
1108 |
|
} |
1109 |
0 |
pid = (float) PIDModel.computePID(seqi, seqj, pidParams); |
1110 |
|
|
1111 |
|
|
1112 |
0 |
if (lngth[j] < lngth[i]) |
1113 |
|
{ |
1114 |
0 |
redundancy[j] = Math.max(pid, redundancy[j]); |
1115 |
|
} |
1116 |
|
else |
1117 |
|
{ |
1118 |
0 |
redundancy[i] = Math.max(pid, redundancy[i]); |
1119 |
|
} |
1120 |
|
|
1121 |
|
} |
1122 |
|
} |
1123 |
0 |
return redundancy; |
1124 |
|
} |
1125 |
|
} |