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