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
22 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
24 ext.vamsas.MuscleWS server;
26 private boolean setWebService(String MsaWSName) {
27 if (MsaWServices.info.containsKey(MsaWSName)) {
28 WebServiceName = MsaWSName;
29 String[] wsinfo = (String[]) MsaWServices.info.get(MsaWSName);
31 WebServiceJobTitle = wsinfo[1];
32 WebServiceReference = wsinfo[2];
40 public MsaWSClient(String MsaWSName, String altitle, SequenceI[] msa, boolean submitGaps, boolean preserveOrder)
42 if (setWebService(MsaWSName)==false) {
43 JOptionPane.showMessageDialog(Desktop.desktop, "The Multiple Sequence Alignment Service named "+MsaWSName+" is unknown",
44 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
48 wsInfo = new jalview.gui.WebserviceInfo(WebServiceJobTitle, WebServiceReference);
50 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")+" of "+altitle+"\nJob details\n");
52 // TODO: MuscleWS transmuted to generic MsaWS client
53 MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default
55 this.server = (MuscleWS) loc.getMuscleWS(new java.net.URL(WsURL));
57 catch (Exception ex) {
58 wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
59 +WsURL+"\n"+ex.getMessage());
60 wsInfo.setStatus(wsInfo.ERROR);
64 MsaWSThread musclethread = new MsaWSThread(WebServiceName+" alignment of "+altitle, msa, submitGaps, preserveOrder);
65 wsInfo.setthisService(musclethread);
70 protected class MsaWSThread extends Thread implements WSClientI
72 String ServiceName = WebServiceName;
74 public boolean isCancellable()
80 vamsas.objects.simple.MsaResult result = null;
82 vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple.
85 Hashtable SeqNames = null;
86 boolean submitGaps = false,// default is to strip gaps from sequences
87 preserveOrder = true; // and always store and recover sequence order
90 String alTitle; // name which will be used to form new alignment window.
91 int allowedServerExceptions = 3; // thread dies if too many exceptions.
92 MsaWSThread(String title, SequenceI[] msa, boolean subgaps, boolean presorder)
96 preserveOrder = presorder;
98 OutputHeader = wsInfo.getProgressText();
99 SeqNames = new Hashtable();
100 vamsas.objects.simple.Sequence[] seqarray = new vamsas.objects.simple.
101 Sequence[msa.length];
103 for (int i = 0; i < msa.length; i++)
105 String newname = jalview.analysis.SeqsetUtils.unique_name(i);
107 // TODO: JBPNote: this is a ubiquitous transformation - set of jalview seq objects to vamsas sequences with name preservation
108 SeqNames.put(newname, jalview.analysis.SeqsetUtils.SeqCharacterHash(msa[i]));
109 seqarray[i] = new vamsas.objects.simple.Sequence();
110 seqarray[i].setId(newname);
111 seqarray[i].setSeq((submitGaps) ? msa[i].getSequence()
112 : AlignSeq.extractGaps(jalview.util.Comparison.GapChars, msa[i].getSequence()));
115 this.seqs = new vamsas.objects.simple.SequenceSet();
116 this.seqs.setSeqs(seqarray);
119 boolean jobComplete = false;
121 public void cancelJob() {
123 String cancelledMessage="";
125 vamsas.objects.simple.WsJobId cancelledJob = server.cancel(jobId);
126 if (cancelledJob.getStatus() == 2)
129 cancelledMessage = "Job cancelled.";
130 wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK);
136 if (cancelledJob.getStatus() == 3)
138 // VALID UNSTOPPABLE JOB
140 "Server cannot cancel this job. just close the window.\n";
142 if (cancelledJob.getJobId() != null)
143 cancelledMessage += "[" + cancelledJob.getJobId() + "]";
144 cancelledMessage +="\n";
145 } catch (Exception exc) {
146 cancelledMessage +="\nProblems cancelling the job : Exception received...\n"+exc+"\n";
147 exc.printStackTrace();
149 wsInfo.setProgressText(OutputHeader + cancelledMessage+"\n");
158 while (!jobComplete && (allowedServerExceptions > 0))
162 result = server.getResult(jobId);
164 if (result.isRunning())
165 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
166 else if (result.isQueued())
167 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
169 if (result.isFinished())
177 if (result.getStatus() != null)
178 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
179 if (! (result.isJobFailed() || result.isServerError()))
182 // System.out.println("I'm alive "+seqid+" "+jobid);
192 allowedServerExceptions--;
193 wsInfo.appendProgressText("\n" + ServiceName + " Server exception!\n" +
195 ex.printStackTrace();
198 if (allowedServerExceptions == 0)
200 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
204 if (! (result != null && (result.isJobFailed() || result.isServerError())))
205 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
208 if (result.isFailed())
209 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
210 if (result.isServerError())
211 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
219 vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs);
220 if (jobsubmit.getStatus()==1) {
221 jobId=jobsubmit.getJobId();
222 System.out.println(WsURL+" Job Id '"+jobId+"'");
224 throw new Exception(jobsubmit.getJobId());
229 System.err.println(ServiceName + " Client: Failed to submit the prediction\n" +
230 e.toString() + "\n");
235 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
237 Annotation[] annotations = new Annotation[al.getWidth()];
238 for (int j = 0; j < values.size(); j++)
240 float value = Float.parseFloat(values.get(j).toString());
241 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
243 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
245 private jalview.datamodel.Sequence[] getVamsasAlignment(vamsas.objects.simple.Alignment valign) {
246 vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs();
247 jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs.length];
248 for (int i=0, j=seqs.length; i<j;i++)
249 msa[i] = new jalview.datamodel.Sequence(seqs[i].getId(), seqs[i].getSeq());
254 SequenceI[] seqs=null;
256 // OutputHeader = output.getText();
257 if (result.isFailed()) {
258 OutputHeader +="Job failed.\n";
260 if (result.getStatus()!=null) {
261 OutputHeader += "\n"+result.getStatus();
263 if (result.getMsa()!=null) {
264 OutputHeader += "\nAlignment Object Method Notes\n";
265 String lines[] = result.getMsa().getMethod();
266 for (int line=0;line<lines.length; line++)
267 OutputHeader+=lines[line]+"\n";
269 // JBPNote The returned files from a webservice could be hidden behind icons in the monitor window that, when clicked, pop up their corresponding data
270 seqs = getVamsasAlignment(result.getMsa());
273 wsInfo.setProgressText(OutputHeader);
275 AlignmentOrder msaorder = new AlignmentOrder(seqs);
278 jalview.analysis.AlignmentSorter.recoverOrder(seqs);
281 jalview.analysis.SeqsetUtils.deuniquify(SeqNames, seqs);
283 Alignment al = new Alignment(seqs);
285 // TODO: JBPNote Should also rename the query sequence sometime...
286 AlignFrame af = new AlignFrame(al);
287 af.addSortByOrderMenuItem(ServiceName+" Ordering", msaorder);
289 Desktop.addInternalFrame(af,
291 AlignFrame.NEW_WINDOW_WIDTH,
292 AlignFrame.NEW_WINDOW_HEIGHT);
294 }catch(Exception ex){ex.printStackTrace();}