JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / io / TCoffeeScoreFileTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
22
23 import jalview.io.TCoffeeScoreFile.Block;
24 import jalview.io.TCoffeeScoreFile.Header;
25
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.util.List;
30
31 import org.testng.AssertJUnit;
32 import org.testng.annotations.Test;
33
34 public class TCoffeeScoreFileTest
35 {
36
37   final static File SCORE_FILE = new File(
38           "test/jalview/io/tcoffee.score_ascii");
39
40   final static File ALIGN_FILE = new File(
41           "test/jalview/io/tcoffee.fasta_aln");
42
43   @Test(groups = { "Functional" })
44   public void testReadHeader() throws IOException
45   {
46
47     TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),
48             AppletFormatAdapter.FILE);
49     AssertJUnit.assertTrue(scoreFile.getWarningMessage(),
50             scoreFile.isValid());
51
52     Header header = scoreFile.header;
53     AssertJUnit.assertNotNull(header);
54     AssertJUnit
55             .assertEquals(
56                     "T-COFFEE, Version_9.02.r1228 (2012-02-16 18:15:12 - Revision 1228 - Build 336)",
57                     header.head);
58     AssertJUnit.assertEquals(90, header.score);
59     AssertJUnit.assertEquals(89, header.getScoreFor("1PHT"));
60     AssertJUnit.assertEquals(90, header.getScoreFor("1BB9"));
61     AssertJUnit.assertEquals(94, header.getScoreFor("1UHC"));
62     AssertJUnit.assertEquals(94, header.getScoreFor("1YCS"));
63     AssertJUnit.assertEquals(93, header.getScoreFor("1OOT"));
64     AssertJUnit.assertEquals(94, header.getScoreFor("1ABO"));
65     AssertJUnit.assertEquals(94, header.getScoreFor("1FYN"));
66     AssertJUnit.assertEquals(94, header.getScoreFor("1QCF"));
67     AssertJUnit.assertEquals(90, header.getScoreFor("cons"));
68   }
69
70   @Test(groups = { "Functional" })
71   public void testWrongFile()
72   {
73     try
74     {
75       TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(),
76               FormatAdapter.FILE);
77       AssertJUnit.assertFalse(result.isValid());
78     } catch (IOException x)
79     {
80       AssertJUnit.assertTrue("File not found exception thrown",
81               x instanceof FileNotFoundException);
82     }
83   }
84
85   @Test(groups = { "Functional" })
86   public void testHeightAndWidth() throws IOException
87   {
88     TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(),
89             FormatAdapter.FILE);
90     AssertJUnit.assertTrue(result.isValid());
91     AssertJUnit.assertEquals(8, result.getHeight());
92     AssertJUnit.assertEquals(83, result.getWidth());
93   }
94
95   @Test(groups = { "Functional" })
96   public void testReadBlock() throws IOException
97   {
98
99     String BLOCK = "\n" + "\n" + "\n"
100             + "1PHT   999999999999999999999999998762112222543211112134\n"
101             + "1BB9   99999999999999999999999999987-------4322----2234  \n"
102             + "1UHC   99999999999999999999999999987-------5321----2246\n"
103             + "1YCS   99999999999999999999999999986-------4321----1-35\n"
104             + "1OOT   999999999999999999999999999861-------3------1135  \n"
105             + "1ABO   99999999999999999999999999986-------422-------34\n"
106             + "1FYN   99999999999999999999999999985-------32--------35\n"
107             + "1QCF   99999999999999999999999999974-------2---------24\n"
108             + "cons   999999999999999999999999999851000110321100001134\n"
109             + "\n" + "\n";
110     FileParse source = new FileParse(BLOCK, FormatAdapter.PASTE);
111     Block block = TCoffeeScoreFile.readBlock(source, 0);
112
113     AssertJUnit.assertNotNull(block);
114     AssertJUnit.assertEquals(
115             "999999999999999999999999998762112222543211112134",
116             block.getScoresFor("1PHT"));
117     AssertJUnit.assertEquals(
118             "99999999999999999999999999987-------4322----2234",
119             block.getScoresFor("1BB9"));
120     AssertJUnit.assertEquals(
121             "99999999999999999999999999987-------5321----2246",
122             block.getScoresFor("1UHC"));
123     AssertJUnit.assertEquals(
124             "99999999999999999999999999986-------4321----1-35",
125             block.getScoresFor("1YCS"));
126     AssertJUnit.assertEquals(
127             "999999999999999999999999999861-------3------1135",
128             block.getScoresFor("1OOT"));
129     AssertJUnit.assertEquals(
130             "99999999999999999999999999986-------422-------34",
131             block.getScoresFor("1ABO"));
132     AssertJUnit.assertEquals(
133             "99999999999999999999999999985-------32--------35",
134             block.getScoresFor("1FYN"));
135     AssertJUnit.assertEquals(
136             "99999999999999999999999999974-------2---------24",
137             block.getScoresFor("1QCF"));
138     AssertJUnit.assertEquals(
139             "999999999999999999999999999851000110321100001134",
140             block.getConsensus());
141   }
142
143   @Test(groups = { "Functional" })
144   public void testParse() throws IOException
145   {
146
147     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
148             FormatAdapter.FILE);
149
150     AssertJUnit
151             .assertEquals(
152                     "999999999999999999999999998762112222543211112134----------5666642367889999999999889",
153                     parser.getScoresFor("1PHT"));
154     AssertJUnit
155             .assertEquals(
156                     "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889",
157                     parser.getScoresFor("1BB9"));
158     AssertJUnit
159             .assertEquals(
160                     "99999999999999999999999999987-------5321----2246----------788774--66789999999999889",
161                     parser.getScoresFor("1UHC"));
162     AssertJUnit
163             .assertEquals(
164                     "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889",
165                     parser.getScoresFor("1YCS"));
166     AssertJUnit
167             .assertEquals(
168                     "999999999999999999999999999861-------3------1135----------78877--356789999999997-67",
169                     parser.getScoresFor("1OOT"));
170     AssertJUnit
171             .assertEquals(
172                     "99999999999999999999999999986-------422-------34----------687774--56779999999999889",
173                     parser.getScoresFor("1ABO"));
174     AssertJUnit
175             .assertEquals(
176                     "99999999999999999999999999985-------32--------35----------6888842356789999999999889",
177                     parser.getScoresFor("1FYN"));
178     AssertJUnit
179             .assertEquals(
180                     "99999999999999999999999999974-------2---------24----------6878742356789999999999889",
181                     parser.getScoresFor("1QCF"));
182     AssertJUnit
183             .assertEquals(
184                     "99999999999999999999999999985100011032110000113400100000006877641356789999999999889",
185                     parser.getScoresFor("cons"));
186   }
187
188   @Test(groups = { "Functional" })
189   public void testGetAsList() throws IOException
190   {
191
192     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
193             FormatAdapter.FILE);
194     AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
195     List<String> scores = parser.getScoresList();
196     AssertJUnit
197             .assertEquals(
198                     "999999999999999999999999998762112222543211112134----------5666642367889999999999889",
199                     scores.get(0));
200     AssertJUnit
201             .assertEquals(
202                     "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889",
203                     scores.get(1));
204     AssertJUnit
205             .assertEquals(
206                     "99999999999999999999999999987-------5321----2246----------788774--66789999999999889",
207                     scores.get(2));
208     AssertJUnit
209             .assertEquals(
210                     "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889",
211                     scores.get(3));
212     AssertJUnit
213             .assertEquals(
214                     "999999999999999999999999999861-------3------1135----------78877--356789999999997-67",
215                     scores.get(4));
216     AssertJUnit
217             .assertEquals(
218                     "99999999999999999999999999986-------422-------34----------687774--56779999999999889",
219                     scores.get(5));
220     AssertJUnit
221             .assertEquals(
222                     "99999999999999999999999999985-------32--------35----------6888842356789999999999889",
223                     scores.get(6));
224     AssertJUnit
225             .assertEquals(
226                     "99999999999999999999999999974-------2---------24----------6878742356789999999999889",
227                     scores.get(7));
228     AssertJUnit
229             .assertEquals(
230                     "99999999999999999999999999985100011032110000113400100000006877641356789999999999889",
231                     scores.get(8));
232
233   }
234
235   @Test(groups = { "Functional" })
236   public void testGetAsArray() throws IOException
237   {
238
239     TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
240             FormatAdapter.FILE);
241     AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
242     byte[][] scores = parser.getScoresArray();
243
244     AssertJUnit.assertEquals(9, scores[0][0]);
245     AssertJUnit.assertEquals(9, scores[1][0]);
246     AssertJUnit.assertEquals(9, scores[2][0]);
247     AssertJUnit.assertEquals(9, scores[3][0]);
248     AssertJUnit.assertEquals(9, scores[4][0]);
249     AssertJUnit.assertEquals(9, scores[5][0]);
250     AssertJUnit.assertEquals(9, scores[6][0]);
251     AssertJUnit.assertEquals(9, scores[7][0]);
252     AssertJUnit.assertEquals(9, scores[8][0]);
253
254     AssertJUnit.assertEquals(5, scores[0][36]);
255     AssertJUnit.assertEquals(4, scores[1][36]);
256     AssertJUnit.assertEquals(5, scores[2][36]);
257     AssertJUnit.assertEquals(4, scores[3][36]);
258     AssertJUnit.assertEquals(-1, scores[4][36]);
259     AssertJUnit.assertEquals(4, scores[5][36]);
260     AssertJUnit.assertEquals(3, scores[6][36]);
261     AssertJUnit.assertEquals(2, scores[7][36]);
262     AssertJUnit.assertEquals(3, scores[8][36]);
263
264   }
265
266   @Test(groups = { "Functional" })
267   public void testHeightAndWidthWithResidueNumbers() throws Exception
268   {
269     String file = "test/jalview/io/tcoffee.score_ascii_with_residue_numbers";
270     TCoffeeScoreFile result = new TCoffeeScoreFile(file, FormatAdapter.FILE);
271     AssertJUnit.assertTrue(result.isValid());
272     AssertJUnit.assertEquals(5, result.getHeight());
273     AssertJUnit.assertEquals(84, result.getWidth());
274   }
275
276 }