2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
23 import javax.swing.*;
\r
25 import ext.vamsas.*;
\r
26 import jalview.analysis.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.gui.*;
\r
30 public class JPredClient
\r
33 ext.vamsas.JPredWS server;
\r
34 String altitle = "";
\r
35 java.util.Hashtable SequenceInfo = null;
\r
37 public JPredClient(String title, SequenceI[] msf)
\r
39 wsInfo = setWebService();
\r
41 SequenceI seq = msf[0];
\r
42 altitle = "JNet prediction on " + seq.getName() +
\r
43 " using alignment from " + title;
\r
45 wsInfo.setProgressText("Job details for MSA based prediction (" +
\r
46 title + ") on sequence :\n>" + seq.getName() + "\n" +
\r
47 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
50 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
52 if (!locateWebService())
\r
57 JPredThread jthread = new JPredThread(msf);
\r
61 public JPredClient(String title, SequenceI seq)
\r
63 wsInfo = setWebService();
\r
64 wsInfo.setProgressText("Job details for prediction on sequence :\n>" +
\r
65 seq.getName() + "\n" +
\r
66 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
68 altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
71 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
73 if (!locateWebService())
\r
78 JPredThread jthread = new JPredThread(seq);
\r
82 private WebserviceInfo setWebService()
\r
84 WebServiceName = "JNetWS";
\r
85 WebServiceJobTitle = "JNet secondary structure prediction";
\r
86 WebServiceReference =
\r
87 "\"Cuff J. A and Barton G.J (1999) Application of enhanced " +
\r
88 "multiple sequence alignment profiles to improve protein secondary structure prediction, " +
\r
89 "Proteins 40:502-511\".";
\r
90 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
92 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
93 WebServiceReference);
\r
98 private boolean locateWebService()
\r
100 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
104 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
105 ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub
\r
107 catch (Exception ex)
\r
109 JOptionPane.showMessageDialog(Desktop.desktop,
\r
110 "The Secondary Structure Prediction Service named " +
\r
111 WebServiceName + " at " + WsURL +
\r
112 " couldn't be located.",
\r
113 "Internal Jalview Error",
\r
114 JOptionPane.WARNING_MESSAGE);
\r
115 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
116 " Service location failed\nfor URL :" + WsURL +
\r
119 wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);
\r
130 String OutputHeader;
\r
131 ext.vamsas.JpredResult result;
\r
132 ext.vamsas.Sequence sequence;
\r
133 ext.vamsas.Msfalignment msa;
\r
135 boolean jobComplete = false;
\r
136 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
138 JPredThread(SequenceI seq)
\r
140 OutputHeader = wsInfo.getProgressText();
\r
141 this.sequence = new ext.vamsas.Sequence();
\r
142 this.sequence.setId(seq.getName());
\r
143 this.sequence.setSeq(AlignSeq.extractGaps("-. ", seq.getSequence()));
\r
146 JPredThread(SequenceI[] msf)
\r
148 OutputHeader = wsInfo.getProgressText();
\r
149 this.sequence = new ext.vamsas.Sequence();
\r
150 this.sequence.setId(msf[0].getName());
\r
151 this.sequence.setSeq(AlignSeq.extractGaps("-. ",
\r
152 msf[0].getSequence()));
\r
154 jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();
\r
155 this.msa = new ext.vamsas.Msfalignment();
\r
156 msa.setMsf(mwrite.print(msf));
\r
163 while (!jobComplete && (allowedServerExceptions > 0))
\r
167 if ( (result = server.getresult(jobId)) == null)
\r
169 throw (new Exception(
\r
170 "Timed out when communicating with server\nTry again later.\n"));
\r
173 if (result.isRunning())
\r
175 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
177 else if (result.isQueued())
\r
179 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
182 if (result.isFinished())
\r
185 jobComplete = true;
\r
190 wsInfo.setProgressText(OutputHeader + "\n" +
\r
191 result.getStatus());
\r
193 if (! (result.isJobFailed() || result.isServerError()))
\r
197 Thread.sleep(5000);
\r
199 catch (InterruptedException ex1)
\r
203 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
207 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
211 catch (Exception ex)
\r
213 allowedServerExceptions--;
\r
214 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
219 if (allowedServerExceptions > 0)
\r
221 Thread.sleep(5000);
\r
224 catch (InterruptedException ex1)
\r
230 if (! (result.isJobFailed() || result.isServerError()))
\r
232 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
236 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
246 jobId = server.predictOnMsa(msa);
\r
250 jobId = server.predict(sequence);
\r
255 if (jobId.startsWith("Broken"))
\r
257 throw new Exception("Submission " + jobId);
\r
261 System.out.println(WsURL + " Job Id '" + jobId + "'");
\r
266 throw new Exception("Server timed out - try again later\n");
\r
269 catch (Exception e)
\r
271 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
272 allowedServerExceptions = 0;
\r
273 jobComplete = false;
\r
275 wsInfo.appendProgressText("Failed to submit the prediction.\n"
\r
277 "It is most likely that there is a problem with the server.\n"
\r
278 + "Just close the window\n");
\r
279 System.err.println(
\r
280 "JPredWS Client: Failed to submit the prediction (Probably a server error - see below)\n" +
\r
281 e.toString() + "\n");
\r
283 // e.printStackTrace(); TODO: JBPNote DEBUG
\r
287 private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
288 Vector values, String Symname,
\r
289 String Visname, float min,
\r
290 float max, int winLength)
\r
292 Annotation[] annotations = new Annotation[al.getWidth()];
\r
294 for (int j = 0; j < values.size(); j++)
\r
296 float value = Float.parseFloat(values.get(j).toString());
\r
297 annotations[gapmap[j]] = new Annotation("", value + "", ' ',
\r
301 al.addAnnotation(new AlignmentAnnotation(Symname, Visname,
\r
302 annotations, min, max, winLength));
\r
307 // OutputHeader = output.getText();
\r
308 if (result.isFailed())
\r
310 OutputHeader += "Job failed.\n";
\r
313 if (result.getStatus() != null)
\r
315 OutputHeader += ("\n" + result.getStatus());
\r
318 if (result.getPredfile() != null)
\r
320 OutputHeader += ("\n" + result.getPredfile());
\r
322 // JBPNote The returned files from a webservice could be hidden behind icons in the monitor window that, when clicked, pop up their corresponding data
\r
325 if (result.getAligfile() != null)
\r
327 OutputHeader += ("\n" + result.getAligfile());
\r
330 wsInfo.setProgressText(OutputHeader);
\r
334 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
335 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
338 SequenceI[] preds = prediction.getSeqsAsArray();
\r
340 int FirstSeq; // the position of the query sequence in Alignment al
\r
341 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
343 if ( (this.msa != null) && (result.getAligfile() != null))
\r
345 // we ignore the returned alignment if we only predicted on a single sequence
\r
346 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),
\r
349 if (jalview.io.FormatAdapter.formats.contains(format))
\r
351 al = new Alignment(jalview.io.FormatAdapter.readFile(
\r
352 result.getAligfile(), "Paste", format));
\r
358 throw (new Exception(
\r
359 "Unknown format 'format' for file : \n" +
\r
360 result.getAligfile()));
\r
365 al = new Alignment(preds);
\r
366 FirstSeq = prediction.getQuerySeqPosition();
\r
369 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(
\r
370 al.getSequenceAt(FirstSeq), SequenceInfo))
\r
372 throw (new Exception(
\r
373 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
376 AlignmentAnnotation annot;
\r
377 Annotation[] annotations = null;
\r
379 int width = preds[0].getSequence().length();
\r
381 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
383 if (gapmap.length != width)
\r
385 throw (new Exception(
\r
386 "Jnet Client Error\nNumber of residues in supposed query sequence :\n" +
\r
387 al.getSequenceAt(FirstSeq).getName() + "\n" +
\r
388 al.getSequenceAt(FirstSeq).getSequence() +
\r
389 "\nDiffer from number of prediction sites in \n" +
\r
390 result.getPredfile() + "\n"));
\r
393 // JBPNote Should also rename the query sequence sometime...
\r
396 while (i < preds.length)
\r
398 String id = preds[i].getName().toUpperCase();
\r
400 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
401 id.startsWith("JPRED"))
\r
403 annotations = new Annotation[al.getWidth()];
\r
405 if (id.equals("JNETPRED") || id.equals("JNETPSSM") ||
\r
406 id.equals("JNETFREQ") || id.equals("JNETHMM") ||
\r
407 id.equals("JNETALIGN") || id.equals("JPRED"))
\r
409 for (int j = 0; j < width; j++)
\r
411 annotations[gapmap[j]] = new Annotation("", "",
\r
412 preds[i].getCharAt(j), 0);
\r
415 else if (id.equals("JNETCONF"))
\r
417 for (int j = 0; j < width; j++)
\r
419 float value = Float.parseFloat(preds[i].getCharAt(
\r
421 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
422 j) + "", "", preds[i].getCharAt(j),
\r
428 for (int j = 0; j < width; j++)
\r
430 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(
\r
431 j) + "", "", ' ', 0);
\r
435 if (id.equals("JNETCONF"))
\r
437 annot = new AlignmentAnnotation(preds[i].getName(),
\r
438 "JNet Output", annotations, 0f,
\r
443 annot = new AlignmentAnnotation(preds[i].getName(),
\r
444 "JNet Output", annotations);
\r
447 al.addAnnotation(annot);
\r
451 al.deleteSequence(preds[i]);
\r
458 Hashtable scores = prediction.getScores();
\r
460 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
461 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
463 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
464 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
466 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
467 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
469 AlignFrame af = new AlignFrame(al);
\r
471 Desktop.addInternalFrame(af, altitle,
\r
472 AlignFrame.NEW_WINDOW_WIDTH,
\r
473 AlignFrame.NEW_WINDOW_HEIGHT);
\r
475 catch (Exception ex)
\r
477 ex.printStackTrace();
\r