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 jalview.datamodel.AlignmentI;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceI;
26 import jalview.gui.AlignFrame;
27 import jalview.gui.JvOptionPane;
28 import jalview.io.DataSourceType;
29 import jalview.io.FileLoader;
31 import java.util.Arrays;
33 import org.testng.Assert;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 public class FeatureScoreModelTest
40 @BeforeClass(alwaysRun = true)
41 public void setUpJvOptionPane()
43 JvOptionPane.setInteractiveMode(false);
44 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47 public static String alntestFile = "FER1_MESCR/72-76 DVYIL\nFER1_SPIOL/71-75 DVYIL\nFER3_RAPSA/21-25 DVYVL\nFER1_MAIZE/73-77 DVYIL\n";
49 int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
51 int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
53 int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
55 public AlignFrame getTestAlignmentFrame()
57 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
58 alntestFile, DataSourceType.PASTE);
59 AlignmentI al = alf.getViewport().getAlignment();
60 Assert.assertEquals(al.getHeight(), 4);
61 Assert.assertEquals(al.getWidth(), 5);
62 for (int i = 0; i < 4; i++)
64 SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
67 ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
68 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
72 ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
73 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
77 ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
78 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
81 alf.setShowSeqFeatures(true);
82 alf.getFeatureRenderer().setVisible("sf1");
83 alf.getFeatureRenderer().setVisible("sf2");
84 alf.getFeatureRenderer().setVisible("sf3");
85 alf.getFeatureRenderer().findAllFeatures(true);
86 Assert.assertEquals(alf.getFeatureRenderer().getDisplayedFeatureTypes()
87 .size(), 3, "Number of feature types");
88 Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
92 @Test(groups = { "Functional" })
93 public void testFeatureScoreModel() throws Exception
95 AlignFrame alf = getTestAlignmentFrame();
96 FeatureScoreModel fsm = new FeatureScoreModel();
97 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
99 alf.selectAllSequenceMenuItem_actionPerformed(null);
100 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
102 Assert.assertTrue(dm[0][2] == 0f,
103 "FER1_MESCR (0) should be identical with RAPSA (2)");
104 Assert.assertTrue(dm[0][1] > dm[0][2],
105 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
108 @Test(groups = { "Functional" })
109 public void testFeatureScoreModel_hiddenFirstColumn() throws Exception
111 AlignFrame alf = getTestAlignmentFrame();
112 // hiding first two columns shouldn't affect the tree
113 alf.getViewport().hideColumns(0, 1);
114 FeatureScoreModel fsm = new FeatureScoreModel();
115 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
117 alf.selectAllSequenceMenuItem_actionPerformed(null);
118 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
120 Assert.assertTrue(dm[0][2] == 0f,
121 "FER1_MESCR (0) should be identical with RAPSA (2)");
122 Assert.assertTrue(dm[0][1] > dm[0][2],
123 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
126 @Test(groups = { "Functional" })
127 public void testFeatureScoreModel_HiddenColumns() throws Exception
129 AlignFrame alf = getTestAlignmentFrame();
130 // hide columns and check tree changes
131 alf.getViewport().hideColumns(3, 4);
132 alf.getViewport().hideColumns(0, 1);
133 FeatureScoreModel fsm = new FeatureScoreModel();
134 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
136 alf.selectAllSequenceMenuItem_actionPerformed(null);
137 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
141 "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)");
144 "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)");
145 for (int s = 0; s < 3; s++)
147 Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns "
148 + alf.getViewport().getAlignment().getSequenceAt(s).getName()
149 + "(" + s + ") should still be distinct from FER1_MAIZE (3)");
154 * Check findFeatureAt doesn't return contact features except at contact
155 * points TODO:move to under the FeatureRendererModel test suite
157 @Test(groups = { "Functional" })
158 public void testFindFeatureAt_PointFeature() throws Exception
160 String alignment = "a CCCCCCGGGGGGCCCCCC\n" + "b CCCCCCGGGGGGCCCCCC\n"
161 + "c CCCCCCGGGGGGCCCCCC\n";
162 AlignFrame af = new jalview.io.FileLoader(false)
163 .LoadFileWaitTillLoaded(alignment, DataSourceType.PASTE);
164 SequenceI aseq = af.getViewport().getAlignment().getSequenceAt(0);
165 SequenceFeature sf = null;
166 sf = new SequenceFeature("disulphide bond", "", 2, 5, Float.NaN, "");
167 aseq.addSequenceFeature(sf);
168 Assert.assertTrue(sf.isContactFeature());
169 af.refreshFeatureUI(true);
170 af.getFeatureRenderer().setAllVisible(Arrays.asList("disulphide bond"));
171 Assert.assertEquals(af.getFeatureRenderer().getDisplayedFeatureTypes()
172 .size(), 1, "Should be just one feature type displayed");
173 // step through and check for pointwise feature presence/absence
174 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 1)
176 // step through and check for pointwise feature presence/absence
177 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 2)
179 // step through and check for pointwise feature presence/absence
180 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 3)
182 // step through and check for pointwise feature presence/absence
183 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 4)
185 // step through and check for pointwise feature presence/absence
186 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 5)
188 // step through and check for pointwise feature presence/absence
189 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 6)