812cd6f334115fa1fd64e15e2cd795bb23d4a957
[proteocache.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.FileWriter;\r
29 import java.io.IOException;\r
30 import java.io.Writer;\r
31 \r
32 import org.testng.annotations.Test;\r
33 \r
34 import compbio.metadata.AllTestSuit;\r
35 \r
36 public class ClustalAlignmentUtilTester {\r
37 \r
38         @Test()\r
39         public void testReadClustalFile() {\r
40                 try {\r
41                         readWriteClustal("TO1381.aln");\r
42                 } catch (FileNotFoundException e) {\r
43                         e.printStackTrace();\r
44                         fail(e.getMessage());\r
45                 } catch (Exception e) {\r
46                         e.printStackTrace();\r
47                         fail(e.getMessage());\r
48                 }\r
49         }\r
50 \r
51         static void readWriteClustal(String fname) throws IOException,\r
52                         UnknownFileFormatException {\r
53                 FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
54                                 + fname);\r
55                 Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);\r
56                 assertTrue(seqAl != null);\r
57                 assertTrue(seqAl.getSize() == 3);\r
58                 assertNotNull(seqAl.getSequences());\r
59                 assertEquals(3, seqAl.getSequences().size());\r
60 \r
61                 // Now try to write the alignment read\r
62                 Writer os = new FileWriter(AllTestSuit.TEST_DATA_PATH + fname\r
63                                 + ".written");\r
64                 ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);\r
65                 fio.close();\r
66                 os.close();\r
67 \r
68                 fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname\r
69                                 + ".written");\r
70                 Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);\r
71                 assertTrue(readseqs != null);\r
72                 assertTrue(readseqs.getSize() == 3);\r
73                 fio.close();\r
74         }\r
75 \r
76         @Test()\r
77         public void testReadClustalFileShortNames() {\r
78                 try {\r
79                         readWriteClustal("TO1381s.aln");\r
80                 } catch (FileNotFoundException e) {\r
81                         e.printStackTrace();\r
82                         fail(e.getMessage());\r
83                 } catch (Exception e) {\r
84                         e.printStackTrace();\r
85                         fail(e.getMessage());\r
86                 }\r
87         }\r
88 \r
89         @Test()\r
90         public void testReadClustalFileLongNames() {\r
91                 try {\r
92                         readWriteClustal("TO1381L.aln");\r
93                 } catch (FileNotFoundException e) {\r
94                         e.printStackTrace();\r
95                         fail(e.getMessage());\r
96                 } catch (Exception e) {\r
97                         e.printStackTrace();\r
98                         fail(e.getMessage());\r
99                 }\r
100         }\r
101 \r
102 }\r