+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
+ * Copyright (C) 2014 The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.io;
import static org.junit.Assert.*;
import jalview.io.TCoffeeScoreFile.Block;
import jalview.io.TCoffeeScoreFile.Header;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
-import java.io.StringReader;
import java.util.List;
import org.junit.Test;
public class TCoffeeScoreFileTest {
- final static File SCORE_FILE = new File("./test/jalview/io/tcoffee.score_ascii");
+ final static File SCORE_FILE = new File("test/jalview/io/tcoffee.score_ascii");
+ final static File ALIGN_FILE = new File("test/jalview/io/tcoffee.fasta_aln");
@Test
- public void testReadHeader() throws FileNotFoundException {
+ public void testReadHeader() throws IOException, FileNotFoundException {
- Header header = TCoffeeScoreFile.readHeader( new BufferedReader(new FileReader(SCORE_FILE)) );
+ TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),AppletFormatAdapter.FILE);
+ assertTrue(scoreFile.getWarningMessage(),scoreFile.isValid());
+
+ Header header = scoreFile.header;
assertNotNull(header);
assertEquals( "T-COFFEE, Version_9.02.r1228 (2012-02-16 18:15:12 - Revision 1228 - Build 336)", header.head );
assertEquals( 90, header.score );
@Test
public void testWrongFile() {
- TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.fasta_aln"));
- assertNull(result);
+ try {
+ TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(), FormatAdapter.FILE);
+ assertFalse(result.isValid());
+ }
+ catch (IOException x)
+ {
+ assertTrue("File not found exception thrown",x instanceof FileNotFoundException);
+ }
}
@Test
- public void testHeightAndWidth() {
- TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.score_ascii"));
- assertNotNull(result);
+ public void testHeightAndWidth() throws IOException {
+ TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
+ assertTrue(result.isValid());
assertEquals( 8, result.getHeight() );
assertEquals( 83, result.getWidth() );
}
"cons 999999999999999999999999999851000110321100001134\n" +
"\n" +
"\n";
-
- Block block = TCoffeeScoreFile.readBlock(new BufferedReader(new StringReader(BLOCK)), 0);
- assertNotNull(block);
+ FileParse source=new FileParse(BLOCK, FormatAdapter.PASTE);
+ Block block = TCoffeeScoreFile.readBlock(source, 0);
+
+ assertNotNull(block);
assertEquals( "999999999999999999999999998762112222543211112134", block.getScoresFor("1PHT") );
assertEquals( "99999999999999999999999999987-------4322----2234", block.getScoresFor("1BB9") );
assertEquals( "99999999999999999999999999987-------5321----2246", block.getScoresFor("1UHC") );
}
@Test
- public void testParse() throws FileNotFoundException {
+ public void testParse() throws IOException {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", parser.getScoresFor("1PHT") );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", parser.getScoresFor("1BB9") );
@Test
- public void testGetAsList() throws FileNotFoundException {
+ public void testGetAsList() throws IOException {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
-
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
+ assertTrue(parser.getWarningMessage(),parser.isValid());
List<String> scores = parser.getScoresList();
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", scores.get(0) );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", scores.get(1) );
@Test
- public void testGetAsArray() throws FileNotFoundException {
+ public void testGetAsArray() throws IOException {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
-
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
+ assertTrue(parser.getWarningMessage(),parser.isValid());
byte[][] scores = parser.getScoresArray();
assertEquals( 9, scores[0][0] );
}
+ @Test
+ public void testHeightAndWidthWithResidueNumbers() throws IOException {
+ String file = "test/jalview/io/tcoffee.score_ascii_with_residue_numbers";
+ TCoffeeScoreFile result = new TCoffeeScoreFile(file, FormatAdapter.FILE);
+ assertTrue(result.isValid());
+ assertEquals( 5, result.getHeight() );
+ assertEquals( 84, result.getWidth() );
+ }
+
}