JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / analysis / scoremodels / FeatureScoreModelTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.analysis.scoremodels;
22
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;
29
30 import org.testng.AssertJUnit;
31 import org.testng.annotations.Test;
32
33 public class FeatureScoreModelTest
34 {
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";
36
37   int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 };
38
39   int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 };
40
41   int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 };
42
43   @Test(groups = { "Functional" })
44   public void testFeatureScoreModel() throws Exception
45   {
46     AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
47             alntestFile, FormatAdapter.PASTE);
48     AlignmentI al = alf.getViewport().getAlignment();
49     AssertJUnit.assertEquals(4, al.getHeight());
50     AssertJUnit.assertEquals(5, al.getWidth());
51     for (int i = 0; i < 4; i++)
52     {
53       SequenceI ds = al.getSequenceAt(i).getDatasetSequence();
54       if (sf1[i * 2] > 0)
55       {
56         ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1",
57                 sf1[i * 2], sf1[i * 2 + 1], "sf1"));
58       }
59       if (sf2[i * 2] > 0)
60       {
61         ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2",
62                 sf2[i * 2], sf2[i * 2 + 1], "sf2"));
63       }
64       if (sf3[i * 2] > 0)
65       {
66         ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3",
67                 sf3[i * 2], sf3[i * 2 + 1], "sf3"));
68       }
69     }
70     alf.setShowSeqFeatures(true);
71     alf.getFeatureRenderer().setVisible("sf1");
72     alf.getFeatureRenderer().setVisible("sf2");
73     alf.getFeatureRenderer().setVisible("sf3");
74     alf.getFeatureRenderer().findAllFeatures(true);
75     AssertJUnit.assertEquals("Number of feature types", 3, alf
76             .getFeatureRenderer().getDisplayedFeatureTypes().length);
77     AssertJUnit.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
78     FeatureScoreModel fsm = new FeatureScoreModel();
79     AssertJUnit.assertTrue(fsm.configureFromAlignmentView(alf
80             .getCurrentView().getAlignPanel()));
81     alf.selectAllSequenceMenuItem_actionPerformed(null);
82     float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView(
83             true));
84     AssertJUnit.assertTrue("FER1_MESCR should be identical with RAPSA (2)",
85             dm[0][2] == 0f);
86     AssertJUnit
87             .assertTrue(
88                     "FER1_MESCR should be further from SPIOL (1) than it is from RAPSA (2)",
89                     dm[0][1] > dm[0][2]);
90
91   }
92 }