+package compbio.ws.server;\r
+\r
+import java.io.File;\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.Annotation;\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.conservation.AACon;\r
+import compbio.runner.disorder.Jronn;\r
+\r
+@WebService(endpointInterface = "compbio.data.msa.Annotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "JronnWS")\r
+public class JronnWS implements Annotation<Jronn> {\r
+\r
+ // Ask for resource injection\r
+ @Resource\r
+ WebServiceContext wsContext;\r
+\r
+ private static Logger statLog = Logger.getLogger("JronnWS-stats");\r
+\r
+ private static Logger log = Logger.getLogger(JronnWS.class);\r
+\r
+ private static final RunnerConfig<Jronn> aaconOptions = Util\r
+ .getSupportedOptions(Jronn.class);\r
+\r
+ private static final PresetManager<Jronn> aaconPresets = Util\r
+ .getPresets(Jronn.class);\r
+\r
+ ConfiguredExecutable<Jronn> init(List<FastaSequence> sequences)\r
+ throws JobSubmissionException {\r
+ Jronn jronn = new Jronn();\r
+ jronn.setInput("fasta.in").setOutput("aacon.out");\r
+ return Configurator.configureExecutable(jronn, sequences);\r
+ }\r
+\r
+ @Override\r
+ public HashSet<Score> getAnnotation(String jobId)\r
+ throws ResultNotAvailableException {\r
+ WSUtil.validateJobId(jobId);\r
+ AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
+ ConfiguredExecutable<AACon> aacon = (ConfiguredExecutable<AACon>) asyncEngine\r
+ .getResults(jobId);\r
+ HashSet<Score> mas = aacon.getResults();\r
+ log.trace(jobId + " getConservation : " + mas);\r
+ return mas;\r
+ }\r
+ /*\r
+ * @SuppressWarnings("unchecked") public JalviewAnnotation\r
+ * getJalviewAnnotation(String jobId) throws ResultNotAvailableException {\r
+ * MultiAnnotatedSequence<Method> result = getResult(jobId); // TODO //\r
+ * log(jobId, "getResults"); return result.toJalviewAnnotation(); }\r
+ */\r
+\r
+ @Override\r
+ public Limit<Jronn> getLimit(String presetName) {\r
+ return new Jronn().getLimit(presetName);\r
+ }\r
+\r
+ @Override\r
+ public LimitsManager<Jronn> getLimits() {\r
+ return new Jronn().getLimits();\r
+ }\r
+\r
+ @Override\r
+ public ChunkHolder pullExecStatistics(String jobId, long position) {\r
+ WSUtil.validateJobId(jobId);\r
+ String file = Configurator.getWorkDirectory(jobId) + File.separator\r
+ + Jronn.getStatFile();\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<Jronn> getPresets() {\r
+ return aaconPresets;\r
+ }\r
+\r
+ @Override\r
+ public RunnerConfig<Jronn> getRunnerOptions() {\r
+ return aaconOptions;\r
+ }\r
+\r
+ String analize(List<FastaSequence> sequences,\r
+ ConfiguredExecutable<Jronn> confExec, Logger log, String method,\r
+ Limit<Jronn> 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<Jronn> confAAcon = init(sequences);\r
+\r
+ // set default conservation method to fastest - SHENKIN\r
+ // TODO: This violates encapsulation, should be moved to the runners\r
+ // level.\r
+ // confAAcon.addParameters(Arrays.asList("-m=SHENKIN"));\r
+ return analize(sequences, confAAcon, null, "analize", getLimit(""));\r
+ }\r
+\r
+ @Override\r
+ public String customAnalize(List<FastaSequence> sequences,\r
+ List<Option<Jronn>> options) throws UnsupportedRuntimeException,\r
+ LimitExceededException, JobSubmissionException,\r
+ WrongParameterException {\r
+ WSUtil.validateFastaInput(sequences);\r
+ ConfiguredExecutable<Jronn> confJronn = init(sequences);\r
+ // Could not do that! Space separated values\r
+ // will all be treated as keys! thus duplicates removed\r
+ // String params = cbuilder.getCommand();\r
+ List<String> params = WSUtil.getCommands(options,\r
+ AACon.KEY_VALUE_SEPARATOR);\r
+ confJronn.addParameters(params);\r
+ return analize(sequences, confJronn, null, "customAnalize",\r
+ getLimit(""));\r
+ }\r
+\r
+ @Override\r
+ public String presetAnalize(List<FastaSequence> sequences,\r
+ Preset<Jronn> preset) throws UnsupportedRuntimeException,\r
+ LimitExceededException, JobSubmissionException,\r
+ WrongParameterException {\r
+ WSUtil.validateFastaInput(sequences);\r
+ if (preset == null) {\r
+ throw new WrongParameterException("Preset must be provided!");\r
+ }\r
+ ConfiguredExecutable<Jronn> confJronn = init(sequences);\r
+ confJronn.addParameters(preset.getOptions());\r
+ Limit<Jronn> limit = getLimit(preset.getName());\r
+ return WSUtil.align(sequences, confJronn, null, "presetAnalize", limit);\r
+ }\r
+\r
+}\r