GlobPlot service, runner and result parser
[jabaws.git] / webservices / compbio / ws / server / GlobPlotWS.java
diff --git a/webservices/compbio/ws/server/GlobPlotWS.java b/webservices/compbio/ws/server/GlobPlotWS.java
new file mode 100644 (file)
index 0000000..df402fa
--- /dev/null
@@ -0,0 +1,157 @@
+package compbio.ws.server;\r
+\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+\r
+import javax.annotation.Resource;\r
+import javax.jws.WebService;\r
+import javax.xml.ws.WebServiceContext;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.msa.SequenceAnnotation;\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.Score;\r
+import compbio.engine.AsyncExecutor;\r
+import compbio.engine.Configurator;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.metadata.ChunkHolder;\r
+import compbio.metadata.JobStatus;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.Limit;\r
+import compbio.metadata.LimitExceededException;\r
+import compbio.metadata.LimitsManager;\r
+import compbio.metadata.Option;\r
+import compbio.metadata.Preset;\r
+import compbio.metadata.PresetManager;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.metadata.RunnerConfig;\r
+import compbio.metadata.UnsupportedRuntimeException;\r
+import compbio.metadata.WrongParameterException;\r
+import compbio.runner.Util;\r
+import compbio.runner.disorder.GlobPlot;\r
+\r
+@WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "GlobPlotWS")\r
+public class GlobPlotWS implements SequenceAnnotation<GlobPlot> {\r
+\r
+       // Ask for resource injection\r
+       @Resource\r
+       WebServiceContext wsContext;\r
+\r
+       private static Logger statLog = Logger.getLogger("GlobPlotWS-stats");\r
+\r
+       private static Logger log = Logger.getLogger(GlobPlotWS.class);\r
+\r
+       private static final RunnerConfig<GlobPlot> globPlotOptions = Util\r
+                       .getSupportedOptions(GlobPlot.class);\r
+\r
+       private static final PresetManager<GlobPlot> globPlotPresets = Util\r
+                       .getPresets(GlobPlot.class);\r
+\r
+       ConfiguredExecutable<GlobPlot> init(List<FastaSequence> sequences)\r
+                       throws JobSubmissionException {\r
+               GlobPlot globPlot = new GlobPlot();\r
+               globPlot.setInput("fasta.in").setOutput("globPlot.out");\r
+               return Configurator.configureExecutable(globPlot, sequences);\r
+       }\r
+\r
+       @Override\r
+       public HashMap<String, HashSet<Score>> getAnnotation(String jobId)\r
+                       throws ResultNotAvailableException {\r
+               WSUtil.validateJobId(jobId);\r
+               AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
+               ConfiguredExecutable<GlobPlot> globPlot = (ConfiguredExecutable<GlobPlot>) asyncEngine\r
+                               .getResults(jobId);\r
+               HashMap<String, HashSet<Score>> mas = globPlot.getResults();\r
+               log.trace(jobId + " getConservation : " + mas);\r
+               return mas;\r
+       }\r
+\r
+       @Override\r
+       public Limit<GlobPlot> getLimit(String presetName) {\r
+               return new GlobPlot().getLimit(presetName);\r
+       }\r
+\r
+       @Override\r
+       public LimitsManager<GlobPlot> getLimits() {\r
+               return new GlobPlot().getLimits();\r
+       }\r
+\r
+       @Override\r
+       public ChunkHolder pullExecStatistics(String jobId, long position) {\r
+               // Execution stat is not supported\r
+               return new ChunkHolder("", -1);\r
+       }\r
+\r
+       @Override\r
+       public boolean cancelJob(String jobId) {\r
+               WSUtil.validateJobId(jobId);\r
+               return WSUtil.cancelJob(jobId);\r
+       }\r
+\r
+       @Override\r
+       public JobStatus getJobStatus(String jobId) {\r
+               WSUtil.validateJobId(jobId);\r
+               return WSUtil.getJobStatus(jobId);\r
+       }\r
+\r
+       @Override\r
+       public PresetManager<GlobPlot> getPresets() {\r
+               return globPlotPresets;\r
+       }\r
+\r
+       @Override\r
+       public RunnerConfig<GlobPlot> getRunnerOptions() {\r
+               return globPlotOptions;\r
+       }\r
+\r
+       String analize(List<FastaSequence> sequences,\r
+                       ConfiguredExecutable<GlobPlot> confExec, Logger log, String method,\r
+                       Limit<GlobPlot> limit) throws JobSubmissionException {\r
+               if (limit != null && limit.isExceeded(sequences)) {\r
+                       throw LimitExceededException.newLimitExceeded(limit, sequences);\r
+               }\r
+\r
+               compbio.runner.Util.writeInput(sequences, confExec);\r
+               AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
+               String jobId = engine.submitJob(confExec);\r
+               return jobId;\r
+       }\r
+\r
+       @Override\r
+       public String analize(List<FastaSequence> sequences)\r
+                       throws UnsupportedRuntimeException, LimitExceededException,\r
+                       JobSubmissionException {\r
+               WSUtil.validateFastaInput(sequences);\r
+               ConfiguredExecutable<GlobPlot> confGlobPlot = init(sequences);\r
+\r
+               return analize(sequences, confGlobPlot, null, "analize", getLimit(""));\r
+       }\r
+\r
+       /*\r
+        * No options are supported, thus the result of this call will be as simple\r
+        * call to analize without parameters\r
+        */\r
+       @Override\r
+       public String customAnalize(List<FastaSequence> sequences,\r
+                       List<Option<GlobPlot>> options) throws UnsupportedRuntimeException,\r
+                       LimitExceededException, JobSubmissionException,\r
+                       WrongParameterException {\r
+               return analize(sequences);\r
+       }\r
+\r
+       /*\r
+        * No presets are supported, thus the result of this call will be as simple\r
+        * call to analize without parameters\r
+        */\r
+       @Override\r
+       public String presetAnalize(List<FastaSequence> sequences,\r
+                       Preset<GlobPlot> preset) throws UnsupportedRuntimeException,\r
+                       LimitExceededException, JobSubmissionException,\r
+                       WrongParameterException {\r
+\r
+               return analize(sequences);\r
+       }\r
+\r
+}\r