/* Copyright (c) 2009 Peter Troshin * * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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.annotation.Resource; import javax.jws.WebService; import javax.xml.ws.WebServiceContext; import org.apache.log4j.Logger; import compbio.data.msa.MsaWS; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.client.ConfiguredExecutable; 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.Util; import compbio.runner.msa.ClustalW; import compbio.util.Timer; import compbio.ws.client.Services; @WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = "http://msa.data.compbio/01/01/2010/", serviceName = "ClustalWS") public class ClustalWS implements MsaWS { // Ask for resource injection @Resource private WebServiceContext wsContext; private static Logger log = Logger.getLogger(ClustalWS.class); private static volatile WSLogger logger; private static final RunnerConfig clustalOptions = Util .getSupportedOptions(ClustalW.class); private static final PresetManager clustalPresets = Util .getPresets(ClustalW.class); /* * Initialise the logger. This cannot be done in the constructor as the * WebServiceContext is not available at the object construction time */ private WSLogger getLogger() { if (logger == null) { synchronized (ClustalWS.class) { if (logger == null) { logger = WSLogger.getStatLogger(Services.ClustalWS, wsContext); } } } return logger; } @Override public String align(List sequences) throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confClust = init(sequences); return WSUtil.align(sequences, confClust, getLogger(), "align", getLimit("")); } ConfiguredExecutable init(List dataSet) throws JobSubmissionException { ClustalW clustal = new ClustalW(); ConfiguredExecutable confClust = Configurator .configureExecutable(clustal, dataSet); return confClust; } @Override public String presetAlign(List sequences, Preset preset) throws JobSubmissionException, WrongParameterException { WSUtil.validateFastaInput(sequences); if (preset == null) { throw new WrongParameterException("Preset must be provided!"); } Limit limit = getLimit(preset.getName()); ConfiguredExecutable confClust = init(sequences); confClust.addParameters(preset.getOptions()); return WSUtil.align(sequences, confClust, getLogger(), "presetAlign", limit); } @Override public String customAlign(List sequences, List> options) throws JobSubmissionException, WrongParameterException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confClust = init(sequences); List params = WSUtil.getCommands(options, ClustalW.KEY_VALUE_SEPARATOR); confClust.addParameters(params); log.info("Setting parameters: " + params); return WSUtil.align(sequences, confClust, getLogger(), "customAlign", getLimit("")); } @Override public RunnerConfig getRunnerOptions() { Timer timer = Timer.getMilliSecondsTimer(); getLogger().logAll(timer, "getRunnerOptions"); return clustalOptions; } @SuppressWarnings("unchecked") @Override public Alignment getResult(String jobId) throws ResultNotAvailableException { Timer timer = Timer.getMilliSecondsTimer(); WSUtil.validateJobId(jobId); AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); ConfiguredExecutable clustal = (ConfiguredExecutable) asyncEngine .getResults(jobId); Alignment al = clustal.getResults(); getLogger().log(timer, "getResults", jobId); return al; } @Override public Limit getLimit(String presetName) { Timer timer = Timer.getMilliSecondsTimer(); Limit limit = new ClustalW().getLimit(presetName); getLogger().logAll(timer, "getLimit"); return limit; } @Override public LimitsManager getLimits() { Timer timer = Timer.getMilliSecondsTimer(); LimitsManager limits = new ClustalW().getLimits(); getLogger().logAll(timer, "getLimits"); return limits; } @Override public boolean cancelJob(String jobId) { Timer timer = Timer.getMilliSecondsTimer(); WSUtil.validateJobId(jobId); boolean result = WSUtil.cancelJob(jobId); getLogger().logFine(timer, "Cancel"); return result; } @Override public JobStatus getJobStatus(String jobId) { Timer timer = Timer.getMilliSecondsTimer(); WSUtil.validateJobId(jobId); JobStatus status = WSUtil.getJobStatus(jobId); getLogger().logFine(timer, "getJobStatus"); return status; } @Override public PresetManager getPresets() { Timer timer = Timer.getMilliSecondsTimer(); getLogger().logAll(timer, "pullExecStatistics"); return clustalPresets; } @Override public ChunkHolder pullExecStatistics(String jobId, long position) { Timer timer = Timer.getMilliSecondsTimer(); WSUtil.validateJobId(jobId); String file = Configurator.getWorkDirectory(jobId) + File.separator + ClustalW.getStatFile(); ChunkHolder cholder = WSUtil.pullFile(file, position); getLogger().logFine(timer, "pullExecStatistics"); return cholder; } }