File: MSAprobsWS.java

package info (click to toggle)
libjaba-client-java 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,052 kB
  • sloc: java: 17,308; makefile: 12
file content (157 lines) | stat: -rw-r--r-- 5,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (c) 2011 Peter Troshin
 *  
 *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     
 * 
 *  This library is free software; you can redistribute it and/or modify it under the terms of the
 *  Apache License version 2 as published by the Apache Software Foundation
 * 
 *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache 
 *  License for more details.
 * 
 *  A copy of the license is in apache_license.txt. It is also available here:
 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
 * 
 * Any republication or derived work distributed in source code form
 * must include this copyright and license notice.
 */

package compbio.ws.server;

import java.io.File;
import java.util.List;

import javax.jws.WebService;

import org.apache.log4j.Logger;

import compbio.data.msa.JABAService;
import compbio.data.msa.MsaWS;
import compbio.data.sequence.Alignment;
import compbio.data.sequence.FastaSequence;
import compbio.data.sequence.Program;
import compbio.engine.AsyncExecutor;
import compbio.engine.Configurator;
import compbio.engine.client.ConfiguredExecutable;
import compbio.engine.client.SkeletalExecutable;
import compbio.engine.client.EngineUtil;
import compbio.metadata.ChunkHolder;
import compbio.metadata.JobStatus;
import compbio.metadata.JobSubmissionException;
import compbio.metadata.Limit;
import compbio.metadata.LimitsManager;
import compbio.metadata.Option;
import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
import compbio.metadata.ResultNotAvailableException;
import compbio.metadata.RunnerConfig;
import compbio.metadata.WrongParameterException;
import compbio.runner.RunnerUtil;
import compbio.runner.msa.MSAprobs;

@WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = JABAService.V2_SERVICE_NAMESPACE, serviceName = "MSAprobsWS")
public class MSAprobsWS implements MsaWS<MSAprobs> {

	private static Logger log = Logger.getLogger(MSAprobsWS.class);

	private static final RunnerConfig<MSAprobs> MSAprobsOptions = RunnerUtil.getSupportedOptions(MSAprobs.class);
	private static final LimitsManager<MSAprobs> limitMan = EngineUtil.getLimits(new MSAprobs().getType());

	@Override
	public String align(List<FastaSequence> sequences)
			throws JobSubmissionException {
		WSUtil.validateFastaInput(sequences);
		ConfiguredExecutable<MSAprobs> confMSAprobs = init(sequences);
		return WSUtil.align(sequences, confMSAprobs, log, "align", getLimit(""));
	}

	ConfiguredExecutable<MSAprobs> init(List<FastaSequence> dataSet)
			throws JobSubmissionException {
		MSAprobs MSAprobs = new MSAprobs();
		MSAprobs.setInput(SkeletalExecutable.INPUT);
		MSAprobs.setOutput(SkeletalExecutable.OUTPUT);
		MSAprobs.setError(SkeletalExecutable.ERROR);
		return Configurator.configureExecutable(MSAprobs, dataSet);
	}

	@Override
	public String customAlign(List<FastaSequence> sequences,
			List<Option<MSAprobs>> options) throws JobSubmissionException,
			WrongParameterException {
		WSUtil.validateFastaInput(sequences);
		ConfiguredExecutable<MSAprobs> confMSAprobs = init(sequences);
		List<String> params = WSUtil.getCommands(options, MSAprobs.KEY_VALUE_SEPARATOR);
		log.info("Setting parameters:" + params);
		confMSAprobs.addParameters(params);
		return WSUtil.align(sequences, confMSAprobs, log, "customAlign",getLimit(""));
	}

	@Override
	public String presetAlign(List<FastaSequence> sequences,
			Preset<MSAprobs> preset) throws JobSubmissionException,
			WrongParameterException {
		WSUtil.validateFastaInput(sequences);
		if (preset == null) {
			throw new WrongParameterException("Preset must be provided!");
		}
		ConfiguredExecutable<MSAprobs> confMSAprobs = init(sequences);
		confMSAprobs.addParameters(preset.getOptions());
		Limit<MSAprobs> limit = getLimit(preset.getName());
		return WSUtil.align(sequences, confMSAprobs, log, "presetAlign", limit);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Alignment getResult(String jobId) throws ResultNotAvailableException {
		WSUtil.validateJobId(jobId);
		AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);
		ConfiguredExecutable<MSAprobs> MSAprobs = (ConfiguredExecutable<MSAprobs>) asyncEngine.getResults(jobId);
		Alignment al = MSAprobs.getResults();
		return new Alignment (al.getSequences(), Program.MSAprobs, '-');
	}

	@Override
	public Limit<MSAprobs> getLimit(String presetName) {
		if (limitMan == null) {
			// Limit is not defined
			return null;
		}
		return limitMan.getLimitByName(presetName);
	}

	@Override
	public LimitsManager<MSAprobs> getLimits() {
		return limitMan;
	}

	@Override
	public ChunkHolder pullExecStatistics(String jobId, long position) {
		WSUtil.validateJobId(jobId);
		// TODO check if output is the one to return
		String file = Configurator.getWorkDirectory(jobId) + File.separator + new MSAprobs().getError();
		return WSUtil.pullFile(file, position);
	}

	@Override
	public boolean cancelJob(String jobId) {
		WSUtil.validateJobId(jobId);
		return WSUtil.cancelJob(jobId);
	}

	@Override
	public JobStatus getJobStatus(String jobId) {
		WSUtil.validateJobId(jobId);
		return WSUtil.getJobStatus(jobId);
	}

	@Override
	public PresetManager<MSAprobs> getPresets() {
		return null;
	}

	@Override
	public RunnerConfig<MSAprobs> getRunnerOptions() {
		return MSAprobsOptions;
	}

}