X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=testsrc%2Fcompbio%2Frunner%2Fstructure%2FRNAalifoldParametersTester.java;fp=testsrc%2Fcompbio%2Frunner%2Fstructure%2FRNAalifoldParametersTester.java;h=9c15537700a0f5ac9e40956e6496146a4776de37;hb=424e935319103a35bea321a15911ad51fc78ebaf;hp=0000000000000000000000000000000000000000;hpb=8f275a6850e693e670e77dc6c8c83b77b2c0d25a;p=jabaws.git diff --git a/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java b/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java new file mode 100644 index 0000000..9c15537 --- /dev/null +++ b/testsrc/compbio/runner/structure/RNAalifoldParametersTester.java @@ -0,0 +1,202 @@ +package compbio.runner.structure; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBException; +import javax.xml.bind.ValidationException; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import compbio.engine.Configurator; +import compbio.engine.client.ConfiguredExecutable; +import compbio.engine.client.Executable.ExecProvider; +import compbio.engine.conf.RunnerConfigMarshaller; +import compbio.engine.local.ExecutableWrapper; +import compbio.engine.local.LocalRunner; +import compbio.metadata.AllTestSuit; +import compbio.metadata.JobExecutionException; +import compbio.metadata.JobSubmissionException; +import compbio.metadata.Option; +import compbio.metadata.Parameter; +import compbio.metadata.Preset; +import compbio.metadata.PresetManager; +import compbio.metadata.ResultNotAvailableException; +import compbio.metadata.RunnerConfig; +import compbio.runner.OptionCombinator; +import compbio.runner.structure.RNAalifold; +import compbio.util.FileUtil; + + +public class RNAalifoldParametersTester { + + + // should be: AllTestSuit.TEST_DATA_PATH + "RNAalifoldParameters.xml" + static final String rnaalifoldConfigFile = + AllTestSuit.TEST_DATA_PATH + "RNAalifoldParameters.xml"; + public static String test_outfile = "rnaalifold.out.txt"; + + private static Logger log = Logger + .getLogger(AllTestSuit.RUNNER_TEST_LOGGER); + + static { + log.setLevel(Level.INFO); + } + + RunnerConfig rnaalifoldConfig = null; + OptionCombinator rnaalifoldOpc = null; + + @BeforeMethod(groups = { AllTestSuit.test_group_runner }) + @SuppressWarnings("unchecked") + public void setup() { + try { + RunnerConfigMarshaller rnaalifoldmarsh = + new RunnerConfigMarshaller(RunnerConfig.class); + rnaalifoldConfig = rnaalifoldmarsh.read(new FileInputStream(new File( + rnaalifoldConfigFile)), RunnerConfig.class); + rnaalifoldOpc = new OptionCombinator(rnaalifoldConfig); + + log.info("Num options: " + rnaalifoldOpc.getAllOptions().size()); + log.info("Num params: " + rnaalifoldOpc.getAllParameters().size()); + + + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } + + @Test + public void testConfiguration() { + try { + this.rnaalifoldConfig.validate(); + } catch (ValidationException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IllegalStateException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } + + @Test(groups = { AllTestSuit.test_group_runner }) + public void testDefaultParameters() { + RNAalifold rnaalifold = new RNAalifold(); + rnaalifold.setInput(AllTestSuit.test_input_aln).setOutput(test_outfile); + + try { + // For local execution use relavive + ConfiguredExecutable confRNAalifold = Configurator + .configureExecutable(rnaalifold); + LocalRunner lr = new LocalRunner(confRNAalifold); + lr.executeJob(); + confRNAalifold = (ConfiguredExecutable) lr.waitForResult(); + assertNotNull(confRNAalifold.getResults()); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JobExecutionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } + + @Test(groups = { AllTestSuit.test_group_runner }) + public void testOptions() { + test(rnaalifoldOpc.getAllOptions()); + } + + @Test(groups = { AllTestSuit.test_group_runner }) + public void testParameters() { + List> params = rnaalifoldOpc.getAllParameters(); + Collections.shuffle(params); + test(params); + } + + @Test(groups = { AllTestSuit.test_group_runner }) + public void testArguments() { + List> options = rnaalifoldOpc.getAllOptions(); + options.addAll(rnaalifoldOpc.getAllParameters()); + Collections.shuffle(options); + test(options); + } + + void test(Map, String> paramValue) { + List> paramList = new ArrayList>(paramValue + .keySet()); + for (int i = 0; i < paramValue.size(); i++) { + List args = rnaalifoldOpc.parametersToCommandString(paramList, + paramValue); + singleTest(args); + Collections.shuffle(paramList); + } + log.info("NUMBER OF COMBINATION TESTED: " + paramValue.size()); + } + + void test(List> params) { + for (int i = 0; i < params.size(); i++) { + List args = rnaalifoldOpc.argumentsToCommandString(params); + singleTest(args); + Collections.shuffle(params); + } + log.info("NUMBER OF COMBINATION TESTED: " + params.size()); + } + + void singleTest(List params) { + try { + log.info("Using arguments: " + params); + RNAalifold rnaalifold = new RNAalifold(); + rnaalifold.setInput(AllTestSuit.test_input_aln).setOutput(test_outfile); + + ConfiguredExecutable confRNAalifold = Configurator + .configureExecutable(rnaalifold, ExecProvider.Local); + // Add options to the executable + confRNAalifold.addParameters(params); + LocalRunner lr = new LocalRunner(confRNAalifold); + lr.executeJob(); + confRNAalifold = (ConfiguredExecutable) lr.waitForResult(); + assertNotNull(confRNAalifold.getResults()); + File errors = new File(confRNAalifold.getWorkDirectory(), + ExecutableWrapper.PROC_ERR_FILE); + if (errors.length() != 0) { + log.error("PROBLEMS:\n " + FileUtil.readFileToString(errors)); + } + assertTrue(errors.length() == 0, "Run with arguments : " + params + + " FAILED!"); + Collections.shuffle(params); + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JobExecutionException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (ResultNotAvailableException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } + +}