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.getSupportedOptions(Probcons.class);
\r
56 private static final LimitsManager<Probcons> limitMan = compbio.engine.client.Util.getLimits(new Probcons().getType());
\r
59 public String align(List<FastaSequence> sequences)
\r
60 throws JobSubmissionException {
\r
61 WSUtil.validateFastaInput(sequences);
\r
62 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
63 return WSUtil.align(sequences, confProbcons, log, "align", getLimit(""));
\r
66 ConfiguredExecutable<Probcons> init(List<FastaSequence> dataSet)
\r
67 throws JobSubmissionException {
\r
68 Probcons probcons = new Probcons();
\r
69 probcons.setInput(SkeletalExecutable.INPUT);
\r
70 probcons.setOutput(SkeletalExecutable.OUTPUT);
\r
71 probcons.setError(SkeletalExecutable.ERROR);
\r
72 return Configurator.configureExecutable(probcons, dataSet);
\r
76 public String customAlign(List<FastaSequence> sequences,
\r
77 List<Option<Probcons>> options) throws JobSubmissionException,
\r
78 WrongParameterException {
\r
79 WSUtil.validateFastaInput(sequences);
\r
80 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
81 List<String> params = WSUtil.getCommands(options, Probcons.KEY_VALUE_SEPARATOR);
\r
82 log.info("Setting parameters:" + params);
\r
83 confProbcons.addParameters(params);
\r
84 return WSUtil.align(sequences, confProbcons, log, "customAlign",getLimit(""));
\r
88 public String presetAlign(List<FastaSequence> sequences,
\r
89 Preset<Probcons> preset) throws JobSubmissionException,
\r
90 WrongParameterException {
\r
91 WSUtil.validateFastaInput(sequences);
\r
92 if (preset == null) {
\r
93 throw new WrongParameterException("Preset must be provided!");
\r
95 ConfiguredExecutable<Probcons> confProbcons = init(sequences);
\r
96 confProbcons.addParameters(preset.getOptions());
\r
97 Limit<Probcons> limit = getLimit(preset.getName());
\r
98 return WSUtil.align(sequences, confProbcons, log, "presetAlign", limit);
\r
101 @SuppressWarnings("unchecked")
\r
103 public Alignment getResult(String jobId) throws ResultNotAvailableException {
\r
104 WSUtil.validateJobId(jobId);
\r
105 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);
\r
106 ConfiguredExecutable<Probcons> probcons = (ConfiguredExecutable<Probcons>) asyncEngine.getResults(jobId);
\r
107 Alignment al = probcons.getResults();
\r
108 // log(jobId, "getResults");
\r
113 public Limit<Probcons> getLimit(String presetName) {
\r
114 if (limitMan == null) {
\r
115 // Limit is not defined
\r
118 return limitMan.getLimitByName(presetName);
\r
122 public LimitsManager<Probcons> getLimits() {
\r
127 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
128 WSUtil.validateJobId(jobId);
\r
129 // TODO check if output is the one to return
\r
130 String file = Configurator.getWorkDirectory(jobId) + File.separator + new Probcons().getError();
\r
131 return WSUtil.pullFile(file, position);
\r
135 public boolean cancelJob(String jobId) {
\r
136 WSUtil.validateJobId(jobId);
\r
137 return WSUtil.cancelJob(jobId);
\r
141 public JobStatus getJobStatus(String jobId) {
\r
142 WSUtil.validateJobId(jobId);
\r
143 return WSUtil.getJobStatus(jobId);
\r
147 public PresetManager<Probcons> getPresets() {
\r
152 public RunnerConfig<Probcons> getRunnerOptions() {
\r
153 return probconsOptions;
\r