1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.analysis.AlignSeq; |
24 |
|
import jalview.analysis.scoremodels.ScoreMatrix; |
25 |
|
import jalview.datamodel.Alignment; |
26 |
|
import jalview.datamodel.AlignmentView; |
27 |
|
import jalview.datamodel.SequenceGroup; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.jbgui.GPairwiseAlignPanel; |
30 |
|
import jalview.util.MessageManager; |
31 |
|
import jalview.viewmodel.AlignmentViewport; |
32 |
|
import jalview.math.MiscMath; |
33 |
|
|
34 |
|
import java.awt.event.ActionEvent; |
35 |
|
import java.util.Vector; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
@version |
42 |
|
|
|
|
| 50.5% |
Uncovered Elements: 97 (196) |
Complexity: 50 |
Complexity Density: 0.4 |
|
43 |
|
public class PairwiseAlignPanel extends GPairwiseAlignPanel |
44 |
|
{ |
45 |
|
|
46 |
|
private static final String DASHES = "---------------------\n"; |
47 |
|
|
48 |
|
private float[][] scores; |
49 |
|
|
50 |
|
private float[][] alignmentScores; |
51 |
|
|
52 |
|
private int GAP_OPEN_COST; |
53 |
|
|
54 |
|
private int GAP_EXTEND_COST; |
55 |
|
|
56 |
|
AlignmentViewport av; |
57 |
|
|
58 |
|
Vector<SequenceI> sequences; |
59 |
|
|
60 |
|
private String alignmentOutput; |
61 |
|
|
62 |
|
private boolean quiet; |
63 |
|
|
64 |
|
private boolean discardAlignments; |
65 |
|
|
66 |
|
private boolean endGaps; |
67 |
|
|
68 |
|
|
69 |
|
public static final String TOTAL = "total"; |
70 |
|
|
71 |
|
public static final String PROGRESS = "progress"; |
72 |
|
|
73 |
|
protected static final String ETA = "eta_in_minutes"; |
74 |
|
|
75 |
|
public static final String PROGRESSCOMPLETE = "finished_stop_progress"; |
76 |
|
public static final String PROGRESSMESSAGE = "message_in_progress"; |
77 |
|
|
78 |
|
private volatile boolean cancelled; |
79 |
|
|
80 |
|
private long total; |
81 |
|
|
82 |
|
private long progress; |
83 |
|
|
84 |
|
private SequenceGroup selection; |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
private SequenceI[] seqs = null; |
90 |
|
|
91 |
|
private ScoreMatrix scoreMatrix; |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
private double etime=Double.NaN; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
2 |
public PairwiseAlignPanel(AlignmentViewport viewport)... |
107 |
|
{ |
108 |
2 |
this(viewport, null, false, 120, 20, true, null); |
109 |
|
|
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0 |
public PairwiseAlignPanel(AlignmentViewport viewport, ScoreMatrix params)... |
113 |
|
{ |
114 |
0 |
this(viewport, null, false, 120, 20, true, params); |
115 |
|
|
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps,... |
119 |
|
int gapOpenCost, int gapExtendCost) |
120 |
|
{ |
121 |
0 |
this(viewport, null, endGaps, gapOpenCost, gapExtendCost, true, null); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
@param |
130 |
|
@param |
131 |
|
@param |
132 |
|
@param |
133 |
|
@param |
134 |
|
@param |
135 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
136 |
2 |
public PairwiseAlignPanel(AlignmentViewport viewport,... |
137 |
|
SequenceGroup selection, boolean endGaps, int gapOpenCost, |
138 |
|
int gapExtendCost, boolean run, ScoreMatrix scoreMatrix) |
139 |
|
{ |
140 |
2 |
super(); |
141 |
2 |
this.av = viewport; |
142 |
2 |
this.GAP_OPEN_COST = gapOpenCost; |
143 |
2 |
this.GAP_EXTEND_COST = gapExtendCost; |
144 |
2 |
this.endGaps = endGaps; |
145 |
2 |
this.selection = selection; |
146 |
2 |
this.total = av.getAlignment().getHeight(); |
147 |
2 |
total = (total*total-total)/2; |
148 |
2 |
this.scoreMatrix = scoreMatrix; |
149 |
2 |
if (run) |
150 |
|
{ |
151 |
2 |
calculate(); |
152 |
|
} |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
2 |
public void calculate()... |
156 |
|
{ |
157 |
2 |
calculate(scoreMatrix); |
158 |
|
} |
159 |
|
|
|
|
| 75.7% |
Uncovered Elements: 26 (107) |
Complexity: 19 |
Complexity Density: 0.25 |
|
160 |
2 |
public void calculate(ScoreMatrix sm)... |
161 |
|
{ |
162 |
2 |
cancelled=false; |
163 |
2 |
StringBuilder sb = new StringBuilder(1024); |
164 |
|
|
165 |
2 |
sequences = new Vector<SequenceI>(); |
166 |
2 |
String[] seqStrings; |
167 |
2 |
seqs = null; |
168 |
|
|
169 |
2 |
if (selection != null) |
170 |
|
{ |
171 |
|
|
172 |
0 |
seqs = selection.getSelectionAsNewSequences(av.getAlignment()); |
173 |
0 |
seqStrings = new String[seqs.length]; |
174 |
0 |
int s = 0; |
175 |
0 |
for (SequenceI seq : seqs) |
176 |
|
{ |
177 |
0 |
seqStrings[s++] = seq.getSequenceAsString(); |
178 |
|
} |
179 |
|
} |
180 |
|
else |
181 |
|
{ |
182 |
2 |
SequenceGroup selectionGroup = av.getSelectionGroup(); |
183 |
2 |
boolean isSelection = selectionGroup != null |
184 |
|
&& selectionGroup.getSize() > 0; |
185 |
2 |
AlignmentView view = av.getAlignmentView(isSelection); |
186 |
2 |
seqStrings = view.getSequenceStrings(av.getGapCharacter()); |
187 |
2 |
if (isSelection) |
188 |
|
{ |
189 |
1 |
seqs = (SequenceI[]) view |
190 |
|
.getAlignmentAndHiddenColumns(av.getGapCharacter())[0]; |
191 |
|
} |
192 |
|
else |
193 |
|
{ |
194 |
1 |
seqs = av.getAlignment().getSequencesArray(); |
195 |
|
} |
196 |
|
} |
197 |
|
|
198 |
2 |
String type = (av.getAlignment().isNucleotide()) ? AlignSeq.DNA |
199 |
|
: AlignSeq.PEP; |
200 |
|
|
201 |
2 |
float[][] scores = new float[seqs.length][seqs.length]; |
202 |
2 |
float[][] alignmentScores = new float[seqs.length][seqs.length]; |
203 |
2 |
double totscore = 0D; |
204 |
2 |
int count = seqs.length; |
205 |
2 |
int fracprogress=0; |
206 |
2 |
boolean first = true; |
207 |
2 |
long time=System.currentTimeMillis(); |
208 |
2 |
long fprogress = 0; |
209 |
2 |
firePropertyChange(TOTAL, 0, 500); |
210 |
|
|
211 |
4 |
for (int i = 1; i < count; i++) |
212 |
|
{ |
213 |
|
|
214 |
2 |
alignmentScores[i - 1][i - 1] = Float.NaN; |
215 |
4 |
for (int j = 0; j < i; j++) |
216 |
|
{ |
217 |
2 |
if (cancelled) |
218 |
|
{ |
219 |
0 |
alignmentOutput = "Alignment was cancelled."; |
220 |
0 |
return; |
221 |
|
} |
222 |
2 |
AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], |
223 |
|
seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST); |
224 |
|
|
225 |
2 |
if (sm != null) |
226 |
|
{ |
227 |
0 |
as.setScoreMatrix(sm); |
228 |
|
} |
229 |
|
|
230 |
2 |
if (as.s1str.length() == 0 || as.s2str.length() == 0) |
231 |
|
{ |
232 |
0 |
continue; |
233 |
|
} |
234 |
|
|
235 |
2 |
as.calcScoreMatrix(); |
236 |
2 |
if (endGaps) |
237 |
|
{ |
238 |
0 |
as.traceAlignmentWithEndGaps(); |
239 |
|
} |
240 |
|
else |
241 |
|
{ |
242 |
2 |
as.traceAlignment(); |
243 |
|
} |
244 |
2 |
as.scoreAlignment(); |
245 |
|
|
246 |
2 |
if (!first && !quiet) |
247 |
|
{ |
248 |
0 |
jalview.bin.Console.outPrintln(DASHES); |
249 |
0 |
textarea.append(DASHES); |
250 |
0 |
sb.append(DASHES); |
251 |
|
} |
252 |
2 |
first = false; |
253 |
2 |
if (!discardAlignments) |
254 |
|
{ |
255 |
2 |
as.printAlignment(System.out); |
256 |
|
} |
257 |
2 |
scores[i][j] = as.getMaxScore() / as.getASeq1().length; |
258 |
2 |
alignmentScores[i][j] = as.getAlignmentScore(); |
259 |
2 |
totscore = totscore + scores[i][j]; |
260 |
2 |
if (!quiet) |
261 |
|
{ |
262 |
2 |
textarea.append(as.getOutput()); |
263 |
2 |
sb.append(as.getOutput()); |
264 |
|
} |
265 |
2 |
if (!discardAlignments) |
266 |
|
{ |
267 |
2 |
sequences.add(as.getAlignedSeq1()); |
268 |
2 |
sequences.add(as.getAlignedSeq2()); |
269 |
|
} |
270 |
2 |
++fprogress; |
271 |
|
} |
272 |
2 |
if (i<count) |
273 |
|
{ |
274 |
2 |
int newfracprogress=(int) Math.floor((500.0*(double)fprogress)/((double)total)); |
275 |
|
|
276 |
2 |
firePropertyChange(PROGRESS, fracprogress, newfracprogress); |
277 |
2 |
fracprogress = newfracprogress; |
278 |
2 |
progress=fprogress; |
279 |
|
|
280 |
2 |
double lasteta=etime; |
281 |
2 |
double rate = ((double)(System.currentTimeMillis()-time))/(double)progress; |
282 |
2 |
etime = rate*(total-progress)/60000; |
283 |
2 |
firePropertyChange(ETA, lasteta,etime); |
284 |
|
} |
285 |
|
} |
286 |
2 |
alignmentScores[count - 1][count - 1] = Float.NaN; |
287 |
|
|
288 |
2 |
firePropertyChange(TOTAL, -1, -2); |
289 |
|
|
290 |
|
|
291 |
2 |
this.scores = scores; |
292 |
2 |
this.alignmentScores = alignmentScores; |
293 |
|
|
294 |
2 |
if (count > 2 && !quiet) |
295 |
|
{ |
296 |
0 |
printScoreMatrix(seqs, scores, totscore); |
297 |
|
} |
298 |
|
|
299 |
2 |
alignmentOutput = sb.toString(); |
300 |
|
} |
301 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
0 |
public boolean hasEta()... |
303 |
|
{ |
304 |
0 |
return etime>0; |
305 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
0 |
public double getEta()... |
307 |
|
{ |
308 |
0 |
return etime; |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
313 |
0 |
public void cancel()... |
314 |
|
{ |
315 |
0 |
cancelled=true; |
316 |
|
} |
317 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
318 |
0 |
public float[][] getScores()... |
319 |
|
{ |
320 |
0 |
return this.scores; |
321 |
|
} |
322 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
323 |
0 |
public float[][] getAlignmentScores()... |
324 |
|
{ |
325 |
0 |
return this.alignmentScores; |
326 |
|
} |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
328 |
0 |
public String getAlignmentOutput()... |
329 |
|
{ |
330 |
0 |
return this.alignmentOutput; |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
@param |
337 |
|
@param |
338 |
|
@param |
339 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
340 |
0 |
protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,... |
341 |
|
double totscore) |
342 |
|
{ |
343 |
0 |
System.out |
344 |
|
.println("Pairwise alignment scaled similarity score matrix "+getPairwiseSimscoresAsString()+"\n"); |
345 |
|
|
346 |
0 |
for (int i = 0; i < seqs.length; i++) |
347 |
|
{ |
348 |
0 |
jalview.bin.Console.outPrintln( |
349 |
|
String.format("%3d %s", i + 1, seqs[i].getDisplayId(true))); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
0 |
System.out.print("\n "); |
356 |
0 |
for (int i = 0; i < seqs.length; i++) |
357 |
|
{ |
358 |
0 |
System.out.print(String.format("%7d", i + 1)); |
359 |
|
} |
360 |
0 |
jalview.bin.Console.outPrintln(); |
361 |
|
|
362 |
0 |
for (int i = 0; i < seqs.length; i++) |
363 |
|
{ |
364 |
0 |
System.out.print(String.format("%3d", i + 1)); |
365 |
0 |
for (int j = 0; j < i; j++) |
366 |
|
{ |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
0 |
System.out.print(String.format("%7.3f", scores[i][j] / totscore)); |
371 |
|
} |
372 |
0 |
jalview.bin.Console.outPrintln(); |
373 |
|
} |
374 |
|
|
375 |
0 |
jalview.bin.Console.outPrintln("\n"); |
376 |
|
} |
377 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
378 |
0 |
public String getPairwiseSimscoresAsString()... |
379 |
|
{ |
380 |
0 |
return (scoreMatrix != null |
381 |
|
? " (" + scoreMatrix.getName() + ", open=" + GAP_OPEN_COST |
382 |
|
+ ", extend=" + GAP_EXTEND_COST |
383 |
0 |
+ (endGaps ? ", with endGaps" : ", no endGaps") + ")" |
384 |
|
: ""); |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
@param |
391 |
|
|
392 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
393 |
0 |
@Override... |
394 |
|
protected void viewInEditorButton_actionPerformed(ActionEvent e) |
395 |
|
{ |
396 |
0 |
SequenceI[] seq = new SequenceI[sequences.size()]; |
397 |
|
|
398 |
0 |
for (int i = 0; i < sequences.size(); i++) |
399 |
|
{ |
400 |
0 |
seq[i] = sequences.elementAt(i); |
401 |
|
} |
402 |
|
|
403 |
0 |
AlignFrame af = new AlignFrame(new Alignment(seq), |
404 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
405 |
|
|
406 |
0 |
Desktop.addInternalFrame(af, |
407 |
|
MessageManager.getString("label.pairwise_aligned_sequences")+" "+getPairwiseSimscoresAsString(), |
408 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
409 |
|
} |
410 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
411 |
0 |
public long getTotal()... |
412 |
|
{ |
413 |
0 |
return total; |
414 |
|
} |
415 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
416 |
0 |
public long getProgress()... |
417 |
|
{ |
418 |
0 |
return progress; |
419 |
|
} |
420 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
421 |
0 |
public SequenceI[] getInputSequences()... |
422 |
|
{ |
423 |
0 |
return seqs; |
424 |
|
} |
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
@param |
430 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
431 |
0 |
public void setQuiet(boolean quiet)... |
432 |
|
{ |
433 |
0 |
this.quiet = quiet; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
@return |
438 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
439 |
0 |
public boolean isQuiet()... |
440 |
|
{ |
441 |
0 |
return quiet; |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
@param |
448 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
449 |
0 |
public void setDiscardAlignments(boolean discard)... |
450 |
|
{ |
451 |
0 |
discardAlignments = discard; |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
|
@return |
456 |
|
@return |
457 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
458 |
0 |
public boolean isDiscardAlignments()... |
459 |
|
{ |
460 |
0 |
return discardAlignments; |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
@return |
466 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
467 |
0 |
public boolean isCancelled()... |
468 |
|
{ |
469 |
0 |
return cancelled; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
@param |
475 |
|
@param |
476 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
477 |
0 |
public void updateProgress(String type, String message)... |
478 |
|
{ |
479 |
0 |
firePropertyChange(type, "", MessageManager.getStringOrReturn("progress", message)); |
480 |
|
} |
481 |
|
} |