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.api.analysis.ScoreModelI; |
24 |
|
import jalview.api.analysis.SimilarityParamsI; |
25 |
|
import jalview.analysis.scoremodels.ScoreMatrix; |
26 |
|
import jalview.analysis.scoremodels.ScoreModels; |
27 |
|
import jalview.bin.Console; |
28 |
|
import jalview.datamodel.Point; |
29 |
|
import jalview.datamodel.SequenceI; |
30 |
|
import jalview.datamodel.SequenceGroup; |
31 |
|
import jalview.gui.PairwiseAlignPanel; |
32 |
|
import jalview.math.Matrix; |
33 |
|
import jalview.math.MatrixI; |
34 |
|
import jalview.viewmodel.AlignmentViewport; |
35 |
|
|
36 |
|
import java.io.PrintStream; |
37 |
|
import java.util.Hashtable; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
|
|
| 0% |
Uncovered Elements: 100 (100) |
Complexity: 29 |
Complexity Density: 0.43 |
|
44 |
|
public class PaSiMap implements Runnable |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
final private AlignmentViewport seqs; |
50 |
|
|
51 |
|
final private ScoreMatrix scoreMatrix; |
52 |
|
|
53 |
|
final private byte dim = 8; |
54 |
|
|
55 |
|
final private int openCost = 100; |
56 |
|
|
57 |
|
final private int extendCost = 5; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
final private PairwiseAlignPanel alignment; |
63 |
|
|
64 |
|
private boolean cancelled=false; |
65 |
|
|
66 |
|
private MatrixI pairwiseScores; |
67 |
|
|
68 |
|
private MatrixI eigenMatrix; |
69 |
|
|
70 |
|
private volatile boolean canCancel; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
@param |
78 |
|
@param |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
80 |
0 |
public PaSiMap(AlignmentViewport sequences, ScoreModelI sm,... |
81 |
|
PairwiseAlignPanel pap) |
82 |
|
{ |
83 |
0 |
this.seqs = sequences; |
84 |
|
|
85 |
0 |
if (sm != null && sm instanceof ScoreMatrix) |
86 |
|
{ |
87 |
0 |
this.scoreMatrix = ((ScoreMatrix) sm); |
88 |
|
} |
89 |
|
else |
90 |
|
{ |
91 |
0 |
this.scoreMatrix = null; |
92 |
|
} |
93 |
|
|
94 |
0 |
this.alignment = pap; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
|
102 |
|
|
103 |
|
@return |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0 |
public double getEigenvalue(int i)... |
106 |
|
{ |
107 |
0 |
return eigenMatrix.getD()[i]; |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
@param |
118 |
|
|
119 |
|
@param |
120 |
|
|
121 |
|
|
122 |
|
@return |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
124 |
0 |
public Point[] getComponents(int l, int n, int mm, float factor)... |
125 |
|
{ |
126 |
0 |
Point[] out = new Point[getHeight()]; |
127 |
|
|
128 |
0 |
for (int i = 0; i < out.length; i++) |
129 |
|
{ |
130 |
0 |
float x = (float) component(i, l) * factor; |
131 |
0 |
float y = (float) component(i, n) * factor; |
132 |
0 |
float z = (float) component(i, mm) * factor; |
133 |
0 |
out[i] = new Point(x, y, z); |
134 |
|
} |
135 |
|
|
136 |
0 |
return out; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@param |
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
147 |
0 |
public double[] component(int n)... |
148 |
|
{ |
149 |
|
|
150 |
0 |
double[] out = new double[getWidth()]; |
151 |
|
|
152 |
0 |
for (int i = 0; i < out.length; i++) |
153 |
|
{ |
154 |
0 |
out[i] = component(n, i); |
155 |
|
} |
156 |
|
|
157 |
0 |
return out; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@param |
164 |
|
|
165 |
|
@param |
166 |
|
|
167 |
|
|
168 |
|
@return |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
0 |
double component(int row, int n)... |
171 |
|
{ |
172 |
0 |
return eigenMatrix.getValue(row, n); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
@return |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
181 |
0 |
public String getDetails()... |
182 |
|
{ |
183 |
0 |
StringBuilder sb = new StringBuilder(1024); |
184 |
0 |
sb.append("PaSiMap calculation using ").append(scoreMatrix.getName()) |
185 |
|
.append(" sequence similarity matrix\n========\n\n"); |
186 |
0 |
PrintStream ps = wrapOutputBuffer(sb); |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
0 |
sb.append(" --- Pairwise correlation coefficients ---\n"); |
192 |
0 |
pairwiseScores.print(ps, "%8.6f "); |
193 |
0 |
ps.println(); |
194 |
|
|
195 |
0 |
sb.append(" --- Eigenvalues ---\n"); |
196 |
0 |
eigenMatrix.printD(ps, "%15.4e"); |
197 |
0 |
ps.println(); |
198 |
|
|
199 |
0 |
sb.append(" --- Coordinates ---\n"); |
200 |
0 |
eigenMatrix.print(ps, "%8.6f "); |
201 |
0 |
ps.println(); |
202 |
|
|
203 |
0 |
return sb.toString(); |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 3 |
Complexity Density: 0.16 |
|
230 |
0 |
@Override... |
231 |
|
public void run() |
232 |
|
{ |
233 |
0 |
canCancel=true; |
234 |
0 |
try |
235 |
|
{ |
236 |
|
|
237 |
0 |
alignment.calculate(scoreMatrix); |
238 |
0 |
if (alignment.isCancelled()) |
239 |
|
{ |
240 |
0 |
cancel(); |
241 |
0 |
return; |
242 |
|
} |
243 |
|
|
244 |
0 |
float[][] scores = alignment.getAlignmentScores(); |
245 |
|
|
246 |
0 |
SequenceI[] iseqs = alignment.getInputSequences(); |
247 |
0 |
Connectivity.getConnectivity(iseqs, scores, dim); |
248 |
|
|
249 |
0 |
canCancel=false; |
250 |
0 |
alignment.updateProgress(PairwiseAlignPanel.PROGRESSMESSAGE, "Creating the PaSiMap"); |
251 |
0 |
pairwiseScores = new Matrix(scores); |
252 |
0 |
pairwiseScores.fillDiagonal(); |
253 |
|
|
254 |
0 |
eigenMatrix = pairwiseScores.copy(); |
255 |
|
|
256 |
0 |
ccAnalysis cc = new ccAnalysis(pairwiseScores, dim); |
257 |
0 |
eigenMatrix = cc.run().mirrorCol(); |
258 |
0 |
alignment.updateProgress(PairwiseAlignPanel.PROGRESSCOMPLETE, "Finished PaSiMap."); |
259 |
|
|
260 |
|
} catch (Exception q) |
261 |
|
{ |
262 |
0 |
Console.error("Error computing PaSiMap: " + q.getMessage()); |
263 |
0 |
q.printStackTrace(); |
264 |
|
} |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
269 |
0 |
public void cancel()... |
270 |
|
{ |
271 |
0 |
if (alignment!=null) |
272 |
|
{ |
273 |
0 |
alignment.cancel(); |
274 |
|
} |
275 |
0 |
cancelled=true; |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
0 |
public boolean isCancelled()... |
279 |
|
{ |
280 |
0 |
return cancelled; |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
@param |
288 |
|
@return |
289 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
290 |
0 |
protected PrintStream wrapOutputBuffer(StringBuilder sb)... |
291 |
|
{ |
292 |
0 |
PrintStream ps = new PrintStream(System.out) |
293 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
294 |
0 |
@Override... |
295 |
|
public void print(String x) |
296 |
|
{ |
297 |
0 |
sb.append(x); |
298 |
|
} |
299 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
300 |
0 |
@Override... |
301 |
|
public void println() |
302 |
|
{ |
303 |
0 |
sb.append("\n"); |
304 |
|
} |
305 |
|
}; |
306 |
0 |
return ps; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
@return |
314 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
315 |
0 |
public int getHeight()... |
316 |
|
{ |
317 |
|
|
318 |
0 |
return eigenMatrix.height(); |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
@return |
326 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
327 |
0 |
public int getWidth()... |
328 |
|
{ |
329 |
|
|
330 |
0 |
return eigenMatrix.width(); |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
@return |
338 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
339 |
0 |
public MatrixI getPairwiseScores()... |
340 |
|
{ |
341 |
0 |
return pairwiseScores; |
342 |
|
} |
343 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
344 |
0 |
public void setPairwiseScores(MatrixI m)... |
345 |
|
{ |
346 |
0 |
pairwiseScores = m; |
347 |
|
} |
348 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
349 |
0 |
public MatrixI getEigenmatrix()... |
350 |
|
{ |
351 |
0 |
return eigenMatrix; |
352 |
|
} |
353 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
354 |
0 |
public void setEigenmatrix(MatrixI m)... |
355 |
|
{ |
356 |
0 |
eigenMatrix = m; |
357 |
|
} |
358 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
359 |
0 |
public PairwiseAlignPanel getAlignments()... |
360 |
|
{ |
361 |
0 |
return alignment; |
362 |
|
} |
363 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
364 |
0 |
public String getAlignmentOutput()... |
365 |
|
{ |
366 |
0 |
return alignment.getAlignmentOutput(); |
367 |
|
} |
368 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
369 |
0 |
public byte getDim()... |
370 |
|
{ |
371 |
0 |
return dim; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@return |
377 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
378 |
0 |
public boolean isCancellable()... |
379 |
|
{ |
380 |
0 |
return canCancel; |
381 |
|
} |
382 |
|
} |