Parameters Tester updated. Untested webservice code. generate xsd/wsdl?
authorDaniel Barton <daluke.barton@gmail.com>
Sun, 4 Aug 2013 21:05:46 +0000 (22:05 +0100)
committerDaniel Barton <daluke.barton@gmail.com>
Sun, 4 Aug 2013 21:05:46 +0000 (22:05 +0100)
runner/compbio/runner/structure/RNAalifold.java
testsrc/compbio/runner/structure/RNAalifoldParametersTester.java
testsrc/compbio/runner/structure/RNAalifoldTester.java
testsrc/testdata/RNAalifoldParameters.xml
webservices/compbio/ws/server/RNAalifoldWS.java [new file with mode: 0644]

index ff89fcb..4ec1ec7 100644 (file)
@@ -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<RNAalifold> 
                implements PipedExecutable<RNAalifold> {
        
        
-       
        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<RNAalifold>
                return (Class<RNAalifold>) 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;
+       }
        
 }
index 9c15537..21ed5d4 100644 (file)
@@ -68,6 +68,9 @@ public class RNAalifoldParametersTester {
                                        new RunnerConfigMarshaller<RNAalifold>(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<Option<?>> pair = new ArrayList<Option<?>>();
+               List<Option<?>> options = rnaalifoldOpc.getAllOptions();
+               int numpairs = 0;
+               for (int i = 0; i<options.size(); i++) {
+                       for (int j = i; j<options.size(); j++) {
+                               if (i != j) {
+                                       //System.out.println("special numOptions: " + options.size());
+                                       //System.out.println("special loop varaibles:-  (i,j): (" + i + "," + j +")");
+                                       pair.clear();
+                                       pair.add(options.get(i)); pair.add(options.get(j));
+                                       log.info("option pair to test: " + pair);
+                                       // I want to catch ResultNotAvailableException here so 
+                                       // I can return a list of imcompatable options but
+                                       // singleTest calls a fail() method...
+                                       // can i fail the test and continue running?
+                                       test(pair);
+                                       
+                                       //System.out.println("special numpairstested: " + ++numpairs);
+                               }
+                       }
+               }
+       }
 
        @Test(groups = { AllTestSuit.test_group_runner })
        public void testParameters() {
@@ -141,6 +169,7 @@ public class RNAalifoldParametersTester {
                test(options);
        }
        
+       /*
        void test(Map<Parameter<?>, String> paramValue) {
                List<Parameter<?>> paramList = new ArrayList<Parameter<?>>(paramValue
                                .keySet());
@@ -152,6 +181,7 @@ public class RNAalifoldParametersTester {
                }
                log.info("NUMBER OF COMBINATION TESTED: " + paramValue.size());
        }
+       */
        
        void test(List<? extends Option<?>> 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<Parameter<?>> params = rnaalifoldOpc.getAllParameters();
+               //System.out.println("special: params: " + params);
+               
+               //List<String> args = rnaalifoldOpc.argumentsToCommandString(params);
+               List<String> args = new ArrayList<String>();
+               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<String> params) {
                try {
                        log.info("Using arguments: " + params);
index 123f4b2..2ce3d5f 100644 (file)
@@ -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<RNAalifold> confRNAalifold = Configurator
@@ -73,7 +73,6 @@ public class RNAalifoldTester {
                        LocalRunner lr = new LocalRunner(confRNAalifold);
                        lr.executeJob();
                        confRNAalifold = (ConfiguredExecutable<RNAalifold>) lr.waitForResult();
-                       // getResults method still to come 
                        assertNotNull(confRNAalifold.getResults()); 
                } catch (JobSubmissionException e) {
                        e.printStackTrace();
index b0e8df0..2561ec4 100644 (file)
        </parameters>
 <!--  ?Will Jabaws recognize that arguments for the following params must
 be of the form -s INT and &dash-stochBT=INT -->
-       <parameters isRequired='false'>
-               <name>Stochastic Backtrack</name>
-               <description>Compute a number of random structures</description>
-               <optionNames>-s</optionNames>
+<!--   <parameters isRequired='false'> -->
+<!--           <name>Stochastic Backtrack</name> -->
+<!--           <description>Compute a number of random structures</description> -->
+<!--           <optionNames>-s</optionNames> -->
                <!-- Having multiple optionNames requires a default value but
                        in a parameter defaultValue refers to the argument -->
 <!--           <optionNames>-stochBT</optionNames> -->
-               <defaultValue>5</defaultValue>  <!-- arbitrary -->
-               <validValue>
-                       <type>Int</type>
-               </validValue>
-       </parameters>
+<!--           <defaultValue>5</defaultValue>  arbitrary -->
+<!--           <validValue> -->
+<!--                   <type>Int</type> -->
+<!--           </validValue> -->
+<!--   </parameters> -->
        <parameters isRequired='false'>
                <name>stochBT_en</name>
                <description>Print Backtrack structures</description>
@@ -209,13 +209,14 @@ be of the form -s INT and &dash-stochBT=INT -->
                        <type>String</type>
                </validValue>
        </parameters>
-       <parameters isRequired='false'>
-               <name>betaScale</name>
-               <description>Set scaling of Boltzmann factors</description>
-               <optionNames>--betaScale</optionNames>
-               <defaultValue>1.0</defaultValue>
-               <validValue>
-                       <type>Double</type>
-               </validValue>
-       </parameters>
+       <!--  Is dependant on -p (partfunc) -->
+<!--   <parameters isRequired='false'> -->
+<!--           <name>betaScale</name> -->
+<!--           <description>Set scaling of Boltzmann factors</description> -->
+<!--           <optionNames>-betaScale</optionNames> -->
+<!--           <defaultValue>1.0</defaultValue> -->
+<!--           <validValue> -->
+<!--                   <type>Double</type> -->
+<!--           </validValue> -->
+<!--   </parameters> -->
 </runnerConfig>
\ 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 (file)
index 0000000..4a1d5a1
--- /dev/null
@@ -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<RNAalifold> {
+
+       private static Logger log = Logger.getLogger(ClustalWS.class);
+       
+       private static final RunnerConfig<RNAalifold> rnaalifoldOptions = Util.
+                       getSupportedOptions(RNAalifold.class);
+       
+       private static final PresetManager<RNAalifold> rnaalifoldPresets = Util
+                       .getPresets(RNAalifold.class);
+
+       private static final LimitsManager<RNAalifold> limitMan = compbio.engine.client.Util
+                       .getLimits(new RNAalifold().getType());
+       
+       ConfiguredExecutable<RNAalifold> init() throws JobSubmissionException {
+               RNAalifold rnaalifold = new RNAalifold();
+               rnaalifold.setInput(SkeletalExecutable.INPUT)
+                               .setOutput(SkeletalExecutable.OUTPUT)
+                               .setError(SkeletalExecutable.ERROR);
+               ConfiguredExecutable<RNAalifold> confRNAalifold = Configurator
+                               .configureExecutable(rnaalifold);
+               return confRNAalifold;
+       }
+               
+       @Override
+       public RunnerConfig<RNAalifold> 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> rnaalifold = (ConfiguredExecutable<RNAalifold>) 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<RNAalifold> getLimit(String presetName) {
+               if (limitMan == null) {
+                       // No limit is configured
+                       return null;
+               }
+               Limit<RNAalifold> limit = limitMan.getLimitByName(presetName);
+               return limit;
+       }
+       
+       @Override
+       public LimitsManager<RNAalifold> getLimits() {
+               return limitMan;
+       }
+       
+       @Override 
+       // PlaceHolder
+       public PresetManager<RNAalifold> 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;
+       }
+}
+       
+