import jalview.ws.jws2.MsaWSClient;
import java.awt.event.ActionEvent;
+import java.io.IOError;
import java.io.IOException;
import java.net.URISyntaxException;
{
private static SlivkaWSDiscoverer instance = null;
private SlivkaClient client;
- private ClustaloWS clustalo;
private SlivkaWSDiscoverer() {
try
{
throw new RuntimeException(e);
}
- clustalo = new ClustaloWS(client);
}
public static SlivkaWSDiscoverer getInstance()
{
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);
}
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<JobState, WsJob.JobState> stateMap = new EnumMap<>(JobState.class);
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
}
}
- Service getService()
+ SlivkaService getService()
{
return service;
}
@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;
}
}
@Override
- public JobId align(List<SequenceI> toalign, WsParamSetI parameters, List<ArgumentI> list)
- throws IOException
+ public JobId align(List<SequenceI> toalign, WsParamSetI parameters, List<ArgumentI> list) throws Throwable
{
StringBuilder builder = new StringBuilder();
for (SequenceI seq : toalign)
}
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<String, String> values = new HashMap<>(list != null ? list.size() : 0);
if (list != null)
{
}
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<RemoteFile> 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)
store = new SlivkaDatastore(service);
} catch (IOException e)
{
- throw new RuntimeException(e);
+ throw new IOError(e);
}
}
}
{
return store;
}
-
- @Override
- public Object getEndpoint()
- {
- return this;
- }
}