X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FScoreMatrixFileTest.java;h=c5890826a04575e96114790442450b8ab6182897;hb=0ae965fc73680bdc69b06986c060ff17342c4787;hp=52ad735beae91dff1ea82fd9fa9488c9d1e14416;hpb=a862a922bf20918fc3f5066ac92e4c69da07e105;p=jalview.git
diff --git a/test/jalview/io/ScoreMatrixFileTest.java b/test/jalview/io/ScoreMatrixFileTest.java
index 52ad735..c589082 100644
--- a/test/jalview/io/ScoreMatrixFileTest.java
+++ b/test/jalview/io/ScoreMatrixFileTest.java
@@ -1,3 +1,23 @@
+/*
+ * 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 .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.io;
import static org.testng.Assert.assertEquals;
@@ -13,11 +33,18 @@ import jalview.analysis.scoremodels.ScoreModels;
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
*
@@ -26,8 +53,7 @@ public class ScoreMatrixFileTest
*/
@Test(groups = "Functional")
public void testParseMatrix_ncbiMixedDelimiters()
- throws MalformedURLException,
- IOException
+ throws MalformedURLException, IOException
{
/*
* some messy but valid input data, with comma, space
@@ -51,6 +77,7 @@ public class ScoreMatrixFileTest
assertNull(sm.getDescription());
assertTrue(sm.isDNA());
assertFalse(sm.isProtein());
+ assertEquals(sm.getMinimumScore(), 1.1f);
assertEquals(sm.getPairwiseScore('A', 'A'), 1.1f);
assertEquals(sm.getPairwiseScore('A', 'T'), 1.2f);
assertEquals(sm.getPairwiseScore('a', 'T'), 1.2f); // A/a equivalent
@@ -58,8 +85,9 @@ public class ScoreMatrixFileTest
assertEquals(sm.getPairwiseScore('a', 't'), 1.4f);
assertEquals(sm.getPairwiseScore('U', 'x'), 3.5f);
assertEquals(sm.getPairwiseScore('u', 'x'), 3.5f);
- assertEquals(sm.getPairwiseScore('U', 'X'), 0f); // X (upper) unmapped
- assertEquals(sm.getPairwiseScore('A', '.'), 0f); // . unmapped
+ // X (upper) and '.' unmapped - get minimum score
+ assertEquals(sm.getPairwiseScore('U', 'X'), 1.1f);
+ assertEquals(sm.getPairwiseScore('A', '.'), 1.1f);
assertEquals(sm.getPairwiseScore('-', '-'), 7.6f);
assertEquals(sm.getPairwiseScore('A', (char) 128), 0f); // out of range
}
@@ -253,8 +281,7 @@ public class ScoreMatrixFileTest
fail("expected exception");
} catch (IOException e)
{
- assertEquals(
- e.getMessage(),
+ assertEquals(e.getMessage(),
"Format error: expected 'ScoreMatrix ', found 'ScoreMatrix' at line 1");
}
}
@@ -266,8 +293,8 @@ public class ScoreMatrixFileTest
* @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"
@@ -276,7 +303,7 @@ public class ScoreMatrixFileTest
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");
@@ -293,14 +320,13 @@ public class ScoreMatrixFileTest
*/
@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(),
@@ -308,7 +334,6 @@ public class ScoreMatrixFileTest
assertFalse(sm.isDNA());
assertTrue(sm.isProtein());
assertEquals(20, sm.getSize());
- assertEquals(sm.getGapIndex(), -1);
assertEquals(sm.getPairwiseScore('A', 'A'), 7f);
assertEquals(sm.getPairwiseScore('A', 'R'), -3f);
@@ -322,8 +347,8 @@ public class ScoreMatrixFileTest
* @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
@@ -331,16 +356,14 @@ public class ScoreMatrixFileTest
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.getGapIndex(), -1);
assertEquals(sm.getName(), "MyTest");
assertEquals(sm.getDescription(), "My description");
assertEquals(sm.getPairwiseScore('A', 'A'), 1.0f);
@@ -356,14 +379,12 @@ public class ScoreMatrixFileTest
@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);
@@ -379,12 +400,10 @@ public class ScoreMatrixFileTest
@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
@@ -393,8 +412,7 @@ public class ScoreMatrixFileTest
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");
}
}
@@ -417,8 +435,7 @@ public class ScoreMatrixFileTest
@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";
@@ -436,8 +453,7 @@ public class ScoreMatrixFileTest
@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";
@@ -455,8 +471,7 @@ public class ScoreMatrixFileTest
@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";
@@ -468,8 +483,7 @@ public class ScoreMatrixFileTest
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");
}
}
@@ -481,10 +495,10 @@ public class ScoreMatrixFileTest
* @throws MalformedURLException
*/
@Test(groups = "Functional")
- public void testParse_ncbiFormat() throws MalformedURLException,
- IOException
+ public void testParse_ncbiFormat()
+ throws MalformedURLException, IOException
{
- assertNull(ScoreModels.getInstance().forName("MyNewTest"));
+ assertNull(ScoreModels.getInstance().getScoreModel("MyNewTest", null));
String data = "ScoreMatrix MyNewTest\n" + "\tA\tB\tC\n"
+ "A\t1.0\t2.0\t3.0\n" + "B\t4.0\t5.0\t6.0\n"
@@ -493,9 +507,9 @@ public class ScoreMatrixFileTest
ScoreMatrixFile parser = new ScoreMatrixFile(fp);
parser.parse();
-
- ScoreMatrix sm = (ScoreMatrix) ScoreModels.getInstance().forName(
- "MyNewTest");
+
+ ScoreMatrix sm = (ScoreMatrix) ScoreModels.getInstance()
+ .getScoreModel("MyNewTest", null);
assertNotNull(sm);
assertEquals(sm.getName(), "MyNewTest");
assertEquals(parser.getMatrixName(), "MyNewTest");