3 import org.apache.axis.client.*;
4 import javax.xml.namespace.QName;
6 import jalview.datamodel.*;
11 import jalview.analysis.AlignSeq;
13 import vamsas.objects.*;
18 public class MsaWSClient
21 ext.vamsas.MuscleWS server;
22 WebserviceInfo wsInfo;
26 * @param msa SequenceI[]
29 String WebServiceName;
30 String WebServiceJobTitle;
31 String WebServiceReference;
33 private boolean setWebService(String MsaWSName) {
34 if (MsaWServices.info.contains(MsaWSName.toUpperCase())) {
35 WebServiceName = MsaWSName;
36 String[] wsinfo = (String[]) MsaWServices.info.get(MsaWSName.toUpperCase());
38 WebServiceJobTitle = wsinfo[1];
39 WebServiceReference = wsinfo[2];
46 // public MsaWSClient(String MsaWSName, SequenceI[] msa) {
47 // MsaWSClient(MsaWSName, msa, true);
50 public MsaWSClient(String MsaWSName, SequenceI[] msa, boolean preserveOrder)
52 if (setWebService(MsaWSName)==false) {
53 JOptionPane.showMessageDialog(Desktop.desktop, "The Multiple Sequence Alignment Service named "+MsaWSName+" is unknown",
54 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
58 wsInfo = new jalview.gui.WebserviceInfo(WebServiceJobTitle, WebServiceReference);
60 wsInfo.setProgressText("Job details\n");
62 // TODO: MuscleWS transmuted to generic MsaWS client
63 MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default
65 this.server = (MuscleWS) loc.getMuscleWS(// JBPNote will be set from properties
66 new java.net.URL(WsURL));
68 catch (Exception ex) {
69 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
70 +WsURL+"\n"+ex.getMessage());
71 wsInfo.setStatus(wsInfo.ERROR);
75 MsaWSThread musclethread = new MsaWSThread(msa);
76 wsInfo.setthisService(musclethread);
81 protected class MsaWSThread extends Thread implements WSClientI
83 String ServiceName = WebServiceName;
85 public boolean isCancellable()
91 vamsas.objects.simple.MsaResult result = null;
92 vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple.
95 int allowedServerExceptions = 3; // thread dies if too many exceptions.
96 MsaWSThread(SequenceI[] msa)
98 OutputHeader = wsInfo.getProgressText();
99 vamsas.objects.simple.Sequence[] seqarray = new vamsas.objects.simple.
100 Sequence[msa.length];
101 for (int i = 0; i < msa.length; i++)
103 seqarray[i] = new vamsas.objects.simple.Sequence();
104 seqarray[i].setId(msa[i].getName());
105 seqarray[i].setSeq(AlignSeq.extractGaps("-. ", msa[i].getSequence()));
107 this.seqs = new vamsas.objects.simple.SequenceSet();
108 this.seqs.setSeqs(seqarray);
111 boolean jobComplete = false;
113 public void cancelJob() {
115 String cancelledMessage="";
117 vamsas.objects.simple.WsJobId cancelledJob = server.cancel(jobId);
118 if (cancelledJob.getStatus() == 2)
121 cancelledMessage = "Job cancelled.";
122 wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK);
128 if (cancelledJob.getStatus() == 3)
130 // VALID UNSTOPPABLE JOB
132 "Server cannot cancel this job. just close the window.\n";
134 if (cancelledJob.getJobId() != null)
135 cancelledMessage += "[" + cancelledJob.getJobId() + "]";
136 cancelledMessage +="\n";
137 } catch (Exception exc) {
138 cancelledMessage +="\nProblems cancelling the job : Exception received...\n"+exc+"\n";
139 exc.printStackTrace();
141 wsInfo.setProgressText(OutputHeader + cancelledMessage+"\n");
150 while (!jobComplete && (allowedServerExceptions > 0))
154 result = server.getResult(jobId);
156 if( result.isRunning() )
157 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
158 else if( result.isQueued() )
159 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
161 if (result.isFinished())
169 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
170 if (! (result.isJobFailed() || result.isServerError()))
173 // System.out.println("I'm alive "+seqid+" "+jobid);
179 allowedServerExceptions--;
180 wsInfo.appendProgressText("\n"+ServiceName+" Server exception!\n" + ex.getMessage());
181 ex.printStackTrace();
185 if (! (result!=null && (result.isJobFailed() || result.isServerError())))
186 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
188 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
195 vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs);
196 if (jobsubmit.getStatus()==1) {
197 System.out.println(jobId=jobsubmit.getJobId());
199 throw new Exception(jobsubmit.getJobId());
204 System.out.println(ServiceName + " Client: Failed to submit the prediction\n" +
205 e.toString() + "\n");
210 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
212 Annotation[] annotations = new Annotation[al.getWidth()];
213 for (int j = 0; j < values.size(); j++)
215 float value = Float.parseFloat(values.get(j).toString());
216 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
218 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
220 private jalview.datamodel.Sequence[] getVamsasAlignment(vamsas.objects.simple.Alignment valign) {
221 vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs();
222 jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs.length];
223 for (int i=0, j=seqs.length; i<j;i++)
224 msa[i] = new jalview.datamodel.Sequence(seqs[i].getId(), seqs[i].getSeq());
229 SequenceI[] seqs=null;
231 // OutputHeader = output.getText();
232 if (result.isFailed()) {
233 OutputHeader +="Job failed.\n";
235 if (result.getStatus()!=null) {
236 OutputHeader += "\n"+result.getStatus();
238 if (result.getMsa()!=null) {
239 OutputHeader += "\nAlignment Object Method Notes\n";
240 String lines[] = result.getMsa().getMethod();
241 for (int line=0;line<lines.length; line++)
242 OutputHeader+=lines[line]+"\n";
244 // JBPNote The returned files from a webservice could be hidden behind icons in the monitor window that, when clicked, pop up their corresponding data
245 seqs = getVamsasAlignment(result.getMsa());
248 wsInfo.setProgressText(OutputHeader);
251 al = new Alignment(seqs);
253 // TODO: JBPNote Should also rename the query sequence sometime...
254 AlignFrame af = new AlignFrame(al);
255 Desktop.addInternalFrame(af,
256 ServiceName + " Alignment",
257 AlignFrame.NEW_WINDOW_WIDTH,
258 AlignFrame.NEW_WINDOW_HEIGHT);
260 }catch(Exception ex){ex.printStackTrace();}