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;
24 import static org.testng.Assert.assertTrue;
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;
43 import org.testng.Assert;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
48 // This class tests methods in Class SecondaryStructureDistanceModel
49 public class SecondaryStructureDistanceModelTest
53 * Verify computed distances of sequences with gap
55 @Test(groups = "Functional")
56 public void testFindDistances_withGap()
58 AlignFrame af = setupAlignmentViewWithGap();
59 AlignViewport viewport = af.getViewport();
60 AlignmentView view = viewport.getAlignmentView(false);
62 ScoreModelI sm = new SecondaryStructureDistanceModel();
63 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
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'
74 * score = 0 + 0 + 1 + 0 = 1/4
76 SimilarityParamsI params = new SimilarityParams(false, true, true, true);
77 params.setSecondaryStructureSource("3D Structures");
78 MatrixI distances = sm.findDistances(view, params);
79 assertEquals(distances.getValue(0, 0), 1d);
80 assertEquals(distances.getValue(1, 1), 1d);
81 assertEquals(distances.getValue(0, 1), 0d);
82 assertEquals(distances.getValue(1, 0), 0d);
86 * score = 0 + 0 + 0 + 0 = 0/4
89 SimilarityParamsI params2 = new SimilarityParams(false, true, false, true);
90 params2.setSecondaryStructureSource("3D Structures");
91 MatrixI distances2 = sm.findDistances(view, params2);
92 assertEquals(distances2.getValue(0, 1), 0d);
93 assertEquals(distances2.getValue(1, 0), 0d);
98 * Verify computed distances of sequences with gap
100 @Test(groups = "Functional")
101 public void testFindDistances_withSSUndefinedInEitherOneSeq()
103 AlignFrame af = setupAlignmentViewWithoutSS("either");
104 AlignViewport viewport = af.getViewport();
105 AlignmentView view = viewport.getAlignmentView(false);
107 ScoreModelI sm = new SecondaryStructureDistanceModel();
108 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
112 * feature distance model always normalises by region width
113 * gap-gap is always included (but scores zero)
114 * the only variable parameter is 'includeGaps'
119 * score = 0 + 0 + 2 + 2 = 2/4
121 SimilarityParamsI params = new SimilarityParams(false, true, true, true);
122 params.setSecondaryStructureSource("3D Structures");
123 MatrixI distances = sm.findDistances(view, params);
124 assertEquals(distances.getValue(0, 0), 1d);
125 assertEquals(distances.getValue(1, 1), 1d);
126 assertEquals(distances.getValue(0, 1), 0d);
127 assertEquals(distances.getValue(1, 0), 0d);
131 * score = 0 + 0 + 2 + 2 = 2/4
134 SimilarityParamsI params2 = new SimilarityParams(false, true, false, true);
135 params2.setSecondaryStructureSource("3D Structures");
136 MatrixI distances2 = sm.findDistances(view, params2);
137 assertEquals(distances2.getValue(0, 1), 0d);
138 assertEquals(distances2.getValue(1, 0), 0d);
143 * Verify computed distances of sequences with gap
145 @Test(groups = "Functional")
146 public void testFindDistances_withSSUndefinedInBothSeqs()
148 AlignFrame af = setupAlignmentViewWithoutSS("both");
149 AlignViewport viewport = af.getViewport();
150 AlignmentView view = viewport.getAlignmentView(false);
152 ScoreModelI sm = new SecondaryStructureDistanceModel();
153 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
157 * feature distance model always normalises by region width
158 * gap-gap is always included (but scores zero)
159 * the only variable parameter is 'includeGaps'
164 * score = 0 + 0 + 2 + 2 = 2/4
166 SimilarityParamsI params = new SimilarityParams(false, true, true, true);
167 params.setSecondaryStructureSource("3D Structures");
168 MatrixI distances = sm.findDistances(view, params);
169 assertEquals(distances.getValue(0, 0), 1d);
170 assertEquals(distances.getValue(1, 1), 1d);
171 assertEquals(distances.getValue(0, 1), 0d);
172 assertEquals(distances.getValue(1, 0), 0d);
176 * score = 0 + 0 + 2 + 2 = 2/4
179 SimilarityParamsI params2 = new SimilarityParams(false, true, false, true);
180 params2.setSecondaryStructureSource("3D Structures");
181 MatrixI distances2 = sm.findDistances(view, params2);
182 assertEquals(distances2.getValue(0, 1), 0d);
183 assertEquals(distances2.getValue(1, 0), 0d);
199 protected AlignFrame setupAlignmentView(String similar)
202 * sequences without gaps
204 SequenceI s1 = new Sequence("s1", "FRKS");
205 SequenceI s2 = new Sequence("s2", "FSJL");
207 s1.addSequenceFeature(
208 new SequenceFeature("chain", null, 1, 4, 0f, null));
209 s1.addSequenceFeature(
210 new SequenceFeature("domain", null, 1, 4, 0f, null));
211 s2.addSequenceFeature(
212 new SequenceFeature("chain", null, 1, 4, 0f, null));
213 s2.addSequenceFeature(
214 new SequenceFeature("metal", null, 1, 4, 0f, null));
215 s2.addSequenceFeature(
216 new SequenceFeature("Pfam", null, 1, 4, 0f, null));
220 * Set up secondary structure annotations
222 Annotation ssE = new Annotation("","",'E',0);
223 Annotation ssH = new Annotation("","",'H',0);
224 Annotation ssC = new Annotation(".","",' ',0);
229 /* All secondary structure annotations are similar for each column
238 if(similar == "All Similar") {
240 anns1 = new Annotation[] { ssE, ssH, ssC, ssE};
241 anns2 = new Annotation[] { ssE, ssH, ssC, ssE};
245 /* All secondary structure annotations are dissimilar for each column
254 else if(similar == "Not Similar") {
256 anns1 = new Annotation[] { ssE, ssE, ssC, ssE};
257 anns2 = new Annotation[] { ssH, ssH, ssE, ssC};
261 /* All secondary structure annotations are dissimilar for each column
270 else if(similar == "With Coil") {
272 anns1 = new Annotation[] { ssE, ssE, null, ssE};
273 anns2 = new Annotation[] { ssH, ssH, ssE, null};
287 anns1 = new Annotation[] { ssH, ssE, ssC, ssE};
288 anns2 = new Annotation[] { ssH, ssE, ssE, ssC};
292 AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure",
293 "Secondary Structure", anns1);
294 AlignmentAnnotation ann2 = new AlignmentAnnotation("Secondary Structure",
295 "Secondary Structure", anns2);
297 s1.addAlignmentAnnotation(ann1);
298 s2.addAlignmentAnnotation(ann2);
300 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
301 AlignFrame af = new AlignFrame(al, 300, 300);
302 af.setShowSeqFeatures(true);
303 af.getFeatureRenderer().findAllFeatures(true);
321 protected AlignFrame setupAlignmentViewWithGap()
324 SequenceI s1 = new Sequence("s1", "FR S");
325 SequenceI s2 = new Sequence("s2", "FSJL");
327 s1.addSequenceFeature(
328 new SequenceFeature("chain", null, 1, 3, 0f, null));
329 s1.addSequenceFeature(
330 new SequenceFeature("domain", null, 1, 3, 0f, null));
331 s2.addSequenceFeature(
332 new SequenceFeature("chain", null, 1, 4, 0f, null));
333 s2.addSequenceFeature(
334 new SequenceFeature("metal", null, 1, 4, 0f, null));
335 s2.addSequenceFeature(
336 new SequenceFeature("Pfam", null, 1, 4, 0f, null));
339 Annotation ssE = new Annotation("","",'E',0);
340 Annotation ssH = new Annotation("","",'H',0);
341 Annotation ssC = new Annotation(".","",' ',0);
346 anns1 = new Annotation[] { ssH, ssE, ssC};
347 anns2 = new Annotation[] { ssH, ssE, ssE, ssC};
349 AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure",
350 "Secondary Structure", anns1);
351 AlignmentAnnotation ann2 = new AlignmentAnnotation("Secondary Structure",
352 "Secondary Structure", anns2);
354 s1.addAlignmentAnnotation(ann1);
355 s2.addAlignmentAnnotation(ann2);
357 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
358 AlignFrame af = new AlignFrame(al, 300, 300);
359 af.setShowSeqFeatures(true);
360 af.getFeatureRenderer().findAllFeatures(true);
365 protected AlignFrame setupAlignmentViewWithoutSS(String type) {
367 SequenceI s1 = new Sequence("s1", "FR S");
368 SequenceI s2 = new Sequence("s2", "FSJL");
370 s1.addSequenceFeature(
371 new SequenceFeature("chain", null, 1, 3, 0f, null));
372 s1.addSequenceFeature(
373 new SequenceFeature("domain", null, 1, 3, 0f, null));
374 s2.addSequenceFeature(
375 new SequenceFeature("chain", null, 1, 4, 0f, null));
376 s2.addSequenceFeature(
377 new SequenceFeature("metal", null, 1, 4, 0f, null));
378 s2.addSequenceFeature(
379 new SequenceFeature("Pfam", null, 1, 4, 0f, null));
381 if(!type.equals("both")) {
382 Annotation ssE = new Annotation("","",'E',0);
383 Annotation ssH = new Annotation("","",'H',0);
384 Annotation ssC = new Annotation(".","",' ',0);
388 anns1 = new Annotation[] { ssH, ssE, ssC};
390 AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure",
391 "Secondary Structure", anns1);
393 s1.addAlignmentAnnotation(ann1);
396 AlignmentI al = new Alignment(new SequenceI[] { s1, s2 });
397 AlignFrame af = new AlignFrame(al, 300, 300);
398 af.setShowSeqFeatures(true);
399 af.getFeatureRenderer().findAllFeatures(true);
404 @DataProvider(name = "testData")
405 public Object[][] testData() {
406 return new Object[][] {
407 {"All Similar", 1d, 1d, 0d, 0d / 4},
408 {"Partially Similar", 1d, 1d, 0d, 0d},
409 {"Not Similar", 1d, 1d, 0d, 0d},
410 {"With Coil", 1d, 1d, 0d, 0d},
414 @Test(dataProvider = "testData")
415 public void testFindDistances(String scenario, double expectedValue00, double expectedValue11,
416 double expectedValue01, double expectedValue10) {
417 AlignFrame af = setupAlignmentView(scenario);
418 AlignViewport viewport = af.getViewport();
419 AlignmentView view = viewport.getAlignmentView(false);
421 ScoreModelI sm = new SecondaryStructureDistanceModel();
422 sm = ScoreModels.getInstance().getScoreModel(sm.getName(),
425 SimilarityParamsI params = new SimilarityParams(false, true, true, true);
426 params.setSecondaryStructureSource("3D Structures");
427 MatrixI distances = sm.findDistances(view, params);
429 assertEquals(distances.getValue(0, 0), expectedValue00);
430 assertEquals(distances.getValue(1, 1), expectedValue11);
431 assertEquals(distances.getValue(0, 1), expectedValue01);
432 assertEquals(distances.getValue(1, 0), expectedValue10);