1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertTrue; |
25 |
|
|
26 |
|
import jalview.api.FeatureColourI; |
27 |
|
import jalview.datamodel.DBRefEntry; |
28 |
|
import jalview.datamodel.Sequence; |
29 |
|
import jalview.datamodel.SequenceFeature; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
import jalview.gui.JvOptionPane; |
32 |
|
import jalview.io.gff.GffConstants; |
33 |
|
import jalview.renderer.seqfeatures.FeatureRenderer; |
34 |
|
import jalview.schemes.FeatureColour; |
35 |
|
import jalview.viewmodel.seqfeatures.FeatureRendererModel; |
36 |
|
|
37 |
|
import java.awt.Color; |
38 |
|
import java.util.Map; |
39 |
|
|
40 |
|
import junit.extensions.PA; |
41 |
|
|
42 |
|
import org.testng.annotations.BeforeClass; |
43 |
|
import org.testng.annotations.Test; |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (165) |
Complexity: 13 |
Complexity Density: 0.09 |
|
45 |
|
public class SequenceAnnotationReportTest |
46 |
|
{ |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
1 |
@BeforeClass(alwaysRun = true)... |
49 |
|
public void setUpJvOptionPane() |
50 |
|
{ |
51 |
1 |
JvOptionPane.setInteractiveMode(false); |
52 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
55 |
1 |
@Test(groups = "Functional")... |
56 |
|
public void testAppendFeature_disulfideBond() |
57 |
|
{ |
58 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
59 |
1 |
StringBuilder sb = new StringBuilder(); |
60 |
1 |
sb.append("123456"); |
61 |
1 |
SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1, |
62 |
|
3, 1.2f, "group"); |
63 |
|
|
64 |
|
|
65 |
1 |
sar.appendFeature(sb, 2, null, sf); |
66 |
1 |
assertEquals("123456", sb.toString()); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
1 |
sar.appendFeature(sb, 1, null, sf); |
71 |
1 |
assertEquals("123456disulfide bond 1:3", sb.toString()); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
1 |
sar.appendFeature(sb, 3, null, sf); |
76 |
1 |
assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3", |
77 |
|
sb.toString()); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
80 |
1 |
@Test(groups = "Functional")... |
81 |
|
public void testAppendFeature_status() |
82 |
|
{ |
83 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
84 |
1 |
StringBuilder sb = new StringBuilder(); |
85 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, |
86 |
|
Float.NaN, "group"); |
87 |
1 |
sf.setStatus("Confirmed"); |
88 |
|
|
89 |
1 |
sar.appendFeature(sb, 1, null, sf); |
90 |
1 |
assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString()); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
93 |
1 |
@Test(groups = "Functional")... |
94 |
|
public void testAppendFeature_withScore() |
95 |
|
{ |
96 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
97 |
1 |
StringBuilder sb = new StringBuilder(); |
98 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f, |
99 |
|
"group"); |
100 |
|
|
101 |
1 |
FeatureRendererModel fr = new FeatureRenderer(null); |
102 |
1 |
Map<String, float[][]> minmax = fr.getMinMax(); |
103 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
1 |
assertEquals("METAL 1 3; Fe2-S", sb.toString()); |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
1 |
minmax.put("METAL", new float[][] { { 0f, 1f }, null }); |
113 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
114 |
|
|
115 |
1 |
assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3", |
116 |
|
sb.toString()); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
1 |
minmax.put("METAL", new float[][] { { 2f, 2f }, null }); |
122 |
1 |
sb.setLength(0); |
123 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
124 |
1 |
assertEquals("METAL 1 3; Fe2-S", sb.toString()); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
127 |
1 |
@Test(groups = "Functional")... |
128 |
|
public void testAppendFeature_noScore() |
129 |
|
{ |
130 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
131 |
1 |
StringBuilder sb = new StringBuilder(); |
132 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, |
133 |
|
Float.NaN, "group"); |
134 |
|
|
135 |
1 |
sar.appendFeature(sb, 1, null, sf); |
136 |
1 |
assertEquals("METAL 1 3; Fe2-S", sb.toString()); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
142 |
1 |
@Test(groups = "Functional")... |
143 |
|
public void testAppendFeature_colouredByAttribute() |
144 |
|
{ |
145 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
146 |
1 |
StringBuilder sb = new StringBuilder(); |
147 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, |
148 |
|
Float.NaN, "group"); |
149 |
1 |
sf.setValue("clinical_significance", "Benign"); |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
1 |
FeatureRendererModel fr = new FeatureRenderer(null); |
155 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
156 |
1 |
assertEquals("METAL 1 3; Fe2-S", sb.toString()); |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
1 |
FeatureColourI fc = new FeatureColour(Color.white, Color.black, 5, 10); |
162 |
1 |
fc.setAttributeName("Pfam"); |
163 |
1 |
fr.setColour("METAL", fc); |
164 |
1 |
sb.setLength(0); |
165 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
166 |
1 |
assertEquals("METAL 1 3; Fe2-S", sb.toString()); |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
1 |
fc.setAttributeName("clinical_significance"); |
172 |
1 |
sb.setLength(0); |
173 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
174 |
1 |
assertEquals("METAL 1 3; Fe2-S; clinical_significance=Benign", |
175 |
|
sb.toString()); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
178 |
1 |
@Test(groups = "Functional")... |
179 |
|
public void testAppendFeature_withScoreStatusAttribute() |
180 |
|
{ |
181 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
182 |
1 |
StringBuilder sb = new StringBuilder(); |
183 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f, |
184 |
|
"group"); |
185 |
1 |
sf.setStatus("Confirmed"); |
186 |
1 |
sf.setValue("clinical_significance", "Benign"); |
187 |
|
|
188 |
1 |
FeatureRendererModel fr = new FeatureRenderer(null); |
189 |
1 |
Map<String, float[][]> minmax = fr.getMinMax(); |
190 |
1 |
FeatureColourI fc = new FeatureColour(Color.white, Color.blue, 12, 22); |
191 |
1 |
fc.setAttributeName("clinical_significance"); |
192 |
1 |
fr.setColour("METAL", fc); |
193 |
1 |
minmax.put("METAL", new float[][] { { 0f, 1f }, null }); |
194 |
1 |
sar.appendFeature(sb, 1, fr, sf); |
195 |
|
|
196 |
1 |
assertEquals( |
197 |
|
"METAL 1 3; Fe2-S Score=1.3; (Confirmed); clinical_significance=Benign", |
198 |
|
sb.toString()); |
199 |
|
} |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
201 |
1 |
@Test(groups = "Functional")... |
202 |
|
public void testAppendFeature_DescEqualsType() |
203 |
|
{ |
204 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
205 |
1 |
StringBuilder sb = new StringBuilder(); |
206 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3, |
207 |
|
Float.NaN, "group"); |
208 |
|
|
209 |
|
|
210 |
1 |
sar.appendFeature(sb, 1, null, sf); |
211 |
1 |
assertEquals("METAL 1 3", sb.toString()); |
212 |
|
|
213 |
1 |
sb.setLength(0); |
214 |
1 |
sf.setDescription("Metal"); |
215 |
|
|
216 |
1 |
sar.appendFeature(sb, 1, null, sf); |
217 |
1 |
assertEquals("METAL 1 3; Metal", sb.toString()); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
220 |
1 |
@Test(groups = "Functional")... |
221 |
|
public void testAppendFeature_stripHtml() |
222 |
|
{ |
223 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
224 |
1 |
StringBuilder sb = new StringBuilder(); |
225 |
1 |
SequenceFeature sf = new SequenceFeature("METAL", |
226 |
|
"<html><body>hello<em>world</em></body></html>", 1, 3, |
227 |
|
Float.NaN, "group"); |
228 |
|
|
229 |
1 |
sar.appendFeature(sb, 1, null, sf); |
230 |
|
|
231 |
1 |
assertEquals("METAL 1 3; <body>hello<em>world</em>", sb.toString()); |
232 |
|
|
233 |
1 |
sb.setLength(0); |
234 |
1 |
sf.setDescription("<br>&kHD>6"); |
235 |
1 |
sar.appendFeature(sb, 1, null, sf); |
236 |
|
|
237 |
1 |
assertEquals("METAL 1 3; <br>&kHD>6", sb.toString()); |
238 |
|
} |
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (52) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
240 |
1 |
@Test(groups = "Functional")... |
241 |
|
public void testCreateSequenceAnnotationReport() |
242 |
|
{ |
243 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
244 |
1 |
StringBuilder sb = new StringBuilder(); |
245 |
|
|
246 |
1 |
SequenceI seq = new Sequence("s1", "MAKLKRFQSSTLL"); |
247 |
1 |
seq.setDescription("SeqDesc"); |
248 |
|
|
249 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, null); |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
1 |
seq.addSequenceFeature(new SequenceFeature("Domain", "Ferredoxin", 5, |
255 |
|
10, 1f, null)); |
256 |
1 |
assertEquals("<i><br>SeqDesc</i>", sb.toString()); |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
1 |
seq.addSequenceFeature(new SequenceFeature("Type1", "Nonpos", 0, 0, 1f, |
262 |
|
null)); |
263 |
1 |
sb.setLength(0); |
264 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, null); |
265 |
1 |
String expected = "<i><br>SeqDesc<br>Type1 ; Nonpos Score=1.0</i>"; |
266 |
1 |
assertEquals(expected, sb.toString()); |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
1 |
sb.setLength(0); |
272 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, false, null); |
273 |
1 |
assertEquals("<i><br>SeqDesc</i>", sb.toString()); |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
1 |
seq.addSequenceFeature(new SequenceFeature("Metal", "Desc", 0, 0, 5f, |
282 |
|
null)); |
283 |
|
|
284 |
1 |
FeatureRendererModel fr = new FeatureRenderer(null); |
285 |
1 |
Map<String, float[][]> minmax = fr.getMinMax(); |
286 |
1 |
minmax.put("Metal", new float[][] { null, new float[] { 2f, 5f } }); |
287 |
|
|
288 |
1 |
sb.setLength(0); |
289 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, fr); |
290 |
1 |
expected = "<i><br>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos</i>"; |
291 |
1 |
assertEquals(expected, sb.toString()); |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
1 |
SequenceFeature sf = new SequenceFeature("Metal", "Desc", 0, 0, 5f, |
298 |
|
null); |
299 |
1 |
sf.setValue("linkonly", Boolean.TRUE); |
300 |
1 |
seq.addSequenceFeature(sf); |
301 |
1 |
sb.setLength(0); |
302 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, fr); |
303 |
1 |
assertEquals(expected, sb.toString()); |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
1 |
SequenceFeature sf2 = new SequenceFeature("Variant", "Havana", 0, 0, |
310 |
|
5f, null); |
311 |
1 |
sf2.setValue(GffConstants.CLINICAL_SIGNIFICANCE, "benign"); |
312 |
1 |
seq.addSequenceFeature(sf2); |
313 |
1 |
sb.setLength(0); |
314 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, fr); |
315 |
1 |
expected = "<i><br>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; Havana</i>"; |
316 |
1 |
assertEquals(expected, sb.toString()); |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
1 |
seq.addDBRef(new DBRefEntry("PDB", "0", "3iu1")); |
322 |
1 |
seq.addDBRef(new DBRefEntry("Uniprot", "1", "P30419")); |
323 |
|
|
324 |
|
|
325 |
1 |
sb.setLength(0); |
326 |
1 |
sar.createSequenceAnnotationReport(sb, seq, false, true, fr); |
327 |
1 |
assertEquals(expected, sb.toString()); |
328 |
|
|
329 |
|
|
330 |
1 |
sb.setLength(0); |
331 |
1 |
FeatureColourI fc = new FeatureColour(Color.green, Color.pink, 2, 3); |
332 |
1 |
fc.setAttributeName("clinical_significance"); |
333 |
1 |
fr.setColour("Variant", fc); |
334 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, fr); |
335 |
1 |
expected = "<i><br>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1<br>Metal ; Desc<br>" |
336 |
|
+ "Type1 ; Nonpos<br>Variant ; Havana; clinical_significance=benign</i>"; |
337 |
1 |
assertEquals(expected, sb.toString()); |
338 |
|
|
339 |
1 |
sb.setLength(0); |
340 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, false, fr); |
341 |
1 |
expected = "<i><br>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1</i>"; |
342 |
1 |
assertEquals(expected, sb.toString()); |
343 |
|
|
344 |
|
|
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
1PASS
|
|
352 |
1 |
@Test(groups = "Functional")... |
353 |
|
public void testCreateSequenceAnnotationReport_withEllipsis() |
354 |
|
{ |
355 |
1 |
SequenceAnnotationReport sar = new SequenceAnnotationReport(null); |
356 |
1 |
StringBuilder sb = new StringBuilder(); |
357 |
|
|
358 |
1 |
SequenceI seq = new Sequence("s1", "ABC"); |
359 |
|
|
360 |
1 |
int maxSources = (int) PA.getValue(sar, "MAX_SOURCES"); |
361 |
42 |
for (int i = 0; i <= maxSources; i++) |
362 |
|
{ |
363 |
41 |
seq.addDBRef(new DBRefEntry("PDB" + i, "0", "3iu1")); |
364 |
|
} |
365 |
|
|
366 |
1 |
int maxRefs = (int) PA.getValue(sar, "MAX_REFS_PER_SOURCE"); |
367 |
6 |
for (int i = 0; i <= maxRefs; i++) |
368 |
|
{ |
369 |
5 |
seq.addDBRef(new DBRefEntry("Uniprot", "0", "P3041" + i)); |
370 |
|
} |
371 |
|
|
372 |
1 |
sar.createSequenceAnnotationReport(sb, seq, true, true, null, true); |
373 |
1 |
String report = sb.toString(); |
374 |
1 |
assertTrue(report |
375 |
|
.startsWith("<i><br>UNIPROT P30410, P30411, P30412, P30413,...<br>PDB0 3iu1")); |
376 |
1 |
assertTrue(report |
377 |
|
.endsWith("<br>PDB7 3iu1<br>PDB8,...<br>(Output Sequence Details to list all database references)</i>")); |
378 |
|
} |
379 |
|
} |