Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File TCoffeeScoreFileTest.java

 

Code metrics

0
86
9
1
285
237
10
0.12
9.56
9
1.11

Classes

Class Line # Actions
TCoffeeScoreFileTest 36 86 10 1
0.989473798.9%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ 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.gui.JvOptionPane;
24    import jalview.io.TCoffeeScoreFile.Block;
25    import jalview.io.TCoffeeScoreFile.Header;
26   
27    import java.io.File;
28    import java.io.FileNotFoundException;
29    import java.io.IOException;
30    import java.util.List;
31   
32    import org.testng.AssertJUnit;
33    import org.testng.annotations.BeforeClass;
34    import org.testng.annotations.Test;
35   
 
36    public class TCoffeeScoreFileTest
37    {
38   
 
39  1 toggle @BeforeClass(alwaysRun = true)
40    public void setUpJvOptionPane()
41    {
42  1 JvOptionPane.setInteractiveMode(false);
43  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44    }
45   
46    final static File SCORE_FILE = new File(
47    "test/jalview/io/tcoffee.score_ascii");
48   
49    final static File ALIGN_FILE = new File(
50    "test/jalview/io/tcoffee.fasta_aln");
51   
 
52  1 toggle @Test(groups = { "Functional" })
53    public void testReadHeader() throws IOException
54    {
55   
56  1 TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),
57    DataSourceType.FILE);
58  1 AssertJUnit.assertTrue(scoreFile.getWarningMessage(),
59    scoreFile.isValid());
60   
61  1 Header header = scoreFile.header;
62  1 AssertJUnit.assertNotNull(header);
63  1 AssertJUnit
64    .assertEquals(
65    "T-COFFEE, Version_9.02.r1228 (2012-02-16 18:15:12 - Revision 1228 - Build 336)",
66    header.head);
67  1 AssertJUnit.assertEquals(90, header.score);
68  1 AssertJUnit.assertEquals(89, header.getScoreFor("1PHT"));
69  1 AssertJUnit.assertEquals(90, header.getScoreFor("1BB9"));
70  1 AssertJUnit.assertEquals(94, header.getScoreFor("1UHC"));
71  1 AssertJUnit.assertEquals(94, header.getScoreFor("1YCS"));
72  1 AssertJUnit.assertEquals(93, header.getScoreFor("1OOT"));
73  1 AssertJUnit.assertEquals(94, header.getScoreFor("1ABO"));
74  1 AssertJUnit.assertEquals(94, header.getScoreFor("1FYN"));
75  1 AssertJUnit.assertEquals(94, header.getScoreFor("1QCF"));
76  1 AssertJUnit.assertEquals(90, header.getScoreFor("cons"));
77    }
78   
 
79  1 toggle @Test(groups = { "Functional" })
80    public void testWrongFile()
81    {
82  1 try
83    {
84  1 TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(),
85    DataSourceType.FILE);
86  1 AssertJUnit.assertFalse(result.isValid());
87    } catch (IOException x)
88    {
89  0 AssertJUnit.assertTrue("File not found exception thrown",
90    x instanceof FileNotFoundException);
91    }
92    }
93   
 
94  1 toggle @Test(groups = { "Functional" })
95    public void testHeightAndWidth() throws IOException
96    {
97  1 TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(),
98    DataSourceType.FILE);
99  1 AssertJUnit.assertTrue(result.isValid());
100  1 AssertJUnit.assertEquals(8, result.getHeight());
101  1 AssertJUnit.assertEquals(83, result.getWidth());
102    }
103   
 
104  1 toggle @Test(groups = { "Functional" })
105    public void testReadBlock() throws IOException
106    {
107   
108  1 String BLOCK = "\n" + "\n" + "\n"
109    + "1PHT 999999999999999999999999998762112222543211112134\n"
110    + "1BB9 99999999999999999999999999987-------4322----2234 \n"
111    + "1UHC 99999999999999999999999999987-------5321----2246\n"
112    + "1YCS 99999999999999999999999999986-------4321----1-35\n"
113    + "1OOT 999999999999999999999999999861-------3------1135 \n"
114    + "1ABO 99999999999999999999999999986-------422-------34\n"
115    + "1FYN 99999999999999999999999999985-------32--------35\n"
116    + "1QCF 99999999999999999999999999974-------2---------24\n"
117    + "cons 999999999999999999999999999851000110321100001134\n"
118    + "\n" + "\n";
119  1 FileParse source = new FileParse(BLOCK, DataSourceType.PASTE);
120  1 Block block = TCoffeeScoreFile.readBlock(source, 0);
121   
122  1 AssertJUnit.assertNotNull(block);
123  1 AssertJUnit.assertEquals(
124    "999999999999999999999999998762112222543211112134",
125    block.getScoresFor("1PHT"));
126  1 AssertJUnit.assertEquals(
127    "99999999999999999999999999987-------4322----2234",
128    block.getScoresFor("1BB9"));
129  1 AssertJUnit.assertEquals(
130    "99999999999999999999999999987-------5321----2246",
131    block.getScoresFor("1UHC"));
132  1 AssertJUnit.assertEquals(
133    "99999999999999999999999999986-------4321----1-35",
134    block.getScoresFor("1YCS"));
135  1 AssertJUnit.assertEquals(
136    "999999999999999999999999999861-------3------1135",
137    block.getScoresFor("1OOT"));
138  1 AssertJUnit.assertEquals(
139    "99999999999999999999999999986-------422-------34",
140    block.getScoresFor("1ABO"));
141  1 AssertJUnit.assertEquals(
142    "99999999999999999999999999985-------32--------35",
143    block.getScoresFor("1FYN"));
144  1 AssertJUnit.assertEquals(
145    "99999999999999999999999999974-------2---------24",
146    block.getScoresFor("1QCF"));
147  1 AssertJUnit.assertEquals(
148    "999999999999999999999999999851000110321100001134",
149    block.getConsensus());
150    }
151   
 
152  1 toggle @Test(groups = { "Functional" })
153    public void testParse() throws IOException
154    {
155   
156  1 TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
157    DataSourceType.FILE);
158   
159  1 AssertJUnit
160    .assertEquals(
161    "999999999999999999999999998762112222543211112134----------5666642367889999999999889",
162    parser.getScoresFor("1PHT"));
163  1 AssertJUnit
164    .assertEquals(
165    "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889",
166    parser.getScoresFor("1BB9"));
167  1 AssertJUnit
168    .assertEquals(
169    "99999999999999999999999999987-------5321----2246----------788774--66789999999999889",
170    parser.getScoresFor("1UHC"));
171  1 AssertJUnit
172    .assertEquals(
173    "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889",
174    parser.getScoresFor("1YCS"));
175  1 AssertJUnit
176    .assertEquals(
177    "999999999999999999999999999861-------3------1135----------78877--356789999999997-67",
178    parser.getScoresFor("1OOT"));
179  1 AssertJUnit
180    .assertEquals(
181    "99999999999999999999999999986-------422-------34----------687774--56779999999999889",
182    parser.getScoresFor("1ABO"));
183  1 AssertJUnit
184    .assertEquals(
185    "99999999999999999999999999985-------32--------35----------6888842356789999999999889",
186    parser.getScoresFor("1FYN"));
187  1 AssertJUnit
188    .assertEquals(
189    "99999999999999999999999999974-------2---------24----------6878742356789999999999889",
190    parser.getScoresFor("1QCF"));
191  1 AssertJUnit
192    .assertEquals(
193    "99999999999999999999999999985100011032110000113400100000006877641356789999999999889",
194    parser.getScoresFor("cons"));
195    }
196   
 
197  1 toggle @Test(groups = { "Functional" })
198    public void testGetAsList() throws IOException
199    {
200   
201  1 TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
202    DataSourceType.FILE);
203  1 AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
204  1 List<String> scores = parser.getScoresList();
205  1 AssertJUnit
206    .assertEquals(
207    "999999999999999999999999998762112222543211112134----------5666642367889999999999889",
208    scores.get(0));
209  1 AssertJUnit
210    .assertEquals(
211    "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889",
212    scores.get(1));
213  1 AssertJUnit
214    .assertEquals(
215    "99999999999999999999999999987-------5321----2246----------788774--66789999999999889",
216    scores.get(2));
217  1 AssertJUnit
218    .assertEquals(
219    "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889",
220    scores.get(3));
221  1 AssertJUnit
222    .assertEquals(
223    "999999999999999999999999999861-------3------1135----------78877--356789999999997-67",
224    scores.get(4));
225  1 AssertJUnit
226    .assertEquals(
227    "99999999999999999999999999986-------422-------34----------687774--56779999999999889",
228    scores.get(5));
229  1 AssertJUnit
230    .assertEquals(
231    "99999999999999999999999999985-------32--------35----------6888842356789999999999889",
232    scores.get(6));
233  1 AssertJUnit
234    .assertEquals(
235    "99999999999999999999999999974-------2---------24----------6878742356789999999999889",
236    scores.get(7));
237  1 AssertJUnit
238    .assertEquals(
239    "99999999999999999999999999985100011032110000113400100000006877641356789999999999889",
240    scores.get(8));
241   
242    }
243   
 
244  1 toggle @Test(groups = { "Functional" })
245    public void testGetAsArray() throws IOException
246    {
247   
248  1 TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),
249    DataSourceType.FILE);
250  1 AssertJUnit.assertTrue(parser.getWarningMessage(), parser.isValid());
251  1 byte[][] scores = parser.getScoresArray();
252   
253  1 AssertJUnit.assertEquals(9, scores[0][0]);
254  1 AssertJUnit.assertEquals(9, scores[1][0]);
255  1 AssertJUnit.assertEquals(9, scores[2][0]);
256  1 AssertJUnit.assertEquals(9, scores[3][0]);
257  1 AssertJUnit.assertEquals(9, scores[4][0]);
258  1 AssertJUnit.assertEquals(9, scores[5][0]);
259  1 AssertJUnit.assertEquals(9, scores[6][0]);
260  1 AssertJUnit.assertEquals(9, scores[7][0]);
261  1 AssertJUnit.assertEquals(9, scores[8][0]);
262   
263  1 AssertJUnit.assertEquals(5, scores[0][36]);
264  1 AssertJUnit.assertEquals(4, scores[1][36]);
265  1 AssertJUnit.assertEquals(5, scores[2][36]);
266  1 AssertJUnit.assertEquals(4, scores[3][36]);
267  1 AssertJUnit.assertEquals(-1, scores[4][36]);
268  1 AssertJUnit.assertEquals(4, scores[5][36]);
269  1 AssertJUnit.assertEquals(3, scores[6][36]);
270  1 AssertJUnit.assertEquals(2, scores[7][36]);
271  1 AssertJUnit.assertEquals(3, scores[8][36]);
272   
273    }
274   
 
275  1 toggle @Test(groups = { "Functional" })
276    public void testHeightAndWidthWithResidueNumbers() throws Exception
277    {
278  1 String file = "test/jalview/io/tcoffee.score_ascii_with_residue_numbers";
279  1 TCoffeeScoreFile result = new TCoffeeScoreFile(file, DataSourceType.FILE);
280  1 AssertJUnit.assertTrue(result.isValid());
281  1 AssertJUnit.assertEquals(5, result.getHeight());
282  1 AssertJUnit.assertEquals(84, result.getWidth());
283    }
284   
285    }