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 org.testng.Assert;
31 import org.testng.annotations.Test;
33 public class FeatureScoreModelTest
35 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";
37 int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
39 int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
41 int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
43 public AlignFrame getTestAlignmentFrame()
45 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
46 alntestFile, FormatAdapter.PASTE);
47 AlignmentI al = alf.getViewport().getAlignment();
48 Assert.assertEquals(al.getHeight(), 4);
49 Assert.assertEquals(al.getWidth(), 5);
50 for (int i = 0; i < 4; i++)
52 SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
55 ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
56 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
60 ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
61 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
65 ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
66 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
69 alf.setShowSeqFeatures(true);
70 alf.getFeatureRenderer().setVisible("sf1");
71 alf.getFeatureRenderer().setVisible("sf2");
72 alf.getFeatureRenderer().setVisible("sf3");
73 alf.getFeatureRenderer().findAllFeatures(true);
74 Assert.assertEquals(alf.getFeatureRenderer().getDisplayedFeatureTypes()
75 .size(), 3, "Number of feature types");
76 Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
80 @Test(groups = { "Functional" })
81 public void testFeatureScoreModel() throws Exception
83 AlignFrame alf = getTestAlignmentFrame();
84 FeatureScoreModel fsm = new FeatureScoreModel();
85 Assert.assertTrue(fsm.configureFromAlignmentView(alf
86 .getCurrentView().getAlignPanel()));
87 alf.selectAllSequenceMenuItem_actionPerformed(null);
88 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
90 Assert.assertTrue(dm[0][2] == 0f,
91 "FER1_MESCR (0) should be identical with RAPSA (2)");
92 Assert.assertTrue(dm[0][1] > dm[0][2],
93 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
96 @Test(groups = { "Functional" })
97 public void testFeatureScoreModel_hiddenFirstColumn() throws Exception
99 AlignFrame alf = getTestAlignmentFrame();
100 // hiding first two columns shouldn't affect the tree
101 alf.getViewport().hideColumns(0, 1);
102 FeatureScoreModel fsm = new FeatureScoreModel();
103 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
105 alf.selectAllSequenceMenuItem_actionPerformed(null);
106 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
108 Assert.assertTrue(dm[0][2] == 0f,
109 "FER1_MESCR (0) should be identical with RAPSA (2)");
110 Assert.assertTrue(dm[0][1] > dm[0][2],
111 "FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)");
114 @Test(groups = { "Functional" })
115 public void testFeatureScoreModel_HiddenColumns() throws Exception
117 AlignFrame alf = getTestAlignmentFrame();
118 // hide columns and check tree changes
119 alf.getViewport().hideColumns(3, 4);
120 alf.getViewport().hideColumns(0, 1);
121 FeatureScoreModel fsm = new FeatureScoreModel();
122 Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
124 alf.selectAllSequenceMenuItem_actionPerformed(null);
125 float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
127 Assert.assertTrue(dm[0][2] == 0f,
128 "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)");
129 Assert.assertTrue(dm[0][1] == 0f,
130 "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)");
131 for (int s=0;s<3;s++)
133 Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns "
134 + alf.getViewport().getAlignment().getSequenceAt(s).getName()
135 + "(" + s + ") should still be distinct from FER1_MAIZE (3)");