From: Mateusz Warowny Date: Mon, 23 Sep 2019 15:01:54 +0000 (+0100) Subject: JAL-3066 Annotation Service Instance stub X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=942bf94f9595a3b3755efd2574f235238bc3cdc1;p=jalview.git JAL-3066 Annotation Service Instance stub --- diff --git a/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java new file mode 100644 index 0000000..4d2c4fb --- /dev/null +++ b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java @@ -0,0 +1,75 @@ +package jalview.ws.slivkaws; + +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.SequenceI; +import jalview.ws.api.JobId; +import jalview.ws.api.SequenceAnnotationServiceI; +import jalview.ws.gui.AnnotationWsJob; +import jalview.ws.jws2.SeqAnnotationServiceCalcWorker; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.WsParamSetI; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; + +import uk.ac.dundee.compbio.slivkaclient.FormField; +import uk.ac.dundee.compbio.slivkaclient.RemoteFile; +import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; +import uk.ac.dundee.compbio.slivkaclient.SlivkaForm; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; + +public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements SequenceAnnotationServiceI +{ + public SlivkaAnnotationServiceInstance(SlivkaClient client, SlivkaService service) + { + super(client, service, "Annotations"); + } + + @Override + public JobId submitToService(List seqs, WsParamSetI preset, List paramset) throws Throwable + { + StringBuilder builder = new StringBuilder(); + for (SequenceI seq : seqs) + { + builder.append(">").append(seq.getName()).append("\n"); + builder.append(seq.getSequence()).append("\n"); + } + InputStream stream = new ByteArrayInputStream(builder.toString().getBytes()); + RemoteFile file = client.uploadFile(stream, "input.fasta", "application/fasta"); + SlivkaForm form = service.getForm(); + HashMap values = new HashMap<>(paramset != null ? paramset.size() : 0); + if (paramset != null) + { + for (ArgumentI arg : paramset) + { + values.put(arg.getName(), arg.getValue()); + } + } + for (FormField field : form.getFields()) + { + switch (field.getType()) + { + case FILE: + form.insert(field.getName(), file); + 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()))); + } + } + return new JobId(service.getName(), service.getName(), form.submit()); + } + + @Override + public List getAlignmentAnnotation(AnnotationWsJob running, + SeqAnnotationServiceCalcWorker abstractJabaCalcWorker) throws Throwable + { + // TODO Auto-generated method stub + return null; + } +}