Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.analysis.scoremodels

File PIDModelTest.java

 

Code metrics

0
73
4
1
211
99
4
0.05
18.25
4
1

Classes

Class Line # Actions
PIDModelTest 30 73 4
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.analysis.scoremodels;
22   
23    import static org.testng.Assert.assertEquals;
24   
25    import jalview.api.analysis.SimilarityParamsI;
26    import jalview.util.Comparison;
27   
28    import org.testng.annotations.Test;
29   
 
30    public class PIDModelTest
31    {
32    private static final double DELTA = 0.00001D;
33   
 
34  1 toggle @Test(groups = "Functional")
35    public void testGetPairwiseScore()
36    {
37  1 PIDModel sm = new PIDModel();
38  1 assertEquals(sm.getPairwiseScore('A', 'A'), 1f);
39  1 assertEquals(sm.getPairwiseScore('A', 'a'), 1f);
40  1 assertEquals(sm.getPairwiseScore('a', 'A'), 1f);
41  1 assertEquals(sm.getPairwiseScore('A', 'B'), 0f);
42  1 assertEquals(sm.getPairwiseScore('A', ' '), 0f);
43  1 assertEquals(sm.getPairwiseScore(' ', ' '), 0f);
44  1 assertEquals(sm.getPairwiseScore('.', '.'), 0f);
45  1 assertEquals(sm.getPairwiseScore('-', '-'), 0f);
46    }
47   
48    /**
49    * Regression test to verify that a (suitably configured) PIDModel computes
50    * the same percentage identities as the Comparison.PID method
51    */
 
52  1 toggle @Test(groups = "Functional")
53    public void testComputePID_matchesComparisonPID()
54    {
55  1 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
56   
57    /*
58    * same length, no gaps
59    */
60  1 String s1 = "ARFNQDWSGI";
61  1 String s2 = "ARKNQDQSGI";
62   
63  1 new PIDModel();
64  1 double newScore = PIDModel.computePID(s1, s2, params);
65  1 double oldScore = Comparison.PID(s1, s2);
66  1 assertEquals(newScore, oldScore, DELTA);
67    // and verify PIDModel calculation is symmetric
68  1 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
69   
70    /*
71    * same length, with gaps
72    */
73  1 s1 = "-RFNQDWSGI";
74  1 s2 = "ARKNQ-QSGI";
75  1 new PIDModel();
76  1 newScore = PIDModel.computePID(s1, s2, params);
77  1 oldScore = Comparison.PID(s1, s2);
78  1 assertEquals(newScore, oldScore, DELTA);
79  1 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
80   
81    /*
82    * s2 longer than s1, with gaps
83    */
84  1 s1 = "ARK-";
85  1 s2 = "-RFNQ";
86  1 new PIDModel();
87  1 newScore = PIDModel.computePID(s1, s2, params);
88  1 oldScore = Comparison.PID(s1, s2);
89  1 assertEquals(newScore, oldScore, DELTA);
90  1 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
91   
92    /*
93    * s1 longer than s2, with gaps
94    */
95  1 s1 = "-RFNQ";
96  1 s2 = "ARK-";
97  1 new PIDModel();
98  1 newScore = PIDModel.computePID(s1, s2, params);
99  1 oldScore = Comparison.PID(s1, s2);
100  1 assertEquals(newScore, oldScore, DELTA);
101  1 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
102   
103    /*
104    * same but now also with gapped columns
105    */
106  1 s1 = "-R-F-NQ";
107  1 s2 = "AR-K--";
108  1 new PIDModel();
109  1 newScore = PIDModel.computePID(s1, s2, params);
110  1 oldScore = Comparison.PID(s1, s2);
111  1 assertEquals(newScore, oldScore, DELTA);
112  1 assertEquals(newScore, PIDModel.computePID(s2, s1, params));
113    }
114   
115    /**
116    * Tests for percentage identity variants where only the shorter length of two
117    * sequences is used
118    */
 
119  1 toggle @Test(groups = "Functional")
120    public void testComputePID_matchShortestSequence()
121    {
122  1 String s1 = "FR-K-S";
123  1 String s2 = "FS--L";
124   
125    /*
126    * match gap-gap and gap-char
127    * PID = 4/5 = 80%
128    */
129  1 SimilarityParamsI params = new SimilarityParams(true, true, true, true);
130  1 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
131  1 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
132   
133    /*
134    * match gap-char but not gap-gap
135    * PID = 3/4 = 75%
136    */
137  1 params = new SimilarityParams(false, true, true, true);
138  1 assertEquals(PIDModel.computePID(s1, s2, params), 75d);
139  1 assertEquals(PIDModel.computePID(s2, s1, params), 75d);
140   
141    /*
142    * include gaps but don't match them
143    * include gap-gap, counted as identity
144    * PID = 2/5 = 40%
145    */
146  1 params = new SimilarityParams(true, false, true, true);
147  1 assertEquals(PIDModel.computePID(s1, s2, params), 40d);
148  1 assertEquals(PIDModel.computePID(s2, s1, params), 40d);
149   
150    /*
151    * include gaps but don't match them
152    * exclude gap-gap
153    * PID = 1/4 = 25%
154    */
155  1 params = new SimilarityParams(false, false, true, true);
156  1 assertEquals(PIDModel.computePID(s1, s2, params), 25d);
157  1 assertEquals(PIDModel.computePID(s2, s1, params), 25d);
158    }
159   
160    /**
161    * Tests for percentage identity variants where the longer length of two
162    * sequences is used
163    */
 
164  1 toggle @Test(groups = "Functional")
165    public void testComputePID_matchLongestSequence()
166    {
167  1 String s1 = "FR-K-S";
168  1 String s2 = "FS--L";
169   
170    /*
171    * match gap-gap and gap-char
172    * shorter sequence treated as if with trailing gaps
173    * PID = 5/6 = 83.333...%
174    */
175  1 SimilarityParamsI params = new SimilarityParams(true, true, true,
176    false);
177  1 assertEquals(PIDModel.computePID(s1, s2, params), 500d / 6);
178  1 assertEquals(PIDModel.computePID(s2, s1, params), 500d / 6);
179   
180    /*
181    * match gap-char but not gap-gap
182    * PID = 4/5 = 80%
183    */
184  1 params = new SimilarityParams(false, true, true, false);
185  1 assertEquals(PIDModel.computePID(s1, s2, params), 80d);
186  1 assertEquals(PIDModel.computePID(s2, s1, params), 80d);
187   
188    /*
189    * include gaps but don't match them
190    * include gap-gap, counted as identity
191    * PID = 2/6 = 33.333...%
192    */
193  1 params = new SimilarityParams(true, false, true, false);
194  1 assertEquals(PIDModel.computePID(s1, s2, params), 100d / 3);
195  1 assertEquals(PIDModel.computePID(s2, s1, params), 100d / 3);
196   
197    /*
198    * include gaps but don't match them
199    * exclude gap-gap
200    * PID = 1/5 = 25%
201    */
202  1 params = new SimilarityParams(false, false, true, false);
203  1 assertEquals(PIDModel.computePID(s1, s2, params), 20d);
204  1 assertEquals(PIDModel.computePID(s2, s1, params), 20d);
205   
206    /*
207    * no tests for matchGaps=true, includeGaps=false
208    * as it don't make sense
209    */
210    }
211    }