/* 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 org.apache.log4j.Logger; 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.engine.client.SkeletalExecutable; import compbio.metadata.ChunkHolder; import compbio.metadata.JobSubmissionException; import compbio.metadata.Limit; import compbio.metadata.Option; import compbio.metadata.Preset; import compbio.metadata.ResultNotAvailableException; import compbio.metadata.WrongParameterException; import compbio.runner.msa.ClustalW; /** * * TODO to complete after the approach is tested with SequenceAnnotation! * * Common methods for all SequenceAnnotation web services * * @author pvtroshin * * @param * * @version 1.0 June 2011 * @since 2.0 */ public abstract class _MsaService extends GenericMetadataService { /* * FIXME - instances of the Runner (?) and their types should be defined in * Executable IF */ _MsaService(SkeletalExecutable exec, Logger log) { super(exec, log); } public String align(List sequences) throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confClust = init(sequences); return WSUtil.align(sequences, confClust, log, "align", getLimit("")); } 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, log, "presetAlign", limit); } 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, log, "customAlign", getLimit("")); } @SuppressWarnings("unchecked") public Alignment getResult(String jobId) throws ResultNotAvailableException { WSUtil.validateJobId(jobId); AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); ConfiguredExecutable clustal = (ConfiguredExecutable) asyncEngine .getResults(jobId); Alignment al = clustal.getResults(); return al; } @Override public ChunkHolder pullExecStatistics(String jobId, long position) { WSUtil.validateJobId(jobId); String file = Configurator.getWorkDirectory(jobId) + File.separator + ClustalW.getStatFile(); ChunkHolder cholder = WSUtil.pullFile(file, position); return cholder; } }