1 |
|
package jalview.gui; |
2 |
|
|
3 |
|
import static org.testng.Assert.assertEquals; |
4 |
|
import static org.testng.Assert.assertNull; |
5 |
|
import static org.testng.Assert.assertTrue; |
6 |
|
|
7 |
|
import jalview.api.FeatureColourI; |
8 |
|
import jalview.datamodel.SequenceFeature; |
9 |
|
import jalview.datamodel.SequenceI; |
10 |
|
import jalview.datamodel.features.FeatureMatcher; |
11 |
|
import jalview.datamodel.features.FeatureMatcherSet; |
12 |
|
import jalview.datamodel.features.FeatureMatcherSetI; |
13 |
|
import jalview.io.DataSourceType; |
14 |
|
import jalview.io.FileLoader; |
15 |
|
import jalview.schemes.FeatureColour; |
16 |
|
import jalview.schemes.FeatureColourTest; |
17 |
|
import jalview.util.matcher.Condition; |
18 |
|
|
19 |
|
import java.awt.Color; |
20 |
|
import java.io.File; |
21 |
|
import java.io.IOException; |
22 |
|
import java.util.HashMap; |
23 |
|
|
24 |
|
import org.testng.annotations.Test; |
25 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (106) |
Complexity: 5 |
Complexity Density: 0.05 |
|
26 |
|
public class FeatureSettingsTest |
27 |
|
{ |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@throws |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (78) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
33 |
1 |
@Test(groups = "Functional")... |
34 |
|
public void testSaveLoad() throws IOException |
35 |
|
{ |
36 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
37 |
|
">Seq1\nACDEFGHIKLM", DataSourceType.PASTE); |
38 |
1 |
SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
1 |
int score = 1; |
44 |
1 |
addFeatures(seq1, "type1", score++); |
45 |
1 |
addFeatures(seq1, "type2", score++); |
46 |
1 |
addFeatures(seq1, "type3", score++); |
47 |
1 |
addFeatures(seq1, "type4", score++); |
48 |
1 |
addFeatures(seq1, "type5", score++); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
1 |
FeatureRenderer fr = af.getFeatureRenderer(); |
54 |
|
|
55 |
|
|
56 |
1 |
fr.setColour("type1", new FeatureColour(Color.red)); |
57 |
|
|
58 |
|
|
59 |
1 |
FeatureColourI byLabel = new FeatureColour(); |
60 |
1 |
byLabel.setColourByLabel(true); |
61 |
1 |
fr.setColour("type2", byLabel); |
62 |
|
|
63 |
|
|
64 |
1 |
FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, |
65 |
|
10); |
66 |
1 |
byScore.setAboveThreshold(true); |
67 |
1 |
byScore.setThreshold(2f); |
68 |
1 |
fr.setColour("type3", byScore); |
69 |
|
|
70 |
|
|
71 |
1 |
FeatureColourI byAF = new FeatureColour(); |
72 |
1 |
byAF.setColourByLabel(true); |
73 |
1 |
byAF.setAttributeName("AF"); |
74 |
1 |
fr.setColour("type4", byAF); |
75 |
|
|
76 |
|
|
77 |
1 |
FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, |
78 |
|
1, 10); |
79 |
1 |
byPolyPhen.setBelowThreshold(true); |
80 |
1 |
byPolyPhen.setThreshold(3f); |
81 |
1 |
byPolyPhen.setAttributeName("CSQ", "PolyPhen"); |
82 |
1 |
fr.setColour("type5", byPolyPhen); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
1 |
FeatureMatcherSetI filterByX = new FeatureMatcherSet(); |
90 |
1 |
filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x")); |
91 |
1 |
fr.setFeatureFilter("type1", filterByX); |
92 |
|
|
93 |
|
|
94 |
1 |
FeatureMatcherSetI filterByScore = new FeatureMatcherSet(); |
95 |
1 |
filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4")); |
96 |
1 |
filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1")); |
97 |
1 |
fr.setFeatureFilter("type2", filterByScore); |
98 |
|
|
99 |
|
|
100 |
1 |
FeatureMatcherSetI filterByXY = new FeatureMatcherSet(); |
101 |
1 |
filterByXY |
102 |
|
.and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF")); |
103 |
1 |
filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ", |
104 |
|
"PolyPhen")); |
105 |
1 |
fr.setFeatureFilter("type3", filterByXY); |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
1 |
File coloursFile = File.createTempFile("testSaveLoad", ".fc"); |
111 |
1 |
coloursFile.deleteOnExit(); |
112 |
1 |
FeatureSettings fs = new FeatureSettings(af); |
113 |
1 |
fs.save(coloursFile); |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
1 |
FeatureColourI pink = new FeatureColour(Color.pink); |
119 |
1 |
fr.setColour("type1", pink); |
120 |
1 |
fr.setColour("type2", pink); |
121 |
1 |
fr.setColour("type3", pink); |
122 |
1 |
fr.setColour("type4", pink); |
123 |
1 |
fr.setColour("type5", pink); |
124 |
|
|
125 |
1 |
FeatureMatcherSetI filter2 = new FeatureMatcherSet(); |
126 |
1 |
filter2.and(FeatureMatcher.byLabel(Condition.NotContains, "y")); |
127 |
1 |
fr.setFeatureFilter("type1", filter2); |
128 |
1 |
fr.setFeatureFilter("type2", filter2); |
129 |
1 |
fr.setFeatureFilter("type3", filter2); |
130 |
1 |
fr.setFeatureFilter("type4", filter2); |
131 |
1 |
fr.setFeatureFilter("type5", filter2); |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
1 |
fs.load(coloursFile); |
137 |
1 |
FeatureColourI fc = fr.getFeatureStyle("type1"); |
138 |
1 |
assertTrue(fc.isSimpleColour()); |
139 |
1 |
assertEquals(fc.getColour(), Color.red); |
140 |
1 |
fc = fr.getFeatureStyle("type2"); |
141 |
1 |
assertTrue(fc.isColourByLabel()); |
142 |
1 |
fc = fr.getFeatureStyle("type3"); |
143 |
1 |
assertTrue(fc.isGraduatedColour()); |
144 |
1 |
assertNull(fc.getAttributeName()); |
145 |
1 |
assertTrue(fc.isAboveThreshold()); |
146 |
1 |
assertEquals(fc.getThreshold(), 2f); |
147 |
1 |
fc = fr.getFeatureStyle("type4"); |
148 |
1 |
assertTrue(fc.isColourByLabel()); |
149 |
1 |
assertTrue(fc.isColourByAttribute()); |
150 |
1 |
assertEquals(fc.getAttributeName(), new String[] { "AF" }); |
151 |
1 |
fc = fr.getFeatureStyle("type5"); |
152 |
1 |
assertTrue(fc.isGraduatedColour()); |
153 |
1 |
assertTrue(fc.isColourByAttribute()); |
154 |
1 |
assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" }); |
155 |
1 |
assertTrue(fc.isBelowThreshold()); |
156 |
1 |
assertEquals(fc.getThreshold(), 3f); |
157 |
|
|
158 |
1 |
assertEquals(fr.getFeatureFilter("type1").toStableString(), "Label Contains x"); |
159 |
1 |
assertEquals(fr.getFeatureFilter("type2").toStableString(), |
160 |
|
"(Score LE 2.4) AND (Score GT 1.1)"); |
161 |
1 |
assertEquals(fr.getFeatureFilter("type3").toStableString(), |
162 |
|
"(AF Contains X) OR (CSQ:PolyPhen NE 0.0)"); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
@param |
171 |
|
@param |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
173 |
5 |
private void addFeatures(SequenceI seq, String featureType, int score)... |
174 |
|
{ |
175 |
5 |
addFeature(seq, featureType, score++); |
176 |
5 |
addFeature(seq, featureType, score); |
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
179 |
10 |
private void addFeature(SequenceI seq, String featureType, int score)... |
180 |
|
{ |
181 |
10 |
SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2, |
182 |
|
score, "grp"); |
183 |
10 |
sf.setValue("AF", score); |
184 |
10 |
sf.setValue("CSQ", new HashMap<String, String>() |
185 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
10 |
{... |
187 |
10 |
put("PolyPhen", Integer.toString(score)); |
188 |
|
} |
189 |
|
}); |
190 |
10 |
seq.addSequenceFeature(sf); |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
@see |
195 |
|
@throws |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
197 |
1 |
@Test(groups = "Functional")... |
198 |
|
public void testGetColorTooltip() throws IOException |
199 |
|
{ |
200 |
1 |
assertNull(FeatureSettings.getColorTooltip(null, false)); |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
1 |
FeatureColourI fc = new FeatureColour(Color.black); |
206 |
1 |
String simpleTooltip = "Click to edit, right-click for menu"; |
207 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, true), simpleTooltip); |
208 |
1 |
assertNull(FeatureSettings.getColorTooltip(fc, false)); |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
1 |
fc.setColourByLabel(true); |
214 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, false), |
215 |
|
"<html>By Label</html>"); |
216 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, true), |
217 |
|
"<html>By Label<br>" + simpleTooltip + "</br></html>"); |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
1 |
fc = new FeatureColour(Color.red, Color.blue, 2f, 10f); |
223 |
1 |
fc.setBelowThreshold(true); |
224 |
1 |
fc.setThreshold(4f); |
225 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, false), |
226 |
|
"<html>By Score (< 4.0)</html>"); |
227 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, true), |
228 |
|
"<html>By Score (< 4.0)<br>" + simpleTooltip |
229 |
|
+ "</br></html>"); |
230 |
|
|
231 |
1 |
fc.setAboveThreshold(true); |
232 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, false), |
233 |
|
"<html>By Score (> 4.0)</html>"); |
234 |
1 |
assertEquals(FeatureSettings.getColorTooltip(fc, true), |
235 |
|
"<html>By Score (> 4.0)<br>" + simpleTooltip |
236 |
|
+ "</br></html>"); |
237 |
|
} |
238 |
|
} |