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
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
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
}\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
">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