1 package jalview.analysis.scoremodels;
3 import static org.testng.Assert.assertEquals;
5 import jalview.api.analysis.SimilarityParamsI;
6 import jalview.util.Comparison;
8 import org.testng.annotations.Test;
10 public class PIDModelTest
12 private static final double DELTA = 0.00001D;
14 @Test(groups = "Functional")
15 public void testGetPairwiseScore()
17 PIDModel sm = new PIDModel();
18 assertEquals(sm.getPairwiseScore('A', 'A'), 1f);
19 assertEquals(sm.getPairwiseScore('A', 'a'), 1f);
20 assertEquals(sm.getPairwiseScore('a', 'A'), 1f);
21 assertEquals(sm.getPairwiseScore('A', 'B'), 0f);
22 assertEquals(sm.getPairwiseScore('A', ' '), 0f);
23 assertEquals(sm.getPairwiseScore(' ', ' '), 0f);
24 assertEquals(sm.getPairwiseScore('.', '.'), 0f);
25 assertEquals(sm.getPairwiseScore('-', '-'), 0f);
29 * Regression test to verify that a (suitably configured) PIDModel computes
30 * the same percentage identities as the Comparison.PID method
32 @Test(groups = "Functional")
33 public void testComputePID_matchesComparisonPID()
35 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
38 * same length, no gaps
40 String s1 = "ARFNQDWSGI";
41 String s2 = "ARKNQDQSGI";
44 double newScore = PIDModel.computePID(s1, s2, params);
45 double oldScore = Comparison.PID(s1, s2);
46 assertEquals(newScore, oldScore, DELTA);
49 * same length, with gaps
54 newScore = PIDModel.computePID(s1, s2, params);
55 oldScore = Comparison.PID(s1, s2);
56 assertEquals(newScore, oldScore, DELTA);
59 * s2 longer than s1, with gaps
64 newScore = PIDModel.computePID(s1, s2, params);
65 oldScore = Comparison.PID(s1, s2);
66 assertEquals(newScore, oldScore, DELTA);
69 * s1 longer than s2, with gaps
74 newScore = PIDModel.computePID(s1, s2, params);
75 oldScore = Comparison.PID(s1, s2);
76 assertEquals(newScore, oldScore, DELTA);
79 * same but now also with gapped columns
84 newScore = PIDModel.computePID(s1, s2, params);
85 oldScore = Comparison.PID(s1, s2);
86 assertEquals(newScore, oldScore, DELTA);
90 * Tests for percentage identity variants where only the shorter length of two
93 @Test(groups = "Functional")
94 public void testComputePID_matchShortestSequence()
100 * match gap-gap and gap-char
103 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
104 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
107 * match gap-char but not gap-gap
110 params = new SimilarityParams(false, true, true, true);
111 assertEquals(PIDModel.computePID(s1, s2, params), 75d);
114 * include gaps but don't match them
115 * include gap-gap, counted as identity
118 params = new SimilarityParams(true, false, true, true);
119 assertEquals(PIDModel.computePID(s1, s2, params), 40d);
122 * include gaps but don't match them
126 params = new SimilarityParams(false, false, true, true);
127 assertEquals(PIDModel.computePID(s1, s2, params), 25d);
131 * Tests for percentage identity variants where the longer length of two
134 @Test(groups = "Functional")
135 public void testComputePID_matchLongestSequence()
137 String s1 = "FR-K-S";
141 * match gap-gap and gap-char
142 * shorter sequence treated as if with trailing gaps
143 * PID = 5/6 = 83.333...%
145 SimilarityParamsI params = new SimilarityParams(true, true, true, false);
146 assertEquals(PIDModel.computePID(s1, s2, params), 500d / 6);
149 * match gap-char but not gap-gap
152 params = new SimilarityParams(false, true, true, false);
153 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
156 * include gaps but don't match them
157 * include gap-gap, counted as identity
158 * PID = 2/6 = 33.333...%
160 params = new SimilarityParams(true, false, true, false);
161 assertEquals(PIDModel.computePID(s1, s2, params), 100d / 3);
164 * include gaps but don't match them
168 params = new SimilarityParams(false, false, true, false);
169 assertEquals(PIDModel.computePID(s1, s2, params), 20d);
172 * no tests for matchGaps=true, includeGaps=false
173 * as it don't make sense