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
18 JInternalFrame outputFrame = new JInternalFrame();
\r
19 CutAndPasteTransfer output = new CutAndPasteTransfer(false);
\r
20 int jobsRunning = 0;
\r
21 ext.vamsas.JpredSoapBindingStub server;
\r
23 public JPredClient(SequenceI[] msf)
\r
25 SequenceI seq = msf[0];
\r
26 output.formatForOutput();
\r
27 outputFrame.setContentPane(output);
\r
29 output.setText("Job details for MSA based prediction on sequence :\nName : "
\r
30 + seq.getName() + "\nSequence : "
\r
31 + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
32 Desktop.addInternalFrame(outputFrame,
\r
33 "JNet secondary structure prediction job", 800,
\r
36 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
38 this.server = (JpredSoapBindingStub) loc.getjpred(); // JBPNote will be set from properties
\r
40 catch (Exception ex) {
\r
41 output.setText("Serious! JPred Service location failed\nfor URL :"
\r
42 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
45 JPredThread jthread = new JPredThread(msf);
\r
47 ImageTwirler thread = new ImageTwirler();
\r
51 public JPredClient(SequenceI seq)
\r
53 output.formatForOutput();
\r
54 outputFrame.setContentPane(output);
\r
56 output.setText("Job details for prediction on sequence :\nName : "
\r
57 + seq.getName() + "\nSequence : " + AlignSeq.extractGaps("-. ",seq.getSequence()) + "\n");
\r
58 Desktop.addInternalFrame(outputFrame,
\r
59 "JNet secondary structure prediction job", 800,
\r
62 JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default
\r
64 this.server = (JpredSoapBindingStub) loc.getjpred(); // JBPNote will be set from properties
\r
66 catch (Exception ex) {
\r
67 output.setText("Serious! JPred Service location failed\nfor URL :"
\r
68 +loc.getjpredAddress()+"\n"+ex.getMessage());
\r
71 JPredThread jthread = new JPredThread(seq);
\r
73 ImageTwirler thread = new ImageTwirler();
\r
80 ImageIcon[] imageIcon;
\r
82 public ImageTwirler()
\r
84 imageIcon = new ImageIcon[9];
\r
85 for (int i = 0; i < 9; i++)
\r
87 java.net.URL url = getClass().getResource("/images/dna" + (i + 1) +
\r
90 imageIcon[i] = new ImageIcon(url);
\r
96 while (jobsRunning > 0)
\r
103 outputFrame.setFrameIcon(imageIcon[imageIndex]);
\r
104 outputFrame.setTitle("JNet Secondary Structure Prediction : " +
\r
105 jobsRunning + " jobs running.");
\r
108 catch (Exception ex)
\r
118 String OutputHeader;
\r
119 ext.vamsas.JpredResult result;
\r
120 ext.vamsas.Sequence sequence;
\r
121 ext.vamsas.Msfalignment msa;
\r
123 boolean jobComplete = false;
\r
124 int allowedServerExceptions = 3; // thread dies if too many exceptions.
\r
125 JPredThread(SequenceI seq)
\r
127 OutputHeader = output.getText();
\r
128 this.sequence = new ext.vamsas.Sequence();
\r
129 this.sequence.setId(seq.getName());
\r
130 this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence()));
\r
133 JPredThread(SequenceI[] msf)
\r
135 OutputHeader = output.getText();
\r
136 this.sequence = new ext.vamsas.Sequence();
\r
137 this.sequence.setId(msf[0].getName());
\r
138 this.sequence.setSeq(AlignSeq.extractGaps("-. ",msf[0].getSequence()));
\r
139 jalview.io.MSFfile mwrite = new jalview.io.MSFfile();
\r
140 this.msa = new ext.vamsas.Msfalignment();
\r
141 msa.setMsf(mwrite.print(msf));
\r
150 while (!jobComplete
\r
151 && (allowedServerExceptions > 0))
\r
155 result = server.getresult(jobId);
\r
157 if (result.isFinished())
\r
160 jobComplete = true;
\r
165 output.setText(OutputHeader + "\n" + result.getStatus());
\r
166 if (! (result.isJobFailed() || result.isServerError()))
\r
168 Thread.sleep(5000);
\r
169 // System.out.println("I'm alive "+seqid+" "+jobid);
\r
173 catch (Exception ex)
\r
175 allowedServerExceptions--;
\r
176 String msg = output.getText();
\r
177 output.setText(msg + "\nJPredWS Server exception!\n" + ex.getMessage());
\r
187 jobId = server.predictOnMsa(msa);
\r
189 jobId = server.predict(sequence);
\r
191 System.out.println(jobId);
\r
193 catch (Exception e)
\r
195 System.out.println("JPredWS Client: Failed to submit the prediction\n" +
\r
196 e.toString() + "\n");
\r
197 e.printStackTrace();
\r
201 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
\r
203 Annotation[] annotations = new Annotation[al.getWidth()];
\r
204 for (int j = 0; j < values.size(); j++)
\r
206 float value = Float.parseFloat(values.get(j).toString());
\r
207 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
\r
209 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
\r
214 // OutputHeader = output.getText();
\r
215 if (result.getStatus()!=null) {
\r
216 OutputHeader += "\n"+result.getStatus();
\r
218 if (result.getPredfile()!=null) {
\r
219 OutputHeader += "\n"+result.getPredfile();
\r
220 // 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
222 if (result.getAligfile()!=null) {
\r
223 OutputHeader += "\n"+result.getAligfile();
\r
225 output.setText(OutputHeader);
\r
227 // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File");
\r
228 jalview.io.JPredFile prediction = new jalview.io.JPredFile(result.getPredfile(), "Paste");
\r
229 SequenceI[] preds = prediction.getSeqsAsArray();
\r
231 int FirstSeq; // the position of the query sequence in Alignment al
\r
232 boolean noMsa = true; // set if no MSA has been returned by JPred
\r
234 if (this.msa!=null && result.getAligfile()!=null) {
\r
235 // we ignore the returned alignment if we only predicted on a single sequence
\r
236 String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste");
\r
237 if (jalview.io.FormatProperties.contains(format))
\r
239 al = new Alignment(jalview.io.FormatAdapter.read(result.getAligfile(),"Paste",format));
\r
245 throw (new Exception("Unknown format 'format' for file : \n" +
\r
246 result.getAligfile()));
\r
250 al = new Alignment(preds);
\r
251 FirstSeq = prediction.QuerySeqPosition;
\r
254 AlignmentAnnotation annot;
\r
255 Annotation [] annotations = null;
\r
257 int width = preds[0].getSequence().length();
\r
260 int[] gapmap = al.getSequenceAt(FirstSeq).gapMap();
\r
261 if (gapmap.length!=width) {
\r
262 throw (new Exception("Jpred Client Error\nNumber of residues in supposed query sequence :\n"
\r
263 +al.getSequenceAt(FirstSeq).getName()+"\n"
\r
264 +al.getSequenceAt(FirstSeq).getSequence()
\r
265 +"\nDiffer from number of prediction sites in \n"+result.getPredfile()+"\n"));
\r
267 // JBPNote Should also rename the query sequence sometime...
\r
269 while (i < preds.length)
\r
271 String id = preds[i].getName().toUpperCase();
\r
272 if(id.startsWith("LUPAS") || id.startsWith("JNET") || id.startsWith("JPRED"))
\r
274 annotations = new Annotation[al.getWidth()];
\r
276 if(id.equals("JNETPRED")
\r
277 || id.equals("JNETPSSM")
\r
278 || id.equals("JNETFREQ")
\r
279 || id.equals("JNETHMM")
\r
280 || id.equals("JNETALIGN")
\r
281 || id.equals("JPRED"))
\r
283 for (int j = 0; j < width; j++)
\r
284 annotations[gapmap[j]] = new Annotation("", "", preds[i].getCharAt(j), 0);
\r
286 else if(id.equals("JNETCONF"))
\r
288 for (int j = 0; j < width; j++)
\r
290 float value = Float.parseFloat(preds[i].getCharAt(j)+"");
\r
291 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "",preds[i].getCharAt(j),value);
\r
296 for (int j = 0; j < width; j++) {
\r
297 annotations[gapmap[j]] = new Annotation(preds[i].getCharAt(j)+"", "", ' ', 0);
\r
301 if(id.equals("JNETCONF"))
\r
302 annot = new AlignmentAnnotation(preds[i].getName(),
\r
304 annotations,0f,10f,1);
\r
306 else annot = new AlignmentAnnotation(preds[i].getName(),
\r
309 al.addAnnotation(annot);
\r
311 al.deleteSequence(preds[i]);
\r
316 Hashtable scores = prediction.Scores;
\r
317 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPH"),
\r
318 "JnetpropH", "Jnet Helix Propensity", 0f,1f,1);
\r
320 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPB"),
\r
321 "JnetpropB", "Jnet Beta Sheed Propensity", 0f,1f,1);
\r
323 addFloatAnnotations(al, gapmap, (Vector)scores.get("JNETPROPC"),
\r
324 "JnetpropC", "Jnet Coil Propensity", 0f,1f,1);
\r
326 AlignFrame af = new AlignFrame(al);
\r
329 Desktop.addInternalFrame(af,
\r
330 "JNet Prediction for sequence ",
\r
332 }catch(Exception ex){ex.printStackTrace();}
\r