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;
199 protected void constructJob()
201 service.setInvolvesFlags();
203 // record all aspects of alignment view so we can merge back or recreate
205 undoredo = av.getUndoRedoHash();
207 * delete ? Vector sgs = av.getAlignment().getGroups(); if (sgs!=null) {
208 * _sgs = new SequenceGroup[sgs.size()]; sgs.copyInto(_sgs); } else { _sgs =
209 * new SequenceGroup[0]; }
211 boolean selExists = (av.getSelectionGroup() != null)
212 && (av.getSelectionGroup().getSize() > 1);
213 // TODO: revise to full focus+context+dataset input data staging model
216 if (service.partitiondata)
218 if (av.getAlignment().getGroups()!=null && av.getAlignment().getGroups().size() > 0)
220 // intersect groups with selected region
221 _input = new AlignmentView(av.getAlignment(),
222 av.getColumnSelection(),
223 av.getSelectionGroup(),
224 av.hasHiddenColumns(),
230 // use selected region to partition alignment
231 _input = new AlignmentView(av.getAlignment(),
232 av.getColumnSelection(),
233 av.getSelectionGroup(),
234 av.hasHiddenColumns(),
238 // TODO: verify that some kind of partition can be constructed from input
242 // just take selected region intersection
243 _input = new AlignmentView(av.getAlignment(),
244 av.getColumnSelection(),
245 av.getSelectionGroup(),
246 av.hasHiddenColumns(),
251 // standard alignment view without selection present
252 _input = new AlignmentView(av.getAlignment(),
253 av.getColumnSelection(),
255 av.hasHiddenColumns(),
260 RestJobThread jobsthread = new RestJobThread(this);
262 if (jobsthread.isValid())
264 setWebserviceInfo(false);
265 wsInfo.setthisService(this);
266 jobsthread.setWebServiceInfo(wsInfo);
271 // TODO: try to tell the user why the job couldn't be started.
272 JOptionPane.showMessageDialog(Desktop.desktop,
273 "Unable to start web service analysis",
274 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
278 public static RestClient makeShmmrRestClient()
280 String action = "Analyse", description = "Sequence Harmony and Multi-Relief (UNSTABLE!)", name = "Sequence Harmony";
281 Hashtable<String, InputType> iparams = new Hashtable<String, InputType>();
282 jalview.ws.rest.params.JobConstant toolp;
283 //toolp = new jalview.ws.rest.JobConstant("tool","jalview");
284 //iparams.put(toolp.token, toolp);
285 toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
286 iparams.put(toolp.token, toolp);
287 toolp = new jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
288 iparams.put(toolp.token, toolp);
289 toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
290 iparams.put(toolp.token, toolp);
291 toolp = new jalview.ws.rest.params.JobConstant("blast","0");
292 iparams.put(toolp.token, toolp);
294 jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
295 aliinput.token = "ali";//_file";
296 aliinput.writeAsFile=false;//true;
297 //aliinput.token = "ali_file";
298 //aliinput.writeAsFile=true;
299 iparams.put(aliinput.token, aliinput);
300 jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
302 iparams.put("groups", sgroups);
303 sgroups.token = "groups";
305 RestServiceDescription shmrService = new RestServiceDescription(
309 "http://www.ibi.vu.nl/programs/shmrwww/index.php?tool=jalview",// ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
310 "?tool=jalview", iparams, true, false, '-');
311 // a priori knowledge of the data returned from the service
312 shmrService.addResultDatatype(JvDataType.ANNOTATION);
313 return new RestClient(shmrService);
316 public AlignmentPanel recoverAlignPanelForView()
318 AlignmentPanel[] aps = Desktop.getAlignmentPanels(av.getSequenceSetId());
319 for (AlignmentPanel alp:aps)
329 public boolean isShowResultsInNewView()
331 // TODO make this a property of the service