4 package jalview.ws.rest;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.util.Hashtable;
10 import javax.swing.JMenu;
11 import javax.swing.JMenuItem;
12 import javax.swing.JOptionPane;
13 import javax.swing.event.MenuEvent;
14 import javax.swing.event.MenuListener;
16 import jalview.datamodel.AlignmentView;
17 import jalview.gui.AlignFrame;
18 import jalview.gui.AlignViewport;
19 import jalview.gui.AlignmentPanel;
20 import jalview.gui.Desktop;
21 import jalview.gui.WebserviceInfo;
22 import jalview.io.packed.DataProvider.JvDataType;
23 import jalview.ws.WSClient;
24 import jalview.ws.WSClientI;
25 import jalview.ws.WSMenuEntryProviderI;
31 public class RestClient extends WSClient implements WSClientI,
34 RestServiceDescription service;
36 public RestClient(RestServiceDescription rsd)
42 * parent alignframe for this job
47 * alignment view which provides data for job.
52 * get the alignFrame for the associated input data if it exists.
56 protected AlignFrame recoverAlignFrameForView()
58 return jalview.gui.Desktop.getAlignFrameFor(av);
61 public RestClient(RestServiceDescription service2, AlignFrame alignFrame)
65 av = alignFrame.getViewport();
69 public void setWebserviceInfo(boolean headless)
71 WebServiceJobTitle = service.details.Action + " using "
72 + service.details.Name;
73 WebServiceName = service.details.Name;
74 WebServiceReference = "No reference - go to url for more info";
75 if (service.details.description != null)
77 WebServiceReference = service.details.description;
81 wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceName + "\n"
82 + WebServiceReference);
83 wsInfo.setRenderAsHtml(true);
89 public boolean isCancellable()
91 // TODO define process for cancelling rsbws jobs
96 public boolean canMergeResults()
98 // TODO process service definition to identify if the results might be
100 // TODO: change comparison for annotation merge
105 public void cancelJob()
107 System.err.println("Cannot cancel this job type: " + service);
111 public void attachWSMenuEntry(final JMenu wsmenu,
112 final AlignFrame alignFrame)
114 JMenuItem submit = new JMenuItem(service.details.Name);
115 submit.setToolTipText(service.details.Action+" using "+service.details.Name);
116 submit.addActionListener(new ActionListener()
120 public void actionPerformed(ActionEvent e)
122 new RestClient(service, alignFrame);
127 // TODO: menu listener should enable/disable entry depending upon selection
128 // state of the alignment
129 wsmenu.addMenuListener(new MenuListener()
133 public void menuSelected(MenuEvent e)
135 // TODO Auto-generated method stub
140 public void menuDeselected(MenuEvent e)
142 // TODO Auto-generated method stub
147 public void menuCanceled(MenuEvent e)
149 // TODO Auto-generated method stub
158 * record of initial undoredo hash for the alignFrame providing data for this
161 long[] undoredo = null;
164 * Compare the original input data to the data currently presented to the
165 * user. // LOGIC: compare undo/redo - if same, merge regardless (coping with
166 * any changes in hidden columns as normal) // if different undo/redo then
167 * compare region that was submitted // if same, then merge as before, if
168 * different then prompt user to open a new window.
172 protected boolean isAlignmentModified()
174 if (undoredo == null || av==null || av.getAlignment()==null)
176 // always return modified if we don't have access to live GUI elements anymore.
179 if (av.isUndoRedoHashModified(undoredo))
181 // alignment has been modified in some way.
184 // TODO: look deeper into modification of selection state, etc that may affect RestJobThread.realiseResults(boolean merge);
190 * TODO: combine to form a dataset+alignment+annotation context
192 AlignmentView _input;
197 jalview.io.packed.JalviewDataset jds;
200 * informative name for results
202 public String viewTitle;
204 protected void constructJob()
206 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: JAL-715: refactor to alignViewport methods and 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(),
231 viewTitle = "selected "+(av.hasHiddenColumns() ? "visible" : "") + " region of "+af.getTitle();
235 // use selected region to partition alignment
236 _input = new AlignmentView(av.getAlignment(),
237 av.getColumnSelection(),
238 av.getSelectionGroup(),
239 av.hasHiddenColumns(),
243 viewTitle = "select and unselected "+(av.hasHiddenColumns() ? "visible" : "") + " regions from "+af.getTitle();
247 // just take selected region intersection
248 _input = new AlignmentView(av.getAlignment(),
249 av.getColumnSelection(),
250 av.getSelectionGroup(),
251 av.hasHiddenColumns(),
254 viewTitle = "selected "+(av.hasHiddenColumns() ? "visible" : "") + " region of "+af.getTitle();
257 // standard alignment view without selection present
258 _input = new AlignmentView(av.getAlignment(),
259 av.getColumnSelection(),
261 av.hasHiddenColumns(),
264 viewTitle = ""+(av.hasHiddenColumns() ? "visible region of " : "") + af.getTitle();
267 RestJobThread jobsthread = new RestJobThread(this);
269 if (jobsthread.isValid())
271 setWebserviceInfo(false);
272 wsInfo.setthisService(this);
273 jobsthread.setWebServiceInfo(wsInfo);
278 // TODO: try to tell the user why the job couldn't be started.
279 JOptionPane.showMessageDialog(Desktop.desktop,
280 (jobsthread.hasWarnings() ? jobsthread.getWarnings() : "The Job couldn't be started. Please check your input, and the Jalview console for any warning messages."),
281 "Unable to start web service analysis", JOptionPane.WARNING_MESSAGE);
285 public static RestClient makeShmmrRestClient()
287 String action = "Analysis", description = "Sequence Harmony and Multi-Relief (UNSTABLE!)", name = "Sequence Harmony";
288 Hashtable<String, InputType> iparams = new Hashtable<String, InputType>();
289 jalview.ws.rest.params.JobConstant toolp;
290 //toolp = new jalview.ws.rest.JobConstant("tool","jalview");
291 //iparams.put(toolp.token, toolp);
292 toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
293 iparams.put(toolp.token, toolp);
294 toolp = new jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
295 iparams.put(toolp.token, toolp);
296 toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
297 iparams.put(toolp.token, toolp);
298 toolp = new jalview.ws.rest.params.JobConstant("blast","0");
299 iparams.put(toolp.token, toolp);
301 jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
302 aliinput.token = "ali";//_file";
303 aliinput.writeAsFile=false;//true;
304 //aliinput.token = "ali_file";
305 //aliinput.writeAsFile=true;
306 iparams.put(aliinput.token, aliinput);
307 jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
308 sgroups.setMinsize(2);
309 sgroups.min=2;// need at least two group defined to make a partition
310 iparams.put("groups", sgroups);
311 sgroups.token = "groups";
313 RestServiceDescription shmrService = new RestServiceDescription(
317 "http://www.ibi.vu.nl/programs/shmrwww/index.php?tool=jalview",// ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
318 "?tool=jalview", iparams, true, false, '-');
319 // a priori knowledge of the data returned from the service
320 shmrService.addResultDatatype(JvDataType.ANNOTATION);
321 return new RestClient(shmrService);
324 public AlignmentPanel recoverAlignPanelForView()
326 AlignmentPanel[] aps = Desktop.getAlignmentPanels(av.getSequenceSetId());
327 for (AlignmentPanel alp:aps)
337 public boolean isShowResultsInNewView()
339 // TODO make this a property of the service