1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis.scoremodels; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertNotEquals; |
26 |
|
import static org.testng.Assert.assertNotNull; |
27 |
|
import static org.testng.Assert.assertNotSame; |
28 |
|
import static org.testng.Assert.assertNull; |
29 |
|
import static org.testng.Assert.assertTrue; |
30 |
|
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; |
31 |
|
|
32 |
|
import jalview.api.analysis.SimilarityParamsI; |
33 |
|
import jalview.io.DataSourceType; |
34 |
|
import jalview.io.FileParse; |
35 |
|
import jalview.io.ScoreMatrixFile; |
36 |
|
import jalview.math.Matrix; |
37 |
|
import jalview.math.MatrixI; |
38 |
|
import jalview.schemes.ResidueProperties; |
39 |
|
|
40 |
|
import java.io.IOException; |
41 |
|
import java.net.MalformedURLException; |
42 |
|
import java.util.Arrays; |
43 |
|
|
44 |
|
import org.testng.annotations.Test; |
45 |
|
|
46 |
|
import junit.extensions.PA; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (302) |
Complexity: 34 |
Complexity Density: 0.13 |
|
48 |
|
public class ScoreMatrixTest |
49 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
50 |
1 |
@Test(groups = "Functional")... |
51 |
|
public void testConstructor() |
52 |
|
{ |
53 |
|
|
54 |
1 |
float[][] scores = new float[3][]; |
55 |
1 |
scores[0] = new float[] { 1f, 2f, 3f }; |
56 |
1 |
scores[1] = new float[] { -4f, 5f, 6f }; |
57 |
1 |
scores[2] = new float[] { 7f, 8f, 9f }; |
58 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", "ABC".toCharArray(), scores); |
59 |
1 |
assertFalse(sm.isSymmetric()); |
60 |
1 |
assertEquals(sm.getSize(), 3); |
61 |
1 |
assertArrayEquals(scores, sm.getMatrix()); |
62 |
1 |
assertEquals(sm.getPairwiseScore('A', 'a'), 1f); |
63 |
1 |
assertEquals(sm.getPairwiseScore('b', 'c'), 6f); |
64 |
1 |
assertEquals(sm.getPairwiseScore('c', 'b'), 8f); |
65 |
1 |
assertEquals(sm.getMatrixIndex('c'), 2); |
66 |
1 |
assertEquals(sm.getMatrixIndex(' '), -1); |
67 |
|
|
68 |
|
|
69 |
1 |
assertEquals(sm.getPairwiseScore('A', 'D'), -4f); |
70 |
1 |
assertEquals(sm.getPairwiseScore('D', 'A'), -4f); |
71 |
|
|
72 |
1 |
assertEquals(sm.getPairwiseScore('D', 'D'), 1f); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
75 |
1 |
@Test(... |
76 |
|
groups = "Functional", |
77 |
|
expectedExceptions = |
78 |
|
{ IllegalArgumentException.class }) |
79 |
|
public void testConstructor_matrixTooSmall() |
80 |
|
{ |
81 |
1 |
float[][] scores = new float[2][]; |
82 |
1 |
scores[0] = new float[] { 1f, 2f }; |
83 |
1 |
scores[1] = new float[] { 3f, 4f }; |
84 |
1 |
new ScoreMatrix("Test", "ABC".toCharArray(), scores); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
87 |
1 |
@Test(... |
88 |
|
groups = "Functional", |
89 |
|
expectedExceptions = |
90 |
|
{ IllegalArgumentException.class }) |
91 |
|
public void testConstructor_matrixTooBig() |
92 |
|
{ |
93 |
1 |
float[][] scores = new float[2][]; |
94 |
1 |
scores[0] = new float[] { 1f, 2f }; |
95 |
1 |
scores[1] = new float[] { 3f, 4f }; |
96 |
1 |
new ScoreMatrix("Test", "A".toCharArray(), scores); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
99 |
1 |
@Test(... |
100 |
|
groups = "Functional", |
101 |
|
expectedExceptions = |
102 |
|
{ IllegalArgumentException.class }) |
103 |
|
public void testConstructor_matrixNotSquare() |
104 |
|
{ |
105 |
1 |
float[][] scores = new float[2][]; |
106 |
1 |
scores[0] = new float[] { 1f, 2f }; |
107 |
1 |
scores[1] = new float[] { 3f }; |
108 |
1 |
new ScoreMatrix("Test", "AB".toCharArray(), scores); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
1PASS
|
|
111 |
1 |
@Test(groups = "Functional")... |
112 |
|
public void testBuildSymbolIndex() |
113 |
|
{ |
114 |
1 |
float[][] scores = new float[2][]; |
115 |
1 |
scores[0] = new float[] { 1f, 2f }; |
116 |
1 |
scores[1] = new float[] { 3f, 4f }; |
117 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", new char[] { 'A', '.' }, |
118 |
|
scores); |
119 |
1 |
short[] index = sm.buildSymbolIndex("AX-yxYp".toCharArray()); |
120 |
|
|
121 |
1 |
assertEquals(index.length, 128); |
122 |
|
|
123 |
1 |
assertEquals(index['A'], 0); |
124 |
1 |
assertEquals(index['a'], 0); |
125 |
1 |
assertEquals(index['X'], 1); |
126 |
1 |
assertEquals(index['-'], 2); |
127 |
1 |
assertEquals(index['y'], 3); |
128 |
1 |
assertEquals(index['x'], 4); |
129 |
1 |
assertEquals(index['Y'], 5); |
130 |
1 |
assertEquals(index['p'], 6); |
131 |
1 |
assertEquals(index['P'], -1); |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
129 |
for (int c = 0; c < index.length; c++) |
137 |
|
{ |
138 |
128 |
if (!"AaXx-. Yyp".contains(String.valueOf((char) c))) |
139 |
|
{ |
140 |
118 |
assertEquals(index[c], -1); |
141 |
|
} |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
1PASS
|
|
148 |
1 |
@Test(groups = "Functional")... |
149 |
|
public void testBuildSymbolIndex_nonAscii() |
150 |
|
{ |
151 |
1 |
float[][] scores = new float[2][]; |
152 |
1 |
scores[0] = new float[] { 1f, 2f }; |
153 |
1 |
scores[1] = new float[] { 3f, 4f }; |
154 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", new char[] { 'A', '.' }, |
155 |
|
scores); |
156 |
1 |
char[] weird = new char[] { 128, 245, 'P' }; |
157 |
1 |
short[] index = sm.buildSymbolIndex(weird); |
158 |
1 |
assertEquals(index.length, 128); |
159 |
1 |
assertEquals(index['P'], 2); |
160 |
1 |
assertEquals(index['p'], 2); |
161 |
129 |
for (int c = 0; c < index.length; c++) |
162 |
|
{ |
163 |
128 |
if (c != 'P' && c != 'p') |
164 |
|
{ |
165 |
126 |
assertEquals(index[c], -1); |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
170 |
1 |
@Test(groups = "Functional")... |
171 |
|
public void testGetMatrix() |
172 |
|
{ |
173 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
174 |
1 |
float[][] m = sm.getMatrix(); |
175 |
1 |
assertEquals(m.length, sm.getSize()); |
176 |
1 |
assertEquals(m[2][4], -3f); |
177 |
|
|
178 |
1 |
float[][] m2 = sm.getMatrix(); |
179 |
1 |
assertNotSame(m, m2); |
180 |
1 |
assertTrue(Arrays.deepEquals(m, m2)); |
181 |
|
} |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
183 |
1 |
@Test(groups = "Functional")... |
184 |
|
public void testGetMatrixIndex() |
185 |
|
{ |
186 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
187 |
1 |
assertEquals(sm.getMatrixIndex('A'), 0); |
188 |
1 |
assertEquals(sm.getMatrixIndex('R'), 1); |
189 |
1 |
assertEquals(sm.getMatrixIndex('r'), 1); |
190 |
1 |
assertEquals(sm.getMatrixIndex('N'), 2); |
191 |
1 |
assertEquals(sm.getMatrixIndex('D'), 3); |
192 |
1 |
assertEquals(sm.getMatrixIndex('X'), 22); |
193 |
1 |
assertEquals(sm.getMatrixIndex('x'), 22); |
194 |
1 |
assertEquals(sm.getMatrixIndex('-'), -1); |
195 |
1 |
assertEquals(sm.getMatrixIndex('*'), 23); |
196 |
1 |
assertEquals(sm.getMatrixIndex('.'), -1); |
197 |
1 |
assertEquals(sm.getMatrixIndex(' '), -1); |
198 |
1 |
assertEquals(sm.getMatrixIndex('?'), -1); |
199 |
1 |
assertEquals(sm.getMatrixIndex((char) 128), -1); |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
202 |
1 |
@Test(groups = "Functional")... |
203 |
|
public void testGetSize() |
204 |
|
{ |
205 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
206 |
1 |
assertEquals(sm.getMatrix().length, sm.getSize()); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
1PASS
|
|
209 |
1 |
@Test(groups = "Functional")... |
210 |
|
public void testComputePairwiseScores() |
211 |
|
{ |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
1 |
String[] seqs = new String[] { "FKL", "R-D", "QIA", "GWC" }; |
216 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
217 |
|
|
218 |
1 |
MatrixI pairwise = sm.findSimilarities(seqs, SimilarityParams.Jalview); |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
1 |
assertEquals(pairwise.height(), 4); |
224 |
1 |
assertEquals(pairwise.width(), 4); |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
5 |
for (int i = 0; i < pairwise.height(); i++) |
230 |
|
{ |
231 |
10 |
for (int j = i + 1; j < pairwise.width(); j++) |
232 |
|
{ |
233 |
6 |
assertEquals(pairwise.getValue(i, j), pairwise.getValue(j, i), |
234 |
|
String.format("Not symmetric at [%d, %d]", i, j)); |
235 |
|
} |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
1 |
assertEquals(pairwise.getValue(0, 0), 15d); |
242 |
|
|
243 |
1 |
assertEquals(pairwise.getValue(1, 1), 12d); |
244 |
|
|
245 |
1 |
assertEquals(pairwise.getValue(2, 2), 13d); |
246 |
|
|
247 |
1 |
assertEquals(pairwise.getValue(3, 3), 26d); |
248 |
|
|
249 |
1 |
assertEquals(pairwise.getValue(0, 1), -11d); |
250 |
|
|
251 |
1 |
assertEquals(pairwise.getValue(0, 2), -7d); |
252 |
|
|
253 |
1 |
assertEquals(pairwise.getValue(0, 3), -7d); |
254 |
|
|
255 |
1 |
assertEquals(pairwise.getValue(1, 2), -5d); |
256 |
|
|
257 |
1 |
assertEquals(pairwise.getValue(1, 3), -9d); |
258 |
|
|
259 |
1 |
assertEquals(pairwise.getValue(2, 3), -5d); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
@throws |
267 |
|
@throws |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
269 |
1 |
@Test(groups = "Functional")... |
270 |
|
public void testOutputMatrix_roundTrip() |
271 |
|
throws MalformedURLException, IOException |
272 |
|
{ |
273 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
274 |
1 |
String output = sm.outputMatrix(false); |
275 |
1 |
FileParse fp = new FileParse(output, DataSourceType.PASTE); |
276 |
1 |
ScoreMatrixFile parser = new ScoreMatrixFile(fp); |
277 |
1 |
ScoreMatrix sm2 = parser.parseMatrix(); |
278 |
1 |
assertNotNull(sm2); |
279 |
1 |
assertTrue(sm2.equals(sm)); |
280 |
|
} |
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
282 |
1 |
@Test(groups = "Functional")... |
283 |
|
public void testEqualsAndHashCode() |
284 |
|
{ |
285 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
286 |
1 |
ScoreMatrix sm2 = new ScoreMatrix(sm.getName(), |
287 |
|
sm.getSymbols().toCharArray(), sm.getMatrix()); |
288 |
1 |
assertTrue(sm.equals(sm2)); |
289 |
1 |
assertEquals(sm.hashCode(), sm2.hashCode()); |
290 |
|
|
291 |
1 |
sm2 = ScoreModels.getInstance().getPam250(); |
292 |
1 |
assertFalse(sm.equals(sm2)); |
293 |
1 |
assertNotEquals(sm.hashCode(), sm2.hashCode()); |
294 |
|
|
295 |
1 |
assertFalse(sm.equals("hello")); |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
301 |
1 |
@Test(groups = "Functional")... |
302 |
|
public void testcomputeSimilarity_matchLongestSequence() |
303 |
|
{ |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
1 |
String s1 = "FR-K-S"; |
308 |
1 |
String s2 = "FS--L"; |
309 |
1 |
ScoreMatrix blosum = ScoreModels.getInstance().getBlosum62(); |
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
1 |
SimilarityParamsI params = new SimilarityParams(true, true, true, |
318 |
|
false); |
319 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -6d); |
320 |
|
|
321 |
1 |
params = new SimilarityParams(true, false, true, false); |
322 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -6d); |
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
1 |
params = new SimilarityParams(false, true, true, false); |
330 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -7d); |
331 |
|
|
332 |
1 |
params = new SimilarityParams(false, false, true, false); |
333 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -7d); |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
1 |
params = new SimilarityParams(true, false, false, false); |
341 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 6d); |
342 |
|
|
343 |
1 |
params = new SimilarityParams(true, true, false, false); |
344 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 6d); |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
1 |
params = new SimilarityParams(false, false, false, false); |
352 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 5d); |
353 |
|
|
354 |
1 |
params = new SimilarityParams(false, true, false, false); |
355 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 5d); |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
362 |
1 |
@Test(groups = "Functional")... |
363 |
|
public void testcomputeSimilarity_matchShortestSequence() |
364 |
|
{ |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
1 |
String s1 = "FR-K-S"; |
369 |
1 |
String s2 = "FS--L"; |
370 |
1 |
ScoreMatrix blosum = ScoreModels.getInstance().getBlosum62(); |
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
1 |
SimilarityParamsI params = new SimilarityParams(true, true, true, true); |
379 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -2d); |
380 |
|
|
381 |
1 |
params = new SimilarityParams(true, false, true, true); |
382 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -2d); |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
1 |
params = new SimilarityParams(false, true, true, true); |
390 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -3d); |
391 |
|
|
392 |
1 |
params = new SimilarityParams(false, false, true, true); |
393 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), -3d); |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
1 |
params = new SimilarityParams(true, false, false, true); |
401 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 6d); |
402 |
|
|
403 |
1 |
params = new SimilarityParams(true, true, false, true); |
404 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 6d); |
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
1 |
params = new SimilarityParams(false, false, false, true); |
412 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 5d); |
413 |
|
|
414 |
1 |
params = new SimilarityParams(false, true, false, true); |
415 |
1 |
assertEquals(blosum.computeSimilarity(s1, s2, params), 5d); |
416 |
|
} |
417 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
418 |
1 |
@Test(groups = "Functional")... |
419 |
|
public void testSymmetric() |
420 |
|
{ |
421 |
1 |
verifySymmetric(ScoreModels.getInstance().getBlosum62()); |
422 |
1 |
verifySymmetric(ScoreModels.getInstance().getPam250()); |
423 |
1 |
verifySymmetric(ScoreModels.getInstance().getDefaultModel(false)); |
424 |
|
} |
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
@param |
431 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
432 |
3 |
private void verifySymmetric(ScoreMatrix sm)... |
433 |
|
{ |
434 |
3 |
float[][] m = sm.getMatrix(); |
435 |
3 |
int rows = m.length; |
436 |
62 |
for (int row = 0; row < rows; row++) |
437 |
|
{ |
438 |
59 |
assertEquals(m[row].length, rows); |
439 |
1332 |
for (int col = 0; col < rows; col++) |
440 |
|
{ |
441 |
1273 |
assertEquals(m[row][col], m[col][row], |
442 |
|
String.format("%s [%s, %s]", sm.getName(), |
443 |
|
ResidueProperties.aa[row], |
444 |
|
ResidueProperties.aa[col])); |
445 |
|
} |
446 |
|
} |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
452 |
1 |
@Test(groups = "Functional")... |
453 |
|
public void testBlosum62_values() |
454 |
|
{ |
455 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
456 |
|
|
457 |
1 |
assertTrue(sm.isProtein()); |
458 |
1 |
assertFalse(sm.isDNA()); |
459 |
1 |
assertNull(sm.getDescription()); |
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
1 |
verifyValues(sm, 'A', |
466 |
|
new float[] |
467 |
|
{ 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, |
468 |
|
-3, -2, 0, -2, -1, 0 }); |
469 |
1 |
verifyValues(sm, 'R', |
470 |
|
new float[] |
471 |
|
{ -1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, |
472 |
|
-3, -2, -3, -1, 0, -1 }); |
473 |
1 |
verifyValues(sm, 'N', |
474 |
|
new float[] |
475 |
|
{ -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, |
476 |
|
-2, -3, 3, 0, -1 }); |
477 |
1 |
verifyValues(sm, 'D', |
478 |
|
new float[] |
479 |
|
{ -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, |
480 |
|
-4, -3, -3, 4, 1, -1 }); |
481 |
1 |
verifyValues(sm, 'C', |
482 |
|
new float[] |
483 |
|
{ 0, -3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, |
484 |
|
-1, -2, -2, -1, -3, -3, -2 }); |
485 |
1 |
verifyValues(sm, 'Q', |
486 |
|
new float[] |
487 |
|
{ -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, |
488 |
|
-1, -2, 0, 3, -1 }); |
489 |
1 |
verifyValues(sm, 'E', |
490 |
|
new float[] |
491 |
|
{ -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, |
492 |
|
-3, -2, -2, 1, 4, -1 }); |
493 |
1 |
verifyValues(sm, 'G', |
494 |
|
new float[] |
495 |
|
{ 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, |
496 |
|
-2, -2, -3, -3, -1, -2, -1 }); |
497 |
1 |
verifyValues(sm, 'H', |
498 |
|
new float[] |
499 |
|
{ -2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, |
500 |
|
-2, 2, -3, 0, 0, -1 }); |
501 |
1 |
verifyValues(sm, 'I', |
502 |
|
new float[] |
503 |
|
{ -1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, |
504 |
|
-1, -3, -1, 3, -3, -3, -1 }); |
505 |
1 |
verifyValues(sm, 'L', |
506 |
|
new float[] |
507 |
|
{ -1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, |
508 |
|
-1, -2, -1, 1, -4, -3, -1 }); |
509 |
1 |
verifyValues(sm, 'K', |
510 |
|
new float[] |
511 |
|
{ -1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, |
512 |
|
-3, -2, -2, 0, 1, -1 }); |
513 |
1 |
verifyValues(sm, 'M', |
514 |
|
new float[] |
515 |
|
{ -1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, |
516 |
|
-1, -1, 1, -3, -1, -1 }); |
517 |
1 |
verifyValues(sm, 'F', |
518 |
|
new float[] |
519 |
|
{ -2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, |
520 |
|
-2, 1, 3, -1, -3, -3, -1 }); |
521 |
1 |
verifyValues(sm, 'P', |
522 |
|
new float[] |
523 |
|
{ -1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, |
524 |
|
-1, -4, -3, -2, -2, -1, -2 }); |
525 |
1 |
verifyValues(sm, 'S', |
526 |
|
new float[] |
527 |
|
{ 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3, |
528 |
|
-2, -2, 0, 0, 0 }); |
529 |
1 |
verifyValues(sm, 'T', |
530 |
|
new float[] |
531 |
|
{ 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, |
532 |
|
5, -2, -2, 0, -1, -1, 0 }); |
533 |
1 |
verifyValues(sm, 'W', |
534 |
|
new float[] |
535 |
|
{ -3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, |
536 |
|
-2, 11, 2, -3, -4, -3, -2 }); |
537 |
1 |
verifyValues(sm, 'Y', |
538 |
|
new float[] |
539 |
|
{ -2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, |
540 |
|
-2, 2, 7, -1, -3, -2, -1 }); |
541 |
1 |
verifyValues(sm, 'V', |
542 |
|
new float[] |
543 |
|
{ 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, |
544 |
|
-3, -1, 4, -3, -2, -1 }); |
545 |
1 |
verifyValues(sm, 'B', |
546 |
|
new float[] |
547 |
|
{ -2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, |
548 |
|
-4, -3, -3, 4, 1, -1 }); |
549 |
1 |
verifyValues(sm, 'Z', |
550 |
|
new float[] |
551 |
|
{ -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, |
552 |
|
-3, -2, -2, 1, 4, -1 }); |
553 |
1 |
verifyValues(sm, 'X', |
554 |
|
new float[] |
555 |
|
{ 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, |
556 |
|
0, -2, -1, -1, -1, -1, -1 }); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
@param |
563 |
|
@param |
564 |
|
@param |
565 |
|
|
566 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
567 |
23 |
private void verifyValues(ScoreMatrix sm, char res, float[] expected)... |
568 |
|
{ |
569 |
552 |
for (int j = 0; j < expected.length; j++) |
570 |
|
{ |
571 |
529 |
char c2 = ResidueProperties.aa[j].charAt(0); |
572 |
529 |
assertEquals(sm.getPairwiseScore(res, c2), expected[j], |
573 |
|
String.format("%s->%s", res, c2)); |
574 |
|
} |
575 |
|
} |
576 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
577 |
1 |
@Test(groups = "Functional")... |
578 |
|
public void testConstructor_gapDash() |
579 |
|
{ |
580 |
1 |
float[][] scores = new float[2][]; |
581 |
1 |
scores[0] = new float[] { 1f, 2f }; |
582 |
1 |
scores[1] = new float[] { 4f, 5f }; |
583 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", new char[] { 'A', '-' }, |
584 |
|
scores); |
585 |
1 |
assertEquals(sm.getSize(), 2); |
586 |
1 |
assertArrayEquals(scores, sm.getMatrix()); |
587 |
1 |
assertEquals(sm.getPairwiseScore('A', 'a'), 1f); |
588 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1f); |
589 |
1 |
assertEquals(sm.getPairwiseScore('a', '-'), 2f); |
590 |
1 |
assertEquals(sm.getPairwiseScore('-', 'A'), 4f); |
591 |
1 |
assertEquals(sm.getMatrixIndex('a'), 0); |
592 |
1 |
assertEquals(sm.getMatrixIndex('A'), 0); |
593 |
1 |
assertEquals(sm.getMatrixIndex('-'), 1); |
594 |
1 |
assertEquals(sm.getMatrixIndex(' '), -1); |
595 |
1 |
assertEquals(sm.getMatrixIndex('.'), -1); |
596 |
|
} |
597 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
598 |
1 |
@Test(groups = "Functional")... |
599 |
|
public void testGetPairwiseScore() |
600 |
|
{ |
601 |
1 |
float[][] scores = new float[2][]; |
602 |
1 |
scores[0] = new float[] { 1f, 2f }; |
603 |
1 |
scores[1] = new float[] { -4f, 5f }; |
604 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", new char[] { 'A', 'B' }, |
605 |
|
scores); |
606 |
1 |
assertEquals(sm.getPairwiseScore('A', 'A'), 1f); |
607 |
1 |
assertEquals(sm.getPairwiseScore('A', 'a'), 1f); |
608 |
1 |
assertEquals(sm.getPairwiseScore('A', 'B'), 2f); |
609 |
1 |
assertEquals(sm.getPairwiseScore('b', 'a'), -4f); |
610 |
1 |
assertEquals(sm.getPairwiseScore('B', 'b'), 5f); |
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
1 |
assertEquals(sm.getPairwiseScore('A', '-'), -4f); |
617 |
1 |
assertEquals(sm.getPairwiseScore('-', 'A'), -4f); |
618 |
1 |
assertEquals(sm.getPairwiseScore('-', '-'), 1f); |
619 |
1 |
assertEquals(sm.getPairwiseScore('Q', 'W'), -4f); |
620 |
1 |
assertEquals(sm.getPairwiseScore('Q', 'Q'), 1f); |
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
1 |
char c = (char) 200; |
626 |
1 |
assertEquals(sm.getPairwiseScore('Q', c), 0f); |
627 |
1 |
assertEquals(sm.getPairwiseScore(c, 'Q'), 0f); |
628 |
|
} |
629 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
630 |
1 |
@Test(groups = "Functional")... |
631 |
|
public void testGetMinimumScore() |
632 |
|
{ |
633 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
634 |
1 |
assertEquals(sm.getMinimumScore(), -4f); |
635 |
|
} |
636 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
637 |
1 |
@Test(groups = "Functional")... |
638 |
|
public void testGetMaximumScore() |
639 |
|
{ |
640 |
1 |
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); |
641 |
1 |
assertEquals(sm.getMaximumScore(), 11f); |
642 |
|
} |
643 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
644 |
1 |
@Test(groups = "Functional")... |
645 |
|
public void testOutputMatrix_html() |
646 |
|
{ |
647 |
1 |
float[][] scores = new float[2][]; |
648 |
1 |
scores[0] = new float[] { 1f, 2f }; |
649 |
1 |
scores[1] = new float[] { 4f, -5.3E-10f }; |
650 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", "AB".toCharArray(), scores); |
651 |
1 |
String html = sm.outputMatrix(true); |
652 |
1 |
String expected = "<table border=\"1\"><tr><th></th><th> A </th><th> B </th></tr>\n" |
653 |
|
+ "<tr><td>A</td><td>1.0</td><td>2.0</td></tr>\n" |
654 |
|
+ "<tr><td>B</td><td>4.0</td><td>-5.3E-10</td></tr>\n" |
655 |
|
+ "</table>"; |
656 |
1 |
assertEquals(html, expected); |
657 |
|
} |
658 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
659 |
1 |
@Test(groups = "Functional")... |
660 |
|
public void testIsSymmetric() |
661 |
|
{ |
662 |
1 |
double delta = 0.0001d; |
663 |
1 |
float[][] scores = new float[][] { { 1f, -2f }, { -2f, 3f } }; |
664 |
1 |
ScoreMatrix sm = new ScoreMatrix("Test", "AB".toCharArray(), scores); |
665 |
1 |
assertTrue(sm.isSymmetric()); |
666 |
|
|
667 |
|
|
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
1 |
SimilarityParamsI params = new SimilarityParams(true, true, true, |
676 |
|
false); |
677 |
1 |
String seq1 = "AAABBBAA"; |
678 |
1 |
String seq2 = "AABBABBA"; |
679 |
1 |
String[] seqs1 = new String[] { seq1, seq2 }; |
680 |
1 |
MatrixI res1 = sm.findSimilarities(seqs1, params); |
681 |
1 |
assertTrue( |
682 |
|
res1.equals(new Matrix(new double[][] |
683 |
|
{ { 14d, 3d }, { 3d, 16d } }), delta)); |
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
1 |
String[] seqs2 = new String[] { seq2, seq1 }; |
691 |
1 |
MatrixI res2 = sm.findSimilarities(seqs2, params); |
692 |
1 |
assertFalse(res1.equals(res2)); |
693 |
1 |
assertTrue( |
694 |
|
res2.equals(new Matrix(new double[][] |
695 |
|
{ { 16d, 3d }, { 3d, 14d } }), delta)); |
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
1 |
scores = new float[][] { { 1f, -2f }, { 2f, 3f } }; |
705 |
1 |
sm = new ScoreMatrix("Test", "AB".toCharArray(), scores); |
706 |
1 |
assertFalse(sm.isSymmetric()); |
707 |
1 |
res1 = sm.findSimilarities(seqs1, params); |
708 |
1 |
assertTrue( |
709 |
|
res1.equals(new Matrix(new double[][] |
710 |
|
{ { 14d, 7d }, { 11d, 16d } }), delta)); |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
|
717 |
1 |
res2 = sm.findSimilarities(seqs2, params); |
718 |
1 |
assertFalse(res1.equals(res2)); |
719 |
1 |
assertTrue( |
720 |
|
res2.equals(new Matrix(new double[][] |
721 |
|
{ { 16d, 11d }, { 7d, 14d } }), delta)); |
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
1 |
PA.setValue(sm, "symmetric", true); |
728 |
1 |
assertTrue(sm.isSymmetric()); |
729 |
1 |
res2 = sm.findSimilarities(seqs1, params); |
730 |
1 |
assertFalse(res1.equals(res2, delta)); |
731 |
|
} |
732 |
|
} |