2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis.scoremodels;
23 import static org.testng.Assert.assertEquals;
25 import jalview.api.analysis.SimilarityParamsI;
26 import jalview.util.Comparison;
28 import org.testng.annotations.Test;
30 public class PIDModelTest
32 private static final double DELTA = 0.00001D;
34 @Test(groups = "Functional")
35 public void testGetPairwiseScore()
37 PIDModel sm = new PIDModel();
38 assertEquals(sm.getPairwiseScore('A', 'A'), 1f);
39 assertEquals(sm.getPairwiseScore('A', 'a'), 1f);
40 assertEquals(sm.getPairwiseScore('a', 'A'), 1f);
41 assertEquals(sm.getPairwiseScore('A', 'B'), 0f);
42 assertEquals(sm.getPairwiseScore('A', ' '), 0f);
43 assertEquals(sm.getPairwiseScore(' ', ' '), 0f);
44 assertEquals(sm.getPairwiseScore('.', '.'), 0f);
45 assertEquals(sm.getPairwiseScore('-', '-'), 0f);
49 * Regression test to verify that a (suitably configured) PIDModel computes
50 * the same percentage identities as the Comparison.PID method
52 @Test(groups = "Functional")
53 public void testComputePID_matchesComparisonPID()
55 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
58 * same length, no gaps
60 String s1 = "ARFNQDWSGI";
61 String s2 = "ARKNQDQSGI";
64 double newScore = PIDModel.computePID(s1, s2, params);
65 double oldScore = Comparison.PID(s1, s2);
66 assertEquals(newScore, oldScore, DELTA);
67 // and verify PIDModel calculation is symmetric
68 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
71 * same length, with gaps
76 newScore = PIDModel.computePID(s1, s2, params);
77 oldScore = Comparison.PID(s1, s2);
78 assertEquals(newScore, oldScore, DELTA);
79 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
82 * s2 longer than s1, with gaps
87 newScore = PIDModel.computePID(s1, s2, params);
88 oldScore = Comparison.PID(s1, s2);
89 assertEquals(newScore, oldScore, DELTA);
90 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
93 * s1 longer than s2, with gaps
98 newScore = PIDModel.computePID(s1, s2, params);
99 oldScore = Comparison.PID(s1, s2);
100 assertEquals(newScore, oldScore, DELTA);
101 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
104 * same but now also with gapped columns
109 newScore = PIDModel.computePID(s1, s2, params);
110 oldScore = Comparison.PID(s1, s2);
111 assertEquals(newScore, oldScore, DELTA);
112 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
116 * Tests for percentage identity variants where only the shorter length of two
119 @Test(groups = "Functional")
120 public void testComputePID_matchShortestSequence()
122 String s1 = "FR-K-S";
126 * match gap-gap and gap-char
129 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
130 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
131 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
134 * match gap-char but not gap-gap
137 params = new SimilarityParams(false, true, true, true);
138 assertEquals(PIDModel.computePID(s1, s2, params), 75d);
139 assertEquals(PIDModel.computePID(s2, s1, params), 75d);
142 * include gaps but don't match them
143 * include gap-gap, counted as identity
146 params = new SimilarityParams(true, false, true, true);
147 assertEquals(PIDModel.computePID(s1, s2, params), 40d);
148 assertEquals(PIDModel.computePID(s2, s1, params), 40d);
151 * include gaps but don't match them
155 params = new SimilarityParams(false, false, true, true);
156 assertEquals(PIDModel.computePID(s1, s2, params), 25d);
157 assertEquals(PIDModel.computePID(s2, s1, params), 25d);
161 * Tests for percentage identity variants where the longer length of two
164 @Test(groups = "Functional")
165 public void testComputePID_matchLongestSequence()
167 String s1 = "FR-K-S";
171 * match gap-gap and gap-char
172 * shorter sequence treated as if with trailing gaps
173 * PID = 5/6 = 83.333...%
175 SimilarityParamsI params = new SimilarityParams(true, true, true,
177 assertEquals(PIDModel.computePID(s1, s2, params), 500d / 6);
178 assertEquals(PIDModel.computePID(s2, s1, params), 500d / 6);
181 * match gap-char but not gap-gap
184 params = new SimilarityParams(false, true, true, false);
185 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
186 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
189 * include gaps but don't match them
190 * include gap-gap, counted as identity
191 * PID = 2/6 = 33.333...%
193 params = new SimilarityParams(true, false, true, false);
194 assertEquals(PIDModel.computePID(s1, s2, params), 100d / 3);
195 assertEquals(PIDModel.computePID(s2, s1, params), 100d / 3);
198 * include gaps but don't match them
202 params = new SimilarityParams(false, false, true, false);
203 assertEquals(PIDModel.computePID(s1, s2, params), 20d);
204 assertEquals(PIDModel.computePID(s2, s1, params), 20d);
207 * no tests for matchGaps=true, includeGaps=false
208 * as it don't make sense