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.io.FileLoader;
28 import jalview.io.FormatAdapter;
30 import java.util.Arrays;
32 import org.testng.Assert;
33 import org.testng.annotations.Test;
35 public class FeatureScoreModelTest
37 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";
39 int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
41 int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
43 int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
45 public AlignFrame getTestAlignmentFrame()
47 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
48 alntestFile, FormatAdapter.PASTE);
49 AlignmentI al = alf.getViewport().getAlignment();
50 Assert.assertEquals(al.getHeight(), 4);
51 Assert.assertEquals(al.getWidth(), 5);
52 for (int i = 0; i < 4; i++)
54 SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
57 ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
58 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
62 ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
63 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
67 ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
68 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
71 alf.setShowSeqFeatures(true);
72 alf.getFeatureRenderer().setVisible("sf1");
73 alf.getFeatureRenderer().setVisible("sf2");
74 alf.getFeatureRenderer().setVisible("sf3");
75 alf.getFeatureRenderer().findAllFeatures(true);
76 Assert.assertEquals(alf.getFeatureRenderer().getDisplayedFeatureTypes()
77 .size(), 3, "Number of feature types");
78 Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
82 @Test(groups = { "Functional" })
83 public void testFeatureScoreModel() throws Exception
85 AlignFrame alf = getTestAlignmentFrame();
86 FeatureScoreModel fsm = new FeatureScoreModel();
87 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
89 alf.selectAllSequenceMenuItem_actionPerformed(null);
90 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
92 Assert.assertTrue(dm[0][2] == 0f,
93 "FER1_MESCR (0) should be identical with RAPSA (2)");
94 Assert.assertTrue(dm[0][1] > dm[0][2],
95 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
98 @Test(groups = { "Functional" })
99 public void testFeatureScoreModel_hiddenFirstColumn() throws Exception
101 AlignFrame alf = getTestAlignmentFrame();
102 // hiding first two columns shouldn't affect the tree
103 alf.getViewport().hideColumns(0, 1);
104 FeatureScoreModel fsm = new FeatureScoreModel();
105 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
107 alf.selectAllSequenceMenuItem_actionPerformed(null);
108 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
110 Assert.assertTrue(dm[0][2] == 0f,
111 "FER1_MESCR (0) should be identical with RAPSA (2)");
112 Assert.assertTrue(dm[0][1] > dm[0][2],
113 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
116 @Test(groups = { "Functional" })
117 public void testFeatureScoreModel_HiddenColumns() throws Exception
119 AlignFrame alf = getTestAlignmentFrame();
120 // hide columns and check tree changes
121 alf.getViewport().hideColumns(3, 4);
122 alf.getViewport().hideColumns(0, 1);
123 FeatureScoreModel fsm = new FeatureScoreModel();
124 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
126 alf.selectAllSequenceMenuItem_actionPerformed(null);
127 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
131 "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)");
134 "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)");
135 for (int s = 0; s < 3; s++)
137 Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns "
138 + alf.getViewport().getAlignment().getSequenceAt(s).getName()
139 + "(" + s + ") should still be distinct from FER1_MAIZE (3)");
144 * Check findFeatureAt doesn't return contact features except at contact
145 * points TODO:move to under the FeatureRendererModel test suite
147 @Test(groups = { "Functional" })
148 public void testFindFeatureAt_PointFeature() throws Exception
150 String alignment = "a CCCCCCGGGGGGCCCCCC\n" + "b CCCCCCGGGGGGCCCCCC\n"
151 + "c CCCCCCGGGGGGCCCCCC\n";
152 AlignFrame af = new jalview.io.FileLoader(false)
153 .LoadFileWaitTillLoaded(alignment, FormatAdapter.PASTE);
154 SequenceI aseq = af.getViewport().getAlignment().getSequenceAt(0);
155 SequenceFeature sf = null;
156 sf = new SequenceFeature("disulphide bond", "", 2, 5, Float.NaN, "");
157 aseq.addSequenceFeature(sf);
158 Assert.assertTrue(sf.isContactFeature());
159 af.refreshFeatureUI(true);
160 af.getFeatureRenderer().setAllVisible(Arrays.asList("disulphide bond"));
161 Assert.assertEquals(af.getFeatureRenderer().getDisplayedFeatureTypes()
162 .size(), 1, "Should be just one feature type displayed");
163 // step through and check for pointwise feature presence/absence
164 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 1)
166 // step through and check for pointwise feature presence/absence
167 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 2)
169 // step through and check for pointwise feature presence/absence
170 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 3)
172 // step through and check for pointwise feature presence/absence
173 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 4)
175 // step through and check for pointwise feature presence/absence
176 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 5)
178 // step through and check for pointwise feature presence/absence
179 Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 6)