1 package compbio.ws.server;
\r
3 import java.util.List;
\r
5 import org.apache.log4j.Logger;
\r
7 import compbio.data.sequence.FastaSequence;
\r
8 import compbio.data.sequence.ScoreManager;
\r
9 import compbio.engine.Configurator;
\r
10 import compbio.engine.client.ConfiguredExecutable;
\r
11 import compbio.engine.client.Executable;
\r
12 import compbio.engine.client.SkeletalExecutable;
\r
13 import compbio.metadata.ChunkHolder;
\r
14 import compbio.metadata.JobStatus;
\r
15 import compbio.metadata.JobSubmissionException;
\r
16 import compbio.metadata.Limit;
\r
17 import compbio.metadata.LimitExceededException;
\r
18 import compbio.metadata.LimitsManager;
\r
19 import compbio.metadata.Option;
\r
20 import compbio.metadata.Preset;
\r
21 import compbio.metadata.PresetManager;
\r
22 import compbio.metadata.ResultNotAvailableException;
\r
23 import compbio.metadata.RunnerConfig;
\r
24 import compbio.metadata.UnsupportedRuntimeException;
\r
25 import compbio.metadata.WrongParameterException;
\r
26 import compbio.runner.Util;
\r
27 import compbio.runner.conservation.AACon;
\r
30 * Common methods for all SequenceAnnotation web services
\r
36 * @version 1.0 June 2011
\r
39 public abstract class SAService<T> {
\r
41 private final RunnerConfig<T> aaconOptions;
\r
42 private final PresetManager<T> aaconPresets;
\r
43 private final LimitsManager<T> limitMan;
\r
44 private SkeletalExecutable<T> exec;
\r
45 private final Logger log;
\r
48 * FIXME - instances of the Runner (?) and their types should be defined in
\r
51 SAService(SkeletalExecutable<T> exec, Logger log) {
\r
53 assert exec != null;
\r
56 this.limitMan = compbio.engine.client.Util.getLimits(exec.getType());
\r
57 this.aaconOptions = Util
\r
58 .getSupportedOptions((Class<? extends Executable<T>>) exec
\r
60 this.aaconPresets = Util
\r
61 .getPresets((Class<? extends Executable<T>>) exec.getType());
\r
64 ConfiguredExecutable<T> init(List<FastaSequence> sequences)
\r
65 throws JobSubmissionException {
\r
68 exec = (SkeletalExecutable<T>) exec.getType().newInstance();
\r
69 } catch (InstantiationException e) {
\r
70 log.error(e.getLocalizedMessage(), e);
\r
71 throw new JobSubmissionException(e.getLocalizedMessage(), e);
\r
72 } catch (IllegalAccessException e) {
\r
73 log.error(e.getLocalizedMessage(), e);
\r
74 throw new JobSubmissionException(e.getLocalizedMessage(), e);
\r
76 exec.setInput(SkeletalExecutable.INPUT).setOutput(
\r
77 SkeletalExecutable.OUTPUT);
\r
78 return Configurator.configureExecutable(exec, sequences);
\r
81 public ScoreManager getAnnotation(String jobId)
\r
82 throws ResultNotAvailableException {
\r
83 return WSUtil.getAnnotation(jobId, log);
\r
86 public boolean cancelJob(String jobId) {
\r
87 WSUtil.validateJobId(jobId);
\r
88 return WSUtil.cancelJob(jobId);
\r
91 public JobStatus getJobStatus(String jobId) {
\r
92 WSUtil.validateJobId(jobId);
\r
93 return WSUtil.getJobStatus(jobId);
\r
96 public Limit<T> getLimit(String presetName) {
\r
97 if (limitMan == null) {
\r
98 // Limit is not defined
\r
101 return limitMan.getLimitByName(presetName);
\r
104 public LimitsManager<T> getLimits() {
\r
108 public PresetManager<T> getPresets() {
\r
109 return aaconPresets;
\r
112 public RunnerConfig<T> getRunnerOptions() {
\r
113 return aaconOptions;
\r
116 public String analize(List<FastaSequence> sequences)
\r
117 throws UnsupportedRuntimeException, LimitExceededException,
\r
118 JobSubmissionException {
\r
119 WSUtil.validateFastaInput(sequences);
\r
120 ConfiguredExecutable<T> confIUPred = init(sequences);
\r
121 return WSUtil.analize(sequences, confIUPred, log, "analize",
\r
125 public String customAnalize(List<FastaSequence> sequences,
\r
126 List<Option<T>> options) throws UnsupportedRuntimeException,
\r
127 LimitExceededException, JobSubmissionException,
\r
128 WrongParameterException {
\r
129 WSUtil.validateAAConInput(sequences);
\r
130 ConfiguredExecutable<T> confAACon = init(sequences);
\r
131 // Could not do that! Space separated values
\r
132 // will all be treated as keys! thus duplicates removed
\r
133 // String params = cbuilder.getCommand();
\r
134 List<String> params = WSUtil.getCommands(options,
\r
135 AACon.KEY_VALUE_SEPARATOR);
\r
136 confAACon.addParameters(params);
\r
137 return WSUtil.analize(sequences, confAACon, log, "customAnalize",
\r
141 public String presetAnalize(List<FastaSequence> sequences, Preset<T> preset)
\r
142 throws UnsupportedRuntimeException, LimitExceededException,
\r
143 JobSubmissionException, WrongParameterException {
\r
144 WSUtil.validateAAConInput(sequences);
\r
145 if (preset == null) {
\r
146 throw new WrongParameterException("Preset must be provided!");
\r
148 ConfiguredExecutable<T> confAAcon = init(sequences);
\r
149 confAAcon.addParameters(preset.getOptions());
\r
150 Limit<T> limit = getLimit(preset.getName());
\r
152 .analize(sequences, confAAcon, log, "presetAnalize", limit);
\r
156 * Assume statistics is not supported
\r
162 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
163 // Execution stat is not supported
\r
164 return new ChunkHolder("", -1);
\r