/*
* Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
* Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
*
* 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 .
*/
package jalview.io;
import static org.junit.Assert.*;
import jalview.io.TCoffeeScoreFile.Block;
import jalview.io.TCoffeeScoreFile.Header;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Test;
import org.xml.sax.SAXException;
import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
public class TCoffeeScoreFileTest {
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 IOException {
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 );
assertEquals( 89, header.getScoreFor("1PHT") );
assertEquals( 90, header.getScoreFor("1BB9") );
assertEquals( 94, header.getScoreFor("1UHC") );
assertEquals( 94, header.getScoreFor("1YCS") );
assertEquals( 93, header.getScoreFor("1OOT") );
assertEquals( 94, header.getScoreFor("1ABO") );
assertEquals( 94, header.getScoreFor("1FYN") );
assertEquals( 94, header.getScoreFor("1QCF") );
assertEquals( 90, header.getScoreFor("cons") );
}
@Test
public void testWrongFile() {
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() throws IOException {
TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
assertTrue(result.isValid());
assertEquals( 8, result.getHeight() );
assertEquals( 83, result.getWidth() );
}
@Test
public void testReadBlock( ) throws IOException {
String BLOCK = "\n" +
"\n" +
"\n" +
"1PHT 999999999999999999999999998762112222543211112134\n" +
"1BB9 99999999999999999999999999987-------4322----2234 \n" +
"1UHC 99999999999999999999999999987-------5321----2246\n" +
"1YCS 99999999999999999999999999986-------4321----1-35\n" +
"1OOT 999999999999999999999999999861-------3------1135 \n" +
"1ABO 99999999999999999999999999986-------422-------34\n" +
"1FYN 99999999999999999999999999985-------32--------35\n" +
"1QCF 99999999999999999999999999974-------2---------24\n" +
"cons 999999999999999999999999999851000110321100001134\n" +
"\n" +
"\n";
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") );
assertEquals( "99999999999999999999999999986-------4321----1-35", block.getScoresFor("1YCS") );
assertEquals( "999999999999999999999999999861-------3------1135", block.getScoresFor("1OOT") );
assertEquals( "99999999999999999999999999986-------422-------34", block.getScoresFor("1ABO") );
assertEquals( "99999999999999999999999999985-------32--------35", block.getScoresFor("1FYN") );
assertEquals( "99999999999999999999999999974-------2---------24", block.getScoresFor("1QCF") );
assertEquals( "999999999999999999999999999851000110321100001134", block.getConsensus() );
}
@Test
public void testParse() throws IOException {
TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", parser.getScoresFor("1PHT") );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", parser.getScoresFor("1BB9") );
assertEquals( "99999999999999999999999999987-------5321----2246----------788774--66789999999999889", parser.getScoresFor("1UHC") );
assertEquals( "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889", parser.getScoresFor("1YCS") );
assertEquals( "999999999999999999999999999861-------3------1135----------78877--356789999999997-67", parser.getScoresFor("1OOT") );
assertEquals( "99999999999999999999999999986-------422-------34----------687774--56779999999999889", parser.getScoresFor("1ABO") );
assertEquals( "99999999999999999999999999985-------32--------35----------6888842356789999999999889", parser.getScoresFor("1FYN") );
assertEquals( "99999999999999999999999999974-------2---------24----------6878742356789999999999889", parser.getScoresFor("1QCF") );
assertEquals( "99999999999999999999999999985100011032110000113400100000006877641356789999999999889", parser.getScoresFor("cons") );
}
@Test
public void testGetAsList() throws IOException {
TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
assertTrue(parser.getWarningMessage(),parser.isValid());
List scores = parser.getScoresList();
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", scores.get(0) );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", scores.get(1) );
assertEquals( "99999999999999999999999999987-------5321----2246----------788774--66789999999999889", scores.get(2) );
assertEquals( "99999999999999999999999999986-------4321----1-35----------78777--356789999999999889", scores.get(3) );
assertEquals( "999999999999999999999999999861-------3------1135----------78877--356789999999997-67", scores.get(4) );
assertEquals( "99999999999999999999999999986-------422-------34----------687774--56779999999999889", scores.get(5) );
assertEquals( "99999999999999999999999999985-------32--------35----------6888842356789999999999889", scores.get(6) );
assertEquals( "99999999999999999999999999974-------2---------24----------6878742356789999999999889", scores.get(7) );
assertEquals( "99999999999999999999999999985100011032110000113400100000006877641356789999999999889", scores.get(8) );
}
@Test
public void testGetAsArray() throws IOException {
TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
assertTrue(parser.getWarningMessage(),parser.isValid());
byte[][] scores = parser.getScoresArray();
assertEquals( 9, scores[0][0] );
assertEquals( 9, scores[1][0] );
assertEquals( 9, scores[2][0] );
assertEquals( 9, scores[3][0] );
assertEquals( 9, scores[4][0] );
assertEquals( 9, scores[5][0] );
assertEquals( 9, scores[6][0] );
assertEquals( 9, scores[7][0] );
assertEquals( 9, scores[8][0] );
assertEquals( 5, scores[0][36] );
assertEquals( 4, scores[1][36] );
assertEquals( 5, scores[2][36] );
assertEquals( 4, scores[3][36] );
assertEquals( -1, scores[4][36] );
assertEquals( 4, scores[5][36] );
assertEquals( 3, scores[6][36] );
assertEquals( 2, scores[7][36] );
assertEquals( 3, scores[8][36] );
}
@Test
public void testHeightAndWidthWithResidueNumbers() throws Exception {
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() );
}
}