3 import org.apache.axis.client.*;
\r
4 import javax.xml.namespace.QName;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.gui.*;
\r
8 import javax.swing.*;
\r
11 import jalview.analysis.AlignSeq;
\r
12 import ext.vamsas.*;
\r
14 public class JPredClient
\r
17 ext.vamsas.JPredWS server;
\r
18 String altitle = "";
\r
19 java.util.Hashtable SequenceInfo = null;
\r
20 private WebserviceInfo setWebService()
\r
22 WebServiceName = "JNetWS";
\r
23 WebServiceJobTitle = "JNet secondary structure prediction";
\r
24 WebServiceReference =
\r
25 "\"Cuff J. A and Barton G.J (1999) Application of enhanced "
\r
26 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
\r
27 + "Proteins 40:502-511\".";
\r
28 WsURL = "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
29 WebserviceInfo wsInfo = new WebserviceInfo(WebServiceJobTitle,
\r
30 WebServiceReference);
\r
35 private boolean locateWebService()
\r
38 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
41 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
42 ( (JpredSoapBindingStub)this.server).setTimeout(60000); // one minute stub
\r
44 catch (Exception ex)
\r
46 JOptionPane.showMessageDialog(Desktop.desktop,
\r
47 "The Secondary Structure Prediction Service named "
\r
48 + WebServiceName + " at " + WsURL +
\r
49 " couldn't be located.",
\r
50 "Internal Jalview Error",
\r
51 JOptionPane.WARNING_MESSAGE);
\r
52 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
53 " Service location failed\nfor URL :"
\r
54 + WsURL + "\n" + ex.getMessage());
\r
55 wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);
\r
61 public JPredClient(String title, SequenceI[] msf)
\r
63 wsInfo = setWebService();
\r
64 SequenceI seq = msf[0];
\r
65 altitle = "JNet prediction on " + seq.getName() +
\r
66 " using alignment from " + title;
\r
68 wsInfo.setProgressText("Job details for MSA based prediction (" + title +
\r
69 ") on sequence :\n>"
\r
70 + seq.getName() + "\n"
\r
71 + AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
74 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
75 if (!locateWebService())
\r
78 JPredThread jthread = new JPredThread(msf);
\r
82 public JPredClient(String title, SequenceI seq)
\r
84 wsInfo = setWebService();
\r
85 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
\r
86 + seq.getName() + "\n" +
\r
87 AlignSeq.extractGaps("-. ", seq.getSequence()) +
\r
89 altitle = "JNet prediction for sequence " + seq.getName() + " from " +
\r
92 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
94 if (!locateWebService())
\r
97 JPredThread jthread = new JPredThread(seq);
\r
104 String OutputHeader;
\r
105 ext.vamsas.JpredResult result;
\r
106 ext.vamsas.Sequence sequence;
\r
107 ext.vamsas.Msfalignment msa;
\r
109 boolean jobComplete = false;
\r
110 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
111 JPredThread(SequenceI seq)
\r
113 OutputHeader = wsInfo.getProgressText();
\r
114 this.sequence = new ext.vamsas.Sequence();
\r
115 this.sequence.setId(seq.getName());
\r
116 this.sequence.setSeq(AlignSeq.extractGaps("-. ", seq.getSequence()));
\r
119 JPredThread(SequenceI[] msf)
\r
121 OutputHeader = wsInfo.getProgressText();
\r
122 this.sequence = new ext.vamsas.Sequence();
\r
123 this.sequence.setId(msf[0].getName());
\r
124 this.sequence.setSeq(AlignSeq.extractGaps("-. ", msf[0].getSequence()));
\r
125 jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();
\r
126 this.msa = new ext.vamsas.Msfalignment();
\r
127 msa.setMsf(mwrite.print(msf));
\r
135 while (!jobComplete && (allowedServerExceptions > 0))
\r
139 if ( (result = server.getresult(jobId)) == null)
\r
141 throw (new Exception(
\r
142 "Timed out when communicating with server\nTry again later.\n"));
\r
145 if (result.isRunning())
\r
147 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
149 else if (result.isQueued())
\r
151 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
154 if (result.isFinished())
\r
157 jobComplete = true;
\r
162 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
163 if (! (result.isJobFailed() || result.isServerError()))
\r
167 Thread.sleep(5000);
\r
169 catch (InterruptedException ex1)
\r
172 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
176 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
180 catch (Exception ex)
\r
182 allowedServerExceptions--;
\r
183 wsInfo.appendProgressText("\nJPredWS Server exception!\n" +
\r
187 if (allowedServerExceptions > 0)
\r
189 Thread.sleep(5000);
\r
192 catch (InterruptedException ex1)
\r
198 if (! (result.isJobFailed() || result.isServerError()))
\r
200 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
204 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
214 jobId = server.predictOnMsa(msa);
\r
218 jobId = server.predict(sequence);
\r
222 if (jobId.startsWith("Broken"))
\r
224 throw new Exception("Submission " + jobId);
\r
228 System.out.println(WsURL + " Job Id '" + jobId + "'");
\r
233 throw new Exception("Server timed out - try again later\n");
\r
237 catch (Exception e)
\r
239 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
240 allowedServerExceptions = 0;
\r
241 jobComplete = false;
\r
242 wsInfo.appendProgressText("Failed to submit the prediction: " +
\r
243 e.toString() + "\nJust close the window\n");
\r
244 System.err.println(
\r
245 "JPredWS Client: Failed to submit the prediction\n" +
\r
246 e.toString() + "\n");
\r
247 // e.printStackTrace(); TODO: JBPNote DEBUG
\r
251 private void addFloatAnnotations(Alignment al, int[] gapmap,
\r
252 Vector values, String Symname,
\r
253 String Visname, float min, float max,
\r
257 Annotation[] annotations = new Annotation[al.getWidth()];
\r
258 for (int j = 0; j < values.size(); j++)
\r
260 float value = Float.parseFloat(values.get(j).toString());
\r
261 annotations[gapmap[j]] = new Annotation("", value + "", ' ', value);
\r
263 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations,
\r
264 min, max, winLength));
\r
269 // OutputHeader = output.getText();
\r
270 if (result.isFailed())
\r
272 OutputHeader += "Job failed.\n";
\r
274 if (result.getStatus() != null)
\r
276 OutputHeader += "\n" + result.getStatus();
\r
278 if (result.getPredfile() != null)
\r
280 OutputHeader += "\n" + result.getPredfile();
\r
281 // 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
283 if (result.getAligfile() != null)
\r
285 OutputHeader += "\n" + result.getAligfile();
\r
287 wsInfo.setProgressText(OutputHeader);
\r
290 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
291 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.
\r
292 getPredfile(), "Paste");
\r
293 SequenceI[] preds = prediction.getSeqsAsArray();
\r
295 int FirstSeq; // the position of the query sequence in Alignment al
\r
296 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
298 if (this.msa != null && result.getAligfile() != null)
\r
300 // we ignore the returned alignment if we only predicted on a single sequence
\r
301 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(),
\r
303 if (jalview.io.FormatAdapter.formats.contains(format))
\r
305 al = new Alignment(jalview.io.FormatAdapter.readFile(result.
\r
306 getAligfile(), "Paste", format));
\r
312 throw (new Exception("Unknown format 'format' for file : \n" +
\r
313 result.getAligfile()));
\r
319 al = new Alignment(preds);
\r
320 FirstSeq = prediction.getQuerySeqPosition();
\r
323 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(al.getSequenceAt(
\r
324 FirstSeq), SequenceInfo))
\r
326 throw (new Exception(
\r
327 "Couldn't recover sequence properties for JNet Query sequence!"));
\r
330 AlignmentAnnotation annot;
\r
331 Annotation[] annotations = null;
\r
333 int width = preds[0].getSequence().length();
\r
335 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
337 if (gapmap.length != width)
\r
339 throw (new Exception(
\r
340 "Jnet Client Error\nNumber of residues in supposed query sequence :\n"
\r
341 + al.getSequenceAt(FirstSeq).getName() + "\n"
\r
342 + al.getSequenceAt(FirstSeq).getSequence()
\r
343 + "\nDiffer from number of prediction sites in \n" +
\r
344 result.getPredfile() + "\n"));
\r
346 // JBPNote Should also rename the query sequence sometime...
\r
348 while (i < preds.length)
\r
350 String id = preds[i].getName().toUpperCase();
\r
351 if (id.startsWith("LUPAS") || id.startsWith("JNET") ||
\r
352 id.startsWith("JPRED"))
\r
354 annotations = new Annotation[al.getWidth()];
\r
356 if (id.equals("JNETPRED")
\r
357 || id.equals("JNETPSSM")
\r
358 || id.equals("JNETFREQ")
\r
359 || id.equals("JNETHMM")
\r
360 || id.equals("JNETALIGN")
\r
361 || id.equals("JPRED"))
\r
363 for (int j = 0; j < width; j++)
\r
365 annotations[gapmap[j]] = new Annotation("", "",
\r
366 preds[i].getCharAt(j), 0);
\r
369 else if (id.equals("JNETCONF"))
\r
371 for (int j = 0; j < width; j++)
\r
373 float value = Float.parseFloat(preds[i].getCharAt(j) + "");
\r
374 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j) +
\r
375 "", "", preds[i].getCharAt(j), value);
\r
380 for (int j = 0; j < width; j++)
\r
382 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j) +
\r
387 if (id.equals("JNETCONF"))
\r
389 annot = new AlignmentAnnotation(preds[i].getName(),
\r
391 annotations, 0f, 10f, 1);
\r
396 annot = new AlignmentAnnotation(preds[i].getName(),
\r
400 al.addAnnotation(annot);
\r
403 al.deleteSequence(preds[i]);
\r
409 Hashtable scores = prediction.getScores();
\r
410 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
411 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
413 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
414 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
416 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
417 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
419 AlignFrame af = new AlignFrame(al);
\r
421 Desktop.addInternalFrame(af,
\r
423 AlignFrame.NEW_WINDOW_WIDTH,
\r
424 AlignFrame.NEW_WINDOW_HEIGHT);
\r
426 catch (Exception ex)
\r
428 ex.printStackTrace();
\r