Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package jalview.analysis.scoremodels

File SecondaryStructureDistanceModelTest.java

 

Code metrics

8
139
8
1
440
241
12
0.09
17.38
8
1.5

Classes

Class Line # Actions
SecondaryStructureDistanceModelTest 49 139 12
0.651612965.2%
 

Contributing tests

This file is covered by 3 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    import static org.testng.Assert.assertTrue;
25   
26    import jalview.api.analysis.ScoreModelI;
27    import jalview.api.analysis.SimilarityParamsI;
28    import jalview.datamodel.Alignment;
29    import jalview.datamodel.AlignmentAnnotation;
30    import jalview.datamodel.AlignmentI;
31    import jalview.datamodel.AlignmentView;
32    import jalview.datamodel.Annotation;
33    import jalview.datamodel.Sequence;
34    import jalview.datamodel.SequenceFeature;
35    import jalview.datamodel.SequenceI;
36    import jalview.gui.AlignFrame;
37    import jalview.gui.AlignViewport;
38    import jalview.gui.JvOptionPane;
39    import jalview.io.DataSourceType;
40    import jalview.io.FileLoader;
41    import jalview.math.MatrixI;
42   
43    import org.testng.Assert;
44    import org.testng.annotations.BeforeClass;
45    import org.testng.annotations.DataProvider;
46    import org.testng.annotations.Test;
47   
48    // This class tests methods in Class SecondaryStructureDistanceModel
 
49    public class SecondaryStructureDistanceModelTest
50    {
51   
52    /**
53    * Verify computed distances of sequences with gap
54    */
 
55  1 toggle @Test(groups = "Functional")
56    public void testFindDistances_withGap()
57    {
58  1 AlignFrame af = setupAlignmentViewWithGap();
59  1 AlignViewport viewport = af.getViewport();
60  1 AlignmentView view = viewport.getAlignmentView(false);
61   
62  1 ScoreModelI sm = new SecondaryStructureDistanceModel();
63  1 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
64    af.alignPanel);
65   
66    /*
67    * feature distance model always normalises by region width
68    * gap-gap is always included (but scores zero)
69    * the only variable parameter is 'includeGaps'
70    */
71   
72    /*
73    * include gaps
74    * score = 0 + 0 + 1 + 0 = 1/4
75    */
76  1 SimilarityParamsI params = new SimilarityParams(false, true, true,
77    true);
78  1 params.setSecondaryStructureSource("3D Structures");
79  1 MatrixI distances = sm.findDistances(view, params);
80  1 assertEquals(distances.getValue(0, 0), 1d);
81  1 assertEquals(distances.getValue(1, 1), 1d);
82  1 assertEquals(distances.getValue(0, 1), 0d);
83  1 assertEquals(distances.getValue(1, 0), 0d);
84   
85    /*
86    * exclude gaps
87    * score = 0 + 0 + 0 + 0 = 0/4
88    */
89   
90  1 SimilarityParamsI params2 = new SimilarityParams(false, true, false,
91    true);
92  1 params2.setSecondaryStructureSource("3D Structures");
93  1 MatrixI distances2 = sm.findDistances(view, params2);
94  1 assertEquals(distances2.getValue(0, 1), 0d);
95  1 assertEquals(distances2.getValue(1, 0), 0d);
96    }
97   
98    /**
99    * Verify computed distances of sequences with gap
100    */
 
101  1 toggle @Test(groups = "Functional")
102    public void testFindDistances_withSSUndefinedInEitherOneSeq()
103    {
104  1 AlignFrame af = setupAlignmentViewWithoutSS("either");
105  1 AlignViewport viewport = af.getViewport();
106  1 AlignmentView view = viewport.getAlignmentView(false);
107   
108  1 ScoreModelI sm = new SecondaryStructureDistanceModel();
109  1 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
110    af.alignPanel);
111   
112    /*
113    * feature distance model always normalises by region width
114    * gap-gap is always included (but scores zero)
115    * the only variable parameter is 'includeGaps'
116    */
117   
118    /*
119    * include gaps
120    * score = 0 + 0 + 2 + 2 = 2/4
121    */
122  1 SimilarityParamsI params = new SimilarityParams(false, true, true,
123    true);
124  1 params.setSecondaryStructureSource("3D Structures");
125  1 MatrixI distances = sm.findDistances(view, params);
126  1 assertEquals(distances.getValue(0, 0), 1d);
127  1 assertEquals(distances.getValue(1, 1), 1d);
128  1 assertEquals(distances.getValue(0, 1), 0d);
129  1 assertEquals(distances.getValue(1, 0), 0d);
130   
131    /*
132    * exclude gaps
133    * score = 0 + 0 + 2 + 2 = 2/4
134    */
135   
136  1 SimilarityParamsI params2 = new SimilarityParams(false, true, false,
137    true);
138  1 params2.setSecondaryStructureSource("3D Structures");
139  1 MatrixI distances2 = sm.findDistances(view, params2);
140  1 assertEquals(distances2.getValue(0, 1), 0d);
141  1 assertEquals(distances2.getValue(1, 0), 0d);
142    }
143   
144    /**
145    * Verify computed distances of sequences with gap
146    */
 
147  1 toggle @Test(groups = "Functional")
148    public void testFindDistances_withSSUndefinedInBothSeqs()
149    {
150  1 AlignFrame af = setupAlignmentViewWithoutSS("both");
151  1 AlignViewport viewport = af.getViewport();
152  1 AlignmentView view = viewport.getAlignmentView(false);
153   
154  1 ScoreModelI sm = new SecondaryStructureDistanceModel();
155  1 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
156    af.alignPanel);
157   
158    /*
159    * feature distance model always normalises by region width
160    * gap-gap is always included (but scores zero)
161    * the only variable parameter is 'includeGaps'
162    */
163   
164    /*
165    * include gaps
166    * score = 0 + 0 + 2 + 2 = 2/4
167    */
168  1 SimilarityParamsI params = new SimilarityParams(false, true, true,
169    true);
170  1 params.setSecondaryStructureSource("3D Structures");
171  1 MatrixI distances = sm.findDistances(view, params);
172  1 assertEquals(distances.getValue(0, 0), 1d);
173  1 assertEquals(distances.getValue(1, 1), 1d);
174  1 assertEquals(distances.getValue(0, 1), 0d);
175  1 assertEquals(distances.getValue(1, 0), 0d);
176   
177    /*
178    * exclude gaps
179    * score = 0 + 0 + 2 + 2 = 2/4
180    */
181   
182  1 SimilarityParamsI params2 = new SimilarityParams(false, true, false,
183    true);
184  1 params2.setSecondaryStructureSource("3D Structures");
185  1 MatrixI distances2 = sm.findDistances(view, params2);
186  1 assertEquals(distances2.getValue(0, 1), 0d);
187  1 assertEquals(distances2.getValue(1, 0), 0d);
188    }
189   
190    /**
191    * <pre>
192    * Set up
193    * column 1 2 3 4
194    * seq s1 F R K S
195    *
196    * seq s2 F S J L
197    * </pre>
198    *
199    * @return
200    */
 
201  0 toggle protected AlignFrame setupAlignmentView(String similar)
202    {
203    /*
204    * sequences without gaps
205    */
206  0 SequenceI s1 = new Sequence("s1", "FRKS");
207  0 SequenceI s2 = new Sequence("s2", "FSJL");
208   
209  0 s1.addSequenceFeature(
210    new SequenceFeature("chain", null, 1, 4, 0f, null));
211  0 s1.addSequenceFeature(
212    new SequenceFeature("domain", null, 1, 4, 0f, null));
213  0 s2.addSequenceFeature(
214    new SequenceFeature("chain", null, 1, 4, 0f, null));
215  0 s2.addSequenceFeature(
216    new SequenceFeature("metal", null, 1, 4, 0f, null));
217  0 s2.addSequenceFeature(
218    new SequenceFeature("Pfam", null, 1, 4, 0f, null));
219   
220    /*
221    * Set up secondary structure annotations
222    */
223  0 Annotation ssE = new Annotation("", "", 'E', 0);
224  0 Annotation ssH = new Annotation("", "", 'H', 0);
225  0 Annotation ssC = new Annotation(".", "", ' ', 0);
226   
227  0 Annotation[] anns1;
228  0 Annotation[] anns2;
229   
230    /* All secondary structure annotations are similar for each column
231    * Set up
232    * column 1 2 3 4
233    * seq s1 F R K S
234    * ss E H S E
235    *
236    * seq s2 F S J L
237    * ss E H S E
238    */
239  0 if (similar == "All Similar")
240    {
241   
242  0 anns1 = new Annotation[] { ssE, ssH, ssC, ssE };
243  0 anns2 = new Annotation[] { ssE, ssH, ssC, ssE };
244   
245    }
246   
247    /* All secondary structure annotations are dissimilar for each column
248    * Set up
249    * column 1 2 3 4
250    * seq s1 F R K S
251    * ss E E C E
252    *
253    * seq s2 F S J L
254    * ss H E E C
255    */
256  0 else if (similar == "Not Similar")
257    {
258   
259  0 anns1 = new Annotation[] { ssE, ssE, ssC, ssE };
260  0 anns2 = new Annotation[] { ssH, ssH, ssE, ssC };
261   
262    }
263   
264    /* All secondary structure annotations are dissimilar for each column
265    * Set up
266    * column 1 2 3 4
267    * seq s1 F R K S
268    * ss E E C E
269    *
270    * seq s2 F S J L
271    * ss H E E C
272    */
273  0 else if (similar == "With Coil")
274    {
275   
276  0 anns1 = new Annotation[] { ssE, ssE, null, ssE };
277  0 anns2 = new Annotation[] { ssH, ssH, ssE, null };
278   
279    }
280   
281    /* Set up
282    * column 1 2 3 4
283    * seq s1 F R K S
284    * ss H E C E
285    *
286    * seq s2 F S J L
287    * ss H E E C
288    */
289    else
290    {
291   
292  0 anns1 = new Annotation[] { ssH, ssE, ssC, ssE };
293  0 anns2 = new Annotation[] { ssH, ssE, ssE, ssC };
294    }
295   
296  0 AlignmentAnnotation ann1 = new AlignmentAnnotation(
297    "Secondary Structure", "Secondary Structure", anns1);
298  0 AlignmentAnnotation ann2 = new AlignmentAnnotation(
299    "Secondary Structure", "Secondary Structure", anns2);
300   
301  0 s1.addAlignmentAnnotation(ann1);
302  0 s2.addAlignmentAnnotation(ann2);
303   
304  0 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
305  0 AlignFrame af = new AlignFrame(al, 300, 300);
306  0 af.setShowSeqFeatures(true);
307  0 af.getFeatureRenderer().findAllFeatures(true);
308  0 return af;
309    }
310   
311    /**
312    * <pre>
313    * Set up
314    * column 1 2 3 4
315    * seq s1 F R S
316    * SS H E C
317    *
318    * seq s2 F S J L
319    * ss H E E C
320    * </pre>
321    *
322    * @return
323    */
 
324  1 toggle protected AlignFrame setupAlignmentViewWithGap()
325    {
326   
327  1 SequenceI s1 = new Sequence("s1", "FR S");
328  1 SequenceI s2 = new Sequence("s2", "FSJL");
329   
330  1 s1.addSequenceFeature(
331    new SequenceFeature("chain", null, 1, 3, 0f, null));
332  1 s1.addSequenceFeature(
333    new SequenceFeature("domain", null, 1, 3, 0f, null));
334  1 s2.addSequenceFeature(
335    new SequenceFeature("chain", null, 1, 4, 0f, null));
336  1 s2.addSequenceFeature(
337    new SequenceFeature("metal", null, 1, 4, 0f, null));
338  1 s2.addSequenceFeature(
339    new SequenceFeature("Pfam", null, 1, 4, 0f, null));
340   
341  1 Annotation ssE = new Annotation("", "", 'E', 0);
342  1 Annotation ssH = new Annotation("", "", 'H', 0);
343  1 Annotation ssC = new Annotation(".", "", ' ', 0);
344   
345  1 Annotation[] anns1;
346  1 Annotation[] anns2;
347   
348  1 anns1 = new Annotation[] { ssH, ssE, ssC };
349  1 anns2 = new Annotation[] { ssH, ssE, ssE, ssC };
350   
351  1 AlignmentAnnotation ann1 = new AlignmentAnnotation(
352    "Secondary Structure", "Secondary Structure", anns1);
353  1 AlignmentAnnotation ann2 = new AlignmentAnnotation(
354    "Secondary Structure", "Secondary Structure", anns2);
355   
356  1 s1.addAlignmentAnnotation(ann1);
357  1 s2.addAlignmentAnnotation(ann2);
358   
359  1 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
360  1 AlignFrame af = new AlignFrame(al, 300, 300);
361  1 af.setShowSeqFeatures(true);
362  1 af.getFeatureRenderer().findAllFeatures(true);
363   
364  1 return af;
365    }
366   
 
367  2 toggle protected AlignFrame setupAlignmentViewWithoutSS(String type)
368    {
369   
370  2 SequenceI s1 = new Sequence("s1", "FR S");
371  2 SequenceI s2 = new Sequence("s2", "FSJL");
372   
373  2 s1.addSequenceFeature(
374    new SequenceFeature("chain", null, 1, 3, 0f, null));
375  2 s1.addSequenceFeature(
376    new SequenceFeature("domain", null, 1, 3, 0f, null));
377  2 s2.addSequenceFeature(
378    new SequenceFeature("chain", null, 1, 4, 0f, null));
379  2 s2.addSequenceFeature(
380    new SequenceFeature("metal", null, 1, 4, 0f, null));
381  2 s2.addSequenceFeature(
382    new SequenceFeature("Pfam", null, 1, 4, 0f, null));
383   
384  2 if (!type.equals("both"))
385    {
386  1 Annotation ssE = new Annotation("", "", 'E', 0);
387  1 Annotation ssH = new Annotation("", "", 'H', 0);
388  1 Annotation ssC = new Annotation(".", "", ' ', 0);
389   
390  1 Annotation[] anns1;
391   
392  1 anns1 = new Annotation[] { ssH, ssE, ssC };
393   
394  1 AlignmentAnnotation ann1 = new AlignmentAnnotation(
395    "Secondary Structure", "Secondary Structure", anns1);
396   
397  1 s1.addAlignmentAnnotation(ann1);
398    }
399   
400  2 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
401  2 AlignFrame af = new AlignFrame(al, 300, 300);
402  2 af.setShowSeqFeatures(true);
403  2 af.getFeatureRenderer().findAllFeatures(true);
404  2 return af;
405    }
406   
 
407  0 toggle @DataProvider(name = "testData")
408    public Object[][] testData()
409    {
410  0 return new Object[][] { { "All Similar", 1d, 1d, 0d, 0d / 4 },
411    { "Partially Similar", 1d, 1d, 0d, 0d },
412    { "Not Similar", 1d, 1d, 0d, 0d },
413    { "With Coil", 1d, 1d, 0d, 0d }, };
414    }
415   
 
416  0 toggle @Test(dataProvider = "testData")
417    public void testFindDistances(String scenario, double expectedValue00,
418    double expectedValue11, double expectedValue01,
419    double expectedValue10)
420    {
421  0 AlignFrame af = setupAlignmentView(scenario);
422  0 AlignViewport viewport = af.getViewport();
423  0 AlignmentView view = viewport.getAlignmentView(false);
424   
425  0 ScoreModelI sm = new SecondaryStructureDistanceModel();
426  0 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
427    af.alignPanel);
428   
429  0 SimilarityParamsI params = new SimilarityParams(false, true, true,
430    true);
431  0 params.setSecondaryStructureSource("3D Structures");
432  0 MatrixI distances = sm.findDistances(view, params);
433   
434  0 assertEquals(distances.getValue(0, 0), expectedValue00);
435  0 assertEquals(distances.getValue(1, 1), expectedValue11);
436  0 assertEquals(distances.getValue(0, 1), expectedValue01);
437  0 assertEquals(distances.getValue(1, 0), expectedValue10);
438    }
439   
440    }