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
30 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
\r
31 SequenceI seq = msf[0];
\r
32 altitle = "JNet prediction on "+seq.getName()+" using alignment from "+title;
\r
34 wsInfo.setProgressText("Job details for MSA based prediction ("+title+") on sequence :\n>"
\r
35 + seq.getName() + "\n"
\r
36 + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
38 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
40 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
41 // JBPNote url will be set from properties
\r
43 this.server = loc.getjpred(new java.net.URL(WsURL));
\r
45 catch (Exception ex) {
\r
46 JOptionPane.showMessageDialog(Desktop.desktop, "The Secondary Structure Prediction Service named "
\r
47 +WebServiceName+" at "+WsURL+" couldn't be located.",
\r
48 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
\r
49 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
\r
50 +WsURL+"\n"+ex.getMessage());
\r
53 JPredThread jthread = new JPredThread(msf);
\r
57 public JPredClient(String title, SequenceI seq)
\r
60 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
\r
61 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
\r
62 + seq.getName() + "\n" + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
63 altitle = "JNet prediction for sequence "+seq.getName()+" from "+title;
\r
64 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
66 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
68 this.server = loc.getjpred(new java.net.URL(WsURL)); // JBPNote will be set from properties
\r
70 catch (Exception ex) {
\r
71 JOptionPane.showMessageDialog(Desktop.desktop, "The Secondary Structure Prediction Service named "
\r
72 +WebServiceName+" at "+WsURL+" couldn't be located.",
\r
73 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
\r
74 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
\r
75 +WsURL+"\n"+ex.getMessage());
\r
78 JPredThread jthread = new JPredThread(seq);
\r
86 String OutputHeader;
\r
87 ext.vamsas.JpredResult result;
\r
88 ext.vamsas.Sequence sequence;
\r
89 ext.vamsas.Msfalignment msa;
\r
91 boolean jobComplete = false;
\r
92 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
93 JPredThread(SequenceI seq)
\r
95 OutputHeader = wsInfo.getProgressText();
\r
96 this.sequence = new ext.vamsas.Sequence();
\r
97 this.sequence.setId(seq.getName());
\r
98 this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence()));
\r
101 JPredThread(SequenceI[] msf)
\r
103 OutputHeader = wsInfo.getProgressText();
\r
104 this.sequence = new ext.vamsas.Sequence();
\r
105 this.sequence.setId(msf[0].getName());
\r
106 this.sequence.setSeq(AlignSeq.extractGaps("-. ",msf[0].getSequence()));
\r
107 jalview.io.MSFfile mwrite = new jalview.io.MSFfile();
\r
108 this.msa = new ext.vamsas.Msfalignment();
\r
109 msa.setMsf(mwrite.print(msf));
\r
118 while (!jobComplete && (allowedServerExceptions > 0))
\r
122 result = server.getresult(jobId);
\r
124 if( result.isRunning() )
\r
125 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
126 else if( result.isQueued() )
\r
127 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
129 if (result.isFinished())
\r
132 jobComplete = true;
\r
137 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
138 if (! (result.isJobFailed() || result.isServerError()))
\r
140 Thread.sleep(5000);
\r
141 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
143 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
147 catch (Exception ex)
\r
149 allowedServerExceptions--;
\r
150 wsInfo.appendProgressText("\nJPredWS Server exception!\n" + ex.getMessage());
\r
154 if (! (result.isJobFailed() || result.isServerError()))
\r
155 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
157 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
165 jobId = server.predictOnMsa(msa);
\r
167 jobId = server.predict(sequence);
\r
169 System.out.println(WsURL+" Job Id '"+jobId+"'");
\r
171 catch (Exception e)
\r
173 System.err.println("JPredWS Client: Failed to submit the prediction\n" +
\r
174 e.toString() + "\n");
\r
175 e.printStackTrace();
\r
179 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
\r
181 Annotation[] annotations = new Annotation[al.getWidth()];
\r
182 for (int j = 0; j < values.size(); j++)
\r
184 float value = Float.parseFloat(values.get(j).toString());
\r
185 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
\r
187 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
\r
192 // OutputHeader = output.getText();
\r
193 if (result.isFailed()) {
\r
194 OutputHeader +="Job failed.\n";
\r
196 if (result.getStatus()!=null) {
\r
197 OutputHeader += "\n"+result.getStatus();
\r
199 if (result.getPredfile()!=null) {
\r
200 OutputHeader += "\n"+result.getPredfile();
\r
201 // 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
203 if (result.getAligfile()!=null) {
\r
204 OutputHeader += "\n"+result.getAligfile();
\r
206 wsInfo.setProgressText(OutputHeader);
\r
208 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
209 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.getPredfile(), "Paste");
\r
210 SequenceI[] preds = prediction.getSeqsAsArray();
\r
212 int FirstSeq; // the position of the query sequence in Alignment al
\r
213 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
215 if (this.msa!=null && result.getAligfile()!=null) {
\r
216 // we ignore the returned alignment if we only predicted on a single sequence
\r
217 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste");
\r
218 if (jalview.io.FormatAdapter.formats.contains(format))
\r
220 al = new Alignment(jalview.io.FormatAdapter.readFile(result.getAligfile(),"Paste",format));
\r
226 throw (new Exception("Unknown format 'format' for file : \n" +
\r
227 result.getAligfile()));
\r
231 al = new Alignment(preds);
\r
232 FirstSeq = prediction.getQuerySeqPosition();
\r
235 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(al.getSequenceAt(FirstSeq), SequenceInfo))
\r
236 throw (new Exception("Couldn't recover sequence properties for JNet Query sequence!"));
\r
238 AlignmentAnnotation annot;
\r
239 Annotation [] annotations = null;
\r
241 int width = preds[0].getSequence().length();
\r
244 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
246 if (gapmap.length!=width) {
\r
247 throw (new Exception("Jnet Client Error\nNumber of residues in supposed query sequence :\n"
\r
248 +al.getSequenceAt(FirstSeq).getName()+"\n"
\r
249 +al.getSequenceAt(FirstSeq).getSequence()
\r
250 +"\nDiffer from number of prediction sites in \n"+result.getPredfile()+"\n"));
\r
252 // JBPNote Should also rename the query sequence sometime...
\r
254 while (i < preds.length)
\r
256 String id = preds[i].getName().toUpperCase();
\r
257 if(id.startsWith("LUPAS") || id.startsWith("JNET") || id.startsWith("JPRED"))
\r
259 annotations = new Annotation[al.getWidth()];
\r
261 if(id.equals("JNETPRED")
\r
262 || id.equals("JNETPSSM")
\r
263 || id.equals("JNETFREQ")
\r
264 || id.equals("JNETHMM")
\r
265 || id.equals("JNETALIGN")
\r
266 || id.equals("JPRED"))
\r
268 for (int j = 0; j < width; j++)
\r
269 annotations[gapmap[j]] = new Annotation("", "", preds[i].getCharAt(j), 0);
\r
271 else if(id.equals("JNETCONF"))
\r
273 for (int j = 0; j < width; j++)
\r
275 float value = Float.parseFloat(preds[i].getCharAt(j)+"");
\r
276 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "",preds[i].getCharAt(j),value);
\r
281 for (int j = 0; j < width; j++) {
\r
282 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "", ' ', 0);
\r
286 if(id.equals("JNETCONF"))
\r
287 annot = new AlignmentAnnotation(preds[i].getName(),
\r
289 annotations,0f,10f,1);
\r
291 else annot = new AlignmentAnnotation(preds[i].getName(),
\r
294 al.addAnnotation(annot);
\r
296 al.deleteSequence(preds[i]);
\r
301 Hashtable scores = prediction.getScores();
\r
302 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
303 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
305 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
306 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
308 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
309 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
311 AlignFrame af = new AlignFrame(al);
\r
314 Desktop.addInternalFrame(af,
\r
316 AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
317 }catch(Exception ex){ex.printStackTrace();}
\r