From 88d252a4d6e1b4bdfc03f617c5a97d2d7bb9d050 Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Thu, 4 Aug 2011 13:16:38 +0000 Subject: [PATCH] Clustal Omega web service wrapper and tester git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4463 e3abac25-378b-4346-85de-24260fe3988d --- webservices/compbio/ws/client/Constraints.java | 132 ++++++++--------- webservices/compbio/ws/client/Services.java | 6 +- webservices/compbio/ws/client/client_help.txt | 6 +- webservices/compbio/ws/server/ClustalOWS.java | 185 ++++++++++++++++++++++++ 4 files changed, 259 insertions(+), 70 deletions(-) create mode 100644 webservices/compbio/ws/server/ClustalOWS.java diff --git a/webservices/compbio/ws/client/Constraints.java b/webservices/compbio/ws/client/Constraints.java index e76ee6a..412d9f2 100644 --- a/webservices/compbio/ws/client/Constraints.java +++ b/webservices/compbio/ws/client/Constraints.java @@ -24,71 +24,71 @@ class Constraints { final static String parameterkey = "-p"; final static String presetkey = "-r"; - final static String help_text = "\r\n" - + "JABAWS client v2.0 June 2011 http://www.compbio.dundee.ac.uk/jabaws \r\n" - + " \r\n" - + "Usage: -h=host_and_context <-s=serviceName> ACTION [OPTIONS] \r\n" - + "\r\n" - + "-h= - a full URL to the JABAWS web server including context \r\n" - + " path e.g. http://10.31.1.159:8080/ws\r\n" - + "-s= - one of [MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, \r\n" - + " AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS]\r\n" - + " is required for all ACTIONS but -list_services\r\n" - + "\r\n" - + "ACTIONS: \r\n" - + "-list_services - list available services\r\n" - + "-test - test service \r\n" - + "-i= - full path to fasta formatted sequence file, from which to align \r\n" - + " sequences\r\n" - + "-parameters - lists parameters supported by web service\r\n" - + "-presets - lists presets supported by web service\r\n" - + "-limits - lists web services limits\r\n" - + "\r\n" - + "Please note that if input file is specified other actions are ignored\r\n" - + "\r\n" - + "OPTIONS (only for use with -i action):\r\n" - + "-r= - name of the preset to use\r\n" - + "-o= - full path to the file where to write an alignment\r\n" - + "-f= - the name of the file with the list of parameters to use.\r\n" - + "\r\n" - + "Please note that -r and -f options cannot be used together. Alignment is done with \r\n" - + "either preset or a parameters from the file, but not both!\r\n" - + "\r\n" - + "EXAMPLES: \r\n" - + "\r\n" - + "1) List all available services on the host \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -list_services\r\n" - + "\r\n" - + "2) Test Clustal web service \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=ClustalWS -test \r\n" - + "\r\n" - + "3) Align sequence from file input.txt with Probcons. Record resulting alignment \r\n" - + "into the output.txt \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=ProbconsWS -i=input.txt -o=output.txt\r\n" - + "\r\n" - + "4) Calculate disorder with Disembl take input from input.txt, output results to \r\n" - + "the console \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=DisemblWS -i=input.txt \r\n" - + "\r\n" - + "5) List all parameters available for AAconWS service \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=AAconWS -parameters\r\n" - + "\r\n" - + "6) Calculate conservation with AAConWS using LANDGRAF method, for Clustal alignment \r\n" - + "from input.txt and report the scores to the console \r\n" - + "\r\n" - + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=AAconWS -i=input.txt -f=prm.txt \r\n" - + "\r\n" - + "Where the content of prm.txt file is -m=LANDGRAF\r\n" - + "The list of the supported parameters can be obtained as shown in the example 5. \r\n" - + "\r\n" - + "Citation: Peter V. Troshin, James B. Procter and Geoffrey J. Barton - \"Java \r\n" - + "Bioinformatics Analysis Web Services for Multiple Sequence Alignment - \r\n" - + "JABAWS:MSA\" Bioinformatics 2011; doi: 10.1093/bioinformatics/btr304.\r\n" - + ""; + final static String help_text = "\r\n" + + "JABAWS2 client August 2011 http://www.compbio.dundee.ac.uk/jabaws \r\n" + + " \r\n" + + "Usage: -h=host_and_context <-s=serviceName> ACTION [OPTIONS] \r\n" + + "\r\n" + + "-h= - a full URL to the JABAWS web server including context \r\n" + + " path e.g. http://10.31.1.159:8080/ws\r\n" + + "-s= - one of [MafftWS, MuscleWS, ClustalWS, ClustalOWS, TcoffeeWS, \r\n" + + " ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS]\r\n" + + " is required for all ACTIONS but -list_services\r\n" + + "\r\n" + + "ACTIONS: \r\n" + + "-list_services - list available services\r\n" + + "-test - test service \r\n" + + "-i= - full path to fasta formatted sequence file, from which to align \r\n" + + " sequences\r\n" + + "-parameters - lists parameters supported by web service\r\n" + + "-presets - lists presets supported by web service\r\n" + + "-limits - lists web services limits\r\n" + + "\r\n" + + "Please note that if input file is specified other actions are ignored\r\n" + + "\r\n" + + "OPTIONS (only for use with -i action):\r\n" + + "-r= - name of the preset to use\r\n" + + "-o= - full path to the file where to write an alignment\r\n" + + "-f= - the name of the file with the list of parameters to use.\r\n" + + "\r\n" + + "Please note that -r and -f options cannot be used together. Alignment is done with \r\n" + + "either preset or a parameters from the file, but not both!\r\n" + + "\r\n" + + "EXAMPLES: \r\n" + + "\r\n" + + "1) List all available services on the host \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -list_services\r\n" + + "\r\n" + + "2) Test Clustal web service \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=ClustalWS -test \r\n" + + "\r\n" + + "3) Align sequence from file input.txt with Probcons. Record resulting alignment \r\n" + + "into the output.txt \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=ProbconsWS -i=input.txt -o=output.txt\r\n" + + "\r\n" + + "4) Calculate disorder with Disembl take input from input.txt, output results to \r\n" + + "the console \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=DisemblWS -i=input.txt \r\n" + + "\r\n" + + "5) List all parameters available for AAconWS service \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=AAconWS -parameters\r\n" + + "\r\n" + + "6) Calculate conservation with AAConWS using LANDGRAF method, for Clustal alignment \r\n" + + "from input.txt and report the scores to the console \r\n" + + "\r\n" + + "Jws2Client -h=http://www.compbio.dundee.ac.uk/jabaws -s=AAconWS -i=input.txt -f=prm.txt \r\n" + + "\r\n" + + "Where the content of prm.txt file is -m=LANDGRAF\r\n" + + "The list of the supported parameters can be obtained as shown in the example 5. \r\n" + + "\r\n" + + "Citation: Peter V. Troshin, James B. Procter and Geoffrey J. Barton - \"Java \r\n" + + "Bioinformatics Analysis Web Services for Multiple Sequence Alignment - \r\n" + + "JABAWS:MSA\" Bioinformatics 2011; doi: 10.1093/bioinformatics/btr304.\r\n" + + ""; } diff --git a/webservices/compbio/ws/client/Services.java b/webservices/compbio/ws/client/Services.java index a7b9969..0ddb1a8 100644 --- a/webservices/compbio/ws/client/Services.java +++ b/webservices/compbio/ws/client/Services.java @@ -35,6 +35,7 @@ import compbio.runner.disorder.Disembl; import compbio.runner.disorder.GlobPlot; import compbio.runner.disorder.IUPred; import compbio.runner.disorder.Jronn; +import compbio.runner.msa.ClustalO; import compbio.runner.msa.ClustalW; import compbio.runner.msa.Mafft; import compbio.runner.msa.Muscle; @@ -46,7 +47,7 @@ import compbio.runner.msa.Tcoffee; * */ public enum Services { - MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS; + MafftWS, MuscleWS, ClustalWS, ClustalOWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS; public static Services getService(String servName) { servName = servName.trim().toLowerCase(); @@ -74,6 +75,8 @@ public enum Services { switch (this) { case AAConWS : return AACon.class; + case ClustalOWS : + return ClustalO.class; case ClustalWS : return ClustalW.class; case MafftWS : @@ -161,6 +164,7 @@ public enum Services { // deliberate leaking case ClustalWS : + case ClustalOWS : case MafftWS : case MuscleWS : case ProbconsWS : diff --git a/webservices/compbio/ws/client/client_help.txt b/webservices/compbio/ws/client/client_help.txt index 63947b1..f2d3158 100644 --- a/webservices/compbio/ws/client/client_help.txt +++ b/webservices/compbio/ws/client/client_help.txt @@ -1,12 +1,12 @@ -JABAWS client v2.0 June 2011 http://www.compbio.dundee.ac.uk/jabaws +JABAWS2 client August 2011 http://www.compbio.dundee.ac.uk/jabaws Usage: -h=host_and_context <-s=serviceName> ACTION [OPTIONS] -h= - a full URL to the JABAWS web server including context path e.g. http://10.31.1.159:8080/ws --s= - one of [MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, - AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS] +-s= - one of [MafftWS, MuscleWS, ClustalWS, ClustalOWS, TcoffeeWS, + ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS] is required for all ACTIONS but -list_services ACTIONS: diff --git a/webservices/compbio/ws/server/ClustalOWS.java b/webservices/compbio/ws/server/ClustalOWS.java new file mode 100644 index 0000000..2151139 --- /dev/null +++ b/webservices/compbio/ws/server/ClustalOWS.java @@ -0,0 +1,185 @@ +/* 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.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.engine.AsyncExecutor; +import compbio.engine.Configurator; +import compbio.engine.client.ConfiguredExecutable; +import compbio.engine.client.Executable; +import compbio.engine.client.SkeletalExecutable; +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.ClustalO; +import compbio.runner.msa.ClustalW; +import compbio.runner.msa.Tcoffee; + +@WebService(endpointInterface = "compbio.data.msa.MsaWS", targetNamespace = JABAService.SERVICE_NAMESPACE, serviceName = "ClustalOWS") +public class ClustalOWS implements MsaWS { + + private static Logger log = Logger.getLogger(ClustalOWS.class); + + private static final RunnerConfig clustalOptions = Util + .getSupportedOptions(ClustalO.class); + + private static final PresetManager clustalPresets = Util + .getPresets(ClustalO.class); + + private static final LimitsManager limitMan = compbio.engine.client.Util + .getLimits(new ClustalO().getType()); + + @Override + public String align(List sequences) + throws JobSubmissionException { + + WSUtil.validateFastaInput(sequences); + ConfiguredExecutable confClust = init(sequences); + return WSUtil.align(sequences, confClust, log, "align", getLimit("")); + } + + ConfiguredExecutable init(List dataSet) + throws JobSubmissionException { + ClustalO clustal = new ClustalO(); + clustal.setInput(SkeletalExecutable.INPUT) + .setOutput(SkeletalExecutable.OUTPUT) + .setError(SkeletalExecutable.ERROR); + ConfiguredExecutable confClust = Configurator + .configureExecutable(clustal, dataSet); + // Set the number of threads for the cluster execution from conf file + if (confClust.getExecProvider() == Executable.ExecProvider.Cluster) { + int clusterCpuNum = SkeletalExecutable.getClusterCpuNum(clustal.getType()); + if (clusterCpuNum != 0) { + clustal.setNCore(clusterCpuNum); + } + } + + 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, log, "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, + ClustalO.KEY_VALUE_SEPARATOR); + confClust.addParameters(params); + log.info("Setting parameters: " + params); + return WSUtil.align(sequences, confClust, log, "customAlign", + getLimit("")); + } + + @Override + public RunnerConfig getRunnerOptions() { + return clustalOptions; + } + + @SuppressWarnings("unchecked") + @Override + 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 Limit getLimit(String presetName) { + if (limitMan == null) { + // No limit is configured + return null; + } + Limit limit = limitMan.getLimitByName(presetName); + return limit; + } + + @Override + public LimitsManager getLimits() { + return limitMan; + } + + @Override + public boolean cancelJob(String jobId) { + WSUtil.validateJobId(jobId); + boolean result = WSUtil.cancelJob(jobId); + return result; + } + + @Override + public JobStatus getJobStatus(String jobId) { + WSUtil.validateJobId(jobId); + JobStatus status = WSUtil.getJobStatus(jobId); + return status; + } + + @Override + public PresetManager getPresets() { + return clustalPresets; + } + + @Override + public ChunkHolder pullExecStatistics(String jobId, long position) { + + WSUtil.validateJobId(jobId); + String file = Configurator.getWorkDirectory(jobId) + File.separator + + ClustalO.getStatFile(); + ChunkHolder cholder = WSUtil.pullFile(file, position); + return cholder; + } + +} -- 1.7.10.2