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
18 package compbio.ws.server;
\r
20 import java.io.File;
\r
21 import java.util.List;
\r
23 import org.apache.log4j.Logger;
\r
25 import compbio.data.sequence.Alignment;
\r
26 import compbio.data.sequence.FastaSequence;
\r
27 import compbio.engine.AsyncExecutor;
\r
28 import compbio.engine.Configurator;
\r
29 import compbio.engine.client.ConfiguredExecutable;
\r
30 import compbio.engine.client.SkeletalExecutable;
\r
31 import compbio.metadata.ChunkHolder;
\r
32 import compbio.metadata.JobSubmissionException;
\r
33 import compbio.metadata.Limit;
\r
34 import compbio.metadata.Option;
\r
35 import compbio.metadata.Preset;
\r
36 import compbio.metadata.ResultNotAvailableException;
\r
37 import compbio.metadata.WrongParameterException;
\r
38 import compbio.runner.msa.ClustalW;
\r
42 * TODO to complete after the approach is tested with SequenceAnnotation!
\r
44 * Common methods for all SequenceAnnotation web services
\r
50 * @version 1.0 June 2011
\r
53 public abstract class _MsaService<T> extends GenericMetadataService {
\r
56 * FIXME - instances of the Runner (?) and their types should be defined in
\r
59 _MsaService(SkeletalExecutable<T> exec, Logger log) {
\r
63 public String align(List<FastaSequence> sequences)
\r
64 throws JobSubmissionException {
\r
66 WSUtil.validateFastaInput(sequences);
\r
67 ConfiguredExecutable<T> confClust = init(sequences);
\r
68 return WSUtil.align(sequences, confClust, log, "align", getLimit(""));
\r
71 public String presetAlign(List<FastaSequence> sequences, Preset<T> preset)
\r
72 throws JobSubmissionException, WrongParameterException {
\r
73 WSUtil.validateFastaInput(sequences);
\r
74 if (preset == null) {
\r
75 throw new WrongParameterException("Preset must be provided!");
\r
77 Limit<T> limit = getLimit(preset.getName());
\r
78 ConfiguredExecutable<T> confClust = init(sequences);
\r
79 confClust.addParameters(preset.getOptions());
\r
80 return WSUtil.align(sequences, confClust, log, "presetAlign", limit);
\r
83 public String customAlign(List<FastaSequence> sequences,
\r
84 List<Option<T>> options) throws JobSubmissionException,
\r
85 WrongParameterException {
\r
86 WSUtil.validateFastaInput(sequences);
\r
87 ConfiguredExecutable<T> confClust = init(sequences);
\r
88 List<String> params = WSUtil.getCommands(options,
\r
89 ClustalW.KEY_VALUE_SEPARATOR);
\r
90 confClust.addParameters(params);
\r
91 log.info("Setting parameters: " + params);
\r
92 return WSUtil.align(sequences, confClust, log, "customAlign",
\r
96 @SuppressWarnings("unchecked")
\r
97 public Alignment getResult(String jobId) throws ResultNotAvailableException {
\r
99 WSUtil.validateJobId(jobId);
\r
100 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);
\r
101 ConfiguredExecutable<T> clustal = (ConfiguredExecutable<T>) asyncEngine
\r
102 .getResults(jobId);
\r
103 Alignment al = clustal.getResults();
\r
108 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
109 WSUtil.validateJobId(jobId);
\r
110 String file = Configurator.getWorkDirectory(jobId) + File.separator
\r
111 + ClustalW.getStatFile();
\r
112 ChunkHolder cholder = WSUtil.pullFile(file, position);
\r