Next version of JABA
[jabaws.git] / testsrc / compbio / data / sequence / ClustalAlignmentUtilTester.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.data.sequence;\r
20 \r
21 import static org.testng.AssertJUnit.assertEquals;\r
22 import static org.testng.AssertJUnit.assertNotNull;\r
23 import static org.testng.AssertJUnit.assertTrue;\r
24 import static org.testng.AssertJUnit.fail;\r
25 \r
26 import java.io.FileInputStream;\r
27 import java.io.FileNotFoundException;\r
28 import java.io.FileOutputStream;\r
29 import java.io.IOException;\r
30 \r
31 import org.testng.annotations.Test;\r
32 \r
33 import compbio.metadata.AllTestSuit;\r
34 \r
35 public class ClustalAlignmentUtilTester {\r
36 \r
37     @Test()\r
38     public void testReadClustalFile() {\r
39         try {\r
40             readWriteClustal("TO1381.aln");\r
41         } catch (FileNotFoundException e) {\r
42             e.printStackTrace();\r
43             fail(e.getMessage());\r
44         } catch (Exception e) {\r
45             e.printStackTrace();\r
46             fail(e.getMessage());\r
47         }\r
48     }\r
49 \r
50     static void readWriteClustal(String fname) throws IOException,\r
51             UnknownFileFormatException {\r
52         FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
53                 + fname);\r
54         Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);\r
55         assertTrue(seqAl != null);\r
56         assertTrue(seqAl.getSize() == 3);\r
57         assertNotNull(seqAl.getSequences());\r
58         assertEquals(3, seqAl.getSequences().size());\r
59 \r
60         // Now try to write the alignment read\r
61         FileOutputStream os = new FileOutputStream(AllTestSuit.TEST_DATA_PATH\r
62                 + fname + ".written");\r
63         ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);\r
64         fio.close();\r
65         os.close();\r
66 \r
67         fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname\r
68                 + ".written");\r
69         Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);\r
70         assertTrue(readseqs != null);\r
71         assertTrue(readseqs.getSize() == 3);\r
72         fio.close();\r
73     }\r
74 \r
75     @Test()\r
76     public void testReadClustalFileShortNames() {\r
77         try {\r
78             readWriteClustal("TO1381s.aln");\r
79         } catch (FileNotFoundException e) {\r
80             e.printStackTrace();\r
81             fail(e.getMessage());\r
82         } catch (Exception e) {\r
83             e.printStackTrace();\r
84             fail(e.getMessage());\r
85         }\r
86     }\r
87 \r
88     @Test()\r
89     public void testReadClustalFileLongNames() {\r
90         try {\r
91             readWriteClustal("TO1381L.aln");\r
92         } catch (FileNotFoundException e) {\r
93             e.printStackTrace();\r
94             fail(e.getMessage());\r
95         } catch (Exception e) {\r
96             e.printStackTrace();\r
97             fail(e.getMessage());\r
98         }\r
99     }\r
100 \r
101 }\r