1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.rest; |
22 |
|
|
23 |
|
import jalview.datamodel.AlignmentAnnotation; |
24 |
|
import jalview.datamodel.AlignmentI; |
25 |
|
import jalview.datamodel.AlignmentOrder; |
26 |
|
import jalview.datamodel.SequenceGroup; |
27 |
|
import jalview.datamodel.SequenceI; |
28 |
|
import jalview.io.packed.JalviewDataset; |
29 |
|
import jalview.ws.AWsJob; |
30 |
|
import jalview.ws.rest.params.Alignment; |
31 |
|
import jalview.ws.rest.params.SeqGroupIndexVector; |
32 |
|
|
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.Collection; |
35 |
|
import java.util.Hashtable; |
36 |
|
import java.util.Map; |
37 |
|
import java.util.Set; |
38 |
|
import java.util.Vector; |
39 |
|
|
|
|
| 45% |
Uncovered Elements: 88 (160) |
Complexity: 53 |
Complexity Density: 0.6 |
|
40 |
|
public class RestJob extends AWsJob |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
RestServiceDescription rsd; |
45 |
|
|
46 |
|
|
47 |
|
boolean gotresponse; |
48 |
|
|
49 |
|
boolean error; |
50 |
|
|
51 |
|
boolean waiting; |
52 |
|
|
53 |
|
boolean gotresult; |
54 |
|
|
55 |
|
Hashtable squniq; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
AlignmentI dsForIO; |
61 |
|
|
62 |
|
AlignmentOrder inputOrder; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
int[] origviscontig; |
68 |
|
|
69 |
|
private AlignmentI contextAl = null; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
@param |
76 |
|
@param |
77 |
|
@param |
78 |
|
|
79 |
|
|
|
|
| 77.5% |
Uncovered Elements: 9 (40) |
Complexity: 10 |
Complexity Density: 0.38 |
|
80 |
3 |
public RestJob(int jobNum, RestJobThread restJobThread, AlignmentI _input,... |
81 |
|
int[] viscontigs) |
82 |
|
{ |
83 |
3 |
rsd = restJobThread.restClient.service; |
84 |
3 |
jobnum = jobNum; |
85 |
3 |
if (viscontigs != null) |
86 |
|
{ |
87 |
2 |
origviscontig = new int[viscontigs.length]; |
88 |
2 |
System.arraycopy(viscontigs, 0, origviscontig, 0, viscontigs.length); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
3 |
squniq = jalview.analysis.SeqsetUtils |
94 |
|
.uniquify(_input.getSequencesArray(), true); |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
3 |
ArrayList<InputType> alinp = new ArrayList<InputType>(); |
99 |
3 |
int paramsWithData = 0; |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
3 |
for (Map.Entry<String, InputType> prm : rsd.inputParams.entrySet()) |
105 |
|
{ |
106 |
6 |
if (!prm.getValue().isConstant()) |
107 |
|
{ |
108 |
6 |
if (prm.getValue() instanceof Alignment) |
109 |
|
{ |
110 |
3 |
alinp.add(prm.getValue()); |
111 |
|
} |
112 |
|
else |
113 |
|
{ |
114 |
3 |
if (prm.getValue() instanceof SeqGroupIndexVector |
115 |
|
&& _input.getGroups() != null |
116 |
|
&& _input.getGroups().size() >= -1 + prm.getValue().min) |
117 |
|
{ |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
3 |
alinp.add(prm.getValue()); |
122 |
|
} |
123 |
|
else |
124 |
|
{ |
125 |
0 |
statMessage = ("Not enough groups defined on the alignment - need at least " |
126 |
|
+ prm.getValue().min); |
127 |
|
} |
128 |
|
} |
129 |
|
} |
130 |
|
else |
131 |
|
{ |
132 |
0 |
paramsWithData++; |
133 |
|
} |
134 |
|
} |
135 |
3 |
if ((paramsWithData + alinp.size()) == rsd.inputParams.size()) |
136 |
|
{ |
137 |
3 |
inputOrder = new AlignmentOrder(_input); |
138 |
? |
if ((dsForIO = _input.getDataset()) == null) |
139 |
|
{ |
140 |
2 |
_input.setDataset(null); |
141 |
|
} |
142 |
3 |
dsForIO = _input.getDataset(); |
143 |
3 |
if (contextAl == null) |
144 |
|
{ |
145 |
3 |
contextAl = _input; |
146 |
|
} |
147 |
3 |
setAlignmentForInputs(alinp, _input); |
148 |
3 |
validInput = true; |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
|
|
153 |
0 |
validInput = false; |
154 |
|
} |
155 |
|
} |
156 |
|
|
157 |
|
boolean validInput = false; |
158 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
159 |
0 |
@Override... |
160 |
|
public boolean hasResults() |
161 |
|
{ |
162 |
0 |
return gotresult && (parsedResults ? validJvresults : true); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
2 |
@Override... |
166 |
|
public boolean hasValidInput() |
167 |
|
{ |
168 |
2 |
return validInput; |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
1 |
@Override... |
172 |
|
public boolean isRunning() |
173 |
|
{ |
174 |
1 |
return running; |
175 |
|
|
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
1 |
@Override... |
179 |
|
public boolean isQueued() |
180 |
|
{ |
181 |
1 |
return waiting; |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
1 |
@Override... |
185 |
|
public boolean isFinished() |
186 |
|
{ |
187 |
1 |
return resSet != null; |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
1 |
@Override... |
191 |
|
public boolean isFailed() |
192 |
|
{ |
193 |
|
|
194 |
1 |
return error; |
195 |
|
} |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
197 |
1 |
@Override... |
198 |
|
public boolean isBroken() |
199 |
|
{ |
200 |
|
|
201 |
1 |
return error; |
202 |
|
} |
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
1 |
@Override... |
205 |
|
public boolean isServerError() |
206 |
|
{ |
207 |
|
|
208 |
1 |
return error; |
209 |
|
} |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
211 |
1 |
@Override... |
212 |
|
public boolean hasStatus() |
213 |
|
{ |
214 |
1 |
return statMessage != null; |
215 |
|
} |
216 |
|
|
217 |
|
protected String statMessage = null; |
218 |
|
|
219 |
|
public HttpResultSet resSet; |
220 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
221 |
1 |
@Override... |
222 |
|
public String getStatus() |
223 |
|
{ |
224 |
1 |
return statMessage; |
225 |
|
} |
226 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
0 |
@Override... |
228 |
|
public boolean hasResponse() |
229 |
|
{ |
230 |
0 |
return statMessage != null || resSet != null; |
231 |
|
} |
232 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
233 |
0 |
@Override... |
234 |
|
public void clearResponse() |
235 |
|
{ |
236 |
|
|
237 |
|
|
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@see |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
0 |
@Override... |
246 |
|
public String getState() |
247 |
|
{ |
248 |
|
|
249 |
|
|
250 |
0 |
return "Job is clueless"; |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
253 |
1 |
public String getPostUrl()... |
254 |
|
{ |
255 |
|
|
256 |
|
|
257 |
1 |
return rsd.postUrl; |
258 |
|
} |
259 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
260 |
1 |
public Set<Map.Entry<String, InputType>> getInputParams()... |
261 |
|
{ |
262 |
1 |
return rsd.inputParams.entrySet(); |
263 |
|
} |
264 |
|
|
265 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
0 |
public String getPollUrl()... |
267 |
|
{ |
268 |
0 |
return rsd.getDecoratedResultUrl(jobId); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
@return |
274 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
275 |
0 |
public JalviewDataset newJalviewDataset()... |
276 |
|
{ |
277 |
0 |
if (context == null) |
278 |
|
{ |
279 |
0 |
context = new JalviewDataset(dsForIO, null, squniq, null); |
280 |
0 |
if (contextAl != null) |
281 |
|
{ |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
0 |
if (contextAl.getAlignmentAnnotation() != null) |
286 |
|
{ |
287 |
0 |
for (AlignmentAnnotation alan : contextAl |
288 |
|
.getAlignmentAnnotation()) |
289 |
|
{ |
290 |
0 |
contextAl.deleteAnnotation(alan); |
291 |
|
} |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
0 |
if (contextAl.getGroups() != null) |
297 |
|
{ |
298 |
0 |
contextAl.deleteAllGroups(); |
299 |
|
} |
300 |
0 |
context.addAlignment(contextAl); |
301 |
|
} |
302 |
|
|
303 |
|
} |
304 |
0 |
return context; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
@param |
312 |
|
@param |
313 |
|
@return |
314 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 7 |
Complexity Density: 0.54 |
|
315 |
0 |
public SequenceI[] getSequencesForInput(String token,... |
316 |
|
InputType.molType type) throws NoValidInputDataException |
317 |
|
{ |
318 |
0 |
Object sgdat = inputData.get(token); |
319 |
|
|
320 |
0 |
if (sgdat == null) |
321 |
|
{ |
322 |
0 |
throw new NoValidInputDataException( |
323 |
|
"No Sequence vector data bound to input '" + token |
324 |
|
+ "' for service at " + rsd.postUrl); |
325 |
|
} |
326 |
0 |
if (sgdat instanceof AlignmentI) |
327 |
|
{ |
328 |
0 |
return ((AlignmentI) sgdat).getSequencesArray(); |
329 |
|
} |
330 |
0 |
if (sgdat instanceof SequenceGroup) |
331 |
|
{ |
332 |
0 |
return ((SequenceGroup) sgdat).getSequencesAsArray(null); |
333 |
|
} |
334 |
0 |
if (sgdat instanceof Vector) |
335 |
|
{ |
336 |
0 |
if (((Vector) sgdat).size() > 0 |
337 |
|
&& ((Vector) sgdat).get(0) instanceof SequenceI) |
338 |
|
{ |
339 |
0 |
SequenceI[] sq = new SequenceI[((Vector) sgdat).size()]; |
340 |
0 |
((Vector) sgdat).copyInto(sq); |
341 |
0 |
return sq; |
342 |
|
} |
343 |
|
} |
344 |
0 |
throw new NoValidInputDataException( |
345 |
|
"No Sequence vector data bound to input '" + token |
346 |
|
+ "' for service at " + rsd.postUrl); |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
private Hashtable<String, Object> inputData = new Hashtable<String, Object>(); |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
public boolean running = false; |
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@param |
363 |
|
@param |
364 |
|
|
365 |
|
|
366 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
367 |
4 |
public void setAlignmentForInputs(Collection<InputType> itypes,... |
368 |
|
AlignmentI al) |
369 |
|
{ |
370 |
4 |
for (InputType itype : itypes) |
371 |
|
{ |
372 |
8 |
if (!rsd.inputParams.values().contains(itype)) |
373 |
|
{ |
374 |
0 |
throw new IllegalArgumentException("InputType " + itype.getClass() |
375 |
|
+ " is not valid for service at " + rsd.postUrl); |
376 |
|
} |
377 |
8 |
if (itype instanceof AlignmentProcessor) |
378 |
|
{ |
379 |
4 |
((AlignmentProcessor) itype).prepareAlignment(al); |
380 |
|
} |
381 |
|
|
382 |
8 |
inputData.put(itype.token, al); |
383 |
|
} |
384 |
|
|
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
@param |
390 |
|
@param |
391 |
|
@return |
392 |
|
@throws |
393 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
394 |
4 |
public AlignmentI getAlignmentForInput(String token,... |
395 |
|
InputType.molType type) throws NoValidInputDataException |
396 |
|
{ |
397 |
4 |
Object al = inputData.get(token); |
398 |
|
|
399 |
4 |
if (al == null || !(al instanceof AlignmentI)) |
400 |
|
{ |
401 |
0 |
throw new NoValidInputDataException( |
402 |
|
"No alignment data bound to input '" + token |
403 |
|
+ "' for service at " + rsd.postUrl); |
404 |
|
} |
405 |
4 |
return (AlignmentI) al; |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
@param |
412 |
|
@return |
413 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
414 |
2 |
public boolean hasDataOfType(Class cl)... |
415 |
|
{ |
416 |
2 |
if (AlignmentI.class.isAssignableFrom(cl)) |
417 |
|
{ |
418 |
2 |
return true; |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
0 |
return false; |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
JalviewDataset context = null; |
429 |
|
|
430 |
|
protected boolean parsedResults = false; |
431 |
|
|
432 |
|
protected boolean validJvresults = false; |
433 |
|
|
434 |
|
Object[] jvresultobj = null; |
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
441 |
0 |
public void parseResultSet() throws Exception, Error... |
442 |
|
{ |
443 |
0 |
if (!parsedResults) |
444 |
|
{ |
445 |
0 |
parsedResults = true; |
446 |
0 |
jvresultobj = resSet.parseResultSet(); |
447 |
0 |
validJvresults = true; |
448 |
|
} |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
@return |
454 |
|
|
455 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
456 |
0 |
public boolean isInputContextModified()... |
457 |
|
{ |
458 |
0 |
return contextAl != null && validJvresults |
459 |
|
&& context.getAl().get(0).isModified(); |
460 |
|
} |
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
@return |
465 |
|
|
466 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
467 |
0 |
public boolean isInputUniquified()... |
468 |
|
{ |
469 |
|
|
470 |
0 |
return false; |
471 |
|
} |
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
@return |
478 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
479 |
0 |
public int[] getOrderMap()... |
480 |
|
{ |
481 |
0 |
SequenceI[] contseq = contextAl.getSequencesArray(); |
482 |
0 |
int map[] = new int[contseq.length]; |
483 |
0 |
for (int i = 0; i < contseq.length; i++) |
484 |
|
{ |
485 |
|
|
486 |
|
|
487 |
0 |
map[i] = inputOrder.getOrder().indexOf(contseq[i]); |
488 |
|
} |
489 |
0 |
return map; |
490 |
|
} |
491 |
|
|
492 |
|
} |