Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.analysis.scoremodels

File PIDModelTest.java

 

Code metrics

0
60
4
1
176
85
4
0.07
15
4
1

Classes

Class Line # Actions
PIDModelTest 10 60 4 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

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