2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws2;
23 import jalview.api.AlignCalcWorkerI;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.JvSwingUtils;
27 import jalview.util.MessageManager;
28 import jalview.ws.api.ServiceWithParameters;
29 import jalview.ws.params.AutoCalcSetting;
30 import jalview.ws.params.WsParamSetI;
31 import jalview.ws.uimodel.AlignAnalysisUIText;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.List;
36 import java.util.Locale;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuItem;
46 public class SequenceAnnotationWSClient extends Jws2Client
49 * initialise a client so its attachWSMenuEntry method can be called.
51 public SequenceAnnotationWSClient()
53 // TODO Auto-generated constructor stub
56 public SequenceAnnotationWSClient(final ServiceWithParameters sh,
57 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
59 super(alignFrame, preset, null);
60 initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
63 // dan think. Do I need to change this method to run RNAalifold through the
66 private void initSequenceAnnotationWSClient(final ServiceWithParameters sh,
67 AlignFrame alignFrame, final WsParamSetI preset, boolean editParams)
69 // dan changed! dan test. comment out if conditional
70 // if (alignFrame.getViewport().getAlignment().isNucleotide())
72 // JvOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
73 // + " can only be used\nfor amino acid alignments.",
74 // "Wrong type of sequences!", JvOptionPane.WARNING_MESSAGE);
78 AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
81 Class clientClass = aaui.getClient();
83 // Build an AACon style client - take alignment, return annotation for
86 List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
88 .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class);
90 SeqAnnotationServiceCalcWorker tmpworker = null;
93 for (AlignCalcWorkerI _worker : clnts)
95 tmpworker = (SeqAnnotationServiceCalcWorker) _worker;
96 if (tmpworker.hasService()
97 && tmpworker.getService().getClass().equals(clientClass))
104 final var worker = tmpworker;
107 processParams(sh, editParams).thenAccept((startJob) -> {
110 final SeqAnnotationServiceCalcWorker worker_;
113 worker_ = new SeqAnnotationServiceCalcWorker(sh, alignFrame, this.preset,
115 } catch (Exception x)
119 MessageManager.getString("error.implementation_error"),
122 alignFrame.getViewport().getCalcManager().registerWorker(worker_);
123 // also starts the worker
124 startSeqAnnotationWorker(sh, alignFrame, preset, editParams);
134 paramset = worker.getArguments();
135 preset_ = worker.getPreset();
141 processParams(sh, editParams, true).thenAccept((startJob) -> {
144 // reinstate worker if it was blacklisted (might have happened due
146 // invalid parameters)
147 alignFrame.getViewport().getCalcManager().enableWorker(worker);
148 worker.updateParameters(this.preset, paramset);
149 startSeqAnnotationWorker(sh, alignFrame, preset_, editParams);
156 startSeqAnnotationWorker(sh, alignFrame, preset, editParams);
160 private void startSeqAnnotationWorker(ServiceWithParameters sh,
161 AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
163 if (!sh.isInteractiveUpdate())
165 // build IUPred style client. take sequences, returns annotation per
167 processParams(sh, editParams).thenAccept((startJob) -> {
170 alignFrame.getViewport().getCalcManager().startWorker(
171 new SeqAnnotationServiceCalcWorker(sh, alignFrame, preset, paramset));
177 public SequenceAnnotationWSClient(AutoCalcSetting fave,
178 AlignFrame alignFrame, boolean b)
180 super(alignFrame, fave.getPreset(), fave.getArgumentSet());
181 initSequenceAnnotationWSClient(fave.getService(), alignFrame,
182 fave.getPreset(), b);
188 * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
189 * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
192 public void attachWSMenuEntry(JMenu wsmenu,
193 final ServiceWithParameters service,
194 final AlignFrame alignFrame)
196 if (Jws2ClientFactory.registerAAConWSInstance(wsmenu,
197 service, alignFrame))
199 // Alignment dependent analysis calculation WS gui
202 boolean hasparams = service.hasParameters();
203 String calcName = service.getName();
204 if (calcName.endsWith("WS"))
206 // Remove "WS" suffix
207 calcName = calcName.substring(0, calcName.length() - 2);
210 JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage(
211 "label.calcname_with_default_settings", new String[]
213 annotservice.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 new SequenceAnnotationWSClient(service, alignFrame,
223 wsmenu.add(annotservice);
226 // only add these menu options if the service has user-modifiable
228 annotservice = new JMenuItem(
229 MessageManager.getString("label.edit_settings_and_run"));
230 annotservice.setToolTipText(MessageManager.getString(
231 "label.view_and_change_parameters_before_running_calculation"));
233 annotservice.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 new SequenceAnnotationWSClient(service, alignFrame,
242 wsmenu.add(annotservice);
243 List<WsParamSetI> presets = service.getParamStore().getPresets();
244 if (presets != null && presets.size() > 0)
246 JMenu presetlist = new JMenu(MessageManager
247 .formatMessage("label.run_with_preset", new String[]
250 for (final WsParamSetI preset : presets)
252 final JMenuItem methodR = new JMenuItem(preset.getName());
253 methodR.setToolTipText(JvSwingUtils.wrapTooltip(true, "<strong>"
254 + (preset.isModifiable()
255 ? MessageManager.getString("label.user_preset")
257 .getString("label.service_preset"))
258 + "</strong><br/>" + preset.getDescription()));
259 methodR.addActionListener(new ActionListener()
262 public void actionPerformed(ActionEvent e)
264 new SequenceAnnotationWSClient(service,
270 presetlist.add(methodR);
272 wsmenu.add(presetlist);
278 annotservice = new JMenuItem(
279 MessageManager.getString("label.view_documentation"));
280 if (service != null && service.hasDocumentationUrl())
282 annotservice.addActionListener(new ActionListener()
286 public void actionPerformed(ActionEvent arg0)
288 Desktop.getInstance().showUrl(service.getDocumentationUrl());
291 annotservice.setToolTipText(
292 JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage(
293 "label.view_service_doc_url", new String[]
294 { service.getDocumentationUrl(),
295 service.getDocumentationUrl() })));
296 wsmenu.add(annotservice);