1 package compbio.runner.structure;
3 import static org.testng.Assert.assertFalse;
4 import static org.testng.Assert.assertNotNull;
5 import static org.testng.Assert.assertTrue;
6 import static org.testng.Assert.fail;
9 import java.io.FileInputStream;
10 import java.io.FileNotFoundException;
11 import java.io.IOException;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
17 import javax.xml.bind.JAXBException;
18 import javax.xml.bind.ValidationException;
20 import org.apache.log4j.Level;
21 import org.apache.log4j.Logger;
22 import org.testng.annotations.BeforeMethod;
23 import org.testng.annotations.Test;
25 import compbio.engine.Configurator;
26 import compbio.engine.client.ConfiguredExecutable;
27 import compbio.engine.client.Executable.ExecProvider;
28 import compbio.engine.conf.RunnerConfigMarshaller;
29 import compbio.engine.local.ExecutableWrapper;
30 import compbio.engine.local.LocalRunner;
31 import compbio.metadata.AllTestSuit;
32 import compbio.metadata.JobExecutionException;
33 import compbio.metadata.JobSubmissionException;
34 import compbio.metadata.Option;
35 import compbio.metadata.Parameter;
36 import compbio.metadata.Preset;
37 import compbio.metadata.PresetManager;
38 import compbio.metadata.ResultNotAvailableException;
39 import compbio.metadata.RunnerConfig;
40 import compbio.runner.OptionCombinator;
41 import compbio.runner.structure.RNAalifold;
42 import compbio.util.FileUtil;
45 public class RNAalifoldParametersTester {
48 // should be: AllTestSuit.TEST_DATA_PATH + "RNAalifoldParameters.xml"
49 static final String rnaalifoldConfigFile =
50 AllTestSuit.TEST_DATA_PATH + "RNAalifoldParameters.xml";
51 public static String test_outfile = "rnaalifold.out.txt";
53 private static Logger log = Logger
54 .getLogger(AllTestSuit.RUNNER_TEST_LOGGER);
57 log.setLevel(Level.INFO);
60 RunnerConfig<RNAalifold> rnaalifoldConfig = null;
61 OptionCombinator rnaalifoldOpc = null;
63 @BeforeMethod(groups = { AllTestSuit.test_group_runner })
64 @SuppressWarnings("unchecked")
67 RunnerConfigMarshaller<RNAalifold> rnaalifoldmarsh =
68 new RunnerConfigMarshaller<RNAalifold>(RunnerConfig.class);
69 rnaalifoldConfig = rnaalifoldmarsh.read(new FileInputStream(new File(
70 rnaalifoldConfigFile)), RunnerConfig.class);
71 // set Name value separator
72 rnaalifoldConfig.setPrmSeparator(" ");
73 log.info("prmSeparator: " + rnaalifoldConfig.getPrmSeparator());
74 rnaalifoldOpc = new OptionCombinator(rnaalifoldConfig);
76 log.info("Num options: " + rnaalifoldOpc.getAllOptions().size());
77 log.info("Num params: " + rnaalifoldOpc.getAllParameters().size());
80 } catch (JAXBException e) {
82 fail(e.getLocalizedMessage());
83 } catch (FileNotFoundException e) {
85 fail(e.getLocalizedMessage());
90 public void testConfiguration() {
92 this.rnaalifoldConfig.validate();
93 } catch (ValidationException e) {
95 fail(e.getLocalizedMessage());
96 } catch (IllegalStateException e) {
98 fail(e.getLocalizedMessage());
102 @Test(groups = { AllTestSuit.test_group_runner })
103 public void testDefaultParameters() {
104 RNAalifold rnaalifold = new RNAalifold();
105 rnaalifold.setInput(AllTestSuit.test_input_aln).setOutput(test_outfile);
108 // For local execution use relavive
109 ConfiguredExecutable<RNAalifold> confRNAalifold = Configurator
110 .configureExecutable(rnaalifold);
111 LocalRunner lr = new LocalRunner(confRNAalifold);
113 confRNAalifold = (ConfiguredExecutable<RNAalifold>) lr.waitForResult();
114 assertNotNull(confRNAalifold.getResults());
115 } catch (JobSubmissionException e) {
117 fail(e.getLocalizedMessage());
118 } catch (JobExecutionException e) {
120 fail(e.getLocalizedMessage());
121 } catch (ResultNotAvailableException e) {
123 fail(e.getLocalizedMessage());
127 @Test(groups = { AllTestSuit.test_group_runner })
128 public void testOptions() {
129 test(rnaalifoldOpc.getAllOptions());
132 @Test(groups = { AllTestSuit.test_group_runner })
133 public void testOptionPairs() throws ResultNotAvailableException {
134 List<Option<?>> pair = new ArrayList<Option<?>>();
135 List<Option<?>> options = rnaalifoldOpc.getAllOptions();
137 for (int i = 0; i<options.size(); i++) {
138 for (int j = i; j<options.size(); j++) {
140 //System.out.println("special numOptions: " + options.size());
141 //System.out.println("special loop varaibles:- (i,j): (" + i + "," + j +")");
143 pair.add(options.get(i)); pair.add(options.get(j));
144 log.info("option pair to test: " + pair);
145 // I want to catch ResultNotAvailableException here so
146 // I can return a list of imcompatable options but
147 // singleTest calls a fail() method...
148 // can i fail the test and continue running?
151 //System.out.println("special numpairstested: " + ++numpairs);
157 @Test(groups = { AllTestSuit.test_group_runner })
158 public void testParameters() {
159 List<Parameter<?>> params = rnaalifoldOpc.getAllParameters();
160 Collections.shuffle(params);
164 @Test(groups = { AllTestSuit.test_group_runner })
165 public void testArguments() {
166 List<Option<?>> options = rnaalifoldOpc.getAllOptions();
167 options.addAll(rnaalifoldOpc.getAllParameters());
168 Collections.shuffle(options);
173 void test(Map<Parameter<?>, String> paramValue) {
174 List<Parameter<?>> paramList = new ArrayList<Parameter<?>>(paramValue
176 for (int i = 0; i < paramValue.size(); i++) {
177 List<String> args = rnaalifoldOpc.parametersToCommandString(paramList,
180 Collections.shuffle(paramList);
182 log.info("NUMBER OF COMBINATION TESTED: " + paramValue.size());
186 void test(List<? extends Option<?>> params) {
187 for (int i = 0; i < params.size(); i++) {
188 List<String> args = rnaalifoldOpc.argumentsToCommandString(params);
190 Collections.shuffle(params);
192 log.info("NUMBER OF COMBINATION TESTED: " + params.size());
196 void singleParamTest() {
197 //List<Parameter<?>> params = rnaalifoldOpc.getAllParameters();
198 //System.out.println("special: params: " + params);
200 //List<String> args = rnaalifoldOpc.argumentsToCommandString(params);
201 List<String> args = new ArrayList<String>();
202 args.add("-T 37"); args.add("-S 1.07"); args.add("--stochBT_en=10");
204 System.out.println("special: args: " + args);
209 void singleTest(List<String> params) {
211 log.info("Using arguments: " + params);
212 RNAalifold rnaalifold = new RNAalifold();
213 rnaalifold.setInput(AllTestSuit.test_input_aln).setOutput(test_outfile);
215 ConfiguredExecutable<RNAalifold> confRNAalifold = Configurator
216 .configureExecutable(rnaalifold, ExecProvider.Local);
217 // Add options to the executable
218 confRNAalifold.addParameters(params);
219 LocalRunner lr = new LocalRunner(confRNAalifold);
221 confRNAalifold = (ConfiguredExecutable<RNAalifold>) lr.waitForResult();
222 assertNotNull(confRNAalifold.getResults());
223 File errors = new File(confRNAalifold.getWorkDirectory(),
224 ExecutableWrapper.PROC_ERR_FILE);
225 if (errors.length() != 0) {
226 log.error("PROBLEMS:\n " + FileUtil.readFileToString(errors));
228 assertTrue(errors.length() == 0, "Run with arguments : " + params
230 Collections.shuffle(params);
231 } catch (JobSubmissionException e) {
233 fail(e.getLocalizedMessage());
234 } catch (JobExecutionException e) {
236 fail(e.getLocalizedMessage());
237 } catch (IOException e) {
239 fail(e.getLocalizedMessage());
240 } catch (ResultNotAvailableException e) {
242 fail(e.getLocalizedMessage());