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
21 public JPredClient(SequenceI[] msf)
\r
23 wsInfo = new WebserviceInfo("JNet secondary structure prediction job",
\r
24 "\"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
26 SequenceI seq = msf[0];
\r
27 wsInfo.setProgressText("Job details for MSA based prediction on sequence :\nName : "
\r
28 + seq.getName() + "\nSequence : "
\r
29 + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
32 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
34 this.server = (JpredSoapBindingStub) loc.getjpred(); // JBPNote will be set from properties
\r
36 catch (Exception ex) {
\r
37 wsInfo.setProgressText("Serious! JPred Service location failed\nfor URL :"
\r
38 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
41 JPredThread jthread = new JPredThread(msf);
\r
45 public JPredClient(SequenceI seq)
\r
47 wsInfo = new WebserviceInfo("JNet secondary structure prediction job",
\r
48 "\"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
51 wsInfo.setProgressText("Job details for prediction on sequence :\nName : "
\r
52 + seq.getName() + "\nSequence : " + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
54 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
56 this.server = (JpredSoapBindingStub) loc.getjpred(); // JBPNote will be set from properties
\r
58 catch (Exception ex) {
\r
59 wsInfo.setProgressText("Serious! JPred Service location failed\nfor URL :"
\r
60 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
63 JPredThread jthread = new JPredThread(seq);
\r
71 String OutputHeader;
\r
72 ext.vamsas.JpredResult result;
\r
73 ext.vamsas.Sequence sequence;
\r
74 ext.vamsas.Msfalignment msa;
\r
76 boolean jobComplete = false;
\r
77 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
78 JPredThread(SequenceI seq)
\r
80 OutputHeader = wsInfo.getProgressText();
\r
81 this.sequence = new ext.vamsas.Sequence();
\r
82 this.sequence.setId(seq.getName());
\r
83 this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence()));
\r
86 JPredThread(SequenceI[] msf)
\r
88 OutputHeader = wsInfo.getProgressText();
\r
89 this.sequence = new ext.vamsas.Sequence();
\r
90 this.sequence.setId(msf[0].getName());
\r
91 this.sequence.setSeq(AlignSeq.extractGaps("-. ",msf[0].getSequence()));
\r
92 jalview.io.MSFfile mwrite = new jalview.io.MSFfile();
\r
93 this.msa = new ext.vamsas.Msfalignment();
\r
94 msa.setMsf(mwrite.print(msf));
\r
103 while (!jobComplete && (allowedServerExceptions > 0))
\r
107 result = server.getresult(jobId);
\r
109 if( result.isRunning() )
\r
110 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
\r
111 else if( result.isQueued() )
\r
112 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
\r
114 if (result.isFinished())
\r
117 jobComplete = true;
\r
122 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
\r
123 if (! (result.isJobFailed() || result.isServerError()))
\r
125 Thread.sleep(5000);
\r
126 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
130 catch (Exception ex)
\r
132 allowedServerExceptions--;
\r
133 wsInfo.appendProgressText("\nJPredWS Server exception!\n" + ex.getMessage());
\r
137 if (! (result.isJobFailed() || result.isServerError()))
\r
138 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
\r
140 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
\r
148 jobId = server.predictOnMsa(msa);
\r
150 jobId = server.predict(sequence);
\r
152 System.out.println(jobId);
\r
154 catch (Exception e)
\r
156 System.out.println("JPredWS Client: Failed to submit the prediction\n" +
\r
157 e.toString() + "\n");
\r
158 e.printStackTrace();
\r
162 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
\r
164 Annotation[] annotations = new Annotation[al.getWidth()];
\r
165 for (int j = 0; j < values.size(); j++)
\r
167 float value = Float.parseFloat(values.get(j).toString());
\r
168 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
\r
170 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
\r
175 // OutputHeader = output.getText();
\r
176 if (result.isFailed()) {
\r
177 OutputHeader +="Job failed.\n";
\r
179 if (result.getStatus()!=null) {
\r
180 OutputHeader += "\n"+result.getStatus();
\r
182 if (result.getPredfile()!=null) {
\r
183 OutputHeader += "\n"+result.getPredfile();
\r
184 // 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
186 if (result.getAligfile()!=null) {
\r
187 OutputHeader += "\n"+result.getAligfile();
\r
189 wsInfo.setProgressText(OutputHeader);
\r
191 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
192 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.getPredfile(), "Paste");
\r
193 SequenceI[] preds = prediction.getSeqsAsArray();
\r
195 int FirstSeq; // the position of the query sequence in Alignment al
\r
196 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
198 if (this.msa!=null && result.getAligfile()!=null) {
\r
199 // we ignore the returned alignment if we only predicted on a single sequence
\r
200 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste");
\r
201 if (jalview.io.FormatAdapter.formats.contains(format))
\r
203 al = new Alignment(jalview.io.FormatAdapter.readFile(result.getAligfile(),"Paste",format));
\r
209 throw (new Exception("Unknown format 'format' for file : \n" +
\r
210 result.getAligfile()));
\r
214 al = new Alignment(preds);
\r
215 FirstSeq = prediction.QuerySeqPosition;
\r
218 AlignmentAnnotation annot;
\r
219 Annotation [] annotations = null;
\r
221 int width = preds[0].getSequence().length();
\r
224 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
225 if (gapmap.length!=width) {
\r
226 throw (new Exception("Jpred Client Error\nNumber of residues in supposed query sequence :\n"
\r
227 +al.getSequenceAt(FirstSeq).getName()+"\n"
\r
228 +al.getSequenceAt(FirstSeq).getSequence()
\r
229 +"\nDiffer from number of prediction sites in \n"+result.getPredfile()+"\n"));
\r
231 // JBPNote Should also rename the query sequence sometime...
\r
233 while (i < preds.length)
\r
235 String id = preds[i].getName().toUpperCase();
\r
236 if(id.startsWith("LUPAS") || id.startsWith("JNET") || id.startsWith("JPRED"))
\r
238 annotations = new Annotation[al.getWidth()];
\r
240 if(id.equals("JNETPRED")
\r
241 || id.equals("JNETPSSM")
\r
242 || id.equals("JNETFREQ")
\r
243 || id.equals("JNETHMM")
\r
244 || id.equals("JNETALIGN")
\r
245 || id.equals("JPRED"))
\r
247 for (int j = 0; j < width; j++)
\r
248 annotations[gapmap[j]] = new Annotation("", "", preds[i].getCharAt(j), 0);
\r
250 else if(id.equals("JNETCONF"))
\r
252 for (int j = 0; j < width; j++)
\r
254 float value = Float.parseFloat(preds[i].getCharAt(j)+"");
\r
255 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "",preds[i].getCharAt(j),value);
\r
260 for (int j = 0; j < width; j++) {
\r
261 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "", ' ', 0);
\r
265 if(id.equals("JNETCONF"))
\r
266 annot = new AlignmentAnnotation(preds[i].getName(),
\r
268 annotations,0f,10f,1);
\r
270 else annot = new AlignmentAnnotation(preds[i].getName(),
\r
273 al.addAnnotation(annot);
\r
275 al.deleteSequence(preds[i]);
\r
280 Hashtable scores = prediction.Scores;
\r
281 /* addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
282 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
284 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
285 "JnetpropB", "Jnet Beta Sheet Propensity", 0f,1f,1);
\r
287 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
288 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
290 AlignFrame af = new AlignFrame(al);
\r
293 Desktop.addInternalFrame(af,
\r
294 "JNet Prediction for sequence ",
\r
295 AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
296 }catch(Exception ex){ex.printStackTrace();}
\r