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
15 public class JPredClient extends WSClient
\r
17 ext.vamsas.JPredWS server;
\r
18 String altitle = "";
\r
19 java.util.Hashtable SequenceInfo = null;
\r
20 private void setWebService() {
\r
21 WebServiceName = "JNetWS";
\r
22 WebServiceJobTitle = "JNet secondary structure prediction";
\r
23 WebServiceReference="\"Cuff J. A and Barton G.J (1999) Application of enhanced "
\r
24 + "multiple sequence alignment profiles to improve protein secondary structure prediction, "
\r
25 + "Proteins 40:502-511\".";
\r
26 WsURL="http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred";
\r
28 public JPredClient(String title, SequenceI[] msf)
\r
31 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
\r
32 SequenceI seq = msf[0];
\r
33 altitle = "JNet prediction on "+seq.getName()+" using alignment from "+title;
\r
35 wsInfo.setProgressText("Job details for MSA based prediction ("+title+") on sequence :\n>"
\r
36 + seq.getName() + "\n"
\r
37 + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
39 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
41 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
42 // JBPNote url will be set from properties
\r
44 this.server = loc.getjpred(new java.net.URL(WsURL));
\r
46 catch (Exception ex) {
\r
47 JOptionPane.showMessageDialog(Desktop.desktop, "The Secondary Structure Prediction Service named "
\r
48 +WebServiceName+" at "+WsURL+" couldn't be located.",
\r
49 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
\r
50 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
\r
51 +WsURL+"\n"+ex.getMessage());
\r
54 JPredThread jthread = new JPredThread(msf);
\r
58 public JPredClient(String title, SequenceI seq)
\r
61 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
\r
62 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
\r
63 + seq.getName() + "\n" + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
64 altitle = "JNet prediction for sequence "+seq.getName()+" from "+title;
\r
65 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
67 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
69 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
70 ((JpredSoapBindingStub) this.server).setTimeout(60000); // one minute stub
\r
72 catch (Exception ex) {
\r
73 JOptionPane.showMessageDialog(Desktop.desktop, "The Secondary Structure Prediction Service named "
\r
74 +WebServiceName+" at "+WsURL+" couldn't be located.",
\r
75 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
\r
76 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
\r
77 +WsURL+"\n"+ex.getMessage());
\r
78 wsInfo.setStatus(wsInfo.STATE_STOPPED_SERVERERROR);
\r
81 JPredThread jthread = new JPredThread(seq);
\r
89 String OutputHeader;
\r
90 ext.vamsas.JpredResult result;
\r
91 ext.vamsas.Sequence sequence;
\r
92 ext.vamsas.Msfalignment msa;
\r
94 boolean jobComplete = false;
\r
95 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
96 JPredThread(SequenceI seq)
\r
98 OutputHeader = wsInfo.getProgressText();
\r
99 this.sequence = new ext.vamsas.Sequence();
\r
100 this.sequence.setId(seq.getName());
\r
101 this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence()));
\r
104 JPredThread(SequenceI[] msf)
\r
106 OutputHeader = wsInfo.getProgressText();
\r
107 this.sequence = new ext.vamsas.Sequence();
\r
108 this.sequence.setId(msf[0].getName());
\r
109 this.sequence.setSeq(AlignSeq.extractGaps("-. ",msf[0].getSequence()));
\r
110 jalview.io.PileUpfile mwrite = new jalview.io.PileUpfile();
\r
111 this.msa = new ext.vamsas.Msfalignment();
\r
112 msa.setMsf(mwrite.print(msf));
\r
121 while (!jobComplete && (allowedServerExceptions > 0))
\r
125 if ((result = server.getresult(jobId))==null)
\r
126 throw(new Exception("Timed out when communicating with server\nTry again later.\n"));
\r
128 if( result.isRunning() )
\r
129 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
130 else if( result.isQueued() )
\r
131 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
133 if (result.isFinished())
\r
136 jobComplete = true;
\r
141 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
142 if (! (result.isJobFailed() || result.isServerError()))
\r
146 Thread.sleep(5000);
\r
148 catch (InterruptedException ex1)
\r
151 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
153 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
157 catch (Exception ex)
\r
159 allowedServerExceptions--;
\r
160 wsInfo.appendProgressText("\nJPredWS Server exception!\n" + ex.getMessage());
\r
163 if (allowedServerExceptions>0)
\r
164 Thread.sleep(5000);
\r
166 catch (InterruptedException ex1)
\r
172 if (! (result.isJobFailed() || result.isServerError()))
\r
173 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
175 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
183 jobId = server.predictOnMsa(msa);
\r
185 jobId = server.predict(sequence);
\r
188 if (jobId.startsWith("Broken")) {
\r
189 throw new Exception("Submission " + jobId);
\r
191 System.out.println(WsURL+" Job Id '"+jobId+"'");
\r
194 throw new Exception("Server timed out - try again later\n");
\r
198 catch (Exception e)
\r
200 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
\r
201 allowedServerExceptions=0;
\r
203 wsInfo.appendProgressText("Failed to submit the prediction: "+e.toString()+"\nJust close the window\n");
\r
204 System.err.println("JPredWS Client: Failed to submit the prediction\n" +
\r
205 e.toString() + "\n");
\r
206 // e.printStackTrace(); TODO: JBPNote DEBUG
\r
210 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
\r
212 Annotation[] annotations = new Annotation[al.getWidth()];
\r
213 for (int j = 0; j < values.size(); j++)
\r
215 float value = Float.parseFloat(values.get(j).toString());
\r
216 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
\r
218 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
\r
223 // OutputHeader = output.getText();
\r
224 if (result.isFailed()) {
\r
225 OutputHeader +="Job failed.\n";
\r
227 if (result.getStatus()!=null) {
\r
228 OutputHeader += "\n"+result.getStatus();
\r
230 if (result.getPredfile()!=null) {
\r
231 OutputHeader += "\n"+result.getPredfile();
\r
232 // 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
234 if (result.getAligfile()!=null) {
\r
235 OutputHeader += "\n"+result.getAligfile();
\r
237 wsInfo.setProgressText(OutputHeader);
\r
239 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
240 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.getPredfile(), "Paste");
\r
241 SequenceI[] preds = prediction.getSeqsAsArray();
\r
243 int FirstSeq; // the position of the query sequence in Alignment al
\r
244 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
246 if (this.msa!=null && result.getAligfile()!=null) {
\r
247 // we ignore the returned alignment if we only predicted on a single sequence
\r
248 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste");
\r
249 if (jalview.io.FormatAdapter.formats.contains(format))
\r
251 al = new Alignment(jalview.io.FormatAdapter.readFile(result.getAligfile(),"Paste",format));
\r
257 throw (new Exception("Unknown format 'format' for file : \n" +
\r
258 result.getAligfile()));
\r
262 al = new Alignment(preds);
\r
263 FirstSeq = prediction.getQuerySeqPosition();
\r
266 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(al.getSequenceAt(FirstSeq), SequenceInfo))
\r
267 throw (new Exception("Couldn't recover sequence properties for JNet Query sequence!"));
\r
269 AlignmentAnnotation annot;
\r
270 Annotation [] annotations = null;
\r
272 int width = preds[0].getSequence().length();
\r
275 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
277 if (gapmap.length!=width) {
\r
278 throw (new Exception("Jnet Client Error\nNumber of residues in supposed query sequence :\n"
\r
279 +al.getSequenceAt(FirstSeq).getName()+"\n"
\r
280 +al.getSequenceAt(FirstSeq).getSequence()
\r
281 +"\nDiffer from number of prediction sites in \n"+result.getPredfile()+"\n"));
\r
283 // JBPNote Should also rename the query sequence sometime...
\r
285 while (i < preds.length)
\r
287 String id = preds[i].getName().toUpperCase();
\r
288 if(id.startsWith("LUPAS") || id.startsWith("JNET") || id.startsWith("JPRED"))
\r
290 annotations = new Annotation[al.getWidth()];
\r
292 if(id.equals("JNETPRED")
\r
293 || id.equals("JNETPSSM")
\r
294 || id.equals("JNETFREQ")
\r
295 || id.equals("JNETHMM")
\r
296 || id.equals("JNETALIGN")
\r
297 || id.equals("JPRED"))
\r
299 for (int j = 0; j < width; j++)
\r
300 annotations[gapmap[j]] = new Annotation("", "", preds[i].getCharAt(j), 0);
\r
302 else if(id.equals("JNETCONF"))
\r
304 for (int j = 0; j < width; j++)
\r
306 float value = Float.parseFloat(preds[i].getCharAt(j)+"");
\r
307 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "",preds[i].getCharAt(j),value);
\r
312 for (int j = 0; j < width; j++) {
\r
313 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "", ' ', 0);
\r
317 if(id.equals("JNETCONF"))
\r
318 annot = new AlignmentAnnotation(preds[i].getName(),
\r
320 annotations,0f,10f,1);
\r
322 else annot = new AlignmentAnnotation(preds[i].getName(),
\r
325 al.addAnnotation(annot);
\r
327 al.deleteSequence(preds[i]);
\r
332 Hashtable scores = prediction.getScores();
\r
333 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
334 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
336 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
337 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
339 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
340 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
342 AlignFrame af = new AlignFrame(al);
\r
345 Desktop.addInternalFrame(af,
\r
347 AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
348 }catch(Exception ex){ex.printStackTrace();}
\r