1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.runner.msa;
\r
21 import static org.testng.Assert.assertEquals;
\r
22 import static org.testng.Assert.assertNotNull;
\r
23 import static org.testng.Assert.assertTrue;
\r
24 import static org.testng.Assert.fail;
\r
26 import java.io.File;
\r
27 import java.io.FileInputStream;
\r
28 import java.io.FileNotFoundException;
\r
29 import java.io.IOException;
\r
31 import javax.xml.bind.ValidationException;
\r
33 import org.testng.annotations.BeforeMethod;
\r
34 import org.testng.annotations.Test;
\r
36 import compbio.data.sequence.Alignment;
\r
37 import compbio.engine.AsyncExecutor;
\r
38 import compbio.engine.Configurator;
\r
39 import compbio.engine.FilePuller;
\r
40 import compbio.engine.SyncExecutor;
\r
41 import compbio.engine.client.ConfExecutable;
\r
42 import compbio.engine.client.ConfiguredExecutable;
\r
43 import compbio.engine.client.Executable;
\r
44 import compbio.engine.client.RunConfiguration;
\r
45 import compbio.engine.cluster.drmaa.JobRunner;
\r
46 import compbio.metadata.AllTestSuit;
\r
47 import compbio.metadata.ChunkHolder;
\r
48 import compbio.metadata.JobExecutionException;
\r
49 import compbio.metadata.JobStatus;
\r
50 import compbio.metadata.JobSubmissionException;
\r
51 import compbio.metadata.LimitsManager;
\r
52 import compbio.metadata.PresetManager;
\r
53 import compbio.metadata.ResultNotAvailableException;
\r
54 import compbio.metadata.RunnerConfig;
\r
55 import compbio.runner.msa.Tcoffee;
\r
56 import compbio.util.FileWatcher;
\r
58 public class TcoffeeTester {
\r
60 private Tcoffee tcoffee;
\r
62 @BeforeMethod(groups = { AllTestSuit.test_group_cluster,
\r
63 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
64 public void init() {
\r
65 tcoffee = new Tcoffee();
\r
66 tcoffee.setInput(AllTestSuit.test_input).setOutput("tcoffee.out")
\r
67 .setError("tcoffee.progress");
\r
70 @Test(groups = { AllTestSuit.test_group_runner,
\r
71 AllTestSuit.test_group_non_windows })
\r
72 public void testExecute() {
\r
74 ConfiguredExecutable<Tcoffee> ctcoffee = Configurator
\r
75 .configureExecutable(tcoffee, Executable.ExecProvider.Local);
\r
76 // matrix does not appear to work
\r
77 // ctcoffee.getParameters().setParam("-matrix","BLOSUM62");
\r
78 SyncExecutor sexecutor = Configurator.getSyncEngine(ctcoffee);
\r
79 sexecutor.executeJob();
\r
80 ConfiguredExecutable<?> al = sexecutor.waitForResult();
\r
81 Alignment align = al.getResults();
\r
82 assertNotNull(align);
\r
84 // System.out.println("Tcoffee stat file: " + tcoffee.getError());
\r
85 } catch (JobSubmissionException e) {
\r
86 e.printStackTrace();
\r
87 fail(e.getMessage());
\r
88 } catch (JobExecutionException e) {
\r
89 e.printStackTrace();
\r
90 fail(e.getMessage());
\r
91 } catch (ResultNotAvailableException e) {
\r
92 e.printStackTrace();
\r
93 fail(e.getMessage());
\r
97 @Test(groups = { AllTestSuit.test_group_runner,
\r
98 AllTestSuit.test_group_non_windows })
\r
99 public void readStatistics() {
\r
101 Tcoffee tcoffee = new Tcoffee().setInput(AllTestSuit.test_input);
\r
102 ConfiguredExecutable<Tcoffee> confTcoffee = Configurator
\r
103 .configureExecutable(tcoffee, Executable.ExecProvider.Local);
\r
105 AsyncExecutor sexec = Configurator.getAsyncEngine(confTcoffee);
\r
106 String jobId = sexec.submitJob(confTcoffee);
\r
107 FilePuller fw = FilePuller.newFilePuller(confTcoffee
\r
108 .getWorkDirectory()
\r
109 + File.separator + tcoffee.getError(),
\r
110 FileWatcher.MIN_CHUNK_SIZE_BYTES);
\r
114 while (!(sexec.getJobStatus(jobId) == JobStatus.FINISHED || sexec
\r
115 .getJobStatus(jobId) == JobStatus.FAILED || sexec
\r
116 .getJobStatus(jobId) == JobStatus.UNDEFINED)
\r
117 || fw.hasMoreData()) {
\r
118 ChunkHolder ch = fw.pull(position);
\r
119 String chunk = ch.getChunk();
\r
120 position = ch.getNextPosition();
\r
121 System.out.print(chunk);
\r
124 assertTrue(count > 1);
\r
125 ConfiguredExecutable<?> al = sexec.getResults(jobId);
\r
126 assertNotNull(al.getResults());
\r
127 } catch (JobSubmissionException e) {
\r
128 e.printStackTrace();
\r
129 fail(e.getMessage());
\r
130 } catch (ResultNotAvailableException e) {
\r
131 e.printStackTrace();
\r
132 fail(e.getMessage());
\r
133 } catch (IOException e) {
\r
134 e.printStackTrace();
\r
135 fail(e.getMessage());
\r
139 @Test(groups = { AllTestSuit.test_group_cluster,
\r
140 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
141 public void testClusterExecute() {
\r
143 ConfiguredExecutable<Tcoffee> cmafft = Configurator
\r
144 .configureExecutable(tcoffee,
\r
145 Executable.ExecProvider.Cluster);
\r
146 JobRunner sexecutor = (JobRunner) Configurator.getSyncEngine(
\r
147 cmafft, Executable.ExecProvider.Cluster);
\r
148 sexecutor.executeJob();
\r
149 ConfiguredExecutable<?> al = sexecutor.waitForResult();
\r
150 Alignment align = al.getResults();
\r
151 assertNotNull(align);
\r
152 } catch (JobSubmissionException e) {
\r
153 e.printStackTrace();
\r
154 fail(e.getMessage());
\r
155 } catch (JobExecutionException e) {
\r
156 e.printStackTrace();
\r
157 fail(e.getMessage());
\r
158 } catch (ResultNotAvailableException e) {
\r
159 e.printStackTrace();
\r
160 fail(e.getMessage());
\r
164 @Test(groups = { AllTestSuit.test_group_runner,
\r
165 AllTestSuit.test_group_non_windows })
\r
166 public void testNcore() {
\r
167 Tcoffee tc = new Tcoffee();
\r
168 // System.out.println("TCPRM:" + tc.getParameters(null));
\r
169 assertEquals(tc.getParameters(null).size(), 3);
\r
171 assertEquals(2, tc.getNCore());
\r
172 assertEquals(tc.getParameters(null).size(), 3);
\r
174 assertEquals(4, tc.getNCore());
\r
175 assertEquals(tc.getParameters(null).size(), 3);
\r
178 @Test(groups = { AllTestSuit.test_group_cluster,
\r
179 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
180 public void testPersistance() {
\r
182 Tcoffee tcoffee = new Tcoffee();
\r
183 tcoffee.setError("errrr.txt").setInput(AllTestSuit.test_input)
\r
184 .setOutput("outtt.txt");
\r
185 assertEquals(tcoffee.getInput(), AllTestSuit.test_input);
\r
186 assertEquals(tcoffee.getError(), "errrr.txt");
\r
187 assertEquals(tcoffee.getOutput(), "outtt.txt");
\r
188 ConfiguredExecutable<Tcoffee> ctcofee = Configurator
\r
189 .configureExecutable(tcoffee, Executable.ExecProvider.Local);
\r
191 SyncExecutor sexec = Configurator.getSyncEngine(ctcofee);
\r
192 sexec.executeJob();
\r
193 ConfiguredExecutable<?> al = sexec.waitForResult();
\r
194 assertNotNull(al.getResults());
\r
195 // Save run configuration
\r
196 assertTrue(ctcofee.saveRunConfiguration());
\r
198 // See if loaded configuration is the same as saved
\r
199 RunConfiguration loadedRun = RunConfiguration
\r
200 .load(new FileInputStream(new File(ctcofee
\r
201 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
202 assertEquals(((ConfExecutable<Tcoffee>) ctcofee)
\r
203 .getRunConfiguration(), loadedRun);
\r
204 // Load run configuration as ConfExecutable
\r
205 ConfiguredExecutable<Tcoffee> resurrectedCTcoffee = (ConfiguredExecutable<Tcoffee>) ctcofee
\r
206 .loadRunConfiguration(new FileInputStream(new File(ctcofee
\r
207 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
208 assertNotNull(resurrectedCTcoffee);
\r
209 // See in details whether executables are the same
\r
210 assertEquals(resurrectedCTcoffee.getExecutable(), tcoffee);
\r
212 // Finally rerun the job in the new task directory
\r
213 ConfiguredExecutable<Tcoffee> restcoffee = Configurator
\r
214 .configureExecutable(resurrectedCTcoffee.getExecutable(),
\r
215 Executable.ExecProvider.Local);
\r
217 sexec = Configurator.getSyncEngine(restcoffee,
\r
218 Executable.ExecProvider.Local);
\r
219 sexec.executeJob();
\r
220 al = sexec.waitForResult();
\r
223 } catch (JobSubmissionException e) {
\r
224 e.printStackTrace();
\r
225 fail(e.getMessage());
\r
226 } catch (JobExecutionException e) {
\r
227 e.printStackTrace();
\r
228 fail(e.getMessage());
\r
229 } catch (FileNotFoundException e) {
\r
230 e.printStackTrace();
\r
231 fail(e.getMessage());
\r
232 } catch (IOException e) {
\r
233 e.printStackTrace();
\r
234 fail(e.getMessage());
\r
235 } catch (ResultNotAvailableException e) {
\r
236 e.printStackTrace();
\r
237 fail(e.getMessage());
\r
241 @Test(groups = { AllTestSuit.test_group_runner })
\r
242 public void testConfigurationLoading() {
\r
244 RunnerConfig<Tcoffee> tcoffeeConfig = ConfExecutable
\r
245 .getRunnerOptions(Tcoffee.class);
\r
246 assertNotNull(tcoffeeConfig);
\r
247 assertTrue(tcoffeeConfig.getArguments().size() > 0);
\r
249 PresetManager<Tcoffee> tcoffeePresets = ConfExecutable
\r
250 .getRunnerPresets(Tcoffee.class);
\r
251 assertNotNull(tcoffeePresets);
\r
252 assertTrue(tcoffeePresets.getPresets().size() > 0);
\r
253 tcoffeePresets.validate(tcoffeeConfig);
\r
255 LimitsManager<Tcoffee> tcoffeeLimits = ConfExecutable
\r
256 .getRunnerLimits(Tcoffee.class);
\r
257 assertNotNull(tcoffeeLimits);
\r
258 assertTrue(tcoffeeLimits.getLimits().size() > 0);
\r
259 tcoffeeLimits.validate(tcoffeePresets);
\r
260 } catch (FileNotFoundException e) {
\r
261 e.printStackTrace();
\r
262 fail(e.getLocalizedMessage());
\r
263 } catch (IOException e) {
\r
264 e.printStackTrace();
\r
265 fail(e.getLocalizedMessage());
\r
266 } catch (ValidationException e) {
\r
267 e.printStackTrace();
\r
268 fail(e.getLocalizedMessage());
\r