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.datamodel.features;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNull;
25 import static org.testng.Assert.assertTrue;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.features.FeatureAttributes.Datatype;
30 import java.util.Comparator;
31 import java.util.HashMap;
34 import org.testng.annotations.AfterMethod;
35 import org.testng.annotations.BeforeClass;
36 import org.testng.annotations.Test;
38 import junit.extensions.PA;
40 public class FeatureAttributesTest
44 * clear down attributes map before tests
46 @BeforeClass(alwaysRun = true)
49 FeatureAttributes fa = FeatureAttributes.getInstance();
50 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
54 * clear down attributes map after tests
56 @AfterMethod(alwaysRun = true)
57 public void tearDown()
59 FeatureAttributes fa = FeatureAttributes.getInstance();
60 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
64 * Test the method that keeps attribute names in non-case-sensitive order,
65 * including handling of 'compound' names
67 @Test(groups = "Functional")
68 public void testAttributeNameComparator()
70 FeatureAttributes fa = FeatureAttributes.getInstance();
71 Comparator<String[]> comp = (Comparator<String[]>) PA.getValue(fa,
75 comp.compare(new String[]
76 { "CSQ" }, new String[] { "csq" }), 0);
79 comp.compare(new String[]
80 { "CSQ", "a" }, new String[] { "csq" }) > 0);
83 comp.compare(new String[]
84 { "CSQ" }, new String[] { "csq", "b" }) < 0);
87 comp.compare(new String[]
88 { "CSQ", "AF" }, new String[] { "csq", "ac" }) > 0);
91 comp.compare(new String[]
92 { "CSQ", "ac" }, new String[] { "csq", "AF" }) < 0);
95 @Test(groups = "Functional")
96 public void testGetMinMax()
98 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
100 FeatureAttributes fa = FeatureAttributes.getInstance();
101 assertNull(fa.getMinMax("Pfam", "kd"));
102 sf.setValue("domain", "xyz");
103 assertNull(fa.getMinMax("Pfam", "kd"));
104 sf.setValue("kd", "1.3");
105 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { 1.3f, 1.3f });
106 sf.setValue("kd", "-2.6");
107 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { -2.6f, 1.3f });
108 // setting 'mixed' character and numeric values wipes the min/max value
109 sf.setValue("kd", "some text");
110 assertNull(fa.getMinMax("Pfam", "kd"));
112 Map<String, String> csq = new HashMap<>();
114 sf.setValue("CSQ", csq);
115 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
119 sf.setValue("CSQ", csq);
120 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
126 * Test the method that returns an attribute description, provided it is
127 * recorded and unique
129 @Test(groups = "Functional")
130 public void testGetDescription()
132 FeatureAttributes fa = FeatureAttributes.getInstance();
133 // with no description returns null
134 assertNull(fa.getDescription("Pfam", "kd"));
135 // with a unique description, returns that value
136 fa.addDescription("Pfam", "desc1", "kd");
137 assertEquals(fa.getDescription("Pfam", "kd"), "desc1");
138 // with ambiguous description, returns null
139 fa.addDescription("Pfam", "desc2", "kd");
140 assertNull(fa.getDescription("Pfam", "kd"));
143 @Test(groups = "Functional")
144 public void testDatatype()
146 FeatureAttributes fa = FeatureAttributes.getInstance();
147 assertNull(fa.getDatatype("Pfam", "kd"));
148 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
150 sf.setValue("kd", "-1");
151 sf.setValue("domain", "Metal");
152 sf.setValue("phase", "1");
153 sf.setValue("phase", "reverse");
154 assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number);
155 assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character);
156 assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed);