1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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.MsaWS;
\r
29 import compbio.data.sequence.Alignment;
\r
30 import compbio.data.sequence.FastaSequence;
\r
31 import compbio.engine.AsyncExecutor;
\r
32 import compbio.engine.Configurator;
\r
33 import compbio.engine.client.ConfiguredExecutable;
\r
34 import compbio.metadata.ChunkHolder;
\r
35 import compbio.metadata.JobStatus;
\r
36 import compbio.metadata.JobSubmissionException;
\r
37 import compbio.metadata.Limit;
\r
38 import compbio.metadata.LimitsManager;
\r
39 import compbio.metadata.Option;
\r
40 import compbio.metadata.Preset;
\r
41 import compbio.metadata.PresetManager;
\r
42 import compbio.metadata.ResultNotAvailableException;
\r
43 import compbio.metadata.RunnerConfig;
\r
44 import compbio.metadata.WrongParameterException;
\r
45 import compbio.runner.Util;
\r
46 import compbio.runner.msa.Mafft;
\r
48 @WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = "http://msa.data.compbio/01/01/2010/", serviceName = "MafftWS")
\r
49 public class MafftWS implements MsaWS<Mafft> {
\r
51 private static Logger log = Logger.getLogger(MafftWS.class);
\r
53 private static final RunnerConfig<Mafft> mafftOptions = Util
\r
54 .getSupportedOptions(Mafft.class);
\r
56 private static final PresetManager<Mafft> mafftPresets = Util
\r
57 .getPresets(Mafft.class);
\r
59 private static final LimitsManager<Mafft> limitMan = compbio.engine.client.Util
\r
60 .getLimits(new Mafft().getType());
\r
63 public String align(List<FastaSequence> sequences)
\r
64 throws JobSubmissionException {
\r
65 WSUtil.validateFastaInput(sequences);
\r
66 ConfiguredExecutable<Mafft> confMafft = init(sequences);
\r
67 return WSUtil.align(sequences, confMafft, null, "align", getLimit(""));
\r
70 ConfiguredExecutable<Mafft> init(List<FastaSequence> dataSet)
\r
71 throws JobSubmissionException {
\r
72 Mafft mafft = new Mafft();
\r
73 return Configurator.configureExecutable(mafft, dataSet);
\r
77 public String customAlign(List<FastaSequence> sequences,
\r
78 List<Option<Mafft>> options) throws JobSubmissionException,
\r
79 WrongParameterException {
\r
80 WSUtil.validateFastaInput(sequences);
\r
81 ConfiguredExecutable<Mafft> confMafft = init(sequences);
\r
82 List<String> params = WSUtil.getCommands(options,
\r
83 Mafft.KEY_VALUE_SEPARATOR);
\r
84 log.info("Setting parameters: " + params);
\r
85 confMafft.addParameters(params);
\r
86 return WSUtil.align(sequences, confMafft, null, "customAlign",
\r
91 public String presetAlign(List<FastaSequence> sequences,
\r
92 Preset<Mafft> preset) throws JobSubmissionException,
\r
93 WrongParameterException {
\r
94 WSUtil.validateFastaInput(sequences);
\r
95 if (preset == null) {
\r
96 throw new WrongParameterException("Preset must be provided!");
\r
98 ConfiguredExecutable<Mafft> confMafft = init(sequences);
\r
99 confMafft.addParameters(preset.getOptions());
\r
100 // This will return default limit if a specific the limit for a
\r
101 // particular preset is not found
\r
102 Limit<Mafft> limit = getLimit(preset.getName());
\r
104 return WSUtil.align(sequences, confMafft, null, "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<Mafft> mafft = (ConfiguredExecutable<Mafft>) asyncEngine
\r
113 .getResults(jobId);
\r
114 Alignment al = mafft.getResults();
\r
115 // log(jobId, "getResults");
\r
120 public Limit<Mafft> getLimit(String presetName) {
\r
121 if (limitMan == null) {
\r
122 // Limit is not defined
\r
125 return limitMan.getLimitByName(presetName);
\r
129 public LimitsManager<Mafft> getLimits() {
\r
134 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
135 WSUtil.validateJobId(jobId);
\r
136 String file = Configurator.getWorkDirectory(jobId) + File.separator
\r
137 + new Mafft().getError();
\r
138 return WSUtil.pullFile(file, position);
\r
142 public boolean cancelJob(String jobId) {
\r
143 WSUtil.validateJobId(jobId);
\r
144 return WSUtil.cancelJob(jobId);
\r
148 public JobStatus getJobStatus(String jobId) {
\r
149 WSUtil.validateJobId(jobId);
\r
150 return WSUtil.getJobStatus(jobId);
\r
154 public PresetManager<Mafft> getPresets() {
\r
155 return mafftPresets;
\r
159 public RunnerConfig<Mafft> getRunnerOptions() {
\r
160 return mafftOptions;
\r