+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class ScoreMatrixFileTest
{
+ @AfterMethod(alwaysRun = true)
+ public void tearDownAfterTest()
+ {
+ ScoreModels.getInstance().reset();
+ }
+
/**
* Test a successful parse of a (small) score matrix file
*
*/
@Test(groups = "Functional")
public void testParseMatrix_ncbiMixedDelimiters()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
/*
* some messy but valid input data, with comma, space
fail("expected exception");
} catch (IOException e)
{
- assertEquals(
- e.getMessage(),
+ assertEquals(e.getMessage(),
"Format error: expected 'ScoreMatrix <name>', found 'ScoreMatrix' at line 1");
}
}
* @throws MalformedURLException
*/
@Test(groups = "Functional")
- public void testParseMatrix_ncbiFormat() throws MalformedURLException,
- IOException
+ public void testParseMatrix_ncbiFormat()
+ throws MalformedURLException, IOException
{
// input including comment and blank lines
String data = "ScoreMatrix MyTest\n#comment\n\n" + "\tA\tB\tC\n"
FileParse fp = new FileParse(data, DataSourceType.PASTE);
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
ScoreMatrix sm = parser.parseMatrix();
-
+
assertNotNull(sm);
assertEquals(sm.getName(), "MyTest");
assertEquals(parser.getMatrixName(), "MyTest");
*/
@Test(groups = "Functional")
public void testParseMatrix_aaIndexBlosum80()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
FileParse fp = new FileParse("resources/scoreModel/blosum80.scm",
DataSourceType.FILE);
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
ScoreMatrix sm = parser.parseMatrix();
-
+
assertNotNull(sm);
assertEquals(sm.getName(), "HENS920103");
assertEquals(sm.getDescription(),
* @throws MalformedURLException
*/
@Test(groups = "Functional")
- public void testParseMatrix_aaindexFormat() throws MalformedURLException,
- IOException
+ public void testParseMatrix_aaindexFormat()
+ throws MalformedURLException, IOException
{
/*
* aaindex format has scores for diagonal and below only
String data = "H MyTest\n" + "D My description\n" + "R PMID:1438297\n"
+ "A Authors, names\n" + "T Journal title\n"
+ "J Journal reference\n" + "* matrix in 1/3 Bit Units\n"
- + "M rows = ABC, cols = ABC\n" + "A\t1.0\n"
- + "B\t4.0\t5.0\n"
+ + "M rows = ABC, cols = ABC\n" + "A\t1.0\n" + "B\t4.0\t5.0\n"
+ "C\t7.0\t8.0\t9.0\n";
FileParse fp = new FileParse(data, DataSourceType.PASTE);
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
ScoreMatrix sm = parser.parseMatrix();
-
+
assertNotNull(sm);
assertEquals(sm.getSize(), 3);
assertEquals(sm.getName(), "MyTest");
@Test(groups = "Functional")
public void testParseMatrix_aaindex_mMissing()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
/*
* aaindex format but M cols=, rows= is missing
*/
- String data = "H MyTest\n" + "A\t1.0\n"
- + "B\t4.0\t5.0\n"
+ String data = "H MyTest\n" + "A\t1.0\n" + "B\t4.0\t5.0\n"
+ "C\t7.0\t8.0\t9.0\n";
FileParse fp = new FileParse(data, DataSourceType.PASTE);
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
@Test(groups = "Functional")
public void testParseMatrix_aaindex_rowColMismatch()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
String data = "H MyTest\n" + "M rows=ABC, cols=ABD\n" + "A\t1.0\n"
- + "B\t4.0\t5.0\n"
- + "C\t7.0\t8.0\t9.0\n";
+ + "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n";
FileParse fp = new FileParse(data, DataSourceType.PASTE);
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
try
fail("Expected exception");
} catch (FileFormatException e)
{
- assertEquals(
- e.getMessage(),
+ assertEquals(e.getMessage(),
"Unexpected aaIndex score matrix data at line 2: M rows=ABC, cols=ABD rows != cols");
}
}
@Test(groups = "Functional")
public void testParseMatrix_aaindex_tooManyRows()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n"
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n" + "C\t7.0\t8.0\t9.0\n";
@Test(groups = "Functional")
public void testParseMatrix_aaindex_extraDataLines()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n"
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n" + "something extra\n";
@Test(groups = "Functional")
public void testParseMatrix_aaindex_tooFewColumns()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n"
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\n";
fail("Expected exception");
} catch (FileFormatException e)
{
- assertEquals(
- e.getMessage(),
+ assertEquals(e.getMessage(),
"Expected 3 scores at line 5: 'C\t7.0\t8.0' but found 2");
}
}
* @throws MalformedURLException
*/
@Test(groups = "Functional")
- public void testParse_ncbiFormat() throws MalformedURLException,
- IOException
+ public void testParse_ncbiFormat()
+ throws MalformedURLException, IOException
{
assertNull(ScoreModels.getInstance().getScoreModel("MyNewTest", null));
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
parser.parse();
-
- ScoreMatrix sm = (ScoreMatrix) ScoreModels.getInstance().getScoreModel(
- "MyNewTest", null);
+
+ ScoreMatrix sm = (ScoreMatrix) ScoreModels.getInstance()
+ .getScoreModel("MyNewTest", null);
assertNotNull(sm);
assertEquals(sm.getName(), "MyNewTest");
assertEquals(parser.getMatrixName(), "MyNewTest");