--- /dev/null
+package jalview.ws.slivkaws;
+
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.WebserviceInfo;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FormatAdapter;
+import jalview.ws.api.JalviewServiceEndpointProviderI;
+import jalview.ws.api.JobId;
+import jalview.ws.api.MultipleSequenceAlignmentI;
+import jalview.ws.api.ServiceWithParameters;
+import jalview.ws.gui.WsJob;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamManager;
+import jalview.ws.params.WsParamSetI;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.EnumMap;
+import java.util.List;
+
+import org.apache.http.entity.ContentType;
+
+import uk.ac.dundee.compbio.slivkaclient.Form;
+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;
+
+public class ClustaloWS extends ServiceWithParameters
+ implements MultipleSequenceAlignmentI, JalviewServiceEndpointProviderI
+{
+ private SlivkaClient client;
+ private Service service;
+
+ private EnumMap<JobState, WsJob.JobState> stateMap = new EnumMap<>(JobState.class);
+ {
+ stateMap.put(JobState.PENDING, WsJob.JobState.QUEUED);
+ stateMap.put(JobState.QUEUED, WsJob.JobState.QUEUED);
+ stateMap.put(JobState.RUNNING, WsJob.JobState.RUNNING);
+ stateMap.put(JobState.COMPLETED, WsJob.JobState.FINISHED);
+ stateMap.put(JobState.FAILED, WsJob.JobState.FAILED);
+ stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR);
+ stateMap.put(JobState.UNKNOWN, WsJob.JobState.UNKNOWN);
+ }
+
+
+ ClustaloWS(SlivkaClient client)
+ {
+ super("ClustalO", "Alignment", "ClustalO", "foo", "http://foo.foo");
+
+ this.client = client;
+ try
+ {
+ service = client.getService("clustalo");
+ } catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void updateStatus(WsJob job)
+ {
+ try
+ {
+ job.setState(stateMap.get(client.getJobState(job.getJobId())));
+ } catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public boolean updateJobProgress(WsJob job)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean handleSubmitError(Throwable _lex, WsJob j, WebserviceInfo wsInfo)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean handleCollectionException(Exception e, WsJob msjob, WebserviceInfo wsInfo)
+ {
+ return false;
+ }
+
+ @Override
+ public JobId align(List<SequenceI> toalign, WsParamSetI parameters, List<ArgumentI> list) throws FormValidationException, IOException
+ {
+ StringBuilder builder = new StringBuilder();
+ for (SequenceI seq : toalign)
+ {
+ builder.append(">").append(seq.getName()).append("\n");
+ builder.append(seq.getSequence()).append("\n\n");
+ }
+ InputStream stream = new ByteArrayInputStream(builder.toString().getBytes());
+ RemoteFile file = client.uploadFile(stream, "input.fasta", ContentType.create("application/fasta"));
+ Form form = service.getForm();
+ form.insert("input", file);
+ String jobUUID = form.submit();
+ return new JobId("clustalo", "clustalo", jobUUID);
+ }
+
+ @Override
+ public AlignmentI getAlignmentFor(JobId jobId)
+ {
+ List<RemoteFile> files;
+ try
+ {
+ files = client.getJobResults(jobId.getJobId());
+ for (RemoteFile f: files) {
+ if (f.getMimeType().equals("application/clustal"))
+ {
+ return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Clustal);
+ }
+ }
+ } catch (IOException e1)
+ {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public void initParamStore(ParamManager userParameterStore)
+ {
+
+ }
+
+ @Override
+ public Object getEndpoint()
+ {
+ return this;
+ }
+}
--- /dev/null
+package jalview.ws.slivkaws;
+
+import jalview.datamodel.AlignmentView;
+import jalview.gui.AlignFrame;
+import jalview.ws.WSMenuEntryProviderI;
+import jalview.ws.jws2.MsaWSClient;
+
+import java.awt.event.ActionEvent;
+import java.net.URISyntaxException;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
+
+public class SlivkaWSDiscoverer
+ implements Runnable, WSMenuEntryProviderI
+{
+ private static SlivkaWSDiscoverer instance = null;
+ private SlivkaClient client;
+ private ClustaloWS clustalo;
+
+ private SlivkaWSDiscoverer() {
+ try
+ {
+ client = new SlivkaClient("gjb-www-1.cluster.lifesci.dundee.ac.uk", 3203);
+ } catch (URISyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
+ clustalo = new ClustaloWS(client);
+ }
+
+ public static SlivkaWSDiscoverer getInstance()
+ {
+ if (instance == null) {
+ instance = new SlivkaWSDiscoverer();
+ }
+ return instance;
+ }
+
+ @Override
+ public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
+ {
+ JMenu submenu = new JMenu("Slivka");
+ JMenuItem menuItem = new JMenuItem("ClustalO with defaults");
+ menuItem.addActionListener((ActionEvent e) -> {
+
+ AlignmentView msa = alignFrame.gatherSequencesForAlignment();
+
+ if (msa != null)
+ {
+ new MsaWSClient(clustalo, alignFrame.getTitle(), msa, false,
+ true,
+ alignFrame.getViewport().getAlignment().getDataset(),
+ alignFrame);
+ }
+//
+// List<SequenceI> sequences = alignFrame.getViewport().getAlignment().getSequences();
+// try
+// {
+// clustalo.align(sequences, null, null);
+// } catch (FormValidationException | IOException exc)
+// {
+// throw new RuntimeException(exc);
+// }
+ });
+ submenu.add(menuItem);
+ wsmenu.add(submenu);
+ }
+
+ @Override
+ public void run()
+ {
+
+ }
+}