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.FileLoader;
29 import jalview.io.FormatAdapter;
31 import org.testng.Assert;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.Test;
35 public class FeatureScoreModelTest
38 @BeforeClass(alwaysRun = true)
39 public void setUpJvOptionPane()
41 JvOptionPane.setInteractiveMode(false);
42 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45 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";
47 int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
49 int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
51 int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
53 public AlignFrame getTestAlignmentFrame()
55 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
56 alntestFile, FormatAdapter.PASTE);
57 AlignmentI al = alf.getViewport().getAlignment();
58 Assert.assertEquals(al.getHeight(), 4);
59 Assert.assertEquals(al.getWidth(), 5);
60 for (int i = 0; i < 4; i++)
62 SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
65 ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
66 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
70 ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
71 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
75 ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
76 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
79 alf.setShowSeqFeatures(true);
80 alf.getFeatureRenderer().setVisible("sf1");
81 alf.getFeatureRenderer().setVisible("sf2");
82 alf.getFeatureRenderer().setVisible("sf3");
83 alf.getFeatureRenderer().findAllFeatures(true);
84 Assert.assertEquals(alf.getFeatureRenderer().getDisplayedFeatureTypes()
85 .size(), 3, "Number of feature types");
86 Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
90 @Test(groups = { "Functional" })
91 public void testFeatureScoreModel() throws Exception
93 AlignFrame alf = getTestAlignmentFrame();
94 FeatureScoreModel fsm = new FeatureScoreModel();
95 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
97 alf.selectAllSequenceMenuItem_actionPerformed(null);
98 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
100 Assert.assertTrue(dm[0][2] == 0f,
101 "FER1_MESCR (0) should be identical with RAPSA (2)");
102 Assert.assertTrue(dm[0][1] > dm[0][2],
103 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
106 @Test(groups = { "Functional" })
107 public void testFeatureScoreModel_hiddenFirstColumn() throws Exception
109 AlignFrame alf = getTestAlignmentFrame();
110 // hiding first two columns shouldn't affect the tree
111 alf.getViewport().hideColumns(0, 1);
112 FeatureScoreModel fsm = new FeatureScoreModel();
113 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
115 alf.selectAllSequenceMenuItem_actionPerformed(null);
116 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
118 Assert.assertTrue(dm[0][2] == 0f,
119 "FER1_MESCR (0) should be identical with RAPSA (2)");
120 Assert.assertTrue(dm[0][1] > dm[0][2],
121 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
124 @Test(groups = { "Functional" })
125 public void testFeatureScoreModel_HiddenColumns() throws Exception
127 AlignFrame alf = getTestAlignmentFrame();
128 // hide columns and check tree changes
129 alf.getViewport().hideColumns(3, 4);
130 alf.getViewport().hideColumns(0, 1);
131 FeatureScoreModel fsm = new FeatureScoreModel();
132 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
134 alf.selectAllSequenceMenuItem_actionPerformed(null);
135 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
139 "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)");
142 "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)");
143 for (int s = 0; s < 3; s++)
145 Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns "
146 + alf.getViewport().getAlignment().getSequenceAt(s).getName()
147 + "(" + s + ") should still be distinct from FER1_MAIZE (3)");