X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fslivkaws%2FSlivkaWSDiscoverer.java;h=2b4a95818a37f7e6ee662ad851288b4dcd1bf704;hb=c794c5033adeee182b03a5ea92c0a7495a29661f;hp=2d46c9fb62938269489025bb930c5cac7fc4fab4;hpb=857348180124be7ab86d7de1e4d3f780e65b1fdd;p=jalview.git diff --git a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java index 2d46c9f..2b4a958 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java +++ b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java @@ -1,30 +1,33 @@ package jalview.ws.slivkaws; -import jalview.datamodel.AlignmentView; import jalview.gui.AlignFrame; import jalview.ws.WSMenuEntryProviderI; -import jalview.ws.jws2.MsaWSClient; +import jalview.ws.api.ServiceWithParameters; +import jalview.ws.jws2.PreferredServiceRegistry; -import java.awt.event.ActionEvent; +import java.beans.PropertyChangeSupport; import java.io.IOError; import java.io.IOException; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; import javax.swing.JMenu; -import javax.swing.JMenuItem; import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; -public class SlivkaWSDiscoverer - implements Runnable, WSMenuEntryProviderI +public class SlivkaWSDiscoverer implements Runnable, WSMenuEntryProviderI { private static SlivkaWSDiscoverer instance = null; - private SlivkaClient client; - private SlivkaWSDiscoverer() { + private SlivkaClient slivkaClient; + + private SlivkaWSDiscoverer() + { try { - client = new SlivkaClient("gjb-www-1.cluster.lifesci.dundee.ac.uk", 3203); + slivkaClient = new SlivkaClient("https://www.compbio.dundee.ac.uk/slivka"); } catch (URISyntaxException e) { throw new RuntimeException(e); @@ -33,111 +36,118 @@ public class SlivkaWSDiscoverer public static SlivkaWSDiscoverer getInstance() { - if (instance == null) { - instance = new SlivkaWSDiscoverer(); - } + if (instance == null) + { + instance = new SlivkaWSDiscoverer(); + } return instance; } - @Override - public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame) + /** + * TODO: tests needed for logic for determining type of each discovered + * service. Then reimplement this routine ! + * + * @return (MSA instances, one AAUI type instance, and the remaining all + * sequence analysis instances taking 1 sequence only) + */ + List getServiceInstances() { - JMenu submenu = new JMenu("Slivka"); - + List instances = new ArrayList<>(); + for (SlivkaService service : services) { - // clustalo menu entry - JMenuItem noParamMenuItem = new JMenuItem("ClustalO with defaults"); - SlivkaWSInstance clustalo; - try - { - clustalo = new SlivkaWSInstance(client, client.getService("clustalo")); - } catch (IOException e) + ServiceWithParameters newinstance = null; + for (String classifier : service.classifiers) { - throw new IOError(e); - } - noParamMenuItem.addActionListener((ActionEvent e) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) + if (classifier.contains("Multiple sequence alignment")) { - new MsaWSClient( - clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(), - alignFrame - ); + // MSA services always overwrite + newinstance = new SlivkaMsaServiceInstance(slivkaClient, service); } - }); - submenu.add(noParamMenuItem); - - JMenuItem parametrisedMenuItem = new JMenuItem("ClustalO with custom parameters"); - parametrisedMenuItem.addActionListener((ActionEvent evt) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) + if (classifier.contains("Protein sequence analysis")) { - try - { - SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService()); - new MsaWSClient( - clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true, - alignFrame.getViewport().getAlignment().getDataset(), alignFrame - ); - } catch (IOException e) - { - e.printStackTrace(); - } - } - }); - submenu.add(parametrisedMenuItem); - } + if (newinstance == null) + { + newinstance = (new SlivkaAnnotationServiceInstance( + slivkaClient, - { - // clustalw2 menu entry - JMenuItem noParamMenuItem = new JMenuItem("ClustalW2 with defaults"); - SlivkaWSInstance clustalo; - try - { - clustalo = new SlivkaWSInstance(client, client.getService("clustalw")); - } catch (IOException e) - { - throw new IOError(e); - } - noParamMenuItem.addActionListener((ActionEvent e) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) - { - new MsaWSClient( - clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(), - alignFrame - ); - } - }); - submenu.add(noParamMenuItem); + service, false)); + } + } - JMenuItem parametrisedMenuItem = new JMenuItem("ClustalW2 with custom parameters"); - parametrisedMenuItem.addActionListener((ActionEvent evt) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) + if (classifier + .contains("Sequence alignment analysis (conservation)")) { - try - { - SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService()); - new MsaWSClient( - clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true, - alignFrame.getViewport().getAlignment().getDataset(), alignFrame - ); - } catch (IOException e) - { - e.printStackTrace(); - } + // always overwrite other instances + newinstance = new SlivkaAnnotationServiceInstance(slivkaClient, + service, true); } - }); - submenu.add(parametrisedMenuItem); + } + if (newinstance != null) + { + instances.add(newinstance); + } } + return instances; + } + + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + + @Override + public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame) + { + JMenu slivkaMenu = new JMenu("Slivka"); + wsmenu.add(slivkaMenu); - wsmenu.add(submenu); + JMenu alignmentMenu = new JMenu("Sequence Alignment"); + slivkaMenu.add(alignmentMenu); + JMenu disorderMenu = new JMenu("Protein sequence analysis"); + slivkaMenu.add(disorderMenu); + JMenu conservationMenu = new JMenu("Conservation"); + slivkaMenu.add(conservationMenu); + PreferredServiceRegistry.getRegistry().populateWSMenuEntry( + getServiceInstances(), + changeSupport, slivkaMenu, alignFrame, null); + } + Listservices=null; + + volatile boolean started = false, finished = false; + + Thread discoverer = null; @Override public void run() { + discoverer = Thread.currentThread(); + started = true; + try + { + services = slivkaClient.getServices(); + } catch (IOException e) + { + throw new IOError(e); + } + finished = true; + } + public static List getServices() + { + SlivkaWSDiscoverer us = getInstance(); + if (us.services == null) + { + us.run(); + } + return us.getServiceInstances(); + } + + public boolean hasServices() + { + return finished == true && services != null && services.size() > 0; + } + + public boolean isRunning() + { + return discoverer != null && discoverer.isAlive(); } }