4 package jalview.ws.rest;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.util.Hashtable;
9 import java.util.Vector;
11 import javax.swing.JMenu;
12 import javax.swing.JMenuItem;
13 import javax.swing.JOptionPane;
14 import javax.swing.event.MenuEvent;
15 import javax.swing.event.MenuListener;
17 import com.sun.org.apache.bcel.internal.generic.ISHL;
19 import jalview.datamodel.AlignmentView;
20 import jalview.datamodel.SequenceGroup;
21 import jalview.gui.AlignFrame;
22 import jalview.gui.AlignViewport;
23 import jalview.gui.AlignmentPanel;
24 import jalview.gui.Desktop;
25 import jalview.gui.WebserviceInfo;
26 import jalview.io.packed.DataProvider.JvDataType;
27 import jalview.ws.WSClient;
28 import jalview.ws.WSClientI;
29 import jalview.ws.WSMenuEntryProviderI;
35 public class RestClient extends WSClient implements WSClientI,
38 RestServiceDescription service;
40 public RestClient(RestServiceDescription rsd)
46 * parent alignframe for this job
51 * alignment view which provides data for job.
56 * get the alignFrame for the associated input data if it exists.
60 protected AlignFrame recoverAlignFrameForView()
62 return jalview.gui.Desktop.getAlignFrameFor(av);
65 public RestClient(RestServiceDescription service2, AlignFrame alignFrame)
69 av = alignFrame.getViewport();
73 public void setWebserviceInfo(boolean headless)
75 WebServiceJobTitle = service.details.Action + " using "
76 + service.details.Name;
77 WebServiceName = service.details.Name;
78 WebServiceReference = "No reference - go to url for more info";
79 if (service.details.description != null)
81 WebServiceReference = service.details.description;
85 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceName + "\n"
86 + WebServiceReference);
87 wsInfo.setRenderAsHtml(true);
93 public boolean isCancellable()
95 // TODO define process for cancelling rsbws jobs
100 public boolean canMergeResults()
102 // TODO process service definition to identify if the results might be
104 // TODO: change comparison for annotation merge
109 public void cancelJob()
111 System.err.println("Cannot cancel this job type: " + service);
115 public void attachWSMenuEntry(final JMenu wsmenu,
116 final AlignFrame alignFrame)
118 JMenuItem submit = new JMenuItem(service.details.Name);
119 submit.setToolTipText(service.details.Action+" using "+service.details.Name);
120 submit.addActionListener(new ActionListener()
124 public void actionPerformed(ActionEvent e)
126 new RestClient(service, alignFrame);
131 // TODO: menu listener should enable/disable entry depending upon selection
132 // state of the alignment
133 wsmenu.addMenuListener(new MenuListener()
137 public void menuSelected(MenuEvent e)
139 // TODO Auto-generated method stub
144 public void menuDeselected(MenuEvent e)
146 // TODO Auto-generated method stub
151 public void menuCanceled(MenuEvent e)
153 // TODO Auto-generated method stub
162 * record of initial undoredo hash for the alignFrame providing data for this
165 long[] undoredo = null;
168 * Compare the original input data to the data currently presented to the
169 * user. // LOGIC: compare undo/redo - if same, merge regardless (coping with
170 * any changes in hidden columns as normal) // if different undo/redo then
171 * compare region that was submitted // if same, then merge as before, if
172 * different then prompt user to open a new window.
176 protected boolean isAlignmentModified()
178 if (undoredo == null || av==null || av.getAlignment()==null)
180 // always return modified if we don't have access to live GUI elements anymore.
183 if (av.isUndoRedoHashModified(undoredo))
185 // alignment has been modified in some way.
188 // TODO: look deeper into modification of selection state, etc that may affect RestJobThread.realiseResults(boolean merge);
194 * TODO: combine to form a dataset+alignment+annotation context
196 AlignmentView _input;
201 jalview.io.packed.JalviewDataset jds;
203 protected void constructJob()
205 service.setInvolvesFlags();
207 // record all aspects of alignment view so we can merge back or recreate
209 undoredo = av.getUndoRedoHash();
211 * delete ? Vector sgs = av.getAlignment().getGroups(); if (sgs!=null) {
212 * _sgs = new SequenceGroup[sgs.size()]; sgs.copyInto(_sgs); } else { _sgs =
213 * new SequenceGroup[0]; }
215 boolean selExists = (av.getSelectionGroup() != null)
216 && (av.getSelectionGroup().getSize() > 1);
217 // TODO: revise to full focus+context+dataset input data staging model
220 if (service.partitiondata)
222 if (av.getAlignment().getGroups()!=null && av.getAlignment().getGroups().size() > 0)
224 // intersect groups with selected region
225 _input = new AlignmentView(av.getAlignment(),
226 av.getColumnSelection(),
227 av.getSelectionGroup(),
228 av.hasHiddenColumns(),
234 // use selected region to partition alignment
235 _input = new AlignmentView(av.getAlignment(),
236 av.getColumnSelection(),
237 av.getSelectionGroup(),
238 av.hasHiddenColumns(),
242 // TODO: verify that some kind of partition can be constructed from input
246 // just take selected region intersection
247 _input = new AlignmentView(av.getAlignment(),
248 av.getColumnSelection(),
249 av.getSelectionGroup(),
250 av.hasHiddenColumns(),
255 // standard alignment view without selection present
256 _input = new AlignmentView(av.getAlignment(),
257 av.getColumnSelection(),
259 av.hasHiddenColumns(),
264 RestJobThread jobsthread = new RestJobThread(this);
266 if (jobsthread.isValid())
268 setWebserviceInfo(false);
269 wsInfo.setthisService(this);
270 jobsthread.setWebServiceInfo(wsInfo);
275 // TODO: try to tell the user why the job couldn't be started.
276 JOptionPane.showMessageDialog(Desktop.desktop,
277 "Unable to start web service analysis",
278 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
282 public static RestClient makeShmmrRestClient()
284 String action = "Analyse", description = "Sequence Harmony and Multi-Relief (UNSTABLE!)", name = "Sequence Harmony";
285 Hashtable<String, InputType> iparams = new Hashtable<String, InputType>();
286 jalview.ws.rest.params.JobConstant toolp;
287 //toolp = new jalview.ws.rest.JobConstant("tool","jalview");
288 //iparams.put(toolp.token, toolp);
289 toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
290 iparams.put(toolp.token, toolp);
291 toolp = new jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
292 iparams.put(toolp.token, toolp);
293 toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
294 iparams.put(toolp.token, toolp);
295 toolp = new jalview.ws.rest.params.JobConstant("blast","0");
296 iparams.put(toolp.token, toolp);
298 jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
299 aliinput.token = "ali";//_file";
300 aliinput.writeAsFile=false;//true;
301 //aliinput.token = "ali_file";
302 //aliinput.writeAsFile=true;
303 iparams.put(aliinput.token, aliinput);
304 jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
306 iparams.put("groups", sgroups);
307 sgroups.token = "groups";
309 RestServiceDescription shmrService = new RestServiceDescription(
313 "http://www.ibi.vu.nl/programs/shmrwww/index.php?tool=jalview",// ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
314 "?tool=jalview", iparams, true, false, '-');
315 // a priori knowledge of the data returned from the service
316 shmrService.addResultDatatype(JvDataType.ANNOTATION);
317 return new RestClient(shmrService);
320 public AlignmentPanel recoverAlignPanelForView()
322 AlignmentPanel[] aps = Desktop.getAlignmentPanels(av.getSequenceSetId());
323 for (AlignmentPanel alp:aps)
333 public boolean isShowResultsInNewView()
335 // TODO make this a property of the service