--- /dev/null
+/* Copyright (c) 2011 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.ws.server;\r
+\r
+import java.io.File;\r
+import java.util.List;\r
+\r
+import javax.jws.WebService;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.msa.JABAService;\r
+import compbio.data.msa.MsaWS;\r
+import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.Program;\r
+import compbio.engine.AsyncExecutor;\r
+import compbio.engine.Configurator;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.engine.client.EngineUtil;\r
+import compbio.metadata.ChunkHolder;\r
+import compbio.metadata.JobStatus;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.Limit;\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.WrongParameterException;\r
+import compbio.runner.RunnerUtil;\r
+import compbio.runner.msa.GLprobs;\r
+\r
+@WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = JABAService.SERVICE_NAMESPACE, serviceName = "GLprobsWS")\r
+public class GLprobsWS implements MsaWS<GLprobs> {\r
+\r
+ private static Logger log = Logger.getLogger(GLprobsWS.class);\r
+\r
+ private static final RunnerConfig<GLprobs> GLprobsOptions = RunnerUtil.getSupportedOptions(GLprobs.class);\r
+ private static final LimitsManager<GLprobs> limitMan = EngineUtil.getLimits(new GLprobs().getType());\r
+\r
+ @Override\r
+ public String align(List<FastaSequence> sequences)\r
+ throws JobSubmissionException {\r
+ WSUtil.validateFastaInput(sequences);\r
+ ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);\r
+ return WSUtil.align(sequences, confGLprobs, log, "align", getLimit(""));\r
+ }\r
+\r
+ ConfiguredExecutable<GLprobs> init(List<FastaSequence> dataSet)\r
+ throws JobSubmissionException {\r
+ GLprobs GLprobs = new GLprobs();\r
+ GLprobs.setInput(SkeletalExecutable.INPUT);\r
+ GLprobs.setOutput(SkeletalExecutable.OUTPUT);\r
+ GLprobs.setError(SkeletalExecutable.ERROR);\r
+ return Configurator.configureExecutable(GLprobs, dataSet);\r
+ }\r
+\r
+ @Override\r
+ public String customAlign(List<FastaSequence> sequences,\r
+ List<Option<GLprobs>> options) throws JobSubmissionException,\r
+ WrongParameterException {\r
+ WSUtil.validateFastaInput(sequences);\r
+ ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);\r
+ List<String> params = WSUtil.getCommands(options, GLprobs.KEY_VALUE_SEPARATOR);\r
+ log.info("Setting parameters:" + params);\r
+ confGLprobs.addParameters(params);\r
+ return WSUtil.align(sequences, confGLprobs, log, "customAlign",getLimit(""));\r
+ }\r
+\r
+ @Override\r
+ public String presetAlign(List<FastaSequence> sequences,\r
+ Preset<GLprobs> preset) throws JobSubmissionException,\r
+ WrongParameterException {\r
+ WSUtil.validateFastaInput(sequences);\r
+ if (preset == null) {\r
+ throw new WrongParameterException("Preset must be provided!");\r
+ }\r
+ ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);\r
+ confGLprobs.addParameters(preset.getOptions());\r
+ Limit<GLprobs> limit = getLimit(preset.getName());\r
+ return WSUtil.align(sequences, confGLprobs, log, "presetAlign", limit);\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Alignment getResult(String jobId) throws ResultNotAvailableException {\r
+ WSUtil.validateJobId(jobId);\r
+ AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
+ ConfiguredExecutable<GLprobs> GLprobs = (ConfiguredExecutable<GLprobs>) asyncEngine.getResults(jobId);\r
+ Alignment al = GLprobs.getResults();\r
+ return new Alignment (al.getSequences(), Program.GLprobs, '-');\r
+ }\r
+\r
+ @Override\r
+ public Limit<GLprobs> getLimit(String presetName) {\r
+ if (limitMan == null) {\r
+ // Limit is not defined\r
+ return null;\r
+ }\r
+ return limitMan.getLimitByName(presetName);\r
+ }\r
+\r
+ @Override\r
+ public LimitsManager<GLprobs> getLimits() {\r
+ return limitMan;\r
+ }\r
+\r
+ @Override\r
+ public ChunkHolder pullExecStatistics(String jobId, long position) {\r
+ WSUtil.validateJobId(jobId);\r
+ // TODO check if output is the one to return\r
+ String file = Configurator.getWorkDirectory(jobId) + File.separator + new GLprobs().getError();\r
+ return WSUtil.pullFile(file, position);\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<GLprobs> getPresets() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public RunnerConfig<GLprobs> getRunnerOptions() {\r
+ return GLprobsOptions;\r
+ }\r
+\r
+}\r