Bug Fixg: testing RNAalifold jobs have been considered as real ones
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Mon, 30 Sep 2013 13:29:33 +0000 (14:29 +0100)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Mon, 30 Sep 2013 13:29:33 +0000 (14:29 +0100)
webservices/compbio/stat/collector/InputFilter.java
webservices/compbio/ws/client/WSTester.java

index 03466fe..3b2f45f 100644 (file)
@@ -14,6 +14,7 @@ import compbio.ws.client.WSTester;
 public class InputFilter {\r
 \r
        private static final Logger log = Logger.getLogger(InputFilter.class);\r
+\r
        /**\r
         * Accepts input as valid unless it is a test input\r
         * \r
@@ -28,12 +29,17 @@ public class InputFilter {
                assert fastainput.length == 4;\r
                String[] aligninput = WSTester.fastaAlignment.split("\n");\r
                assert aligninput.length == 4;\r
+               String[] rnaaligninput = WSTester.clustalRNAAlignment.split("\n");\r
+               assert aligninput.length == 5;\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
+               if (!isReference) {\r
+                       isReference = compareClustalLines(input, rnaaligninput);\r
+               }\r
                // only accept genuine input\r
                return !isReference;\r
        }\r
@@ -45,7 +51,7 @@ public class InputFilter {
                        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
+                       for (int i = 0; i < reference.length; i++) {\r
                                String line = reader.readLine();\r
                                if (Util.isEmpty(line)) {\r
                                        status = false;\r
@@ -65,4 +71,32 @@ public class InputFilter {
                }\r
                return status;\r
        }\r
+\r
+       private static boolean compareClustalLines(File input, String[] reference) {\r
+               BufferedReader reader = null;\r
+               boolean status = true;\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
+                       int i = 0;\r
+                       String line;\r
+                       while (null != (line = reader.readLine())) {\r
+                               if (!Util.isEmpty(line)) {\r
+                                       line = line.trim();\r
+                                       if (!line.equals(reference[i].trim())) {\r
+                                               status = false;\r
+                                               break;\r
+                                       }\r
+                                       ++i;\r
+                               }\r
+                       }\r
+                       reader.close();\r
+               } catch (IOException ioe) {\r
+                       log.warn(ioe, ioe.getCause());\r
+               } finally {\r
+                       FileUtil.closeSilently(reader);\r
+               }\r
+               return status;\r
+       }\r
 }\r
index 928288c..5450a1d 100644 (file)
@@ -80,6 +80,12 @@ public class WSTester {
                        ">Foo\nC-UUGCGUUAAUGAGAACAGAAACG-UAAA--CUAUAA-CCUAG-G-GGUUUCUGUUGGAUGGUUG----GCAAC\n"\r
                +   ">Bar\nG-UGGCGCUUAUGACGCAGUUGUCU-UAAA-CUCGAAC--UCGA-GCGGGCAAUUGCUGAU-UACGAUUAACCAC\n";\r
 \r
+       public static final String clustalRNAAlignment = \r
+                       "CLUSTAL\n" +\r
+                       "Foo             C-UUGCGUUAAUGAGAACAGAAACG-UAAA--CUAUAA-CCUAG-G-GGUUUCUGUUGGA\n" +\r
+                       "Bar             G-UGGCGCUUAUGACGCAGUUGUCU-UAAA-CUCGAAC--UCGA-GCGGGCAAUUGCUGA\n" +\r
+                       "Foo             UGGUUG----GCAAC\n" +\r
+                       "Bar             U-UACGAUUAACCAC";\r
        /**\r
         * Status strings\r
         */\r