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.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertSame; |
26 |
|
import static org.testng.Assert.assertTrue; |
27 |
|
|
28 |
|
import java.awt.Color; |
29 |
|
import java.util.Iterator; |
30 |
|
import java.util.Map; |
31 |
|
|
32 |
|
import org.testng.annotations.AfterClass; |
33 |
|
import org.testng.annotations.BeforeClass; |
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
36 |
|
import jalview.api.AlignViewportI; |
37 |
|
import jalview.bin.Cache; |
38 |
|
import jalview.bin.Jalview; |
39 |
|
import jalview.datamodel.AnnotatedCollectionI; |
40 |
|
import jalview.datamodel.SequenceCollectionI; |
41 |
|
import jalview.datamodel.SequenceI; |
42 |
|
import jalview.gui.AlignFrame; |
43 |
|
import jalview.gui.Desktop; |
44 |
|
import jalview.gui.SequenceRenderer; |
45 |
|
import jalview.io.DataSourceType; |
46 |
|
import jalview.io.FileLoader; |
47 |
|
import jalview.schemes.ClustalxColourScheme.ClustalColour; |
48 |
|
|
|
|
| 98.7% |
Uncovered Elements: 1 (75) |
Complexity: 9 |
Complexity Density: 0.14 |
|
49 |
|
public class ColourSchemesTest |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 6 |
Complexity Density: 0.67 |
|
55 |
|
class Stripy extends ResidueColourScheme |
56 |
|
{ |
57 |
|
private ResidueColourScheme odd; |
58 |
|
|
59 |
|
private ResidueColourScheme even; |
60 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
61 |
1 |
private Stripy()... |
62 |
|
{ |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@param |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
71 |
1 |
private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)... |
72 |
|
{ |
73 |
1 |
odd = (ResidueColourScheme) cs1; |
74 |
1 |
even = (ResidueColourScheme) cs2; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
77 |
1 |
@Override... |
78 |
|
public ColourSchemeI getInstance(AlignViewportI view, |
79 |
|
AnnotatedCollectionI sg) |
80 |
|
{ |
81 |
1 |
final ColourSchemeI cs1 = ColourSchemes.getInstance().getColourScheme( |
82 |
|
JalviewColourScheme.Taylor.toString(), |
83 |
|
(AnnotatedCollectionI) null); |
84 |
1 |
final ColourSchemeI cs2 = ColourSchemes.getInstance().getColourScheme( |
85 |
|
JalviewColourScheme.Zappo.toString(), |
86 |
|
(AnnotatedCollectionI) null); |
87 |
1 |
return new Stripy(cs1, cs2); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
90 |
3 |
@Override... |
91 |
|
public Color findColour(char c, int j, SequenceI seq) |
92 |
|
{ |
93 |
3 |
if (j % 2 == 1) |
94 |
|
{ |
95 |
1 |
return odd.findColour(c, j, seq); |
96 |
|
} |
97 |
|
else |
98 |
|
{ |
99 |
2 |
return even.findColour(c, j, seq); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
22 |
@Override... |
104 |
|
public String getSchemeName() |
105 |
|
{ |
106 |
22 |
return "stripy"; |
107 |
|
} |
108 |
|
}; |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 60.5% |
Uncovered Elements: 17 (43) |
Complexity: 13 |
Complexity Density: 0.59 |
|
113 |
|
class MyClustal extends ResidueColourScheme |
114 |
|
{ |
115 |
|
ClustalxColourScheme delegate; |
116 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
117 |
1 |
private MyClustal()... |
118 |
|
{ |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
1 |
private MyClustal(AnnotatedCollectionI sg,... |
122 |
|
Map<SequenceI, SequenceCollectionI> hiddenRepSequences) |
123 |
|
{ |
124 |
1 |
delegate = new ClustalxColourScheme(sg, hiddenRepSequences); |
125 |
|
} |
126 |
|
|
|
|
| 51.4% |
Uncovered Elements: 17 (35) |
Complexity: 9 |
Complexity Density: 0.47 |
|
127 |
3 |
@Override... |
128 |
|
public Color findColour(char c, int j, SequenceI seq) |
129 |
|
{ |
130 |
3 |
Color col = delegate.findColour(c, j, seq); |
131 |
3 |
Color result = col; |
132 |
3 |
if (col.equals(ClustalColour.BLUE.colour)) |
133 |
|
{ |
134 |
1 |
result = Color.blue; |
135 |
|
} |
136 |
2 |
else if (col.equals(ClustalColour.CYAN.colour)) |
137 |
|
{ |
138 |
0 |
result = Color.cyan; |
139 |
|
} |
140 |
2 |
else if (col.equals(ClustalColour.GREEN.colour)) |
141 |
|
{ |
142 |
0 |
result = Color.green; |
143 |
|
} |
144 |
2 |
else if (col.equals(ClustalColour.MAGENTA.colour)) |
145 |
|
{ |
146 |
1 |
result = Color.magenta; |
147 |
|
} |
148 |
1 |
else if (col.equals(ClustalColour.ORANGE.colour)) |
149 |
|
{ |
150 |
1 |
result = Color.orange; |
151 |
|
} |
152 |
0 |
else if (col.equals(ClustalColour.PINK.colour)) |
153 |
|
{ |
154 |
0 |
result = Color.pink; |
155 |
|
} |
156 |
0 |
else if (col.equals(ClustalColour.RED.colour)) |
157 |
|
{ |
158 |
0 |
result = Color.red; |
159 |
|
} |
160 |
0 |
else if (col.equals(ClustalColour.YELLOW.colour)) |
161 |
|
{ |
162 |
0 |
result = Color.yellow; |
163 |
|
} |
164 |
3 |
return result; |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
167 |
1 |
@Override... |
168 |
|
public ColourSchemeI getInstance(AlignViewportI view, |
169 |
|
AnnotatedCollectionI sg) |
170 |
|
{ |
171 |
1 |
return new MyClustal(sg, view.getHiddenRepSequences()); |
172 |
|
} |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
22 |
@Override... |
175 |
|
public String getSchemeName() |
176 |
|
{ |
177 |
22 |
return "MyClustal"; |
178 |
|
} |
179 |
|
|
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
182 |
1 |
@BeforeClass(alwaysRun = true)... |
183 |
|
public static void setUpBeforeClass() throws Exception |
184 |
|
{ |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
1 |
Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
189 |
1 |
Jalview.main(new String[] { "--nonews" }); |
190 |
|
} |
191 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
192 |
1 |
@AfterClass(alwaysRun = true)... |
193 |
|
public static void tearDownAfterClass() throws Exception |
194 |
|
{ |
195 |
1 |
if (Desktop.instance != null) |
196 |
1 |
Desktop.instance.closeAll_actionPerformed(null); |
197 |
|
} |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
1PASS
|
|
199 |
1 |
@Test(groups = "Functional")... |
200 |
|
public void testGetColourSchemes() |
201 |
|
{ |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
1 |
Iterator<ColourSchemeI> schemes = ColourSchemes.getInstance() |
208 |
|
.getColourSchemes().iterator(); |
209 |
1 |
JalviewColourScheme[] jalviewSchemes = JalviewColourScheme.values(); |
210 |
1 |
int i = 0; |
211 |
21 |
while (schemes.hasNext() && i < jalviewSchemes.length) |
212 |
|
{ |
213 |
20 |
assertTrue(schemes.next().getSchemeName() |
214 |
|
.equals(jalviewSchemes[i].toString())); |
215 |
20 |
i++; |
216 |
|
} |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
219 |
1 |
@Test(groups = "Functional")... |
220 |
|
public void testGetColourScheme() |
221 |
|
{ |
222 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
223 |
|
">seq1\nAGLRTWQU", DataSourceType.PASTE); |
224 |
1 |
ColourSchemes schemes = ColourSchemes.getInstance(); |
225 |
|
|
226 |
1 |
AnnotatedCollectionI al = af.getViewport().getAlignment(); |
227 |
|
|
228 |
1 |
for (JalviewColourScheme cs : JalviewColourScheme.values()) |
229 |
|
{ |
230 |
20 |
ColourSchemeI registered = schemes.getColourScheme(cs.toString(), al); |
231 |
20 |
assertSame(registered.getClass(), cs.getSchemeClass()); |
232 |
|
} |
233 |
1 |
af.closeMenuItem_actionPerformed(true); |
234 |
|
} |
235 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
236 |
1 |
@Test(groups = "Functional")... |
237 |
|
public void testRegisterColourScheme() |
238 |
|
{ |
239 |
1 |
ColourSchemes.getInstance().registerColourScheme(new Stripy()); |
240 |
1 |
ColourSchemes.getInstance().registerColourScheme(new MyClustal()); |
241 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
242 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
1 |
SequenceRenderer sr = new SequenceRenderer(af.getViewport()); |
248 |
1 |
SequenceI seq = af.getViewport().getAlignment().findName("FER_CAPAA"); |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
1 |
af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString()); |
254 |
1 |
Color taylor1 = sr.getResidueColour(seq, 88, null); |
255 |
1 |
Color taylor2 = sr.getResidueColour(seq, 89, null); |
256 |
1 |
Color taylor3 = sr.getResidueColour(seq, 90, null); |
257 |
1 |
assertEquals(taylor1, new Color(255, 0, 102)); |
258 |
1 |
assertEquals(taylor2, new Color(204, 255, 0)); |
259 |
1 |
assertEquals(taylor3, new Color(255, 153, 0)); |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
1 |
af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString()); |
265 |
1 |
Color zappo1 = sr.getResidueColour(seq, 88, null); |
266 |
1 |
Color zappo2 = sr.getResidueColour(seq, 89, null); |
267 |
1 |
Color zappo3 = sr.getResidueColour(seq, 90, null); |
268 |
1 |
assertEquals(zappo1, Color.red); |
269 |
1 |
assertEquals(zappo2, Color.pink); |
270 |
1 |
assertEquals(zappo3, Color.magenta); |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
1 |
af.changeColour_actionPerformed("stripy"); |
276 |
1 |
Color stripy1 = sr.getResidueColour(seq, 88, null); |
277 |
1 |
Color stripy2 = sr.getResidueColour(seq, 89, null); |
278 |
1 |
Color stripy3 = sr.getResidueColour(seq, 90, null); |
279 |
1 |
assertEquals(stripy1, zappo1); |
280 |
1 |
assertEquals(stripy2, taylor2); |
281 |
1 |
assertEquals(stripy3, zappo3); |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
1 |
af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString()); |
287 |
1 |
Color clustal1 = sr.getResidueColour(seq, 88, null); |
288 |
1 |
Color clustal2 = sr.getResidueColour(seq, 89, null); |
289 |
1 |
Color clustal3 = sr.getResidueColour(seq, 90, null); |
290 |
1 |
assertEquals(clustal1, ClustalColour.MAGENTA.colour); |
291 |
1 |
assertEquals(clustal2, ClustalColour.BLUE.colour); |
292 |
1 |
assertEquals(clustal3, ClustalColour.ORANGE.colour); |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
1 |
af.changeColour_actionPerformed("MyClustal"); |
298 |
1 |
Color myclustal1 = sr.getResidueColour(seq, 88, null); |
299 |
1 |
Color myclustal2 = sr.getResidueColour(seq, 89, null); |
300 |
1 |
Color myclustal3 = sr.getResidueColour(seq, 90, null); |
301 |
1 |
assertEquals(myclustal1, Color.MAGENTA); |
302 |
1 |
assertEquals(myclustal2, Color.BLUE); |
303 |
1 |
assertEquals(myclustal3, Color.ORANGE); |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
310 |
1 |
@Test(groups = "Functional")... |
311 |
|
public void testNameExists() |
312 |
|
{ |
313 |
1 |
ColourSchemes cs = ColourSchemes.getInstance(); |
314 |
1 |
assertFalse(cs.nameExists(null)); |
315 |
1 |
assertFalse(cs.nameExists("")); |
316 |
1 |
assertTrue(cs.nameExists("Clustal")); |
317 |
1 |
assertTrue(cs.nameExists("CLUSTAL")); |
318 |
1 |
assertFalse(cs.nameExists("CLUSTAL ")); |
319 |
1 |
assertTrue(cs.nameExists("% Identity")); |
320 |
1 |
assertFalse(cs.nameExists("PID")); |
321 |
|
} |
322 |
|
} |