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("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("-. ", 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 wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
178 if (! (result.isJobFailed() || result.isServerError()))
181 // System.out.println("I'm alive "+seqid+" "+jobid);
187 allowedServerExceptions--;
188 wsInfo.appendProgressText("\n"+ServiceName+" Server exception!\n" + ex.getMessage());
189 ex.printStackTrace();
193 if (! (result!=null && (result.isJobFailed() || result.isServerError())))
194 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
196 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
203 vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs);
204 if (jobsubmit.getStatus()==1) {
205 jobId=jobsubmit.getJobId();
206 System.out.println(WsURL+" Job Id '"+jobId+"'");
208 throw new Exception(jobsubmit.getJobId());
213 System.err.println(ServiceName + " Client: Failed to submit the prediction\n" +
214 e.toString() + "\n");
219 private void addFloatAnnotations(Alignment al, int[] gapmap, Vector values, String Symname, String Visname, float min, float max, int winLength) {
221 Annotation[] annotations = new Annotation[al.getWidth()];
222 for (int j = 0; j < values.size(); j++)
224 float value = Float.parseFloat(values.get(j).toString());
225 annotations[gapmap[j]] = new Annotation("", value+"",' ',value);
227 al.addAnnotation(new AlignmentAnnotation(Symname, Visname, annotations, min, max, winLength));
229 private jalview.datamodel.Sequence[] getVamsasAlignment(vamsas.objects.simple.Alignment valign) {
230 vamsas.objects.simple.Sequence[] seqs = valign.getSeqs().getSeqs();
231 jalview.datamodel.Sequence[] msa = new jalview.datamodel.Sequence[seqs.length];
232 for (int i=0, j=seqs.length; i<j;i++)
233 msa[i] = new jalview.datamodel.Sequence(seqs[i].getId(), seqs[i].getSeq());
238 SequenceI[] seqs=null;
240 // OutputHeader = output.getText();
241 if (result.isFailed()) {
242 OutputHeader +="Job failed.\n";
244 if (result.getStatus()!=null) {
245 OutputHeader += "\n"+result.getStatus();
247 if (result.getMsa()!=null) {
248 OutputHeader += "\nAlignment Object Method Notes\n";
249 String lines[] = result.getMsa().getMethod();
250 for (int line=0;line<lines.length; line++)
251 OutputHeader+=lines[line]+"\n";
253 // JBPNote The returned files from a webservice could be hidden behind icons in the monitor window that, when clicked, pop up their corresponding data
254 seqs = getVamsasAlignment(result.getMsa());
257 wsInfo.setProgressText(OutputHeader);
259 AlignmentOrder msaorder = new AlignmentOrder(seqs);
262 jalview.analysis.AlignmentSorter.recoverOrder(seqs);
265 jalview.analysis.SeqsetUtils.deuniquify(SeqNames, seqs);
267 Alignment al = new Alignment(seqs);
269 // TODO: JBPNote Should also rename the query sequence sometime...
270 AlignFrame af = new AlignFrame(al);
271 af.addSortByOrderMenuItem(ServiceName+" Ordering", msaorder);
273 Desktop.addInternalFrame(af,
275 AlignFrame.NEW_WINDOW_WIDTH,
276 AlignFrame.NEW_WINDOW_HEIGHT);
278 }catch(Exception ex){ex.printStackTrace();}