<arguments>\r
</arguments>\r
</buildCommand>\r
+ <buildCommand>\r
+ <name>net.sourceforge.metrics.builder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
</buildSpec>\r
<natures>\r
<nature>org.eclipse.jdt.core.javanature</nature>\r
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>\r
+ <nature>net.sourceforge.metrics.nature</nature>\r
</natures>\r
</projectDescription>\r
--- /dev/null
+package compbio.stat.collector;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.testng.Assert;\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.metadata.AllTestSuit;\r
+\r
+public class TestInputFilter {\r
+\r
+ final static String FASTA_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+ + "TO1381.fasta";\r
+ final static String ALN_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+ + "TO1381L.aln";\r
+ final static String TEST_FASTA_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+ + "test_input.fasta";\r
+ final static String TEST_ALIGNMENT_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+ + "test_input.aln";\r
+ @Test\r
+ public void TestInputFilter() {\r
+ InputFilter ifilter = new InputFilter();\r
+ try {\r
+ // Makes sure real files are accepted\r
+ Assert.assertTrue(ifilter.accept(new File(FASTA_INPUT)));\r
+ Assert.assertTrue(ifilter.accept(new File(ALN_INPUT)));\r
+\r
+ // .. and test files are not\r
+ Assert.assertFalse(ifilter.accept(new File(TEST_ALIGNMENT_INPUT)));\r
+ Assert.assertFalse(ifilter.accept(new File(TEST_FASTA_INPUT)));\r
+ // does not matter if the file is empty, it is still not a test\r
+ // file!\r
+ Assert.assertTrue(ifilter.accept(File.createTempFile("aaa", "bbb")));\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ Assert.fail(e.getMessage());\r
+ }\r
+ }\r
+}\r
--- /dev/null
+>Foo\r
+MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r
+>Bar\r
+ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r
--- /dev/null
+>Foo\r
+MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV\r
+>Bar\r
+ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA\r
}\r
}\r
\r
+ // TODO test!\r
void collectStatistics() {\r
File[] files = workDirectory.listFiles(directories);\r
for (File file : files) {\r
+ if (!InputFilter.accept(new File(file.getPath() + File.separator\r
+ + SkeletalExecutable.INPUT))) {\r
+ // skip work directory with test input\r
+ continue;\r
+ }\r
JobDirectory jd = new JobDirectory(file);\r
JobStat jstat = jd.getJobStat();\r
// Do not record stats on the job that has not completed yet\r
// System.out.println(jd.getJobStat().getJobReportTabulated());\r
}\r
}\r
-\r
@Override\r
public void run() {\r
log.info("Started updating statistics at " + new Date());\r
--- /dev/null
+package compbio.stat.collector;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.util.FileUtil;\r
+import compbio.util.Util;\r
+import compbio.ws.client.WSTester;\r
+\r
+public class InputFilter {\r
+\r
+ private static final Logger log = Logger.getLogger(InputFilter.class);\r
+ /**\r
+ * Accepts input as valid unless it is a test input\r
+ * \r
+ * @param input\r
+ * @return\r
+ */\r
+ static boolean accept(File input) {\r
+ if (input == null)\r
+ return true;\r
+ assert input.isFile() : "Input file is not a file! " + input;\r
+ String[] fastainput = WSTester.fastaInput.split("\n");\r
+ assert fastainput.length == 4;\r
+ String[] aligninput = WSTester.fastaAlignment.split("\n");\r
+ assert aligninput.length == 4;\r
+ // We do now know the type of the input here so must compare with both\r
+ // references\r
+ boolean isReference = compareLines(input, fastainput);\r
+ if (!isReference) {\r
+ isReference = compareLines(input, aligninput);\r
+ }\r
+ // only accept genuine input\r
+ return !isReference;\r
+ }\r
+\r
+ private static boolean compareLines(File input, String[] reference) {\r
+ BufferedReader reader = null;\r
+ try {\r
+ reader = new BufferedReader(new FileReader(input));\r
+ // only compare first four lines of the file with reference\r
+ // because the reference length is only 4 lines\r
+ for (int i = 0; i < 4; i++) {\r
+ String line = reader.readLine();\r
+ if (Util.isEmpty(line)) {\r
+ return false;\r
+ }\r
+ line = line.trim();\r
+ if (!line.equals(reference[i].trim())) {\r
+ return false;\r
+ }\r
+ }\r
+ reader.close();\r
+ } catch (IOException ioe) {\r
+ log.warn(ioe, ioe.getCause());\r
+ } finally {\r
+ FileUtil.closeSilently(reader);\r
+ }\r
+ return true;\r
+ }\r
+}\r
/**\r
* Sequences to be used as input for all WS\r
*/\r
- static final String fastaInput = ">Foo\n"\r
+ public static final String fastaInput = ">Foo\n"\r
+ "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV"\r
+ "\n>Bar\n"\r
- + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA";\r
+ + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA\n";\r
\r
- static final String fastaAlignment = ">Foo\r\n"\r
- + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r\n"\r
- + ">Bar\r\n"\r
- + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r\n"\r
+ public static final String fastaAlignment = ">Foo\n"\r
+ + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\n"\r
+ + ">Bar\n"\r
+ + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\n"\r
+ "";\r
\r
static final List<FastaSequence> seqs = loadSeqs();\r