1 |
|
package jalview.viewmodel; |
2 |
|
|
3 |
|
import java.util.Arrays; |
4 |
|
import java.util.List; |
5 |
|
import java.util.Set; |
6 |
|
import java.util.Vector; |
7 |
|
|
8 |
|
import jalview.analysis.Clusterer; |
9 |
|
import jalview.analysis.SpatialCalculationI; |
10 |
|
import jalview.api.RotatableCanvasI; |
11 |
|
import jalview.api.analysis.ScoreModelI; |
12 |
|
import jalview.api.analysis.SimilarityParamsI; |
13 |
|
import jalview.datamodel.AlignmentView; |
14 |
|
import jalview.datamodel.Point; |
15 |
|
import jalview.datamodel.SequenceGroup; |
16 |
|
import jalview.datamodel.SequenceI; |
17 |
|
import jalview.datamodel.SequencePoint; |
18 |
|
import jalview.math.Matrix; |
19 |
|
import jalview.math.MatrixI; |
20 |
|
|
|
|
| 29.5% |
Uncovered Elements: 93 (132) |
Complexity: 39 |
Complexity Density: 0.46 |
|
21 |
|
public abstract class SpatialModel<T extends SpatialCalculationI> |
22 |
|
{ |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
protected AlignmentViewport av; |
27 |
|
|
28 |
|
protected AlignmentView inputData; |
29 |
|
|
30 |
|
protected final SequenceI[] seqs; |
31 |
|
|
32 |
|
protected final SimilarityParamsI similarityParams; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
protected ScoreModelI scoreModel; |
38 |
|
|
39 |
|
protected boolean nucleotide = false; |
40 |
|
|
41 |
|
protected T outputModel; |
42 |
|
|
43 |
|
private int top; |
44 |
|
|
45 |
|
private List<SequencePoint> points; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
@param |
53 |
|
@param |
54 |
|
@param |
55 |
|
@param |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
57 |
2 |
public SpatialModel(AlignmentViewport av, AlignmentView seqData, SequenceI[] sqs, boolean nuc,... |
58 |
|
ScoreModelI modelName, SimilarityParamsI params) |
59 |
|
{ |
60 |
2 |
this.av = av; |
61 |
2 |
inputData = seqData; |
62 |
2 |
seqs = sqs; |
63 |
2 |
nucleotide = nuc; |
64 |
2 |
scoreModel = modelName; |
65 |
2 |
similarityParams = params; |
66 |
|
} |
67 |
|
|
68 |
|
public abstract T constructModel(); |
69 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
70 |
1 |
public void calculate()... |
71 |
|
{ |
72 |
1 |
outputModel = constructModel(); |
73 |
1 |
outputModel.run(); |
74 |
1 |
if (outputModel.isCancelled()) |
75 |
|
{ |
76 |
|
|
77 |
0 |
return; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
1 |
int height = outputModel.getHeight(); |
91 |
1 |
int width = outputModel.getWidth(); |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
1 |
top = outputModel.getTop(); |
96 |
|
|
97 |
1 |
points = new Vector<>(); |
98 |
1 |
Point[] scores = outputModel.getComponents(top - 1, top - 2, top - 3, 1f); |
99 |
|
|
100 |
16 |
for (int i = 0; i < height; i++) |
101 |
|
{ |
102 |
15 |
SequencePoint sp = new SequencePoint(seqs[i], scores[i]); |
103 |
15 |
points.add(sp); |
104 |
|
} |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
1 |
public void updateRc(RotatableCanvasI rc)... |
108 |
|
{ |
109 |
1 |
rc.setPoints(points, outputModel.getHeight()); |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0 |
public boolean isNucleotide()... |
113 |
|
{ |
114 |
0 |
return nucleotide; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
public void setNucleotide(boolean nucleotide)... |
118 |
|
{ |
119 |
0 |
this.nucleotide = nucleotide; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@return |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
1 |
public int getTop()... |
128 |
|
{ |
129 |
1 |
return top; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
1 |
public void setTop(int t)... |
136 |
|
{ |
137 |
1 |
top = t; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@param |
148 |
|
@param |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
150 |
0 |
public void updateRcView(int dim1, int dim2, int dim3)... |
151 |
|
{ |
152 |
|
|
153 |
0 |
Point[] scores = outputModel.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 1); |
154 |
|
|
155 |
0 |
for (int i = 0; i < outputModel.getHeight(); i++) |
156 |
|
{ |
157 |
0 |
points.get(i).coord = scores[i]; |
158 |
|
} |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0 |
public String getDetails()... |
162 |
|
{ |
163 |
0 |
return outputModel.getDetails(); |
164 |
|
} |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0 |
public String getAlignmentOutput()... |
167 |
|
{ |
168 |
0 |
return outputModel.getAlignmentOutput(); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
0 |
public AlignmentViewport getInputAlignmentView()... |
172 |
|
{ |
173 |
0 |
return av; |
174 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
public AlignmentView getInputData()... |
176 |
|
{ |
177 |
0 |
return inputData; |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 6 |
Complexity Density: 0.24 |
|
180 |
0 |
public String getPointsasCsv(boolean transformed, int xdim, int ydim,... |
181 |
|
int zdim) |
182 |
|
{ |
183 |
0 |
StringBuffer csv = new StringBuffer(); |
184 |
0 |
csv.append("\"Sequence\""); |
185 |
0 |
if (transformed) |
186 |
|
{ |
187 |
0 |
csv.append(","); |
188 |
0 |
csv.append(xdim); |
189 |
0 |
csv.append(","); |
190 |
0 |
csv.append(ydim); |
191 |
0 |
csv.append(","); |
192 |
0 |
csv.append(zdim); |
193 |
|
} |
194 |
|
else |
195 |
|
{ |
196 |
|
|
197 |
0 |
for (int d = 1, dmax = (int) outputModel.getDim(); d <= dmax; d++) |
198 |
|
{ |
199 |
0 |
csv.append("," + d); |
200 |
|
} |
201 |
|
} |
202 |
0 |
csv.append("\n"); |
203 |
0 |
for (int s = 0; s < seqs.length; s++) |
204 |
|
{ |
205 |
0 |
csv.append("\"" + seqs[s].getName() + "\""); |
206 |
0 |
if (!transformed) |
207 |
|
{ |
208 |
0 |
double[] fl = outputModel.component(s); |
209 |
0 |
for (int d = fl.length - 1; d >= 0; d--) |
210 |
|
{ |
211 |
0 |
csv.append(","); |
212 |
0 |
csv.append(fl[d]); |
213 |
|
} |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
0 |
Point p = points.get(s).coord; |
218 |
0 |
csv.append(",").append(p.x); |
219 |
0 |
csv.append(",").append(p.y); |
220 |
0 |
csv.append(",").append(p.z); |
221 |
|
} |
222 |
0 |
csv.append("\n"); |
223 |
|
} |
224 |
0 |
return csv.toString(); |
225 |
|
} |
226 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
227 |
3 |
public String getScoreModelName()... |
228 |
|
{ |
229 |
3 |
return scoreModel == null ? "" : scoreModel.getName(); |
230 |
|
} |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
232 |
0 |
public void setScoreModel(ScoreModelI sm)... |
233 |
|
{ |
234 |
0 |
this.scoreModel = sm; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
@return |
241 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
242 |
1 |
public SimilarityParamsI getSimilarityParameters()... |
243 |
|
{ |
244 |
1 |
return similarityParams; |
245 |
|
} |
246 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
247 |
1 |
public List<SequencePoint> getSequencePoints()... |
248 |
|
{ |
249 |
1 |
return points; |
250 |
|
} |
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
252 |
1 |
public void setSequencePoints(List<SequencePoint> sp)... |
253 |
|
{ |
254 |
1 |
points = sp; |
255 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
0 |
public T getOutputModel() {... |
257 |
0 |
return outputModel; |
258 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
259 |
0 |
public void setOutputModel(T newModel)... |
260 |
|
{ |
261 |
0 |
outputModel = newModel; |
262 |
|
} |
263 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
264 |
0 |
public boolean isCancelled()... |
265 |
|
{ |
266 |
0 |
if (outputModel==null || outputModel.isCancelled()) |
267 |
|
{ |
268 |
0 |
return true; |
269 |
|
} |
270 |
0 |
return false; |
271 |
|
} |
272 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
273 |
0 |
public void cancel()... |
274 |
|
{ |
275 |
0 |
outputModel.cancel(); |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
0 |
public boolean canCancel()... |
279 |
|
{ |
280 |
0 |
return (!isCancelled() && outputModel.isCancellable()); |
281 |
|
} |
282 |
|
|
283 |
|
List<SequenceGroup> groups = Arrays.asList(new SequenceGroup[] {}); |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0 |
List<SequenceGroup> getGroups() {... |
285 |
0 |
return groups; |
286 |
|
} |
287 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
288 |
0 |
public void markGroups()... |
289 |
|
{ |
290 |
0 |
av.getAlignment().deleteAllGroups(); |
291 |
0 |
int w = av.getAlignment().getWidth(); |
292 |
|
|
293 |
|
|
294 |
0 |
for (jalview.datamodel.SequenceGroup sg : groups) |
295 |
|
{ |
296 |
0 |
sg.setStartRes(0); |
297 |
0 |
sg.setEndRes(w); |
298 |
0 |
sg.idColour = new java.awt.Color((int) (Math.random() * 255), |
299 |
|
(int) (Math.random() * 255), (int) (Math.random() * 255)); |
300 |
0 |
sg.recalcConservation(); |
301 |
0 |
av.getAlignment().addGroup(sg); |
302 |
0 |
for (SequenceI sq : sg.getSequences()) |
303 |
|
{ |
304 |
0 |
av.setSequenceColour(sq, sg.getIdColour()); |
305 |
|
} |
306 |
|
} |
307 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
308 |
1 |
public List<String> getClusterOptions()... |
309 |
|
{ |
310 |
1 |
return Arrays.asList(outputModel.getDistanceMatrices().keySet().toArray(new String[0])); |
311 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
312 |
0 |
public MatrixI getSimilarityMatrixFor(String key)... |
313 |
|
{ |
314 |
0 |
return outputModel.getDistanceMatrices().get(key); |
315 |
|
} |
316 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
317 |
0 |
public void doClustering(String method)... |
318 |
|
{ |
319 |
0 |
Clusterer ourClusterer = new Clusterer(); |
320 |
0 |
MatrixI distanceMatrx = outputModel.getDistanceMatrices().get(method); |
321 |
0 |
ourClusterer.cluster(distanceMatrx); |
322 |
0 |
groups = ourClusterer.createGroups(seqs); |
323 |
|
} |
324 |
|
|
325 |
|
} |