| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io; |
| 22 |
|
|
| 23 |
|
import static org.testng.Assert.assertEquals; |
| 24 |
|
import static org.testng.Assert.assertFalse; |
| 25 |
|
import static org.testng.Assert.assertNotNull; |
| 26 |
|
import static org.testng.Assert.assertNull; |
| 27 |
|
import static org.testng.Assert.assertTrue; |
| 28 |
|
import static org.testng.Assert.fail; |
| 29 |
|
|
| 30 |
|
import jalview.analysis.scoremodels.ScoreMatrix; |
| 31 |
|
import jalview.analysis.scoremodels.ScoreModels; |
| 32 |
|
|
| 33 |
|
import java.io.IOException; |
| 34 |
|
import java.net.MalformedURLException; |
| 35 |
|
|
| 36 |
|
import org.testng.annotations.AfterMethod; |
| 37 |
|
import org.testng.annotations.Test; |
| 38 |
|
|
| |
|
| 90.8% |
Uncovered Elements: 18 (196) |
Complexity: 39 |
Complexity Density: 0.22 |
|
| 39 |
|
public class ScoreMatrixFileTest |
| 40 |
|
{ |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 42 |
20 |
@AfterMethod(alwaysRun = true)... |
| 43 |
|
public void tearDownAfterTest() |
| 44 |
|
{ |
| 45 |
20 |
ScoreModels.getInstance().reset(); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@throws |
| 52 |
|
@throws |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 54 |
1 |
@Test(groups = "Functional")... |
| 55 |
|
public void testParseMatrix_ncbiMixedDelimiters() |
| 56 |
|
throws MalformedURLException, IOException |
| 57 |
|
{ |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
1 |
String data = "ScoreMatrix MyTest (example)\n" + "A\tT\tU\tt\tx\t-\n" |
| 64 |
|
+ "A,1.1,1.2,1.3,1.4, 1.5, 1.6\n" |
| 65 |
|
+ "T,2.1 2.2 2.3 2.4 2.5 2.6\n" |
| 66 |
|
+ "U\t3.1\t3.2\t3.3\t3.4\t3.5\t3.6\t\n" |
| 67 |
|
+ "t, 5.1,5.3,5.3,5.4,5.5, 5.6\n" |
| 68 |
|
+ "x\t6.1, 6.2 6.3 6.4 6.5 6.6\n" |
| 69 |
|
+ "-, \t7.1\t7.2 7.3, 7.4, 7.5\t,7.6\n"; |
| 70 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 71 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 72 |
1 |
ScoreMatrix sm = parser.parseMatrix(); |
| 73 |
|
|
| 74 |
1 |
assertNotNull(sm); |
| 75 |
1 |
assertEquals(sm.getName(), "MyTest (example)"); |
| 76 |
1 |
assertEquals(sm.getSize(), 6); |
| 77 |
1 |
assertNull(sm.getDescription()); |
| 78 |
1 |
assertTrue(sm.isDNA()); |
| 79 |
1 |
assertFalse(sm.isProtein()); |
| 80 |
1 |
assertEquals(sm.getMinimumScore(), 1.1f); |
| 81 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1.1f); |
| 82 |
1 |
assertEquals(sm.getPairwiseScore('A', 'T'), 1.2f); |
| 83 |
1 |
assertEquals(sm.getPairwiseScore('a', 'T'), 1.2f); |
| 84 |
1 |
assertEquals(sm.getPairwiseScore('A', 't'), 1.4f); |
| 85 |
1 |
assertEquals(sm.getPairwiseScore('a', 't'), 1.4f); |
| 86 |
1 |
assertEquals(sm.getPairwiseScore('U', 'x'), 3.5f); |
| 87 |
1 |
assertEquals(sm.getPairwiseScore('u', 'x'), 3.5f); |
| 88 |
|
|
| 89 |
1 |
assertEquals(sm.getPairwiseScore('U', 'X'), 1.1f); |
| 90 |
1 |
assertEquals(sm.getPairwiseScore('A', '.'), 1.1f); |
| 91 |
1 |
assertEquals(sm.getPairwiseScore('-', '-'), 7.6f); |
| 92 |
1 |
assertEquals(sm.getPairwiseScore('A', (char) 128), 0f); |
| 93 |
|
} |
| 94 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
| 95 |
1 |
@Test(groups = "Functional")... |
| 96 |
|
public void testParseMatrix_headerMissing() |
| 97 |
|
{ |
| 98 |
1 |
String data; |
| 99 |
|
|
| 100 |
1 |
data = "X Y\n1 2\n3 4\n"; |
| 101 |
1 |
try |
| 102 |
|
{ |
| 103 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 104 |
|
.parseMatrix(); |
| 105 |
0 |
fail("expected exception"); |
| 106 |
|
} catch (IOException e) |
| 107 |
|
{ |
| 108 |
1 |
assertEquals(e.getMessage(), |
| 109 |
|
"Format error: 'ScoreMatrix <name>' should be the first non-comment line"); |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 113 |
1 |
@Test(groups = "Functional")... |
| 114 |
|
public void testParseMatrix_ncbiNotEnoughRows() |
| 115 |
|
{ |
| 116 |
1 |
String data = "ScoreMatrix MyTest\nX Y Z\n1 2 3\n4 5 6\n"; |
| 117 |
1 |
try |
| 118 |
|
{ |
| 119 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 120 |
|
.parseMatrix(); |
| 121 |
0 |
fail("expected exception"); |
| 122 |
|
} catch (IOException e) |
| 123 |
|
{ |
| 124 |
1 |
assertEquals(e.getMessage(), |
| 125 |
|
"Expected 3 rows of score data in score matrix but only found 2"); |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 129 |
1 |
@Test(groups = "Functional")... |
| 130 |
|
public void testParseMatrix_ncbiNotEnoughColumns() |
| 131 |
|
{ |
| 132 |
1 |
String data = "ScoreMatrix MyTest\nX Y Z\n1 2 3\n4 5\n7 8 9\n"; |
| 133 |
1 |
try |
| 134 |
|
{ |
| 135 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 136 |
|
.parseMatrix(); |
| 137 |
0 |
fail("expected exception"); |
| 138 |
|
} catch (IOException e) |
| 139 |
|
{ |
| 140 |
1 |
assertEquals(e.getMessage(), |
| 141 |
|
"Expected 3 scores at line 4: '4 5' but found 2"); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| |
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.27 |
1PASS
|
|
| 145 |
1 |
@Test(groups = "Functional")... |
| 146 |
|
public void testParseMatrix_ncbiTooManyColumns() |
| 147 |
|
{ |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
1 |
String data = "ScoreMatrix MyTest\nX\tY\tZ\n1 2 3\n4 5 6 7\n8 9 10\n"; |
| 152 |
1 |
try |
| 153 |
|
{ |
| 154 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 155 |
|
.parseMatrix(); |
| 156 |
0 |
fail("expected exception"); |
| 157 |
|
} catch (IOException e) |
| 158 |
|
{ |
| 159 |
1 |
assertEquals(e.getMessage(), |
| 160 |
|
"Expected 3 scores at line 4: '4 5 6 7' but found 4"); |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
1 |
data = "ScoreMatrix MyTest\nX Y\nX 1 2\nY 3 4 5\n"; |
| 167 |
1 |
try |
| 168 |
|
{ |
| 169 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 170 |
|
.parseMatrix(); |
| 171 |
0 |
fail("expected exception"); |
| 172 |
|
} catch (IOException e) |
| 173 |
|
{ |
| 174 |
1 |
assertEquals(e.getMessage(), |
| 175 |
|
"Expected 2 scores at line 4: 'Y 3 4 5' but found 3"); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
1 |
data = "ScoreMatrix MyTest\nX Y\n1 2\n3 4 5\n"; |
| 182 |
1 |
try |
| 183 |
|
{ |
| 184 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 185 |
|
.parseMatrix(); |
| 186 |
0 |
fail("expected exception"); |
| 187 |
|
} catch (IOException e) |
| 188 |
|
{ |
| 189 |
1 |
assertEquals(e.getMessage(), |
| 190 |
|
"Expected 2 scores at line 4: '3 4 5' but found 3"); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 194 |
1 |
@Test(groups = "Functional")... |
| 195 |
|
public void testParseMatrix_ncbiTooManyRows() |
| 196 |
|
{ |
| 197 |
1 |
String data = "ScoreMatrix MyTest\n\tX\tY\tZ\n1 2 3\n4 5 6\n7 8 9\n10 11 12\n"; |
| 198 |
1 |
try |
| 199 |
|
{ |
| 200 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 201 |
|
.parseMatrix(); |
| 202 |
0 |
fail("expected exception"); |
| 203 |
|
} catch (IOException e) |
| 204 |
|
{ |
| 205 |
1 |
assertEquals(e.getMessage(), |
| 206 |
|
"Unexpected extra input line in score model file: '10 11 12'"); |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 210 |
1 |
@Test(groups = "Functional")... |
| 211 |
|
public void testParseMatrix_ncbiBadDelimiter() |
| 212 |
|
{ |
| 213 |
1 |
String data = "ScoreMatrix MyTest\n X Y Z\n1|2|3\n4|5|6\n"; |
| 214 |
1 |
try |
| 215 |
|
{ |
| 216 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 217 |
|
.parseMatrix(); |
| 218 |
0 |
fail("expected exception"); |
| 219 |
|
} catch (IOException e) |
| 220 |
|
{ |
| 221 |
1 |
assertEquals(e.getMessage(), |
| 222 |
|
"Invalid score value '1|2|3' at line 3 column 0"); |
| 223 |
|
} |
| 224 |
|
} |
| 225 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 226 |
1 |
@Test(groups = "Functional")... |
| 227 |
|
public void testParseMatrix_ncbiBadFloat() |
| 228 |
|
{ |
| 229 |
1 |
String data = "ScoreMatrix MyTest\n\tX\tY\tZ\n1 2 3\n4 five 6\n7 8 9\n"; |
| 230 |
1 |
try |
| 231 |
|
{ |
| 232 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 233 |
|
.parseMatrix(); |
| 234 |
0 |
fail("expected exception"); |
| 235 |
|
} catch (IOException e) |
| 236 |
|
{ |
| 237 |
1 |
assertEquals(e.getMessage(), |
| 238 |
|
"Invalid score value 'five' at line 4 column 1"); |
| 239 |
|
} |
| 240 |
|
} |
| 241 |
|
|
| |
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.3 |
1PASS
|
|
| 242 |
1 |
@Test(groups = "Functional")... |
| 243 |
|
public void testParseMatrix_ncbiBadGuideCharacter() |
| 244 |
|
{ |
| 245 |
1 |
String data = "ScoreMatrix MyTest\n\tX Y\nX 1 2\ny 3 4\n"; |
| 246 |
1 |
try |
| 247 |
|
{ |
| 248 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 249 |
|
.parseMatrix(); |
| 250 |
0 |
fail("expected exception"); |
| 251 |
|
} catch (IOException e) |
| 252 |
|
{ |
| 253 |
1 |
assertEquals(e.getMessage(), |
| 254 |
|
"Error parsing score matrix at line 4, expected 'Y' but found 'y'"); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
1 |
data = "ScoreMatrix MyTest\n\tX Y\nXX 1 2\nY 3 4\n"; |
| 258 |
1 |
try |
| 259 |
|
{ |
| 260 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 261 |
|
.parseMatrix(); |
| 262 |
0 |
fail("expected exception"); |
| 263 |
|
} catch (IOException e) |
| 264 |
|
{ |
| 265 |
1 |
assertEquals(e.getMessage(), |
| 266 |
|
"Error parsing score matrix at line 3, expected 'X' but found 'XX'"); |
| 267 |
|
} |
| 268 |
|
} |
| 269 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 270 |
1 |
@Test(groups = "Functional")... |
| 271 |
|
public void testParseMatrix_ncbiNameMissing() |
| 272 |
|
{ |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
1 |
String data = "ScoreMatrix\nX Y\n1 2\n3 4\n"; |
| 277 |
1 |
try |
| 278 |
|
{ |
| 279 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 280 |
|
.parseMatrix(); |
| 281 |
0 |
fail("expected exception"); |
| 282 |
|
} catch (IOException e) |
| 283 |
|
{ |
| 284 |
1 |
assertEquals(e.getMessage(), |
| 285 |
|
"Format error: expected 'ScoreMatrix <name>', found 'ScoreMatrix' at line 1"); |
| 286 |
|
} |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
@throws |
| 293 |
|
@throws |
| 294 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 295 |
1 |
@Test(groups = "Functional")... |
| 296 |
|
public void testParseMatrix_ncbiFormat() |
| 297 |
|
throws MalformedURLException, IOException |
| 298 |
|
{ |
| 299 |
|
|
| 300 |
1 |
String data = "ScoreMatrix MyTest\n#comment\n\n" + "\tA\tB\tC\n" |
| 301 |
|
+ "A\t1.0\t2.0\t3.0\n" + "B\t4.0\t5.0\t6.0\n" |
| 302 |
|
+ "C\t7.0\t8.0\t9.0\n"; |
| 303 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 304 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 305 |
1 |
ScoreMatrix sm = parser.parseMatrix(); |
| 306 |
|
|
| 307 |
1 |
assertNotNull(sm); |
| 308 |
1 |
assertEquals(sm.getName(), "MyTest"); |
| 309 |
1 |
assertEquals(parser.getMatrixName(), "MyTest"); |
| 310 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1.0f); |
| 311 |
1 |
assertEquals(sm.getPairwiseScore('B', 'c'), 6.0f); |
| 312 |
1 |
assertEquals(sm.getSize(), 3); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
@throws |
| 319 |
|
@throws |
| 320 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 321 |
1 |
@Test(groups = "Functional")... |
| 322 |
|
public void testParseMatrix_aaIndexBlosum80() |
| 323 |
|
throws MalformedURLException, IOException |
| 324 |
|
{ |
| 325 |
1 |
FileParse fp = new FileParse("resources/scoreModel/blosum80.scm", |
| 326 |
|
DataSourceType.FILE); |
| 327 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 328 |
1 |
ScoreMatrix sm = parser.parseMatrix(); |
| 329 |
|
|
| 330 |
1 |
assertNotNull(sm); |
| 331 |
1 |
assertEquals(sm.getName(), "HENS920103"); |
| 332 |
1 |
assertEquals(sm.getDescription(), |
| 333 |
|
"BLOSUM80 substitution matrix (Henikoff-Henikoff, 1992)"); |
| 334 |
1 |
assertFalse(sm.isDNA()); |
| 335 |
1 |
assertTrue(sm.isProtein()); |
| 336 |
1 |
assertEquals(20, sm.getSize()); |
| 337 |
|
|
| 338 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 7f); |
| 339 |
1 |
assertEquals(sm.getPairwiseScore('A', 'R'), -3f); |
| 340 |
1 |
assertEquals(sm.getPairwiseScore('r', 'a'), -3f); |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
|
@throws |
| 347 |
|
@throws |
| 348 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 349 |
1 |
@Test(groups = "Functional")... |
| 350 |
|
public void testParseMatrix_aaindexFormat() |
| 351 |
|
throws MalformedURLException, IOException |
| 352 |
|
{ |
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
1 |
String data = "H MyTest\n" + "D My description\n" + "R PMID:1438297\n" |
| 357 |
|
+ "A Authors, names\n" + "T Journal title\n" |
| 358 |
|
+ "J Journal reference\n" + "* matrix in 1/3 Bit Units\n" |
| 359 |
|
+ "M rows = ABC, cols = ABC\n" + "A\t1.0\n" + "B\t4.0\t5.0\n" |
| 360 |
|
+ "C\t7.0\t8.0\t9.0\n"; |
| 361 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 362 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 363 |
1 |
ScoreMatrix sm = parser.parseMatrix(); |
| 364 |
|
|
| 365 |
1 |
assertNotNull(sm); |
| 366 |
1 |
assertEquals(sm.getSize(), 3); |
| 367 |
1 |
assertEquals(sm.getName(), "MyTest"); |
| 368 |
1 |
assertEquals(sm.getDescription(), "My description"); |
| 369 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1.0f); |
| 370 |
1 |
assertEquals(sm.getPairwiseScore('A', 'B'), 4.0f); |
| 371 |
1 |
assertEquals(sm.getPairwiseScore('A', 'C'), 7.0f); |
| 372 |
1 |
assertEquals(sm.getPairwiseScore('B', 'A'), 4.0f); |
| 373 |
1 |
assertEquals(sm.getPairwiseScore('B', 'B'), 5.0f); |
| 374 |
1 |
assertEquals(sm.getPairwiseScore('B', 'C'), 8.0f); |
| 375 |
1 |
assertEquals(sm.getPairwiseScore('C', 'C'), 9.0f); |
| 376 |
1 |
assertEquals(sm.getPairwiseScore('C', 'B'), 8.0f); |
| 377 |
1 |
assertEquals(sm.getPairwiseScore('C', 'A'), 7.0f); |
| 378 |
|
} |
| 379 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 380 |
1 |
@Test(groups = "Functional")... |
| 381 |
|
public void testParseMatrix_aaindex_mMissing() |
| 382 |
|
throws MalformedURLException, IOException |
| 383 |
|
{ |
| 384 |
|
|
| 385 |
|
|
| 386 |
|
|
| 387 |
1 |
String data = "H MyTest\n" + "A\t1.0\n" + "B\t4.0\t5.0\n" |
| 388 |
|
+ "C\t7.0\t8.0\t9.0\n"; |
| 389 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 390 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 391 |
1 |
try |
| 392 |
|
{ |
| 393 |
1 |
parser.parseMatrix(); |
| 394 |
0 |
fail("Expected exception"); |
| 395 |
|
} catch (FileFormatException e) |
| 396 |
|
{ |
| 397 |
1 |
assertEquals(e.getMessage(), "No alphabet specified in matrix file"); |
| 398 |
|
} |
| 399 |
|
} |
| 400 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 401 |
1 |
@Test(groups = "Functional")... |
| 402 |
|
public void testParseMatrix_aaindex_rowColMismatch() |
| 403 |
|
throws MalformedURLException, IOException |
| 404 |
|
{ |
| 405 |
1 |
String data = "H MyTest\n" + "M rows=ABC, cols=ABD\n" + "A\t1.0\n" |
| 406 |
|
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n"; |
| 407 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 408 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 409 |
1 |
try |
| 410 |
|
{ |
| 411 |
1 |
parser.parseMatrix(); |
| 412 |
0 |
fail("Expected exception"); |
| 413 |
|
} catch (FileFormatException e) |
| 414 |
|
{ |
| 415 |
1 |
assertEquals(e.getMessage(), |
| 416 |
|
"Unexpected aaIndex score matrix data at line 2: M rows=ABC, cols=ABD rows != cols"); |
| 417 |
|
} |
| 418 |
|
} |
| 419 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 420 |
1 |
@Test(groups = "Functional")... |
| 421 |
|
public void testParseMatrix_ncbiHeaderRepeated() |
| 422 |
|
{ |
| 423 |
1 |
String data = "ScoreMatrix BLOSUM\nScoreMatrix PAM250\nX Y\n1 2\n3 4\n"; |
| 424 |
1 |
try |
| 425 |
|
{ |
| 426 |
1 |
new ScoreMatrixFile(new FileParse(data, DataSourceType.PASTE)) |
| 427 |
|
.parseMatrix(); |
| 428 |
0 |
fail("expected exception"); |
| 429 |
|
} catch (IOException e) |
| 430 |
|
{ |
| 431 |
1 |
assertEquals(e.getMessage(), |
| 432 |
|
"Error: 'ScoreMatrix' repeated in file at line 2"); |
| 433 |
|
} |
| 434 |
|
} |
| 435 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 436 |
1 |
@Test(groups = "Functional")... |
| 437 |
|
public void testParseMatrix_aaindex_tooManyRows() |
| 438 |
|
throws MalformedURLException, IOException |
| 439 |
|
{ |
| 440 |
1 |
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n" |
| 441 |
|
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n" + "C\t7.0\t8.0\t9.0\n"; |
| 442 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 443 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 444 |
1 |
try |
| 445 |
|
{ |
| 446 |
1 |
parser.parseMatrix(); |
| 447 |
0 |
fail("Expected exception"); |
| 448 |
|
} catch (FileFormatException e) |
| 449 |
|
{ |
| 450 |
1 |
assertEquals(e.getMessage(), "Too many data rows in matrix file"); |
| 451 |
|
} |
| 452 |
|
} |
| 453 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 454 |
1 |
@Test(groups = "Functional")... |
| 455 |
|
public void testParseMatrix_aaindex_extraDataLines() |
| 456 |
|
throws MalformedURLException, IOException |
| 457 |
|
{ |
| 458 |
1 |
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n" |
| 459 |
|
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\t9.0\n" + "something extra\n"; |
| 460 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 461 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 462 |
1 |
try |
| 463 |
|
{ |
| 464 |
1 |
parser.parseMatrix(); |
| 465 |
0 |
fail("Expected exception"); |
| 466 |
|
} catch (FileFormatException e) |
| 467 |
|
{ |
| 468 |
1 |
assertEquals(e.getMessage(), "Too many data rows in matrix file"); |
| 469 |
|
} |
| 470 |
|
} |
| 471 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 472 |
1 |
@Test(groups = "Functional")... |
| 473 |
|
public void testParseMatrix_aaindex_tooFewColumns() |
| 474 |
|
throws MalformedURLException, IOException |
| 475 |
|
{ |
| 476 |
1 |
String data = "H MyTest\n" + "M rows=ABC, cols=ABC\n" + "A\t1.0\n" |
| 477 |
|
+ "B\t4.0\t5.0\n" + "C\t7.0\t8.0\n"; |
| 478 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 479 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 480 |
1 |
try |
| 481 |
|
{ |
| 482 |
1 |
parser.parseMatrix(); |
| 483 |
0 |
fail("Expected exception"); |
| 484 |
|
} catch (FileFormatException e) |
| 485 |
|
{ |
| 486 |
1 |
assertEquals(e.getMessage(), |
| 487 |
|
"Expected 3 scores at line 5: 'C\t7.0\t8.0' but found 2"); |
| 488 |
|
} |
| 489 |
|
} |
| 490 |
|
|
| 491 |
|
|
| 492 |
|
|
| 493 |
|
|
| 494 |
|
@throws |
| 495 |
|
@throws |
| 496 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 497 |
1 |
@Test(groups = "Functional")... |
| 498 |
|
public void testParse_ncbiFormat() |
| 499 |
|
throws MalformedURLException, IOException |
| 500 |
|
{ |
| 501 |
1 |
assertNull(ScoreModels.getInstance().getScoreModel("MyNewTest", null)); |
| 502 |
|
|
| 503 |
1 |
String data = "ScoreMatrix MyNewTest\n" + "\tA\tB\tC\n" |
| 504 |
|
+ "A\t1.0\t2.0\t3.0\n" + "B\t4.0\t5.0\t6.0\n" |
| 505 |
|
+ "C\t7.0\t8.0\t9.0\n"; |
| 506 |
1 |
FileParse fp = new FileParse(data, DataSourceType.PASTE); |
| 507 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
| 508 |
|
|
| 509 |
1 |
parser.parse(); |
| 510 |
|
|
| 511 |
1 |
ScoreMatrix sm = (ScoreMatrix) ScoreModels.getInstance() |
| 512 |
|
.getScoreModel("MyNewTest", null); |
| 513 |
1 |
assertNotNull(sm); |
| 514 |
1 |
assertEquals(sm.getName(), "MyNewTest"); |
| 515 |
1 |
assertEquals(parser.getMatrixName(), "MyNewTest"); |
| 516 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1.0f); |
| 517 |
1 |
assertEquals(sm.getPairwiseScore('B', 'c'), 6.0f); |
| 518 |
1 |
assertEquals(sm.getSize(), 3); |
| 519 |
|
} |
| 520 |
|
} |