2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws1;
23 import jalview.analysis.AlignSeq;
24 import jalview.bin.Cache;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.AlignmentView;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.gui.Desktop;
32 import jalview.gui.WebserviceInfo;
33 import jalview.io.FileParse;
34 import jalview.io.FormatAdapter;
35 import jalview.util.Comparison;
36 import jalview.util.MessageManager;
37 import jalview.ws.AWsJob;
38 import jalview.ws.JobStateSummary;
39 import jalview.ws.WSClientI;
41 import java.io.IOException;
42 import java.util.Hashtable;
44 import vamsas.objects.simple.JpredResult;
46 class JPredThread extends JWS1Thread implements WSClientI
48 // TODO: put mapping between JPredJob input and input data here -
49 // JNetAnnotation adding is done after result parsing.
50 class JPredJob extends WSJob
52 // TODO: make JPredJob deal only with what was sent to and received from a
54 int[] predMap = null; // mapping from sequence(i) to the original
56 // sequence(predMap[i]) being predicted on
58 vamsas.objects.simple.Sequence sequence;
60 vamsas.objects.simple.Msfalignment msa;
62 java.util.Hashtable SequenceInfo = null;
66 * @return true if getResultSet will return a valid alignment and prediction
70 public boolean hasResults()
72 if (subjobComplete && result != null && result.isFinished()
73 && ((JpredResult) result).getPredfile() != null
74 && ((JpredResult) result).getAligfile() != null)
82 public boolean hasValidInput()
93 * @return null or Object[] { annotated alignment for this prediction,
94 * ColumnSelection for this prediction} or null if no results
98 public Object[] getResultSet() throws Exception
100 if (result == null || !result.isFinished())
105 JpredResult result = (JpredResult) this.result;
107 jalview.bin.Cache.log.debug("Parsing output from JNet job.");
108 Object[] resview = JPredWSUtils.processJnetResult(currentView, input,
109 getGapChar(), SequenceInfo, this.msa != null,
111 result.getPredfile(), result.getAligfile(),
112 getFullAlignmentSource());
113 return resview; // Alignment, ColumnSelection
116 public FileParse getFullAlignmentSource() throws IOException
118 // locate full alignment
119 // http://www.compbio.dundee.ac.uk/jpred/results/jp_GuygEzV/jp_GuygEzV.full_MSA.fasta
120 String jobid = getJobId().substring(getJobId().lastIndexOf("/") + 1);
121 String job_alignment = "http://www.compbio.dundee.ac.uk/jpred/results/"
122 + jobid + "/" + jobid + ".full_MSA.fasta";
123 return new FileParse(job_alignment, FormatAdapter.URL);
126 public JPredJob(Hashtable SequenceInfo, SequenceI seq, int[] delMap)
129 this.predMap = delMap;
130 String sq = AlignSeq.extractGaps(Comparison.GapChars,
131 seq.getSequenceAsString());
132 if (sq.length() >= 20)
134 this.SequenceInfo = SequenceInfo;
135 sequence = new vamsas.objects.simple.Sequence();
136 sequence.setId(seq.getName());
141 errorMessage = "Sequence is too short to predict with JPred - need at least 20 amino acids.";
145 public JPredJob(Hashtable SequenceInfo, SequenceI[] msf, int[] delMap)
147 this(SequenceInfo, msf[0], delMap);
148 if (sequence != null)
152 msa = new vamsas.objects.simple.Msfalignment();
153 jalview.io.PileUpfile pileup = new jalview.io.PileUpfile();
154 msa.setMsf(pileup.print(msf));
159 String errorMessage = "";
161 public String getValidationMessages()
163 return errorMessage + "\n";
167 ext.vamsas.Jpred server;
171 JPredThread(WebserviceInfo wsinfo, String altitle,
172 ext.vamsas.Jpred server, String wsurl, AlignmentView alview,
175 super(alframe, wsinfo, alview, wsurl);
176 this.altitle = altitle;
177 this.server = server;
180 JPredThread(WebserviceInfo wsinfo, String altitle,
181 ext.vamsas.Jpred server, String wsurl, Hashtable SequenceInfo,
182 SequenceI seq, int[] delMap, AlignmentView alview,
185 this(wsinfo, altitle, server, wsurl, alview, alframe);
186 JPredJob job = new JPredJob(SequenceInfo, seq, delMap);
187 if (job.hasValidInput())
189 OutputHeader = wsInfo.getProgressText();
190 jobs = new WSJob[] { job };
195 wsInfo.appendProgressText(job.getValidationMessages());
199 JPredThread(WebserviceInfo wsinfo, String altitle,
200 ext.vamsas.Jpred server, Hashtable SequenceInfo, SequenceI[] msf,
201 int[] delMap, AlignmentView alview, AlignFrame alframe,
204 this(wsinfo, altitle, server, wsurl, alview, alframe);
205 JPredJob job = new JPredJob(SequenceInfo, msf, delMap);
206 if (job.hasValidInput())
208 jobs = new WSJob[] { job };
209 OutputHeader = wsInfo.getProgressText();
214 wsInfo.appendProgressText(job.getValidationMessages());
219 public void StartJob(AWsJob j)
221 if (!(j instanceof JPredJob))
223 throw new Error(MessageManager.formatMessage(
224 "error.implementation_error_startjob_called",
225 new String[] { j.getClass().toString() }));
229 JPredJob job = (JPredJob) j;
232 job.setJobId(server.predictOnMsa(job.msa));
234 else if (job.sequence != null)
236 job.setJobId(server.predict(job.sequence)); // debug like : job.jobId =
237 // "/jobs/www-jpred/jp_Yatat29";//
240 if (job.getJobId() != null)
242 if (job.getJobId().startsWith("Broken"))
244 job.result = new JpredResult();
245 job.result.setInvalid(true);
246 job.result.setStatus(MessageManager.formatMessage(
247 "label.submission_params", new String[] { job.getJobId()
249 throw new Exception(job.getJobId());
253 job.setSubmitted(true);
254 job.setSubjobComplete(false);
255 Cache.log.info(WsUrl + " Job Id '" + job.getJobId() + "'");
262 .getString("exception.server_timeout_try_later"));
264 } catch (Exception e)
266 // kill the whole job.
267 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
268 if (e.getMessage().indexOf("Exception") > -1)
270 wsInfo.setStatus(j.getJobnum(),
271 WebserviceInfo.STATE_STOPPED_SERVERERROR);
272 wsInfo.setProgressText(
274 "Failed to submit the prediction. (Just close the window)\n"
275 + "It is most likely that there is a problem with the server.\n");
277 .println("JPredWS Client: Failed to submit the prediction. Quite possibly because of a server error - see below)\n"
278 + e.getMessage() + "\n");
280 jalview.bin.Cache.log.warn("Server Exception", e);
284 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
285 // JBPNote - this could be a popup informing the user of the problem.
286 wsInfo.appendProgressText(j.getJobnum(), MessageManager
288 "info.failed_to_submit_prediction",
289 new String[] { e.getMessage(),
290 wsInfo.getProgressText() }));
292 jalview.bin.Cache.log.debug(
293 "Failed Submission of job " + j.getJobnum(), e);
296 j.setAllowedServerExceptions(-1);
297 j.setSubjobComplete(true);
302 public void parseResult()
304 int results = 0; // number of result sets received
305 JobStateSummary finalState = new JobStateSummary();
308 for (int j = 0; j < jobs.length; j++)
310 finalState.updateJobPanelState(wsInfo, OutputHeader, jobs[j]);
311 if (jobs[j].isSubmitted() && jobs[j].isSubjobComplete()
312 && jobs[j].hasResults())
317 } catch (Exception ex)
320 Cache.log.error("Unexpected exception when processing results for "
322 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
326 wsInfo.showResultsNewFrame
327 .addActionListener(new java.awt.event.ActionListener()
330 public void actionPerformed(java.awt.event.ActionEvent evt)
332 displayResults(true);
336 .addActionListener(new java.awt.event.ActionListener()
339 public void actionPerformed(java.awt.event.ActionEvent evt)
341 displayResults(false);
344 wsInfo.setResultsReady();
348 wsInfo.setStatus(wsInfo.STATE_STOPPED_ERROR);
349 wsInfo.appendInfoText("No jobs ran.");
350 wsInfo.setFinishedNoResults();
354 void displayResults(boolean newWindow)
356 // TODO: cope with multiple subjobs.
361 for (int jn = 0; jn < jobs.length; jn++)
363 Object[] jobres = null;
364 JPredJob j = (JPredJob) jobs[jn];
368 // hack - we only deal with all single seuqence predictions or all
369 // profile predictions
370 msa = (j.msa != null) ? true : msa;
373 jalview.bin.Cache.log.debug("Parsing output of job " + jn);
374 jobres = j.getResultSet();
375 jalview.bin.Cache.log.debug("Finished parsing output.");
376 if (jobs.length == 1)
382 // do merge with other job results
385 .getString("error.multiple_jnet_subjob_merge_not_implemented"));
387 } catch (Exception e)
389 jalview.bin.Cache.log.error(
390 "JNet Client: JPred Annotation Parse Error", e);
391 wsInfo.setStatus(j.getJobnum(),
392 WebserviceInfo.STATE_STOPPED_ERROR);
393 wsInfo.appendProgressText(j.getJobnum(), MessageManager
394 .formatMessage("info.invalid_jnet_job_result_data",
395 new String[] { OutputHeader.toString(),
396 j.result.getStatus(), e.getMessage() }));
397 j.result.setBroken(true);
407 ((AlignmentI) res[0]).setSeqrep(((AlignmentI) res[0])
413 af = new AlignFrame((Alignment) res[0],
414 (ColumnSelection) res[1], AlignFrame.DEFAULT_WIDTH,
415 AlignFrame.DEFAULT_HEIGHT);
419 af = new AlignFrame((Alignment) res[0],
420 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
426 * java.lang.Object[] alandcolsel =
427 * input.getAlignmentAndColumnSelection
428 * (alignFrame.getViewport().getGapCharacter()); if
429 * (((SequenceI[])alandcolsel[0])[0].getLength()!=res.getWidth()) {
430 * if (msa) { throw new Error("Implementation Error! ColumnSelection
431 * from input alignment will not map to result alignment!"); } } if
432 * (!msa) { // update hidden regions to account for loss of gaps in
433 * profile. - if any // gapMap returns insert list, interpreted as
434 * delete list by pruneDeletions //((ColumnSelection)
435 * alandcolsel[1]).pruneDeletions(ShiftList.parseMap(((SequenceI[])
436 * alandcolsel[0])[0].gapMap())); }
439 af = new AlignFrame((Alignment) res[0],
440 (ColumnSelection) res[1], AlignFrame.DEFAULT_WIDTH,
441 AlignFrame.DEFAULT_HEIGHT);
443 Desktop.addInternalFrame(af, altitle, AlignFrame.DEFAULT_WIDTH,
444 AlignFrame.DEFAULT_HEIGHT);
448 Cache.log.info("Append results onto existing alignment.");
455 public void pollJob(AWsJob job) throws Exception
457 ((JPredJob) job).result = server.getresult(job.getJobId());
461 public boolean isCancellable()
467 public void cancelJob()
469 throw new Error(MessageManager.getString("error.implementation_error"));
473 public boolean canMergeResults()