1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.ws.server;
\r
21 import java.io.File;
\r
22 import java.util.List;
\r
24 import javax.jws.WebService;
\r
26 import org.apache.log4j.Logger;
\r
28 import compbio.data.msa.JABAService;
\r
29 import compbio.data.msa.MsaWS;
\r
30 import compbio.data.sequence.Alignment;
\r
31 import compbio.data.sequence.FastaSequence;
\r
32 import compbio.data.sequence.Program;
\r
33 import compbio.engine.AsyncExecutor;
\r
34 import compbio.engine.Configurator;
\r
35 import compbio.engine.client.ConfiguredExecutable;
\r
36 import compbio.engine.client.SkeletalExecutable;
\r
37 import compbio.engine.client.EngineUtil;
\r
38 import compbio.metadata.ChunkHolder;
\r
39 import compbio.metadata.JobStatus;
\r
40 import compbio.metadata.JobSubmissionException;
\r
41 import compbio.metadata.Limit;
\r
42 import compbio.metadata.LimitsManager;
\r
43 import compbio.metadata.Option;
\r
44 import compbio.metadata.Preset;
\r
45 import compbio.metadata.PresetManager;
\r
46 import compbio.metadata.ResultNotAvailableException;
\r
47 import compbio.metadata.RunnerConfig;
\r
48 import compbio.metadata.WrongParameterException;
\r
49 import compbio.runner.RunnerUtil;
\r
50 import compbio.runner.msa.GLprobs;
\r
52 @WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = JABAService.V2_SERVICE_NAMESPACE, serviceName = "GLprobsWS")
\r
53 public class GLprobsWS implements MsaWS<GLprobs> {
\r
55 private static Logger log = Logger.getLogger(GLprobsWS.class);
\r
57 private static final RunnerConfig<GLprobs> GLprobsOptions = RunnerUtil.getSupportedOptions(GLprobs.class);
\r
58 private static final LimitsManager<GLprobs> limitMan = EngineUtil.getLimits(new GLprobs().getType());
\r
61 public String align(List<FastaSequence> sequences)
\r
62 throws JobSubmissionException {
\r
63 WSUtil.validateFastaInput(sequences);
\r
64 ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);
\r
65 return WSUtil.align(sequences, confGLprobs, log, "align", getLimit(""));
\r
68 ConfiguredExecutable<GLprobs> init(List<FastaSequence> dataSet)
\r
69 throws JobSubmissionException {
\r
70 GLprobs GLprobs = new GLprobs();
\r
71 GLprobs.setInput(SkeletalExecutable.INPUT);
\r
72 GLprobs.setOutput(SkeletalExecutable.OUTPUT);
\r
73 GLprobs.setError(SkeletalExecutable.ERROR);
\r
74 return Configurator.configureExecutable(GLprobs, dataSet);
\r
78 public String customAlign(List<FastaSequence> sequences,
\r
79 List<Option<GLprobs>> options) throws JobSubmissionException,
\r
80 WrongParameterException {
\r
81 WSUtil.validateFastaInput(sequences);
\r
82 ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);
\r
83 List<String> params = WSUtil.getCommands(options, GLprobs.KEY_VALUE_SEPARATOR);
\r
84 log.info("Setting parameters:" + params);
\r
85 confGLprobs.addParameters(params);
\r
86 return WSUtil.align(sequences, confGLprobs, log, "customAlign",getLimit(""));
\r
90 public String presetAlign(List<FastaSequence> sequences,
\r
91 Preset<GLprobs> preset) throws JobSubmissionException,
\r
92 WrongParameterException {
\r
93 WSUtil.validateFastaInput(sequences);
\r
94 if (preset == null) {
\r
95 throw new WrongParameterException("Preset must be provided!");
\r
97 ConfiguredExecutable<GLprobs> confGLprobs = init(sequences);
\r
98 confGLprobs.addParameters(preset.getOptions());
\r
99 Limit<GLprobs> limit = getLimit(preset.getName());
\r
100 return WSUtil.align(sequences, confGLprobs, log, "presetAlign", limit);
\r
103 @SuppressWarnings("unchecked")
\r
105 public Alignment getResult(String jobId) throws ResultNotAvailableException {
\r
106 WSUtil.validateJobId(jobId);
\r
107 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);
\r
108 ConfiguredExecutable<GLprobs> GLprobs = (ConfiguredExecutable<GLprobs>) asyncEngine.getResults(jobId);
\r
109 Alignment al = GLprobs.getResults();
\r
110 return new Alignment (al.getSequences(), Program.GLprobs, '-');
\r
114 public Limit<GLprobs> getLimit(String presetName) {
\r
115 if (limitMan == null) {
\r
116 // Limit is not defined
\r
119 return limitMan.getLimitByName(presetName);
\r
123 public LimitsManager<GLprobs> getLimits() {
\r
128 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
129 WSUtil.validateJobId(jobId);
\r
130 // TODO check if output is the one to return
\r
131 String file = Configurator.getWorkDirectory(jobId) + File.separator + new GLprobs().getError();
\r
132 return WSUtil.pullFile(file, position);
\r
136 public boolean cancelJob(String jobId) {
\r
137 WSUtil.validateJobId(jobId);
\r
138 return WSUtil.cancelJob(jobId);
\r
142 public JobStatus getJobStatus(String jobId) {
\r
143 WSUtil.validateJobId(jobId);
\r
144 return WSUtil.getJobStatus(jobId);
\r
148 public PresetManager<GLprobs> getPresets() {
\r
153 public RunnerConfig<GLprobs> getRunnerOptions() {
\r
154 return GLprobsOptions;
\r