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.engine.AsyncExecutor;
\r
33 import compbio.engine.Configurator;
\r
34 import compbio.engine.client.ConfiguredExecutable;
\r
35 import compbio.engine.client.SkeletalExecutable;
\r
36 import compbio.metadata.ChunkHolder;
\r
37 import compbio.metadata.JobStatus;
\r
38 import compbio.metadata.JobSubmissionException;
\r
39 import compbio.metadata.Limit;
\r
40 import compbio.metadata.LimitsManager;
\r
41 import compbio.metadata.Option;
\r
42 import compbio.metadata.Preset;
\r
43 import compbio.metadata.PresetManager;
\r
44 import compbio.metadata.ResultNotAvailableException;
\r
45 import compbio.metadata.RunnerConfig;
\r
46 import compbio.metadata.WrongParameterException;
\r
47 import compbio.runner.Util;
\r
48 import compbio.runner.msa.Probcons;
\r
50 @WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = JABAService.SERVICE_NAMESPACE, serviceName = "ProbconsWS")
\r
51 public class ProbconsWS implements MsaWS<Probcons> {
\r
53 private static Logger log = Logger.getLogger(ProbconsWS.class);
\r
55 private static final RunnerConfig<Probcons> probconsOptions = Util
\r
56 .getSupportedOptions(Probcons.class);
\r
58 private static final LimitsManager<Probcons> limitMan = compbio.engine.client.Util
\r
59 .getLimits(new Probcons().getType());
\r
62 public String align(List<FastaSequence> sequences)
\r
63 throws JobSubmissionException {
\r
64 WSUtil.validateFastaInput(sequences);
\r
65 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
67 .align(sequences, confProbcons, log, "align", getLimit(""));
\r
70 ConfiguredExecutable<Probcons> init(List<FastaSequence> dataSet)
\r
71 throws JobSubmissionException {
\r
72 Probcons probcons = new Probcons();
\r
73 probcons.setInput(SkeletalExecutable.INPUT)
\r
74 .setOutput(SkeletalExecutable.OUTPUT)
\r
75 .setError(SkeletalExecutable.ERROR);
\r
76 return Configurator.configureExecutable(probcons, dataSet);
\r
80 public String customAlign(List<FastaSequence> sequences,
\r
81 List<Option<Probcons>> options) throws JobSubmissionException,
\r
82 WrongParameterException {
\r
83 WSUtil.validateFastaInput(sequences);
\r
84 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
85 List<String> params = WSUtil.getCommands(options,
\r
86 Probcons.KEY_VALUE_SEPARATOR);
\r
87 log.info("Setting parameters:" + params);
\r
88 confProbcons.addParameters(params);
\r
89 return WSUtil.align(sequences, confProbcons, log, "customAlign",
\r
94 public String presetAlign(List<FastaSequence> sequences,
\r
95 Preset<Probcons> preset) throws JobSubmissionException,
\r
96 WrongParameterException {
\r
97 WSUtil.validateFastaInput(sequences);
\r
98 if (preset == null) {
\r
99 throw new WrongParameterException("Preset must be provided!");
\r
101 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
102 confProbcons.addParameters(preset.getOptions());
\r
103 Limit<Probcons> limit = getLimit(preset.getName());
\r
104 return WSUtil.align(sequences, confProbcons, log, "presetAlign", limit);
\r
107 @SuppressWarnings("unchecked")
\r
109 public Alignment getResult(String jobId) throws ResultNotAvailableException {
\r
110 WSUtil.validateJobId(jobId);
\r
111 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);
\r
112 ConfiguredExecutable<Probcons> probcons = (ConfiguredExecutable<Probcons>) asyncEngine
\r
113 .getResults(jobId);
\r
114 Alignment al = probcons.getResults();
\r
115 // log(jobId, "getResults");
\r
120 public Limit<Probcons> getLimit(String presetName) {
\r
121 if (limitMan == null) {
\r
122 // Limit is not defined
\r
125 return limitMan.getLimitByName(presetName);
\r
129 public LimitsManager<Probcons> getLimits() {
\r
134 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
135 WSUtil.validateJobId(jobId);
\r
136 // TODO check if output is the one to return
\r
137 String file = Configurator.getWorkDirectory(jobId) + File.separator
\r
138 + new Probcons().getError();
\r
139 return WSUtil.pullFile(file, position);
\r
143 public boolean cancelJob(String jobId) {
\r
144 WSUtil.validateJobId(jobId);
\r
145 return WSUtil.cancelJob(jobId);
\r
149 public JobStatus getJobStatus(String jobId) {
\r
150 WSUtil.validateJobId(jobId);
\r
151 return WSUtil.getJobStatus(jobId);
\r
155 public PresetManager<Probcons> getPresets() {
\r
160 public RunnerConfig<Probcons> getRunnerOptions() {
\r
161 return probconsOptions;
\r