1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.schemes; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertFalse; |
25 |
|
import static org.testng.AssertJUnit.assertNull; |
26 |
|
import static org.testng.AssertJUnit.assertTrue; |
27 |
|
import static org.testng.AssertJUnit.fail; |
28 |
|
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; |
29 |
|
|
30 |
|
import jalview.api.FeatureColourI; |
31 |
|
import jalview.datamodel.SequenceFeature; |
32 |
|
import jalview.gui.JvOptionPane; |
33 |
|
import jalview.util.ColorUtils; |
34 |
|
import jalview.util.Format; |
35 |
|
|
36 |
|
import java.awt.Color; |
37 |
|
|
38 |
|
import org.testng.annotations.BeforeClass; |
39 |
|
import org.testng.annotations.Test; |
40 |
|
|
41 |
|
import junit.extensions.PA; |
42 |
|
|
|
|
| 99.7% |
Uncovered Elements: 1 (365) |
Complexity: 13 |
Complexity Density: 0.04 |
|
43 |
|
public class FeatureColourTest |
44 |
|
{ |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
1 |
@BeforeClass(alwaysRun = true)... |
47 |
|
public void setUpJvOptionPane() |
48 |
|
{ |
49 |
1 |
JvOptionPane.setInteractiveMode(false); |
50 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (68) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
53 |
1 |
@Test(groups = { "Functional" })... |
54 |
|
public void testCopyConstructor() |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
1 |
FeatureColour fc = new FeatureColour(Color.RED); |
60 |
1 |
FeatureColour fc1 = new FeatureColour(fc); |
61 |
1 |
assertTrue(fc1.getColour().equals(Color.RED)); |
62 |
1 |
assertFalse(fc1.isGraduatedColour()); |
63 |
1 |
assertFalse(fc1.isColourByLabel()); |
64 |
1 |
assertFalse(fc1.isColourByAttribute()); |
65 |
1 |
assertNull(fc1.getAttributeName()); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
1 |
fc = new FeatureColour(Color.gray, Color.black, 10f, 20f); |
71 |
1 |
fc.setAboveThreshold(true); |
72 |
1 |
fc.setThreshold(12f); |
73 |
1 |
fc1 = new FeatureColour(fc); |
74 |
1 |
assertTrue(fc1.isGraduatedColour()); |
75 |
1 |
assertFalse(fc1.isColourByLabel()); |
76 |
1 |
assertTrue(fc1.isAboveThreshold()); |
77 |
1 |
assertFalse(fc1.isColourByAttribute()); |
78 |
1 |
assertNull(fc1.getAttributeName()); |
79 |
1 |
assertEquals(12f, fc1.getThreshold()); |
80 |
1 |
assertEquals(Color.gray, fc1.getMinColour()); |
81 |
1 |
assertEquals(Color.black, fc1.getMaxColour()); |
82 |
1 |
assertEquals(Color.gray, fc1.getNoColour()); |
83 |
1 |
assertEquals(10f, fc1.getMin()); |
84 |
1 |
assertEquals(20f, fc1.getMax()); |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
1 |
fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); |
90 |
1 |
fc.setAboveThreshold(true); |
91 |
1 |
fc.setThreshold(12f); |
92 |
1 |
fc1 = new FeatureColour(fc); |
93 |
1 |
assertTrue(fc1.isGraduatedColour()); |
94 |
1 |
assertFalse(fc1.isColourByLabel()); |
95 |
1 |
assertFalse(fc1.isColourByAttribute()); |
96 |
1 |
assertNull(fc1.getAttributeName()); |
97 |
1 |
assertTrue(fc1.isAboveThreshold()); |
98 |
1 |
assertEquals(12f, fc1.getThreshold()); |
99 |
1 |
assertEquals(Color.gray, fc1.getMinColour()); |
100 |
1 |
assertEquals(Color.black, fc1.getMaxColour()); |
101 |
1 |
assertEquals(Color.green, fc1.getNoColour()); |
102 |
1 |
assertEquals(10f, fc1.getMin()); |
103 |
1 |
assertEquals(20f, fc1.getMax()); |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
1 |
fc = new FeatureColour(); |
109 |
1 |
fc.setColourByLabel(true); |
110 |
1 |
fc1 = new FeatureColour(fc); |
111 |
1 |
assertTrue(fc1.isColourByLabel()); |
112 |
1 |
assertFalse(fc1.isGraduatedColour()); |
113 |
1 |
assertFalse(fc1.isColourByAttribute()); |
114 |
1 |
assertNull(fc1.getAttributeName()); |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
1 |
fc = new FeatureColour(); |
120 |
1 |
fc.setColourByLabel(true); |
121 |
1 |
fc.setAttributeName("AF"); |
122 |
1 |
fc1 = new FeatureColour(fc); |
123 |
1 |
assertTrue(fc1.isColourByLabel()); |
124 |
1 |
assertFalse(fc1.isGraduatedColour()); |
125 |
1 |
assertTrue(fc1.isColourByAttribute()); |
126 |
1 |
assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
1 |
fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); |
132 |
1 |
fc.setAboveThreshold(true); |
133 |
1 |
fc.setThreshold(12f); |
134 |
1 |
fc.setAttributeName("AF"); |
135 |
1 |
fc1 = new FeatureColour(fc); |
136 |
1 |
assertTrue(fc1.isGraduatedColour()); |
137 |
1 |
assertFalse(fc1.isColourByLabel()); |
138 |
1 |
assertTrue(fc1.isColourByAttribute()); |
139 |
1 |
assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); |
140 |
1 |
assertTrue(fc1.isAboveThreshold()); |
141 |
1 |
assertEquals(12f, fc1.getThreshold()); |
142 |
1 |
assertEquals(Color.gray, fc1.getMinColour()); |
143 |
1 |
assertEquals(Color.black, fc1.getMaxColour()); |
144 |
1 |
assertEquals(Color.green, fc1.getNoColour()); |
145 |
1 |
assertEquals(10f, fc1.getMin()); |
146 |
1 |
assertEquals(20f, fc1.getMax()); |
147 |
|
} |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (55) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
149 |
1 |
@Test(groups = { "Functional" })... |
150 |
|
public void testCopyConstructor_minMax() |
151 |
|
{ |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
1 |
FeatureColour fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); |
156 |
1 |
assertTrue(fc.isGraduatedColour()); |
157 |
1 |
assertFalse(fc.isColourByLabel()); |
158 |
1 |
assertFalse(fc.isColourByAttribute()); |
159 |
1 |
assertNull(fc.getAttributeName()); |
160 |
1 |
assertEquals(1f, fc.getMin()); |
161 |
1 |
assertEquals(5f, fc.getMax()); |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
1 |
FeatureColour fc1 = new FeatureColour(fc, 2f, 6f); |
167 |
1 |
assertTrue(fc1.isGraduatedColour()); |
168 |
1 |
assertFalse(fc1.isColourByLabel()); |
169 |
1 |
assertFalse(fc1.isColourByAttribute()); |
170 |
1 |
assertNull(fc1.getAttributeName()); |
171 |
1 |
assertEquals(2f, fc1.getMin()); |
172 |
1 |
assertEquals(6f, fc1.getMax()); |
173 |
1 |
assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
1 |
fc1 = new FeatureColour(fc, 23f, 16f); |
179 |
1 |
assertTrue(fc1.isGraduatedColour()); |
180 |
1 |
assertFalse(fc1.isColourByLabel()); |
181 |
1 |
assertFalse(fc1.isColourByAttribute()); |
182 |
1 |
assertNull(fc1.getAttributeName()); |
183 |
1 |
assertEquals(23f, fc1.getMin()); |
184 |
1 |
assertEquals(16f, fc1.getMax()); |
185 |
1 |
assertTrue((boolean) PA.getValue(fc1, "isHighToLow")); |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
1 |
fc1.setAttributeName("AF"); |
191 |
1 |
fc1 = new FeatureColour(fc1, 13f, 36f); |
192 |
1 |
assertTrue(fc1.isGraduatedColour()); |
193 |
1 |
assertFalse(fc1.isColourByLabel()); |
194 |
1 |
assertTrue(fc1.isColourByAttribute()); |
195 |
1 |
assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); |
196 |
1 |
assertEquals(13f, fc1.getMin()); |
197 |
1 |
assertEquals(36f, fc1.getMax()); |
198 |
1 |
assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
1 |
fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); |
204 |
1 |
fc.setColourByLabel(true); |
205 |
1 |
assertFalse(fc.isGraduatedColour()); |
206 |
1 |
assertTrue(fc.isColourByLabel()); |
207 |
1 |
assertFalse(fc.isColourByAttribute()); |
208 |
1 |
assertNull(fc.getAttributeName()); |
209 |
1 |
assertEquals(1f, fc.getMin()); |
210 |
1 |
assertEquals(5f, fc.getMax()); |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
1 |
fc1 = new FeatureColour(fc, 2f, 6f); |
216 |
1 |
assertFalse(fc1.isGraduatedColour()); |
217 |
1 |
assertTrue(fc1.isColourByLabel()); |
218 |
1 |
assertFalse(fc1.isColourByAttribute()); |
219 |
1 |
assertNull(fc1.getAttributeName()); |
220 |
1 |
assertEquals(2f, fc1.getMin()); |
221 |
1 |
assertEquals(6f, fc1.getMax()); |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
1 |
fc1.setAttributeName("AC"); |
227 |
1 |
fc1 = new FeatureColour(fc1, 13f, 36f); |
228 |
1 |
assertFalse(fc1.isGraduatedColour()); |
229 |
1 |
assertTrue(fc1.isColourByLabel()); |
230 |
1 |
assertTrue(fc1.isColourByAttribute()); |
231 |
1 |
assertArrayEquals(new String[] { "AC" }, fc1.getAttributeName()); |
232 |
1 |
assertEquals(13f, fc1.getMin()); |
233 |
1 |
assertEquals(36f, fc1.getMax()); |
234 |
|
} |
235 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
236 |
1 |
@Test(groups = { "Functional" })... |
237 |
|
public void testGetColor_simpleColour() |
238 |
|
{ |
239 |
1 |
FeatureColour fc = new FeatureColour(Color.RED); |
240 |
1 |
assertEquals(Color.RED, |
241 |
|
fc.getColor(new SequenceFeature("Cath", "", 1, 2, 0f, null))); |
242 |
|
} |
243 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
244 |
1 |
@Test(groups = { "Functional" })... |
245 |
|
public void testGetColor_colourByLabel() |
246 |
|
{ |
247 |
1 |
FeatureColour fc = new FeatureColour(); |
248 |
1 |
fc.setColourByLabel(true); |
249 |
1 |
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f, |
250 |
|
null); |
251 |
1 |
Color expected = ColorUtils.createColourFromName("desc"); |
252 |
1 |
assertEquals(expected, fc.getColor(sf)); |
253 |
|
} |
254 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
255 |
1 |
@Test(groups = { "Functional" })... |
256 |
|
public void testGetColor_Graduated() |
257 |
|
{ |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
1 |
FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f); |
264 |
|
|
265 |
1 |
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f, |
266 |
|
null); |
267 |
|
|
268 |
1 |
float red = 128 / 255f + 3 / 4f * (255 - 128) / 255f; |
269 |
1 |
float green = 128 / 255f + 3 / 4f * (0 - 128) / 255f; |
270 |
1 |
float blue = 128 / 255f + 3 / 4f * (0 - 128) / 255f; |
271 |
1 |
Color expected = new Color(red, green, blue); |
272 |
1 |
assertEquals(expected, fc.getColor(sf)); |
273 |
|
} |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
275 |
1 |
@Test(groups = { "Functional" })... |
276 |
|
public void testGetColor_aboveBelowThreshold() |
277 |
|
{ |
278 |
|
|
279 |
1 |
FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f, |
280 |
|
150f); |
281 |
1 |
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f, |
282 |
|
null); |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
1 |
SequenceFeature sf2 = new SequenceFeature("type", "desc", 0, 20, |
288 |
|
Float.NaN, null); |
289 |
|
|
290 |
1 |
fc.setThreshold(100f); |
291 |
1 |
assertEquals(new Color(204, 204, 204), fc.getColor(sf)); |
292 |
1 |
assertEquals(Color.white, fc.getColor(sf2)); |
293 |
|
|
294 |
1 |
fc.setAboveThreshold(true); |
295 |
1 |
assertNull(fc.getColor(sf)); |
296 |
1 |
assertEquals(Color.white, fc.getColor(sf2)); |
297 |
|
|
298 |
1 |
fc.setBelowThreshold(true); |
299 |
1 |
fc.setThreshold(70f); |
300 |
1 |
assertNull(fc.getColor(sf)); |
301 |
1 |
assertEquals(Color.white, fc.getColor(sf2)); |
302 |
1 |
fc.setThreshold(69f); |
303 |
1 |
assertNull(fc.getColor(sf)); |
304 |
1 |
assertEquals(Color.white, fc.getColor(sf2)); |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (50) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
310 |
1 |
@Test(groups = { "Functional" })... |
311 |
|
public void testToJalviewFormat() |
312 |
|
{ |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
1 |
FeatureColour fc = new FeatureColour(Color.RED); |
317 |
1 |
String redHex = Format.getHexString(Color.RED); |
318 |
1 |
String hexColour = redHex; |
319 |
1 |
assertEquals("domain\t" + hexColour, fc.toJalviewFormat("domain")); |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
1 |
fc = new FeatureColour(); |
325 |
1 |
fc.setColourByLabel(true); |
326 |
1 |
assertEquals("domain\tlabel", fc.toJalviewFormat("domain")); |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
1 |
fc = new FeatureColour(); |
332 |
1 |
fc.setColourByLabel(true); |
333 |
1 |
fc.setAttributeName("CLIN_SIG"); |
334 |
1 |
assertEquals("domain\tattribute|CLIN_SIG", fc.toJalviewFormat("domain")); |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
1 |
fc.setAttributeName((String[]) null); |
342 |
1 |
fc.setAutoScaled(true); |
343 |
1 |
assertEquals("domain\tlabel", fc.toJalviewFormat("domain")); |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
1 |
fc.setAutoScaled(false); |
349 |
1 |
fc.setThreshold(12.5f); |
350 |
1 |
fc.setAboveThreshold(true); |
351 |
|
|
352 |
1 |
assertEquals("domain\tlabel|||0.0|0.0|above|12.5", |
353 |
|
fc.toJalviewFormat("domain")); |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
1 |
fc.setBelowThreshold(true); |
359 |
1 |
assertEquals("domain\tlabel|||0.0|0.0|below|12.5", |
360 |
|
fc.toJalviewFormat("domain")); |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
1 |
fc.setBelowThreshold(true); |
366 |
1 |
fc.setAttributeName("CSQ", "Consequence"); |
367 |
1 |
assertEquals("domain\tattribute|CSQ:Consequence|||0.0|0.0|below|12.5", |
368 |
|
fc.toJalviewFormat("domain")); |
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
1 |
fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); |
375 |
1 |
String greenHex = Format.getHexString(Color.GREEN); |
376 |
1 |
String expected = String.format( |
377 |
|
"domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, |
378 |
|
redHex); |
379 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
1 |
fc = new FeatureColour(Color.GREEN, Color.RED, Color.GREEN, 12f, 25f); |
385 |
1 |
expected = String.format( |
386 |
|
"domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, |
387 |
|
redHex); |
388 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
1 |
fc = new FeatureColour(Color.GREEN, Color.RED, Color.RED, 12f, 25f); |
394 |
1 |
expected = String.format( |
395 |
|
"domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex, |
396 |
|
redHex); |
397 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
1 |
fc.setAutoScaled(true); |
403 |
1 |
expected = String.format( |
404 |
|
"domain\tscore|%s|%s|noValueMax|12.0|25.0|none", greenHex, |
405 |
|
redHex); |
406 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
1 |
fc.setThreshold(12.5f); |
412 |
1 |
fc.setBelowThreshold(true); |
413 |
1 |
expected = String.format( |
414 |
|
"domain\tscore|%s|%s|noValueMax|12.0|25.0|below|12.5", |
415 |
|
greenHex, redHex); |
416 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
1 |
fc.setThreshold(12.5f); |
422 |
1 |
fc.setAboveThreshold(true); |
423 |
1 |
fc.setAutoScaled(false); |
424 |
1 |
expected = String.format( |
425 |
|
"domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|above|12.5", |
426 |
|
greenHex, redHex); |
427 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
1 |
fc.setAttributeName("CSQ", "AF"); |
433 |
1 |
fc.setAboveThreshold(true); |
434 |
1 |
fc.setAutoScaled(false); |
435 |
1 |
expected = String.format( |
436 |
|
"domain\tattribute|CSQ:AF|%s|%s|noValueMax|abso|12.0|25.0|above|12.5", |
437 |
|
greenHex, redHex); |
438 |
1 |
assertEquals(expected, fc.toJalviewFormat("domain")); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
|
|
| 98.9% |
Uncovered Elements: 1 (94) |
Complexity: 2 |
Complexity Density: 0.02 |
1PASS
|
|
444 |
1 |
@Test(groups = { "Functional" })... |
445 |
|
public void testParseJalviewFeatureColour() |
446 |
|
{ |
447 |
|
|
448 |
|
|
449 |
|
|
450 |
1 |
FeatureColourI fc = FeatureColour.parseJalviewFeatureColour("red"); |
451 |
1 |
assertTrue(fc.isSimpleColour()); |
452 |
1 |
assertEquals(Color.RED, fc.getColour()); |
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
1 |
fc = FeatureColour.parseJalviewFeatureColour(Format |
458 |
|
.getHexString(Color.RED)); |
459 |
1 |
assertTrue(fc.isSimpleColour()); |
460 |
1 |
assertEquals(Color.RED, fc.getColour()); |
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
1 |
fc = FeatureColour.parseJalviewFeatureColour("255,0,0"); |
466 |
1 |
assertTrue(fc.isSimpleColour()); |
467 |
1 |
assertEquals(Color.RED, fc.getColour()); |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
1 |
try |
473 |
|
{ |
474 |
1 |
fc = FeatureColour.parseJalviewFeatureColour("oops"); |
475 |
0 |
fail("expected exception"); |
476 |
|
} catch (IllegalArgumentException e) |
477 |
|
{ |
478 |
1 |
assertEquals("Invalid colour descriptor: oops", e.getMessage()); |
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
1 |
fc = FeatureColour.parseJalviewFeatureColour("label"); |
485 |
1 |
assertTrue(fc.isColourByLabel()); |
486 |
1 |
assertFalse(fc.hasThreshold()); |
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
1 |
fc = FeatureColour |
492 |
|
.parseJalviewFeatureColour("label|||0.0|0.0|above|12.0"); |
493 |
1 |
assertTrue(fc.isColourByLabel()); |
494 |
1 |
assertTrue(fc.isAboveThreshold()); |
495 |
1 |
assertEquals(12.0f, fc.getThreshold()); |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
1 |
fc = FeatureColour.parseJalviewFeatureColour("attribute|CLIN_SIG"); |
501 |
1 |
assertTrue(fc.isColourByAttribute()); |
502 |
1 |
assertTrue(fc.isColourByLabel()); |
503 |
1 |
assertFalse(fc.hasThreshold()); |
504 |
1 |
assertArrayEquals(new String[] { "CLIN_SIG" }, fc.getAttributeName()); |
505 |
|
|
506 |
|
|
507 |
|
|
508 |
|
|
509 |
1 |
fc = FeatureColour.parseJalviewFeatureColour( |
510 |
|
"attribute|CSQ:Consequence|||0.0|0.0|above|12.0"); |
511 |
1 |
assertTrue(fc.isColourByLabel()); |
512 |
1 |
assertTrue(fc.isColourByAttribute()); |
513 |
1 |
assertArrayEquals(new String[] { "CSQ", "Consequence" }, |
514 |
|
fc.getAttributeName()); |
515 |
1 |
assertTrue(fc.isAboveThreshold()); |
516 |
1 |
assertEquals(12.0f, fc.getThreshold()); |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
1 |
fc = FeatureColour.parseJalviewFeatureColour("red|green|10.0|20.0"); |
522 |
1 |
assertTrue(fc.isGraduatedColour()); |
523 |
1 |
assertFalse(fc.hasThreshold()); |
524 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
525 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
526 |
1 |
assertEquals(10f, fc.getMin()); |
527 |
1 |
assertEquals(20f, fc.getMax()); |
528 |
1 |
assertTrue(fc.isAutoScaled()); |
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
1 |
fc = FeatureColour |
534 |
|
.parseJalviewFeatureColour("Score|red|green|10.0|20.0"); |
535 |
1 |
assertTrue(fc.isGraduatedColour()); |
536 |
1 |
assertFalse(fc.hasThreshold()); |
537 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
538 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
539 |
1 |
assertEquals(10f, fc.getMin()); |
540 |
1 |
assertEquals(20f, fc.getMax()); |
541 |
1 |
assertTrue(fc.isAutoScaled()); |
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
1 |
fc = FeatureColour |
547 |
|
.parseJalviewFeatureColour("attribute|AF|red|green|10.0|20.0"); |
548 |
1 |
assertTrue(fc.isGraduatedColour()); |
549 |
1 |
assertTrue(fc.isColourByAttribute()); |
550 |
1 |
assertArrayEquals(new String[] { "AF" }, fc.getAttributeName()); |
551 |
1 |
assertFalse(fc.hasThreshold()); |
552 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
553 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
554 |
1 |
assertEquals(10f, fc.getMin()); |
555 |
1 |
assertEquals(20f, fc.getMax()); |
556 |
1 |
assertTrue(fc.isAutoScaled()); |
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
1 |
String descriptor = String.format("%s|%s|10.0|20.0|above|15", |
562 |
|
Format.getHexString(Color.RED), |
563 |
|
Format.getHexString(Color.GREEN)); |
564 |
1 |
fc = FeatureColour.parseJalviewFeatureColour(descriptor); |
565 |
1 |
assertTrue(fc.isGraduatedColour()); |
566 |
1 |
assertTrue(fc.hasThreshold()); |
567 |
1 |
assertTrue(fc.isAboveThreshold()); |
568 |
1 |
assertEquals(15f, fc.getThreshold()); |
569 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
570 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
571 |
1 |
assertEquals(10f, fc.getMin()); |
572 |
1 |
assertEquals(20f, fc.getMax()); |
573 |
1 |
assertTrue(fc.isAutoScaled()); |
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
1 |
fc = FeatureColour.parseJalviewFeatureColour( |
579 |
|
"attribute|CSQ:AF|red|green|10.0|20.0|below|13"); |
580 |
1 |
assertTrue(fc.isGraduatedColour()); |
581 |
1 |
assertTrue(fc.isColourByAttribute()); |
582 |
1 |
assertArrayEquals(new String[] { "CSQ", "AF" }, fc.getAttributeName()); |
583 |
1 |
assertTrue(fc.hasThreshold()); |
584 |
1 |
assertTrue(fc.isBelowThreshold()); |
585 |
1 |
assertEquals(13f, fc.getThreshold()); |
586 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
587 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
588 |
1 |
assertEquals(10f, fc.getMin()); |
589 |
1 |
assertEquals(20f, fc.getMax()); |
590 |
1 |
assertTrue(fc.isAutoScaled()); |
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
1 |
descriptor = "255,0,0|0,255,0|abso|10.0|20.0|below|15"; |
596 |
1 |
fc = FeatureColour.parseJalviewFeatureColour(descriptor); |
597 |
1 |
assertTrue(fc.isGraduatedColour()); |
598 |
1 |
assertFalse(fc.isAutoScaled()); |
599 |
1 |
assertTrue(fc.hasThreshold()); |
600 |
1 |
assertTrue(fc.isBelowThreshold()); |
601 |
1 |
assertEquals(15f, fc.getThreshold()); |
602 |
1 |
assertEquals(Color.RED, fc.getMinColour()); |
603 |
1 |
assertEquals(Color.GREEN, fc.getMaxColour()); |
604 |
1 |
assertEquals(10f, fc.getMin()); |
605 |
1 |
assertEquals(20f, fc.getMax()); |
606 |
|
|
607 |
1 |
descriptor = "blue|255,0,255|absolute|20.0|95.0|below|66.0"; |
608 |
1 |
fc = FeatureColour.parseJalviewFeatureColour(descriptor); |
609 |
1 |
assertTrue(fc.isGraduatedColour()); |
610 |
|
} |
611 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
612 |
1 |
@Test(groups = { "Functional" })... |
613 |
|
public void testGetColor_colourByAttributeText() |
614 |
|
{ |
615 |
1 |
FeatureColour fc = new FeatureColour(); |
616 |
1 |
fc.setColourByLabel(true); |
617 |
1 |
fc.setAttributeName("consequence"); |
618 |
1 |
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f, |
619 |
|
null); |
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
1 |
assertEquals(FeatureColour.DEFAULT_NO_COLOUR, fc.getColor(sf)); |
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
1 |
sf.setValue("consequence", "benign"); |
630 |
1 |
Color expected = ColorUtils.createColourFromName("benign"); |
631 |
1 |
assertEquals(expected, fc.getColor(sf)); |
632 |
|
} |
633 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
634 |
1 |
@Test(groups = { "Functional" })... |
635 |
|
public void testGetColor_GraduatedByAttributeValue() |
636 |
|
{ |
637 |
|
|
638 |
|
|
639 |
|
|
640 |
|
|
641 |
1 |
FeatureColour fc = new FeatureColour(new Color(50, 100, 150), |
642 |
|
new Color(150, 200, 250), Color.yellow, 0f, 100f); |
643 |
1 |
String attName = "AF"; |
644 |
1 |
fc.setAttributeName(attName); |
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
1 |
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f, |
650 |
|
null); |
651 |
1 |
assertEquals(Color.yellow, fc.getColor(sf)); |
652 |
|
|
653 |
|
|
654 |
|
|
655 |
|
|
656 |
1 |
sf.setValue(attName, "twelve"); |
657 |
1 |
assertEquals(Color.yellow, fc.getColor(sf)); |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
1 |
sf.setValue(attName, "20.0"); |
663 |
1 |
Color expected = new Color(70, 120, 170); |
664 |
1 |
assertEquals(expected, fc.getColor(sf)); |
665 |
|
} |
666 |
|
|
667 |
|
|
668 |
|
|
669 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
670 |
1 |
@Test(groups = { "Functional" })... |
671 |
|
public void testGetDescription() |
672 |
|
{ |
673 |
|
|
674 |
|
|
675 |
|
|
676 |
1 |
FeatureColour fc = new FeatureColour(Color.RED); |
677 |
1 |
assertEquals( |
678 |
|
String.format("r=%d,g=%d,b=%d", Color.RED.getRed(), |
679 |
|
Color.red.getGreen(), Color.red.getBlue()), |
680 |
|
fc.getDescription()); |
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
|
685 |
1 |
fc = new FeatureColour(); |
686 |
1 |
fc.setColourByLabel(true); |
687 |
1 |
assertEquals("By Label", fc.getDescription()); |
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
|
692 |
1 |
fc = new FeatureColour(); |
693 |
1 |
fc.setColourByLabel(true); |
694 |
1 |
fc.setAttributeName("CLIN_SIG"); |
695 |
1 |
assertEquals("By CLIN_SIG", fc.getDescription()); |
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
1 |
fc = new FeatureColour(); |
701 |
1 |
fc.setColourByLabel(true); |
702 |
1 |
fc.setAutoScaled(false); |
703 |
1 |
fc.setThreshold(12.5f); |
704 |
1 |
fc.setAboveThreshold(true); |
705 |
1 |
assertEquals("By Label (Score > 12.5)", |
706 |
|
fc.getDescription()); |
707 |
|
|
708 |
|
|
709 |
|
|
710 |
|
|
711 |
1 |
fc.setBelowThreshold(true); |
712 |
1 |
assertEquals("By Label (Score < 12.5)", |
713 |
|
fc.getDescription()); |
714 |
|
|
715 |
|
|
716 |
|
|
717 |
|
|
718 |
1 |
fc.setBelowThreshold(true); |
719 |
1 |
fc.setAttributeName("CSQ", "Consequence"); |
720 |
1 |
assertEquals( |
721 |
|
"By CSQ:Consequence (Score < 12.5)", |
722 |
|
fc.getDescription()); |
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
1 |
fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); |
728 |
1 |
assertEquals("By Score", fc.getDescription()); |
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
1 |
fc.setThreshold(12.5f); |
734 |
1 |
fc.setBelowThreshold(true); |
735 |
1 |
assertEquals("By Score (< 12.5)", |
736 |
|
fc.getDescription()); |
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
1 |
fc.setThreshold(12.5f); |
742 |
1 |
fc.setAboveThreshold(true); |
743 |
1 |
fc.setAutoScaled(false); |
744 |
1 |
assertEquals("By Score (> 12.5)", |
745 |
|
fc.getDescription()); |
746 |
|
|
747 |
|
|
748 |
|
|
749 |
|
|
750 |
1 |
fc.setAttributeName("CSQ", "AF"); |
751 |
1 |
fc.setAboveThreshold(false); |
752 |
1 |
fc.setAutoScaled(false); |
753 |
1 |
assertEquals("By CSQ:AF", fc.getDescription()); |
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
|
758 |
1 |
fc.setAboveThreshold(true); |
759 |
1 |
fc.setAutoScaled(false); |
760 |
1 |
assertEquals("By CSQ:AF (> 12.5)", |
761 |
|
fc.getDescription()); |
762 |
|
} |
763 |
|
} |