From 0ec796d8e2a97d2c006a88522010cd2fff5a0d96 Mon Sep 17 00:00:00 2001 From: Daniel Barton Date: Sun, 4 Aug 2013 22:05:46 +0100 Subject: [PATCH] Parameters Tester updated. Untested webservice code. generate xsd/wsdl? --- runner/compbio/runner/structure/RNAalifold.java | 73 +++++++++-- .../structure/RNAalifoldParametersTester.java | 44 +++++++ .../compbio/runner/structure/RNAalifoldTester.java | 3 +- testsrc/testdata/RNAalifoldParameters.xml | 37 +++--- webservices/compbio/ws/server/RNAalifoldWS.java | 127 ++++++++++++++++++++ 5 files changed, 254 insertions(+), 30 deletions(-) create mode 100644 webservices/compbio/ws/server/RNAalifoldWS.java diff --git a/runner/compbio/runner/structure/RNAalifold.java b/runner/compbio/runner/structure/RNAalifold.java index ff89fcb..4ec1ec7 100644 --- a/runner/compbio/runner/structure/RNAalifold.java +++ b/runner/compbio/runner/structure/RNAalifold.java @@ -6,6 +6,11 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +//imports for filereader method +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.File; + import org.apache.log4j.Logger; import compbio.data.sequence.Alignment; @@ -15,23 +20,16 @@ import compbio.engine.client.SkeletalExecutable; import compbio.metadata.ResultNotAvailableException; import compbio.runner.Util; + +import compbio.engine.client.CommandBuilder; + public class RNAalifold extends SkeletalExecutable implements PipedExecutable { - private static Logger log = Logger.getLogger(RNAalifold.class); - @SuppressWarnings("unchecked") - @Override - // PlaceHolder method - public String getResults(String resultFile) - throws ResultNotAvailableException { - return "null"; - } - - @Override public RNAalifold setOutput(String outFile) { log.info("Set ouput file: " + outFile.toString()); @@ -53,5 +51,60 @@ public class RNAalifold extends SkeletalExecutable return (Class) this.getClass(); } + @SuppressWarnings("unchecked") + @Override + // PlaceHolder method + public String getResults(String workDirectory) + throws ResultNotAvailableException { + try { + // System.out.print(readRNAStruct(workDirectory, getOutput())); + return readRNAStruct(workDirectory, getOutput()); + } catch (FileNotFoundException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (IOException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } + } + + + // Simple and generic methods for reading a whole file + // Should surfice until a more detailed datamodel and parser are developed + private static String readRNAStruct(String workDirectory, + String structFile) throws IOException, FileNotFoundException { + assert !compbio.util.Util.isEmpty(workDirectory); + assert !compbio.util.Util.isEmpty(structFile); + File sfile = new File(compbio.engine.client.Util.getFullPath( + workDirectory, structFile)); + log.trace("RNAALIFOLD OUTPUT FILE PATH: " + sfile.getAbsolutePath()); + if(!(sfile.exists() && sfile.length() > 0)) { + throw new FileNotFoundException("Result for the jobId " + + workDirectory + "with file name " + structFile + + " is not found!"); + } + return readFile(sfile); + } + + private static BufferedReader input; + public static String readFile(File inputFile) throws + FileNotFoundException, IOException { + + input = new BufferedReader(new FileReader(inputFile)); + + String file = new String(); + String line = new String(); + + while (true) { + line = input.readLine(); + + if (line != null) { + file = file + line + "\r\n"; + } else break; + } + // Close file + input.close(); + return file; + } } diff --git a/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java b/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java index 9c15537..21ed5d4 100644 --- a/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java +++ b/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java @@ -68,6 +68,9 @@ public class RNAalifoldParametersTester { new RunnerConfigMarshaller(RunnerConfig.class); rnaalifoldConfig = rnaalifoldmarsh.read(new FileInputStream(new File( rnaalifoldConfigFile)), RunnerConfig.class); + // set Name value separator + rnaalifoldConfig.setPrmSeparator(" "); + log.info("prmSeparator: " + rnaalifoldConfig.getPrmSeparator()); rnaalifoldOpc = new OptionCombinator(rnaalifoldConfig); log.info("Num options: " + rnaalifoldOpc.getAllOptions().size()); @@ -125,6 +128,31 @@ public class RNAalifoldParametersTester { public void testOptions() { test(rnaalifoldOpc.getAllOptions()); } + + @Test(groups = { AllTestSuit.test_group_runner }) + public void testOptionPairs() throws ResultNotAvailableException { + List> pair = new ArrayList>(); + List> options = rnaalifoldOpc.getAllOptions(); + int numpairs = 0; + for (int i = 0; i, String> paramValue) { List> paramList = new ArrayList>(paramValue .keySet()); @@ -152,6 +181,7 @@ public class RNAalifoldParametersTester { } log.info("NUMBER OF COMBINATION TESTED: " + paramValue.size()); } + */ void test(List> params) { for (int i = 0; i < params.size(); i++) { @@ -162,6 +192,20 @@ public class RNAalifoldParametersTester { log.info("NUMBER OF COMBINATION TESTED: " + params.size()); } + @Test + void singleParamTest() { + //List> params = rnaalifoldOpc.getAllParameters(); + //System.out.println("special: params: " + params); + + //List args = rnaalifoldOpc.argumentsToCommandString(params); + List args = new ArrayList(); + args.add("-T 37"); args.add("-S 1.07"); args.add("--stochBT_en=10"); + args.add("--MEA=1"); + System.out.println("special: args: " + args); + singleTest(args); + + } + void singleTest(List params) { try { log.info("Using arguments: " + params); diff --git a/testsrc/compbio/runner/structure/RNAalifoldTester.java b/testsrc/compbio/runner/structure/RNAalifoldTester.java index 123f4b2..2ce3d5f 100644 --- a/testsrc/compbio/runner/structure/RNAalifoldTester.java +++ b/testsrc/compbio/runner/structure/RNAalifoldTester.java @@ -65,7 +65,7 @@ public class RNAalifoldTester { @Test(groups = { AllTestSuit.test_group_runner }) public void testRunLocally() { RNAalifold rnaalifold = new RNAalifold(); - rnaalifold.setInput(AllTestSuit.test_input).setOutput(test_outfile); + rnaalifold.setInput(AllTestSuit.test_input_aln).setOutput(test_outfile); try{ ConfiguredExecutable confRNAalifold = Configurator @@ -73,7 +73,6 @@ public class RNAalifoldTester { LocalRunner lr = new LocalRunner(confRNAalifold); lr.executeJob(); confRNAalifold = (ConfiguredExecutable) lr.waitForResult(); - // getResults method still to come assertNotNull(confRNAalifold.getResults()); } catch (JobSubmissionException e) { e.printStackTrace(); diff --git a/testsrc/testdata/RNAalifoldParameters.xml b/testsrc/testdata/RNAalifoldParameters.xml index b0e8df0..2561ec4 100644 --- a/testsrc/testdata/RNAalifoldParameters.xml +++ b/testsrc/testdata/RNAalifoldParameters.xml @@ -107,18 +107,18 @@ - - Stochastic Backtrack - Compute a number of random structures - -s + + + + - 5 - - Int - - + + + + + stochBT_en Print Backtrack structures @@ -209,13 +209,14 @@ be of the form -s INT and &dash-stochBT=INT --> String - - betaScale - Set scaling of Boltzmann factors - --betaScale - 1.0 - - Double - - + + + + + + + + + + \ No newline at end of file diff --git a/webservices/compbio/ws/server/RNAalifoldWS.java b/webservices/compbio/ws/server/RNAalifoldWS.java new file mode 100644 index 0000000..4a1d5a1 --- /dev/null +++ b/webservices/compbio/ws/server/RNAalifoldWS.java @@ -0,0 +1,127 @@ +package compbio.ws.server; + +import java.io.File; +import java.util.List; + +import javax.jws.WebParam; +import javax.jws.WebService; + +import org.apache.log4j.Logger; + +import compbio.data.msa.JABAService; +import compbio.data.msa.JManagement; +import compbio.data.msa.Metadata; +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.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.ClustalW; +import compbio.runner.structure.RNAalifold; + +@WebService(targetNamespace = JABAService.SERVICE_NAMESPACE, serviceName = "RNAalifoldWS") +public class RNAalifoldWS implements JABAService, JManagement, Metadata { + + private static Logger log = Logger.getLogger(ClustalWS.class); + + private static final RunnerConfig rnaalifoldOptions = Util. + getSupportedOptions(RNAalifold.class); + + private static final PresetManager rnaalifoldPresets = Util + .getPresets(RNAalifold.class); + + private static final LimitsManager limitMan = compbio.engine.client.Util + .getLimits(new RNAalifold().getType()); + + ConfiguredExecutable init() throws JobSubmissionException { + RNAalifold rnaalifold = new RNAalifold(); + rnaalifold.setInput(SkeletalExecutable.INPUT) + .setOutput(SkeletalExecutable.OUTPUT) + .setError(SkeletalExecutable.ERROR); + ConfiguredExecutable confRNAalifold = Configurator + .configureExecutable(rnaalifold); + return confRNAalifold; + } + + @Override + public RunnerConfig getRunnerOptions() { + return rnaalifoldOptions; + } + + @SuppressWarnings("unchecked") + public String getResult(@WebParam(name = "jobId") String jobId) throws ResultNotAvailableException { + + WSUtil.validateJobId(jobId); + AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); + ConfiguredExecutable rnaalifold = (ConfiguredExecutable) asyncEngine + .getResults(jobId); + return rnaalifold.getResults(); + } + + @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 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 + // PlaceHolder + public PresetManager getPresets() { + if (rnaalifoldPresets == null) { + // No presets are configured + return null; + } + return rnaalifoldPresets; + } + + @Override + // PlaceHolder + public ChunkHolder pullExecStatistics(String jobId, long position) { + + WSUtil.validateJobId(jobId); +// String file = Configurator.getWorkDirectory(jobId) + File.separator +// + RNAalifold.getStatFile(); +// ChunkHolder cholder = WSUtil.pullFile(file, position); +// return cholder; + return null; + } +} + + -- 1.7.10.2