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