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;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceFeature;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.AlignFrame;
29 import jalview.gui.JvOptionPane;
30 import jalview.io.DataSourceType;
31 import jalview.io.FileLoader;
33 import java.util.Arrays;
35 import org.testng.Assert;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
39 public class FeatureDistanceModelTest
42 @BeforeClass(alwaysRun = true)
43 public void setUpJvOptionPane()
45 JvOptionPane.setInteractiveMode(false);
46 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49 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";
51 int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
53 int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
55 int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
59 * Load test alignment and add features to sequences:
60 * FER1_MESCR FER1_SPIOL FER3_RAPSA FER1_MAIZE
68 public AlignFrame getTestAlignmentFrame()
70 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
71 alntestFile, DataSourceType.PASTE);
72 AlignmentI al = alf.getViewport().getAlignment();
73 Assert.assertEquals(al.getHeight(), 4);
74 Assert.assertEquals(al.getWidth(), 5);
75 for (int i = 0; i < 4; i++)
77 SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
80 ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
81 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
85 ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
86 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
90 ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
91 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
94 alf.setShowSeqFeatures(true);
95 alf.getFeatureRenderer().setVisible("sf1");
96 alf.getFeatureRenderer().setVisible("sf2");
97 alf.getFeatureRenderer().setVisible("sf3");
98 alf.getFeatureRenderer().findAllFeatures(true);
99 Assert.assertEquals(alf.getFeatureRenderer().getDisplayedFeatureTypes()
100 .size(), 3, "Number of feature types");
101 Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
105 @Test(groups = { "Functional" })
106 public void testFeatureScoreModel() throws Exception
108 AlignFrame alf = getTestAlignmentFrame();
109 FeatureDistanceModel fsm = new FeatureDistanceModel();
110 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
112 alf.selectAllSequenceMenuItem_actionPerformed(null);
114 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
116 Assert.assertTrue(dm[0][2] == 0f,
117 "FER1_MESCR (0) should be identical with RAPSA (2)");
118 Assert.assertTrue(dm[0][1] > dm[0][2],
119 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
122 @Test(groups = { "Functional" })
123 public void testFeatureScoreModel_hiddenFirstColumn() throws Exception
125 AlignFrame alf = getTestAlignmentFrame();
126 // hiding first two columns shouldn't affect the tree
127 alf.getViewport().hideColumns(0, 1);
128 FeatureDistanceModel fsm = new FeatureDistanceModel();
129 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
131 alf.selectAllSequenceMenuItem_actionPerformed(null);
132 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
134 Assert.assertTrue(dm[0][2] == 0f,
135 "FER1_MESCR (0) should be identical with RAPSA (2)");
136 Assert.assertTrue(dm[0][1] > dm[0][2],
137 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
140 @Test(groups = { "Functional" })
141 public void testFeatureScoreModel_HiddenColumns() throws Exception
143 AlignFrame alf = getTestAlignmentFrame();
144 // hide columns and check tree changes
145 alf.getViewport().hideColumns(3, 4);
146 alf.getViewport().hideColumns(0, 1);
147 FeatureDistanceModel fsm = new FeatureDistanceModel();
148 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
150 alf.selectAllSequenceMenuItem_actionPerformed(null);
151 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
155 "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)");
158 "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)");
159 for (int s = 0; s < 3; s++)
161 Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns "
162 + alf.getViewport().getAlignment().getSequenceAt(s).getName()
163 + "(" + s + ") should still be distinct from FER1_MAIZE (3)");
168 * Check findFeatureAt doesn't return contact features except at contact
169 * points TODO:move to under the FeatureRendererModel test suite
171 @Test(groups = { "Functional" })
172 public void testFindFeatureAt_PointFeature() throws Exception
174 String alignment = "a CCCCCCGGGGGGCCCCCC\n" + "b CCCCCCGGGGGGCCCCCC\n"
175 + "c CCCCCCGGGGGGCCCCCC\n";
176 AlignFrame af = new jalview.io.FileLoader(false)
177 .LoadFileWaitTillLoaded(alignment, DataSourceType.PASTE);
178 SequenceI aseq = af.getViewport().getAlignment().getSequenceAt(0);
179 SequenceFeature sf = null;
180 sf = new SequenceFeature("disulphide bond", "", 2, 5, Float.NaN, "");
181 aseq.addSequenceFeature(sf);
182 Assert.assertTrue(sf.isContactFeature());
183 af.refreshFeatureUI(true);
184 af.getFeatureRenderer().setAllVisible(Arrays.asList("disulphide bond"));
185 Assert.assertEquals(af.getFeatureRenderer().getDisplayedFeatureTypes()
186 .size(), 1, "Should be just one feature type displayed");
187 // step through and check for pointwise feature presence/absence
188 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 1)
190 // step through and check for pointwise feature presence/absence
191 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 2)
193 // step through and check for pointwise feature presence/absence
194 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 3)
196 // step through and check for pointwise feature presence/absence
197 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 4)
199 // step through and check for pointwise feature presence/absence
200 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 5)
202 // step through and check for pointwise feature presence/absence
203 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 6)
207 @Test(groups = { "Functional" })
208 public void testFindDistances() throws Exception
210 String seqs = ">s1\nABCDE\n>seq2\nABCDE\n";
211 AlignFrame alf = new FileLoader().LoadFileWaitTillLoaded(seqs,
212 DataSourceType.PASTE);
213 SequenceI s1 = alf.getViewport().getAlignment().getSequenceAt(0);
214 SequenceI s2 = alf.getViewport().getAlignment().getSequenceAt(1);
217 * set domain and variant features thus:
224 * The number of unshared feature types per column is
225 * 20120 (two features of the same type doesn't affect score)
226 * giving an average (pairwise distance) of 5/5 or 1.0
228 s1.addSequenceFeature(new SequenceFeature("domain", null, 1, 3, 0f,
230 s1.addSequenceFeature(new SequenceFeature("variant", null, 2, 4, 0f,
232 s1.addSequenceFeature(new SequenceFeature("variant", null, 3, 5, 0f,
234 s2.addSequenceFeature(new SequenceFeature("domain", null, 2, 4, 0f,
236 s2.addSequenceFeature(new SequenceFeature("variant", null, 1, 2, 0f,
238 s2.addSequenceFeature(new SequenceFeature("variant", null, 5, 5, 0f,
240 alf.setShowSeqFeatures(true);
241 alf.getFeatureRenderer().findAllFeatures(true);
243 FeatureDistanceModel fsm = new FeatureDistanceModel();
244 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
246 alf.selectAllSequenceMenuItem_actionPerformed(null);
248 float[][] distances = fsm.findDistances(alf.getViewport()
249 .getAlignmentView(true));
250 assertEquals(distances.length, 2);
251 assertEquals(distances[0][0], 0f);
252 assertEquals(distances[1][1], 0f);
253 // these left to fail pending resolution of
254 // JAL-2424 (dividing score by 6, not 5)
255 assertEquals(distances[0][1], 1f);
256 assertEquals(distances[1][0], 1f);