Add testing dirs
[proteocache.git] / testsrc / compbio / data / sequence / ClustalAlignmentUtilTester.java
diff --git a/testsrc/compbio/data/sequence/ClustalAlignmentUtilTester.java b/testsrc/compbio/data/sequence/ClustalAlignmentUtilTester.java
new file mode 100644 (file)
index 0000000..812cd6f
--- /dev/null
@@ -0,0 +1,102 @@
+/* Copyright (c) 2009 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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.data.sequence;\r
+\r
+import static org.testng.AssertJUnit.assertEquals;\r
+import static org.testng.AssertJUnit.assertNotNull;\r
+import static org.testng.AssertJUnit.assertTrue;\r
+import static org.testng.AssertJUnit.fail;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileWriter;\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.metadata.AllTestSuit;\r
+\r
+public class ClustalAlignmentUtilTester {\r
+\r
+       @Test()\r
+       public void testReadClustalFile() {\r
+               try {\r
+                       readWriteClustal("TO1381.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+       static void readWriteClustal(String fname) throws IOException,\r
+                       UnknownFileFormatException {\r
+               FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+                               + fname);\r
+               Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);\r
+               assertTrue(seqAl != null);\r
+               assertTrue(seqAl.getSize() == 3);\r
+               assertNotNull(seqAl.getSequences());\r
+               assertEquals(3, seqAl.getSequences().size());\r
+\r
+               // Now try to write the alignment read\r
+               Writer os = new FileWriter(AllTestSuit.TEST_DATA_PATH + fname\r
+                               + ".written");\r
+               ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);\r
+               fio.close();\r
+               os.close();\r
+\r
+               fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname\r
+                               + ".written");\r
+               Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);\r
+               assertTrue(readseqs != null);\r
+               assertTrue(readseqs.getSize() == 3);\r
+               fio.close();\r
+       }\r
+\r
+       @Test()\r
+       public void testReadClustalFileShortNames() {\r
+               try {\r
+                       readWriteClustal("TO1381s.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+       @Test()\r
+       public void testReadClustalFileLongNames() {\r
+               try {\r
+                       readWriteClustal("TO1381L.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+}\r