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