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);
47 // and verify PIDModel calculation is symmetric
48 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
51 * same length, with gaps
56 newScore = PIDModel.computePID(s1, s2, params);
57 oldScore = Comparison.PID(s1, s2);
58 assertEquals(newScore, oldScore, DELTA);
59 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
62 * s2 longer than s1, with gaps
67 newScore = PIDModel.computePID(s1, s2, params);
68 oldScore = Comparison.PID(s1, s2);
69 assertEquals(newScore, oldScore, DELTA);
70 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
73 * s1 longer than s2, with gaps
78 newScore = PIDModel.computePID(s1, s2, params);
79 oldScore = Comparison.PID(s1, s2);
80 assertEquals(newScore, oldScore, DELTA);
81 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
84 * same but now also with gapped columns
89 newScore = PIDModel.computePID(s1, s2, params);
90 oldScore = Comparison.PID(s1, s2);
91 assertEquals(newScore, oldScore, DELTA);
92 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
96 * Tests for percentage identity variants where only the shorter length of two
99 @Test(groups = "Functional")
100 public void testComputePID_matchShortestSequence()
102 String s1 = "FR-K-S";
106 * match gap-gap and gap-char
109 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
110 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
111 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
114 * match gap-char but not gap-gap
117 params = new SimilarityParams(false, true, true, true);
118 assertEquals(PIDModel.computePID(s1, s2, params), 75d);
119 assertEquals(PIDModel.computePID(s2, s1, params), 75d);
122 * include gaps but don't match them
123 * include gap-gap, counted as identity
126 params = new SimilarityParams(true, false, true, true);
127 assertEquals(PIDModel.computePID(s1, s2, params), 40d);
128 assertEquals(PIDModel.computePID(s2, s1, params), 40d);
131 * include gaps but don't match them
135 params = new SimilarityParams(false, false, true, true);
136 assertEquals(PIDModel.computePID(s1, s2, params), 25d);
137 assertEquals(PIDModel.computePID(s2, s1, params), 25d);
141 * Tests for percentage identity variants where the longer length of two
144 @Test(groups = "Functional")
145 public void testComputePID_matchLongestSequence()
147 String s1 = "FR-K-S";
151 * match gap-gap and gap-char
152 * shorter sequence treated as if with trailing gaps
153 * PID = 5/6 = 83.333...%
155 SimilarityParamsI params = new SimilarityParams(true, true, true, false);
156 assertEquals(PIDModel.computePID(s1, s2, params), 500d / 6);
157 assertEquals(PIDModel.computePID(s2, s1, params), 500d / 6);
160 * match gap-char but not gap-gap
163 params = new SimilarityParams(false, true, true, false);
164 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
165 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
168 * include gaps but don't match them
169 * include gap-gap, counted as identity
170 * PID = 2/6 = 33.333...%
172 params = new SimilarityParams(true, false, true, false);
173 assertEquals(PIDModel.computePID(s1, s2, params), 100d / 3);
174 assertEquals(PIDModel.computePID(s2, s1, params), 100d / 3);
177 * include gaps but don't match them
181 params = new SimilarityParams(false, false, true, false);
182 assertEquals(PIDModel.computePID(s1, s2, params), 20d);
183 assertEquals(PIDModel.computePID(s2, s1, params), 20d);
186 * no tests for matchGaps=true, includeGaps=false
187 * as it don't make sense