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
\r
17 int jobsRunning = 0;
\r
18 ext.vamsas.JpredSoapBindingStub server;
\r
19 WebserviceInfo wsInfo;
\r
20 String altitle = "";
\r
21 java.util.Hashtable SequenceInfo = null;
\r
22 public JPredClient(String title, SequenceI[] msf)
\r
24 wsInfo = new WebserviceInfo("JNet secondary structure prediction on "+title,
\r
25 "\"Cuff J. A and Barton G.J (1999) Application of enhanced multiple sequence alignment profiles to improve protein secondary structure prediction, Proteins 40:502-511\".");
\r
27 SequenceI seq = msf[0];
\r
28 altitle = "JNet prediction on "+seq.getName()+" using "+title;
\r
29 wsInfo.setProgressText("Job details for MSA based prediction ("+title+") on sequence :\n>"
\r
30 + seq.getName() + "\n"
\r
31 + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
33 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
35 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
36 // JBPNote url will be set from properties
\r
38 this.server = (JpredSoapBindingStub) loc.getjpred(new java.net.URL("http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred"));
\r
40 catch (Exception ex) {
\r
41 wsInfo.setProgressText("Serious! JPred Service location failed\nfor URL :"
\r
42 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
45 JPredThread jthread = new JPredThread(msf);
\r
49 public JPredClient(SequenceI seq)
\r
51 wsInfo = new WebserviceInfo("JNet secondary structure prediction Job",
\r
52 "\"Cuff J. A and Barton G.J (1999) Application of enhanced multiple sequence alignment profiles to improve protein secondary structure prediction, Proteins 40:502-511\".");
\r
55 wsInfo.setProgressText("Job details for prediction on sequence :\n>"
\r
56 + seq.getName() + "\n" + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
57 altitle = "JNet prediction for sequence "+seq.getName();
\r
58 SequenceInfo = jalview.analysis.SeqsetUtils.SeqCharacterHash(seq);
\r
59 // TODO: put proper url in
\r
60 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
62 this.server = (JpredSoapBindingStub) loc.getjpred(new java.net.URL("http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred")); // JBPNote will be set from properties
\r
64 catch (Exception ex) {
\r
65 wsInfo.setProgressText("Serious! JPred Service location failed\nfor URL :"
\r
66 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
69 JPredThread jthread = new JPredThread(seq);
\r
77 String OutputHeader;
\r
78 ext.vamsas.JpredResult result;
\r
79 ext.vamsas.Sequence sequence;
\r
80 ext.vamsas.Msfalignment msa;
\r
82 boolean jobComplete = false;
\r
83 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
84 JPredThread(SequenceI seq)
\r
86 OutputHeader = wsInfo.getProgressText();
\r
87 this.sequence = new ext.vamsas.Sequence();
\r
88 this.sequence.setId(seq.getName());
\r
89 this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence()));
\r
92 JPredThread(SequenceI[] msf)
\r
94 OutputHeader = wsInfo.getProgressText();
\r
95 this.sequence = new ext.vamsas.Sequence();
\r
96 this.sequence.setId(msf[0].getName());
\r
97 this.sequence.setSeq(AlignSeq.extractGaps("-. ",msf[0].getSequence()));
\r
98 jalview.io.MSFfile mwrite = new jalview.io.MSFfile();
\r
99 this.msa = new ext.vamsas.Msfalignment();
\r
100 msa.setMsf(mwrite.print(msf));
\r
109 while (!jobComplete && (allowedServerExceptions > 0))
\r
113 result = server.getresult(jobId);
\r
115 if( result.isRunning() )
\r
116 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
117 else if( result.isQueued() )
\r
118 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
120 if (result.isFinished())
\r
123 jobComplete = true;
\r
128 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
129 if (! (result.isJobFailed() || result.isServerError()))
\r
131 Thread.sleep(5000);
\r
132 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
134 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
138 catch (Exception ex)
\r
140 allowedServerExceptions--;
\r
141 wsInfo.appendProgressText("\nJPredWS Server exception!\n" + ex.getMessage());
\r
145 if (! (result.isJobFailed() || result.isServerError()))
\r
146 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
148 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
156 jobId = server.predictOnMsa(msa);
\r
158 jobId = server.predict(sequence);
\r
160 System.out.println(jobId);
\r
162 catch (Exception e)
\r
164 System.out.println("JPredWS Client: Failed to submit the prediction\n" +
\r
165 e.toString() + "\n");
\r
166 e.printStackTrace();
\r
170 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
\r
172 Annotation[] annotations = new Annotation[al.getWidth()];
\r
173 for (int j = 0; j < values.size(); j++)
\r
175 float value = Float.parseFloat(values.get(j).toString());
\r
176 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
\r
178 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
\r
183 // OutputHeader = output.getText();
\r
184 if (result.isFailed()) {
\r
185 OutputHeader +="Job failed.\n";
\r
187 if (result.getStatus()!=null) {
\r
188 OutputHeader += "\n"+result.getStatus();
\r
190 if (result.getPredfile()!=null) {
\r
191 OutputHeader += "\n"+result.getPredfile();
\r
192 // 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
194 if (result.getAligfile()!=null) {
\r
195 OutputHeader += "\n"+result.getAligfile();
\r
197 wsInfo.setProgressText(OutputHeader);
\r
199 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
200 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.getPredfile(), "Paste");
\r
201 SequenceI[] preds = prediction.getSeqsAsArray();
\r
203 int FirstSeq; // the position of the query sequence in Alignment al
\r
204 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
206 if (this.msa!=null && result.getAligfile()!=null) {
\r
207 // we ignore the returned alignment if we only predicted on a single sequence
\r
208 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste");
\r
209 if (jalview.io.FormatAdapter.formats.contains(format))
\r
211 al = new Alignment(jalview.io.FormatAdapter.readFile(result.getAligfile(),"Paste",format));
\r
217 throw (new Exception("Unknown format 'format' for file : \n" +
\r
218 result.getAligfile()));
\r
222 al = new Alignment(preds);
\r
223 FirstSeq = prediction.getQuerySeqPosition();
\r
226 if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(al.getSequenceAt(FirstSeq), SequenceInfo))
\r
227 throw (new Exception("Couldn't recover sequence properties for JNet Query sequence!"));
\r
229 AlignmentAnnotation annot;
\r
230 Annotation [] annotations = null;
\r
232 int width = preds[0].getSequence().length();
\r
235 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
237 if (gapmap.length!=width) {
\r
238 throw (new Exception("Jnet Client Error\nNumber of residues in supposed query sequence :\n"
\r
239 +al.getSequenceAt(FirstSeq).getName()+"\n"
\r
240 +al.getSequenceAt(FirstSeq).getSequence()
\r
241 +"\nDiffer from number of prediction sites in \n"+result.getPredfile()+"\n"));
\r
243 // JBPNote Should also rename the query sequence sometime...
\r
245 while (i < preds.length)
\r
247 String id = preds[i].getName().toUpperCase();
\r
248 if(id.startsWith("LUPAS") || id.startsWith("JNET") || id.startsWith("JPRED"))
\r
250 annotations = new Annotation[al.getWidth()];
\r
252 if(id.equals("JNETPRED")
\r
253 || id.equals("JNETPSSM")
\r
254 || id.equals("JNETFREQ")
\r
255 || id.equals("JNETHMM")
\r
256 || id.equals("JNETALIGN")
\r
257 || id.equals("JPRED"))
\r
259 for (int j = 0; j < width; j++)
\r
260 annotations[gapmap[j]] = new Annotation("", "", preds[i].getCharAt(j), 0);
\r
262 else if(id.equals("JNETCONF"))
\r
264 for (int j = 0; j < width; j++)
\r
266 float value = Float.parseFloat(preds[i].getCharAt(j)+"");
\r
267 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "",preds[i].getCharAt(j),value);
\r
272 for (int j = 0; j < width; j++) {
\r
273 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "", ' ', 0);
\r
277 if(id.equals("JNETCONF"))
\r
278 annot = new AlignmentAnnotation(preds[i].getName(),
\r
280 annotations,0f,10f,1);
\r
282 else annot = new AlignmentAnnotation(preds[i].getName(),
\r
285 al.addAnnotation(annot);
\r
287 al.deleteSequence(preds[i]);
\r
292 Hashtable scores = prediction.getScores();
\r
293 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
294 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
296 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
297 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
299 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
300 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
302 AlignFrame af = new AlignFrame(al);
\r
305 Desktop.addInternalFrame(af,
\r
307 AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
308 }catch(Exception ex){ex.printStackTrace();}
\r