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