--- /dev/null
+/*\r
+ * Copyright (c) 2011 Peter Troshin JAva Bioinformatics Analysis Web Services\r
+ * (JABAWS) @version: 2.0 This library is free software; you can redistribute it\r
+ * and/or modify it under the terms of the Apache License version 2 as published\r
+ * by the Apache Software Foundation This library is distributed in the hope\r
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * Apache License for more details. A copy of the license is in\r
+ * apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or\r
+ * derived work distributed in source code form must include this copyright and\r
+ * license notice.\r
+ */\r
+\r
+package compbio.runner.disorder;\r
+\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.TreeMap;\r
+import java.util.TreeSet;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
+import compbio.data.sequence.SequenceUtil;\r
+import compbio.data.sequence.UnknownFileFormatException;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.ResultNotAvailableException;\r
+\r
+/**\r
+ * iupred sequenceFile <short long glob >\r
+ * \r
+ * Maximum sequence length is 40000 chars. Single string length max is a 1000\r
+ * chars!\r
+ * \r
+ */\r
+public class IUPred extends SkeletalExecutable<IUPred> {\r
+\r
+ private static Logger log = Logger.getLogger(IUPred.class);\r
+ private static final String GLOB_SUFFIX = ".glob";\r
+ private static final String SHORT_SUFFIX = ".short";\r
+ private static final String LONG_SUFFIX = ".long";\r
+\r
+ @Override\r
+ @SuppressWarnings("unchecked")\r
+ public ScoreManager getResults(String workDirectory)\r
+ throws ResultNotAvailableException {\r
+\r
+ ScoreManager results = null;\r
+ try {\r
+\r
+ Map<String, Score> globScores = SequenceUtil.readIUPred(new File(\r
+ workDirectory, getOutput() + GLOB_SUFFIX));\r
+ Map<String, Score> shortScores = SequenceUtil.readIUPred(new File(\r
+ workDirectory, getOutput() + SHORT_SUFFIX));\r
+ Map<String, Score> longScores = SequenceUtil.readIUPred(new File(\r
+ workDirectory, getOutput() + LONG_SUFFIX));\r
+ Map<String, Set<Score>> combined = new TreeMap<String, Set<Score>>();\r
+ for (String key : globScores.keySet()) {\r
+ Set<Score> all = new TreeSet<Score>();\r
+ Score globsc = globScores.get(key);\r
+ assert globsc != null;\r
+ Score shortsc = shortScores.get(key);\r
+ assert shortsc != null;\r
+ all.add(shortsc);\r
+ Score longsc = longScores.get(key);\r
+ assert longsc != null;\r
+ all.add(longsc);\r
+ combined.put(key, all);\r
+ }\r
+ results = ScoreManager.newInstance(combined);\r
+\r
+ } catch (FileNotFoundException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ } catch (IOException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ } catch (UnknownFileFormatException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ } catch (NullPointerException e) {\r
+ log.error(e.getMessage(), e.getCause());\r
+ throw new ResultNotAvailableException(e);\r
+ }\r
+ return results;\r
+ }\r
+\r
+ @Override\r
+ public IUPred setInput(String inFile) {\r
+ super.setInput(inFile);\r
+ cbuilder.setFirst(inFile);\r
+ return this;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Class<IUPred> getType() {\r
+ return (Class<IUPred>) this.getClass();\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (c) 2011 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.runner.disorder;\r
+\r
+import static org.testng.Assert.assertEquals;\r
+import static org.testng.Assert.assertFalse;\r
+import static org.testng.Assert.assertNotNull;\r
+import static org.testng.Assert.assertNull;\r
+import static org.testng.Assert.assertTrue;\r
+import static org.testng.Assert.fail;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.text.ParseException;\r
+\r
+import javax.xml.bind.ValidationException;\r
+\r
+import org.ggf.drmaa.DrmaaException;\r
+import org.ggf.drmaa.JobInfo;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.data.sequence.ScoreManager;\r
+import compbio.engine.AsyncExecutor;\r
+import compbio.engine.Configurator;\r
+import compbio.engine.SyncExecutor;\r
+import compbio.engine.client.ConfExecutable;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.Executable;\r
+import compbio.engine.client.RunConfiguration;\r
+import compbio.engine.cluster.drmaa.ClusterUtil;\r
+import compbio.engine.cluster.drmaa.JobRunner;\r
+import compbio.engine.cluster.drmaa.StatisticManager;\r
+import compbio.engine.local.LocalRunner;\r
+import compbio.metadata.AllTestSuit;\r
+import compbio.metadata.JobExecutionException;\r
+import compbio.metadata.JobStatus;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.LimitsManager;\r
+import compbio.metadata.PresetManager;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.metadata.RunnerConfig;\r
+import compbio.util.SysPrefs;\r
+\r
+public class IUPredTester {\r
+\r
+ public static String test_outfile = "output";\r
+\r
+ private IUPred iupred;\r
+\r
+ @BeforeMethod(alwaysRun = true)\r
+ void init() {\r
+ iupred = new IUPred();\r
+ iupred.setInput(AllTestSuit.test_input).setOutput(test_outfile);\r
+ }\r
+\r
+ @Test(groups = {AllTestSuit.test_group_cluster,\r
+ AllTestSuit.test_group_runner})\r
+ public void testRunOnCluster() {\r
+ assertFalse(SysPrefs.isWindows,\r
+ "Cluster execution can only be in unix environment");\r
+ try {\r
+ ConfiguredExecutable<IUPred> confIUPred = Configurator\r
+ .configureExecutable(iupred,\r
+ Executable.ExecProvider.Cluster);\r
+ JobRunner runner = JobRunner.getInstance(confIUPred);\r
+\r
+ assertNotNull(runner, "Runner is NULL");\r
+ runner.executeJob();\r
+ // assertNotNull("JobId is null", jobId1);\r
+ JobStatus status = runner.getJobStatus();\r
+ assertTrue(status == JobStatus.PENDING\r
+ || status == JobStatus.RUNNING,\r
+ "Status of the process is wrong!");\r
+ JobInfo info = runner.getJobInfo();\r
+ assertNotNull(info, "JobInfo is null");\r
+ StatisticManager sm = new StatisticManager(info);\r
+ assertNotNull(sm, "Statictic manager is null");\r
+ try {\r
+\r
+ String exits = sm.getExitStatus();\r
+ assertNotNull("Exit status is null", exits);\r
+ // cut 4 trailing zeros from the number\r
+ int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits)\r
+ .intValue();\r
+ assertEquals(0, exitsInt);\r
+ System.out.println(sm.getAllStats());\r
+\r
+ } catch (ParseException e) {\r
+ e.printStackTrace();\r
+ fail("Parse Exception: " + e.getMessage());\r
+ }\r
+ // assertFalse(runner.cleanup());\r
+ assertTrue(sm.hasExited());\r
+ assertFalse(sm.wasAborted());\r
+ assertFalse(sm.hasDump());\r
+ assertFalse(sm.hasSignaled());\r
+\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail("DrmaaException caught:" + e.getMessage());\r
+ } catch (JobExecutionException e) {\r
+ e.printStackTrace();\r
+ fail("DrmaaException caught:" + e.getMessage());\r
+ } catch (DrmaaException e) {\r
+ e.printStackTrace();\r
+ fail("DrmaaException caught:" + e.getMessage());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * This tests fails from time to time depending on the cluster load or some\r
+ * other factors. Any client code has to adjust for this issue\r
+ */\r
+ @Test(groups = {AllTestSuit.test_group_cluster,\r
+ AllTestSuit.test_group_runner})\r
+ public void testRunOnClusterAsync() {\r
+ assertFalse(SysPrefs.isWindows,\r
+ "Cluster execution can only be in unix environment");\r
+ try {\r
+ ConfiguredExecutable<IUPred> confIUPred = Configurator\r
+ .configureExecutable(iupred,\r
+ Executable.ExecProvider.Cluster);\r
+ AsyncExecutor aengine = Configurator.getAsyncEngine(confIUPred);\r
+ String jobId = aengine.submitJob(confIUPred);\r
+ assertNotNull(jobId, "Runner is NULL");\r
+ // let drmaa to start\r
+ Thread.sleep(500);\r
+ JobStatus status = aengine.getJobStatus(jobId);\r
+ while (status != JobStatus.FINISHED) {\r
+ System.out.println("Job Status: " + status);\r
+ Thread.sleep(1000);\r
+ status = aengine.getJobStatus(jobId);\r
+ ConfiguredExecutable<IUPred> result = (ConfiguredExecutable<IUPred>) aengine\r
+ .getResults(jobId);\r
+ assertNotNull(result);\r
+ System.out.println("RES:" + result);\r
+ // Some times the job could be removed from the cluster\r
+ // accounting\r
+ // before it has been reported to finish. Make sure\r
+ // to stop waiting in such case\r
+ if (status == JobStatus.UNDEFINED) {\r
+ break;\r
+ }\r
+ }\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail("DrmaaException caught:" + e.getMessage());\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ } catch (ResultNotAvailableException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Test(groups = {AllTestSuit.test_group_runner})\r
+ public void testRunLocally() {\r
+ try {\r
+ ConfiguredExecutable<IUPred> confIUPred = Configurator\r
+ .configureExecutable(iupred, Executable.ExecProvider.Local);\r
+\r
+ // For local execution use relative\r
+ LocalRunner lr = new LocalRunner(confIUPred);\r
+ lr.executeJob();\r
+ ConfiguredExecutable<?> al1 = lr.waitForResult();\r
+ assertNotNull(al1.getResults());\r
+ ScoreManager al2 = confIUPred.getResults();\r
+ assertNotNull(al2);\r
+ assertEquals(al2.asMap().size(), 3);\r
+ assertEquals(al1.getResults(), al2);\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (ResultNotAvailableException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (JobExecutionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+ @Test(groups = {AllTestSuit.test_group_runner})\r
+ public void readStatistics() {\r
+ // No execution statistics is available!\r
+ }\r
+\r
+ @Test(groups = {AllTestSuit.test_group_runner})\r
+ public void testPersistance() {\r
+ try {\r
+ IUPred disembl = new IUPred();\r
+ disembl.setError("errrr.txt").setInput(AllTestSuit.test_input)\r
+ .setOutput("outtt.txt");\r
+ assertEquals(disembl.getInput(), AllTestSuit.test_input);\r
+ assertEquals(disembl.getError(), "errrr.txt");\r
+ assertEquals(disembl.getOutput(), "outtt.txt");\r
+ ConfiguredExecutable<IUPred> cIUPred = Configurator\r
+ .configureExecutable(disembl, Executable.ExecProvider.Local);\r
+\r
+ SyncExecutor sexec = Configurator.getSyncEngine(cIUPred);\r
+ sexec.executeJob();\r
+ ConfiguredExecutable<?> al = sexec.waitForResult();\r
+ assertNotNull(al.getResults());\r
+ // Save run configuration\r
+ assertTrue(cIUPred.saveRunConfiguration());\r
+\r
+ // See if loaded configuration is the same as saved\r
+ RunConfiguration loadedRun = RunConfiguration\r
+ .load(new FileInputStream(new File(cIUPred\r
+ .getWorkDirectory(), RunConfiguration.rconfigFile)));\r
+ assertEquals(\r
+ ((ConfExecutable<IUPred>) cIUPred).getRunConfiguration(),\r
+ loadedRun);\r
+ // Load run configuration as ConfExecutable\r
+ ConfiguredExecutable<IUPred> resurrectedCIUPred = (ConfiguredExecutable<IUPred>) cIUPred\r
+ .loadRunConfiguration(new FileInputStream(new File(cIUPred\r
+ .getWorkDirectory(), RunConfiguration.rconfigFile)));\r
+ assertNotNull(resurrectedCIUPred);\r
+ assertEquals(resurrectedCIUPred.getExecutable().getInput(),\r
+ AllTestSuit.test_input);\r
+ assertEquals(resurrectedCIUPred.getExecutable().getError(),\r
+ "errrr.txt");\r
+ assertEquals(resurrectedCIUPred.getExecutable().getOutput(),\r
+ "outtt.txt");\r
+ // See in details whether executables are the same\r
+ assertEquals(resurrectedCIUPred.getExecutable(), disembl);\r
+\r
+ ConfiguredExecutable<IUPred> resIUPred = Configurator\r
+ .configureExecutable(resurrectedCIUPred.getExecutable(),\r
+ Executable.ExecProvider.Local);\r
+\r
+ sexec = Configurator.getSyncEngine(resIUPred,\r
+ Executable.ExecProvider.Local);\r
+ sexec.executeJob();\r
+ al = sexec.waitForResult();\r
+ assertNotNull(al);\r
+\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ } catch (JobExecutionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ } catch (ResultNotAvailableException e) {\r
+ e.printStackTrace();\r
+ fail(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Test(groups = {AllTestSuit.test_group_runner})\r
+ public void testConfigurationLoading() {\r
+ try {\r
+ RunnerConfig<IUPred> disemblConfig = ConfExecutable\r
+ .getRunnerOptions(IUPred.class);\r
+ // There is no disembl parameters\r
+ assertNull(disemblConfig);\r
+\r
+ // If there were a IUPredParameter.xml file and reference to it,\r
+ // it would be like that\r
+ // assertTrue(disemblConfig.getArguments().size() == 0);\r
+\r
+ PresetManager<IUPred> disemblPresets = ConfExecutable\r
+ .getRunnerPresets(IUPred.class);\r
+ assertNull(disemblPresets); // there is no presets\r
+\r
+ LimitsManager<IUPred> disemblLimits = ConfExecutable\r
+ .getRunnerLimits(IUPred.class);\r
+ assertNotNull(disemblLimits);\r
+ assertTrue(disemblLimits.getLimits().size() > 0);\r
+ disemblLimits.validate(disemblPresets);\r
+\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (ValidationException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+}\r