From: Mateusz Warowny Date: Wed, 11 Sep 2019 10:18:38 +0000 (+0100) Subject: Create generic msa service instance X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=857348180124be7ab86d7de1e4d3f780e65b1fdd;p=jalview.git Create generic msa service instance --- diff --git a/j11lib/slivka-client.jar b/j11lib/slivka-client.jar index 7c00c7c..9efae32 100644 Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ diff --git a/src/jalview/ws/slivkaws/SlivkaDatastore.java b/src/jalview/ws/slivkaws/SlivkaDatastore.java index 24d11c7..ef10006 100644 --- a/src/jalview/ws/slivkaws/SlivkaDatastore.java +++ b/src/jalview/ws/slivkaws/SlivkaDatastore.java @@ -8,14 +8,14 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import uk.ac.dundee.compbio.slivkaclient.Service; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; public class SlivkaDatastore implements ParamDatastoreI { private SlivkaParamSet defaultPreset; private List presets = new ArrayList<>(); - SlivkaDatastore(Service service) throws IOException { + SlivkaDatastore(SlivkaService service) throws IOException { defaultPreset = new SlivkaParamSet(service); presets.add(defaultPreset); } diff --git a/src/jalview/ws/slivkaws/SlivkaParamSet.java b/src/jalview/ws/slivkaws/SlivkaParamSet.java index 7feb2f1..86755cb 100644 --- a/src/jalview/ws/slivkaws/SlivkaParamSet.java +++ b/src/jalview/ws/slivkaws/SlivkaParamSet.java @@ -18,19 +18,20 @@ import uk.ac.dundee.compbio.slivkaclient.DecimalField; import uk.ac.dundee.compbio.slivkaclient.Form; import uk.ac.dundee.compbio.slivkaclient.FormField; import uk.ac.dundee.compbio.slivkaclient.IntegerField; -import uk.ac.dundee.compbio.slivkaclient.Service; +import uk.ac.dundee.compbio.slivkaclient.SlivkaForm; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; import uk.ac.dundee.compbio.slivkaclient.TextField; public class SlivkaParamSet implements WsParamSetI { - private Service service; + private SlivkaService service; private List args = new ArrayList<>(); - SlivkaParamSet(Service service) throws IOException { + SlivkaParamSet(SlivkaService service) throws IOException { this.service = service; - Form form = service.getForm(); + SlivkaForm form = service.getForm(); for (FormField field : form.getFields()) { ArgumentI arg; diff --git a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java index dfa3d89..2d46c9f 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java +++ b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java @@ -6,6 +6,7 @@ import jalview.ws.WSMenuEntryProviderI; import jalview.ws.jws2.MsaWSClient; import java.awt.event.ActionEvent; +import java.io.IOError; import java.io.IOException; import java.net.URISyntaxException; @@ -19,7 +20,6 @@ public class SlivkaWSDiscoverer { private static SlivkaWSDiscoverer instance = null; private SlivkaClient client; - private ClustaloWS clustalo; private SlivkaWSDiscoverer() { try @@ -29,7 +29,6 @@ public class SlivkaWSDiscoverer { throw new RuntimeException(e); } - clustalo = new ClustaloWS(client); } public static SlivkaWSDiscoverer getInstance() @@ -45,38 +44,93 @@ public class SlivkaWSDiscoverer { JMenu submenu = new JMenu("Slivka"); - JMenuItem noParamMenuItem = new JMenuItem("ClustalO with defaults"); - noParamMenuItem.addActionListener((ActionEvent e) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) + { + // clustalo menu entry + JMenuItem noParamMenuItem = new JMenuItem("ClustalO with defaults"); + SlivkaWSInstance clustalo; + try + { + clustalo = new SlivkaWSInstance(client, client.getService("clustalo")); + } catch (IOException e) { - new MsaWSClient( - clustalo, alignFrame.getTitle(), msa, false, true, - alignFrame.getViewport().getAlignment().getDataset(), - alignFrame); + throw new IOError(e); } - }); - submenu.add(noParamMenuItem); + 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); - JMenuItem parametrisedMenuItem = new JMenuItem("ClustalO with custom parameters"); - parametrisedMenuItem.addActionListener((ActionEvent evt) -> { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - if (msa != null) + JMenuItem parametrisedMenuItem = new JMenuItem("ClustalO with custom parameters"); + parametrisedMenuItem.addActionListener((ActionEvent evt) -> { + AlignmentView msa = alignFrame.gatherSequencesForAlignment(); + if (msa != null) + { + 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); + } + + { + // clustalw2 menu entry + JMenuItem noParamMenuItem = new JMenuItem("ClustalW2 with defaults"); + SlivkaWSInstance clustalo; + try { - 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) { - SlivkaParamSet paramSet = new SlivkaParamSet(clustalo.getService()); new MsaWSClient( - clustalo, paramSet, null, true, alignFrame.getTitle(), msa, false, true, - alignFrame.getViewport().getAlignment().getDataset(), alignFrame + clustalo, alignFrame.getTitle(), msa, false, true, alignFrame.getViewport().getAlignment().getDataset(), + alignFrame ); - } catch (IOException e) + } + }); + submenu.add(noParamMenuItem); + + JMenuItem parametrisedMenuItem = new JMenuItem("ClustalW2 with custom parameters"); + parametrisedMenuItem.addActionListener((ActionEvent evt) -> { + AlignmentView msa = alignFrame.gatherSequencesForAlignment(); + if (msa != null) { - e.printStackTrace(); + 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); + }); + submenu.add(parametrisedMenuItem); + } wsmenu.add(submenu); } diff --git a/src/jalview/ws/slivkaws/ClustaloWS.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java similarity index 71% rename from src/jalview/ws/slivkaws/ClustaloWS.java rename to src/jalview/ws/slivkaws/SlivkaWSInstance.java index 6a2dae6..d5456a6 100644 --- a/src/jalview/ws/slivkaws/ClustaloWS.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -12,32 +12,34 @@ import jalview.ws.api.MultipleSequenceAlignmentI; import jalview.ws.api.ServiceWithParameters; import jalview.ws.gui.WsJob; import jalview.ws.params.ArgumentI; +import jalview.ws.params.InvalidArgumentException; import jalview.ws.params.ParamDatastoreI; import jalview.ws.params.ParamManager; import jalview.ws.params.WsParamSetI; import java.io.ByteArrayInputStream; +import java.io.IOError; import java.io.IOException; import java.io.InputStream; +import java.rmi.ServerError; import java.util.EnumMap; import java.util.HashMap; import java.util.List; -import uk.ac.dundee.compbio.slivkaclient.FieldType; -import uk.ac.dundee.compbio.slivkaclient.Form; import uk.ac.dundee.compbio.slivkaclient.FormField; import uk.ac.dundee.compbio.slivkaclient.FormValidationException; import uk.ac.dundee.compbio.slivkaclient.JobState; import uk.ac.dundee.compbio.slivkaclient.RemoteFile; -import uk.ac.dundee.compbio.slivkaclient.Service; import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; +import uk.ac.dundee.compbio.slivkaclient.SlivkaForm; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; import uk.ac.dundee.compbio.slivkaclient.ValidationException; -public class ClustaloWS extends ServiceWithParameters +public class SlivkaWSInstance extends ServiceWithParameters implements MultipleSequenceAlignmentI, JalviewServiceEndpointProviderI { private SlivkaClient client; - private Service service; + private SlivkaService service; private SlivkaDatastore store = null; private EnumMap stateMap = new EnumMap<>(JobState.class); @@ -51,19 +53,10 @@ public class ClustaloWS extends ServiceWithParameters stateMap.put(JobState.UNKNOWN, WsJob.JobState.UNKNOWN); } - - ClustaloWS(SlivkaClient client) - { - super("ClustalO", "Alignment", "ClustalO", "Slivka", client.getUrl().toString()); - + SlivkaWSInstance(SlivkaClient client, SlivkaService service) { + super(service.getName(), "Alignment", service.getName(), "Slivka", client.getUrl().toString()); this.client = client; - try - { - this.service = client.getService("clustalo"); - } catch (IOException e) - { - throw new RuntimeException(e); - } + this.service = service; } @Override @@ -78,7 +71,7 @@ public class ClustaloWS extends ServiceWithParameters } } - Service getService() + SlivkaService getService() { return service; } @@ -92,6 +85,19 @@ public class ClustaloWS extends ServiceWithParameters @Override public boolean handleSubmitError(Throwable _lex, WsJob j, WebserviceInfo wsInfo) { + if (_lex instanceof FormValidationException) + { + FormValidationException formError = (FormValidationException) _lex; + String[] messages = new String[formError.getErrors().size()]; + int i = 0; + for (ValidationException e : formError.getErrors()) + { + messages[i++] = String.format("%s: %s,", e.getField().getName(), e.getMessage()); + } + j.setState(WsJob.JobState.INVALID); + j.setStatus(String.join(", ", messages)); + return true; + } return false; } @@ -102,8 +108,7 @@ public class ClustaloWS extends ServiceWithParameters } @Override - public JobId align(List toalign, WsParamSetI parameters, List list) - throws IOException + public JobId align(List toalign, WsParamSetI parameters, List list) throws Throwable { StringBuilder builder = new StringBuilder(); for (SequenceI seq : toalign) @@ -113,7 +118,7 @@ public class ClustaloWS extends ServiceWithParameters } InputStream stream = new ByteArrayInputStream(builder.toString().getBytes()); RemoteFile file = client.uploadFile(stream, "input.fasta", "application/fasta"); - Form form = service.getForm(); + SlivkaForm form = service.getForm(); HashMap values = new HashMap<>(list != null ? list.size() : 0); if (list != null) { @@ -124,49 +129,49 @@ public class ClustaloWS extends ServiceWithParameters } for (FormField field : form.getFields()) { - if (field.getType() == FieldType.FILE) - { + switch (field.getType()) { + case FILE: form.insert(field.getName(), file); - } else - { + break; + case BOOLEAN: + String value = values.get(field.getName()); + form.insert(field.getName(), (value != null && !value.isBlank()) ? true : false); + break; + default: form.insert(field.getName(), field.valueOf(values.get(field.getName()))); } } - try - { - return new JobId("clustalo", "clustalo", form.submit()); - } catch (FormValidationException e) - { - for (ValidationException ve : e.getErrors()) - { - System.out.format("%s: %s%n", ve.getField().getName(), ve.getMessage()); - } - return null; - } + return new JobId(service.getName(), service.getName(), form.submit()); } @Override - public AlignmentI getAlignmentFor(JobId jobId) + public AlignmentI getAlignmentFor(JobId jobId) throws InvalidArgumentException, ServerError, IOError { List files; try { files = client.getJobResults(jobId.getJobId()); - for (RemoteFile f: files) { + for (RemoteFile f : files) + { if (f.getMimeType().equals("application/clustal")) { return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Clustal); } } - } catch (IOException e1) + } catch (IOException e) { - // TODO Auto-generated catch block - e1.printStackTrace(); + throw new IOError(e); } return null; } @Override + public Object getEndpoint() + { + return this; + } + + @Override public void initParamStore(ParamManager userParameterStore) { if (store == null) @@ -176,7 +181,7 @@ public class ClustaloWS extends ServiceWithParameters store = new SlivkaDatastore(service); } catch (IOException e) { - throw new RuntimeException(e); + throw new IOError(e); } } } @@ -192,10 +197,4 @@ public class ClustaloWS extends ServiceWithParameters { return store; } - - @Override - public Object getEndpoint() - { - return this; - } }