X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FMsaWSClient.java;h=76a1c56ed89a16f5102e8eb08e476e74ab666b81;hb=a37f0ae9a4e8c0f318bac29dcf56811e220ee3c6;hp=820dfb456d0e9b53ac1cd8149655947a3bd940cc;hpb=b26ca522d2067ef5a4078c99458e7aeb4b44a268;p=jalview.git diff --git a/src/jalview/ws/jws2/MsaWSClient.java b/src/jalview/ws/jws2/MsaWSClient.java index 820dfb4..76a1c56 100644 --- a/src/jalview/ws/jws2/MsaWSClient.java +++ b/src/jalview/ws/jws2/MsaWSClient.java @@ -1,35 +1,49 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.jws2; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentView; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.gui.JvSwingUtils; +import jalview.util.MessageManager; +import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.params.WsParamSetI; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.List; -import javax.swing.*; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.ToolTipManager; -import jalview.datamodel.*; -import jalview.gui.*; import compbio.data.msa.MsaWS; import compbio.metadata.Argument; -import compbio.metadata.Preset; -import compbio.metadata.PresetManager; -import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; /** * DOCUMENT ME! @@ -44,13 +58,7 @@ public class MsaWSClient extends Jws2Client */ MsaWS server; - AlignFrame alignFrame; - - private Preset preset; - - private List paramset; - - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, String altitle, + public MsaWSClient(Jws2Instance sh, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) @@ -60,9 +68,9 @@ public class MsaWSClient extends Jws2Client // TODO Auto-generated constructor stub } - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, - String altitle, jalview.datamodel.AlignmentView msa, - boolean submitGaps, boolean preserveOrder, Alignment seqdataset, + public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle, + jalview.datamodel.AlignmentView msa, boolean submitGaps, + boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) { this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder, @@ -86,51 +94,38 @@ public class MsaWSClient extends Jws2Client * DOCUMENT ME! */ - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, + public MsaWSClient(Jws2Instance sh, WsParamSetI preset, List arguments, boolean editParams, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) { - super(); - alignFrame = _alignFrame; + super(_alignFrame, preset, arguments); + if (!processParams(sh, editParams)) + { + return; + } + if (!(sh.service instanceof MsaWS)) { // redundant at mo - but may change - JOptionPane - .showMessageDialog( - Desktop.desktop, - "The Service called \n" - + sh.serviceType - + "\nis not a \nMultiple Sequence Alignment Service !", - "Internal Jalview Error", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(Desktop.desktop, MessageManager + .formatMessage("label.service_called_is_not_msa_service", + new String[] + { sh.serviceType }), MessageManager + .getString("label.internal_jalview_error"), + JOptionPane.WARNING_MESSAGE); return; } - server = sh.service; - this.preset = preset; - this.paramset = arguments; - if (editParams) - { - WsJobParameters jobParams = new WsJobParameters(sh, preset); - if (!jobParams.showRunDialog()) - { - return; - } - if ((this.preset = jobParams.getPreset())==null) - { - paramset = jobParams.getJobParams(); - } else { - paramset = null; // no user supplied parameters. - } - } - + server = (MsaWS) sh.service; if ((wsInfo = setWebService(sh, false)) == null) { - JOptionPane.showMessageDialog(Desktop.desktop, - "The Multiple Sequence Alignment Service named " - + sh.serviceType + " is unknown", - "Internal Jalview Error", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(Desktop.desktop, MessageManager + .formatMessage("label.msa_service_is_unknown", new String[] + { sh.serviceType }), MessageManager + .getString("label.internal_jalview_error"), + JOptionPane.WARNING_MESSAGE); return; } @@ -180,9 +175,57 @@ public class MsaWSClient extends Jws2Client WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps, preserveOrder, seqdataset); wsInfo.setthisService(msathread); + if (isValidAlignment(alignFrame.getCurrentView().getAlignment())) + { + msathread.start(); + } } + private boolean isValidAlignment(AlignmentI seqdataset) + { + String header = wsInfo.getInfoText() + + "\nValidating submited Alignment..."; + wsInfo.setInfoText(header); + int validSeqCount = 0; + List seqs = seqdataset.getSequences(); + if (seqs.size() < 2) + { + wsInfo.setInfoText(header + + "\nA minimum of two sequences is required to perform this operation"); + return false; + } + + for (SequenceI seq : seqs) + { + + if (seq.getSequenceAsString().matches( + "([(a-zA-Z?)(-?)(.?)]+)?[a-zA-Z]([(a-zA-Z?)(-?)(.?)]+)?")) + { + ++validSeqCount; + } + if (validSeqCount > 1) + { + wsInfo.setInfoText(header + + "\nAlignment sequences was successfully validated"); + return true; + } + } + + wsInfo.setInfoText(header + + "\nA minimum of two sequences with at least one non-gap character in each sequence is required to perform this operation"); + return false; + } + + public static void main(String[] args) + { + System.out + .println("A" + .matches("([(a-zA-Z?)(-?)(.?)]+)?[a-zA-Z]([(a-zA-Z?)(-?)(.?)]+)?")); + } + + + protected String getServiceActionKey() { return "MsaWS"; @@ -209,13 +252,18 @@ public class MsaWSClient extends Jws2Client public void attachWSMenuEntry(JMenu rmsawsmenu, final Jws2Instance service, final AlignFrame alignFrame) { + if (registerAAConWSInstance(rmsawsmenu, service, alignFrame)) + { + // Alignment dependent analysis calculation WS gui + return; + } setWebService(service, true); // headless boolean finished = true, submitGaps = false; JMenu msawsmenu = rmsawsmenu; String svcname = WebServiceName; if (svcname.endsWith("WS")) { - svcname = svcname.substring(0,svcname.length()-2); + svcname = svcname.substring(0, svcname.length() - 2); } String calcName = svcname + " "; if (canSubmitGaps()) @@ -224,17 +272,28 @@ public class MsaWSClient extends Jws2Client rmsawsmenu.add(msawsmenu); calcName = ""; } - + boolean hasparams = service.hasParameters(); do { + String action = "Align "; if (submitGaps == true) { - msawsmenu = new JMenu("profile " + svcname); + action = "Realign "; + msawsmenu = new JMenu(MessageManager.formatMessage( + "label.realign_with_params", new String[] + { svcname })); + msawsmenu.setToolTipText(MessageManager + .getString("label.align_sequences_to_existing_alignment")); rmsawsmenu.add(msawsmenu); } final boolean withGaps = submitGaps; - JMenuItem method = new JMenuItem(calcName + "Defaults"); - method.setToolTipText("Align with default settings"); + + JMenuItem method = new JMenuItem(MessageManager.formatMessage( + "label.calcname_with_default_settings", new String[] + { calcName })); + method.setToolTipText(MessageManager.formatMessage( + "label.action_with_default_settings", new String[] + { action })); method.addActionListener(new ActionListener() { @@ -248,45 +307,84 @@ public class MsaWSClient extends Jws2Client } }); msawsmenu.add(method); - method = new JMenuItem(calcName + "Edit and run ..."); - method.setToolTipText("View and change the parameters before alignment."); - - method.addActionListener(new ActionListener() + if (hasparams) { - public void actionPerformed(ActionEvent e) - { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - new MsaWSClient(service, null, null, true, alignFrame.getTitle(), - msa, withGaps, true, alignFrame.getViewport() - .getAlignment().getDataset(), alignFrame); + // only add these menu options if the service has user-modifiable + // arguments + method = new JMenuItem( + MessageManager.getString("label.edit_settings_and_run")); + method.setToolTipText(MessageManager + .getString("label.view_and_change_parameters_before_alignment")); - } - }); - msawsmenu.add(method); - PresetManager presets = service.getPresets(); - if (presets != null && presets.getPresets().size() > 0) - { - JMenu presetlist = new JMenu(calcName + "Presets"); + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AlignmentView msa = alignFrame.gatherSequencesForAlignment(); + new MsaWSClient(service, null, null, true, alignFrame + .getTitle(), msa, withGaps, true, alignFrame + .getViewport().getAlignment().getDataset(), alignFrame); - for (final Preset preset : (List) presets.getPresets()) + } + }); + msawsmenu.add(method); + List presets = service.getParamStore().getPresets(); + if (presets != null && presets.size() > 0) { - final JMenuItem methodR = new JMenuItem(preset.getName()); - methodR.setToolTipText("

"+preset.getDescription()+"

"); - methodR.addActionListener(new ActionListener() + JMenu presetlist = new JMenu(MessageManager.formatMessage( + "label.run_with_preset_params", new String[] + { calcName })); + + final int showToolTipFor = ToolTipManager.sharedInstance() + .getDismissDelay(); + for (final WsParamSetI preset : presets) { - public void actionPerformed(ActionEvent e) + final JMenuItem methodR = new JMenuItem(preset.getName()); + final int QUICK_TOOLTIP = 1500; + // JAL-1582 shorten tooltip display time in these menu items as + // they can obscure other options + methodR.addMouseListener(new MouseAdapter() + { + @Override + public void mouseEntered(MouseEvent e) + { + ToolTipManager.sharedInstance().setDismissDelay( + QUICK_TOOLTIP); + } + + @Override + public void mouseExited(MouseEvent e) + { + ToolTipManager.sharedInstance().setDismissDelay(showToolTipFor); + } + + }); + methodR.setToolTipText(JvSwingUtils.wrapTooltip( + true, + "

" + + (preset.isModifiable() ? MessageManager + .getString("label.user_preset") + : MessageManager + .getString("label.service_preset")) + + "
" + preset.getDescription() + + "

")); + methodR.addActionListener(new ActionListener() { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - new MsaWSClient(service, preset, alignFrame.getTitle(), msa, - false, true, alignFrame.getViewport().getAlignment() - .getDataset(), alignFrame); + public void actionPerformed(ActionEvent e) + { + AlignmentView msa = alignFrame + .gatherSequencesForAlignment(); + new MsaWSClient(service, preset, alignFrame.getTitle(), + msa, false, true, alignFrame.getViewport() + .getAlignment().getDataset(), alignFrame); - } + } - }); - presetlist.add(methodR); + }); + presetlist.add(methodR); + } + msawsmenu.add(presetlist); } - msawsmenu.add(presetlist); } if (!submitGaps && canSubmitGaps()) {