1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
|
25 |
|
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; |
26 |
|
import jalview.datamodel.Alignment; |
27 |
|
import jalview.datamodel.AlignmentAnnotation; |
28 |
|
import jalview.datamodel.Sequence; |
29 |
|
import jalview.datamodel.SequenceI; |
30 |
|
import jalview.gui.JvOptionPane; |
31 |
|
|
32 |
|
import java.util.ArrayList; |
33 |
|
import java.util.List; |
34 |
|
import java.util.Random; |
35 |
|
|
36 |
|
import org.testng.annotations.BeforeClass; |
37 |
|
import org.testng.annotations.BeforeMethod; |
38 |
|
import org.testng.annotations.Test; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (215) |
Complexity: 20 |
Complexity Density: 0.11 |
|
40 |
|
public class AnnotationSorterTest |
41 |
|
{ |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
1 |
@BeforeClass(alwaysRun = true)... |
44 |
|
public void setUpJvOptionPane() |
45 |
|
{ |
46 |
1 |
JvOptionPane.setInteractiveMode(false); |
47 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
48 |
|
} |
49 |
|
|
50 |
|
private static final int NUM_SEQS = 6; |
51 |
|
|
52 |
|
private static final int NUM_ANNS = 7; |
53 |
|
|
54 |
|
private static final String SS = "secondary structure"; |
55 |
|
|
56 |
|
AlignmentAnnotation[] anns = new AlignmentAnnotation[0]; |
57 |
|
|
58 |
|
Alignment al = null; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
8 |
@BeforeMethod(alwaysRun = true)... |
64 |
|
public void setUp() |
65 |
|
{ |
66 |
8 |
al = buildAlignment(NUM_SEQS); |
67 |
8 |
anns = buildAnnotations(NUM_ANNS); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@return |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
77 |
17 |
protected AlignmentAnnotation[] buildAnnotations(int numAnns)... |
78 |
|
{ |
79 |
17 |
List<AlignmentAnnotation> annlist = new ArrayList<AlignmentAnnotation>(); |
80 |
33373 |
for (int i = 0; i < numAnns; i++) |
81 |
|
{ |
82 |
33356 |
AlignmentAnnotation ann = new AlignmentAnnotation(SS + i, "", 0); |
83 |
33356 |
annlist.add(ann); |
84 |
|
} |
85 |
17 |
return annlist.toArray(anns); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
|
93 |
|
@return |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
95 |
17 |
private Alignment buildAlignment(int numSeqs)... |
96 |
|
{ |
97 |
17 |
SequenceI[] seqs = new Sequence[numSeqs]; |
98 |
16715 |
for (int i = 0; i < numSeqs; i++) |
99 |
|
{ |
100 |
16698 |
seqs[i] = new Sequence("Sequence" + i, "axrdkfp"); |
101 |
|
} |
102 |
17 |
return new Alignment(seqs); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
117 |
1 |
@Test(groups = { "Functional" })... |
118 |
|
public void testSortBySequenceAndType_autocalcLast() |
119 |
|
{ |
120 |
|
|
121 |
1 |
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; |
122 |
1 |
anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; |
123 |
1 |
anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; |
124 |
1 |
anns[3].autoCalculated = true; anns[3].label = "Quality"; |
125 |
1 |
anns[4].autoCalculated = true; anns[4].label = "Consensus"; |
126 |
1 |
anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5"; |
127 |
1 |
anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP"; |
128 |
|
|
129 |
|
|
130 |
1 |
AnnotationSorter testee = new AnnotationSorter(al, false); |
131 |
1 |
testee.sort(anns, SequenceAnnotationOrder.SEQUENCE_AND_LABEL); |
132 |
1 |
assertEquals("label5", anns[0].label); |
133 |
1 |
assertEquals("label0", anns[1].label); |
134 |
1 |
assertEquals("iron", anns[2].label); |
135 |
1 |
assertEquals("IRP", anns[3].label); |
136 |
1 |
assertEquals("structure", anns[4].label); |
137 |
1 |
assertEquals("Quality", anns[5].label); |
138 |
1 |
assertEquals("Consensus", anns[6].label); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
144 |
1 |
@Test(groups = { "Functional" })... |
145 |
|
public void testSortBySequenceAndType_autocalcFirst() |
146 |
|
{ |
147 |
|
|
148 |
1 |
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; |
149 |
1 |
anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; |
150 |
1 |
anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; |
151 |
1 |
anns[3].autoCalculated = true; anns[3].label = "Quality"; |
152 |
1 |
anns[4].autoCalculated = true; anns[4].label = "Consensus"; |
153 |
1 |
anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5"; |
154 |
1 |
anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP"; |
155 |
|
|
156 |
|
|
157 |
1 |
AnnotationSorter testee = new AnnotationSorter(al, true); |
158 |
1 |
testee.sort(anns, SequenceAnnotationOrder.SEQUENCE_AND_LABEL); |
159 |
1 |
assertEquals("Quality", anns[0].label); |
160 |
1 |
assertEquals("Consensus", anns[1].label); |
161 |
1 |
assertEquals("label5", anns[2].label); |
162 |
1 |
assertEquals("label0", anns[3].label); |
163 |
1 |
assertEquals("iron", anns[4].label); |
164 |
1 |
assertEquals("IRP", anns[5].label); |
165 |
1 |
assertEquals("structure", anns[6].label); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
180 |
1 |
@Test(groups = { "Functional" })... |
181 |
|
public void testSortByTypeAndSequence_autocalcLast() |
182 |
|
{ |
183 |
|
|
184 |
1 |
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; |
185 |
1 |
anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; |
186 |
1 |
anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; |
187 |
1 |
anns[3].autoCalculated = true; anns[3].label = "Quality"; |
188 |
1 |
anns[4].autoCalculated = true; anns[4].label = "Consensus"; |
189 |
1 |
anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; |
190 |
1 |
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; |
191 |
|
|
192 |
|
|
193 |
1 |
AnnotationSorter testee = new AnnotationSorter(al, false); |
194 |
1 |
testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); |
195 |
1 |
assertEquals("IRON", anns[0].label); |
196 |
1 |
assertEquals("iron", anns[1].label); |
197 |
1 |
assertEquals("label0", anns[2].label); |
198 |
1 |
assertEquals("Structure", anns[3].label); |
199 |
1 |
assertEquals("structure", anns[4].label); |
200 |
1 |
assertEquals("Quality", anns[5].label); |
201 |
1 |
assertEquals("Consensus", anns[6].label); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
207 |
1 |
@Test(groups = { "Functional" })... |
208 |
|
public void testSortByTypeAndSequence_autocalcFirst() |
209 |
|
{ |
210 |
|
|
211 |
1 |
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; |
212 |
1 |
anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; |
213 |
1 |
anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; |
214 |
1 |
anns[3].autoCalculated = true; anns[3].label = "Quality"; |
215 |
1 |
anns[4].autoCalculated = true; anns[4].label = "Consensus"; |
216 |
1 |
anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; |
217 |
1 |
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; |
218 |
|
|
219 |
|
|
220 |
1 |
AnnotationSorter testee = new AnnotationSorter(al, true); |
221 |
1 |
testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); |
222 |
1 |
assertEquals("Quality", anns[0].label); |
223 |
1 |
assertEquals("Consensus", anns[1].label); |
224 |
1 |
assertEquals("IRON", anns[2].label); |
225 |
1 |
assertEquals("iron", anns[3].label); |
226 |
1 |
assertEquals("label0", anns[4].label); |
227 |
1 |
assertEquals("Structure", anns[5].label); |
228 |
1 |
assertEquals("structure", anns[6].label); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
235 |
1 |
@Test(groups = { "Functional" })... |
236 |
|
public void testNoSort_autocalcFirst() |
237 |
|
{ |
238 |
|
|
239 |
1 |
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; |
240 |
1 |
anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; |
241 |
1 |
anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; |
242 |
1 |
anns[3].autoCalculated = true; anns[3].label = "Quality"; |
243 |
1 |
anns[4].autoCalculated = true; anns[4].label = "Consensus"; |
244 |
1 |
anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; |
245 |
1 |
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; |
246 |
|
|
247 |
|
|
248 |
1 |
AnnotationSorter testee = new AnnotationSorter(al, true); |
249 |
1 |
testee.sort(anns, SequenceAnnotationOrder.NONE); |
250 |
1 |
assertEquals("Quality", anns[0].label); |
251 |
1 |
assertEquals("Consensus", anns[1].label); |
252 |
1 |
assertEquals("label0", anns[2].label); |
253 |
1 |
assertEquals("structure", anns[3].label); |
254 |
1 |
assertEquals("iron", anns[4].label); |
255 |
1 |
assertEquals("IRON", anns[5].label); |
256 |
1 |
assertEquals("Structure", anns[6].label); |
257 |
|
} |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
259 |
1 |
@Test(groups = { "Functional" })... |
260 |
|
public void testSort_timingPresorted() |
261 |
|
{ |
262 |
1 |
testTiming_presorted(50, 100); |
263 |
1 |
testTiming_presorted(500, 1000); |
264 |
1 |
testTiming_presorted(5000, 10000); |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
@param |
271 |
|
@param |
272 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
273 |
3 |
private void testTiming_presorted(final int numSeqs, final int numAnns)... |
274 |
|
{ |
275 |
3 |
Alignment alignment = buildAlignment(numSeqs); |
276 |
3 |
AlignmentAnnotation[] annotations = buildAnnotations(numAnns); |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
3 |
Random r = new Random(); |
282 |
3 |
final SequenceI[] sequences = alignment.getSequencesArray(); |
283 |
11103 |
for (int i = 0; i < annotations.length; i++) |
284 |
|
{ |
285 |
11100 |
SequenceI randomSequenceRef = sequences[r.nextInt(sequences.length)]; |
286 |
11100 |
annotations[i].sequenceRef = randomSequenceRef; |
287 |
11100 |
annotations[i].label = "label" + i; |
288 |
|
} |
289 |
3 |
long startTime = System.currentTimeMillis(); |
290 |
3 |
AnnotationSorter testee = new AnnotationSorter(alignment, false); |
291 |
3 |
testee.sort(annotations, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); |
292 |
3 |
long endTime = System.currentTimeMillis(); |
293 |
3 |
final long elapsed = endTime - startTime; |
294 |
3 |
System.out.println( |
295 |
|
"Timing test for presorted " + numSeqs + " sequences and " |
296 |
|
+ numAnns + " annotations took " + elapsed + "ms"); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
302 |
1 |
@Test(groups = { "Functional" })... |
303 |
|
public void testSort_timingUnsorted() |
304 |
|
{ |
305 |
1 |
testTiming_unsorted(50, 100); |
306 |
1 |
testTiming_unsorted(500, 1000); |
307 |
1 |
testTiming_unsorted(5000, 10000); |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
@param |
315 |
|
@param |
316 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
317 |
3 |
private void testTiming_unsorted(final int numSeqs, final int numAnns)... |
318 |
|
{ |
319 |
3 |
Alignment alignment = buildAlignment(numSeqs); |
320 |
3 |
AlignmentAnnotation[] annotations = buildAnnotations(numAnns); |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
3 |
Random r = new Random(); |
326 |
3 |
final SequenceI[] sequences = alignment.getSequencesArray(); |
327 |
11103 |
for (int i = 0; i < annotations.length; i++) |
328 |
|
{ |
329 |
11100 |
SequenceI randomSequenceRef = sequences[r.nextInt(sequences.length)]; |
330 |
11100 |
annotations[i].sequenceRef = randomSequenceRef; |
331 |
11100 |
annotations[i].label = "label" + i; |
332 |
|
} |
333 |
3 |
long startTime = System.currentTimeMillis(); |
334 |
3 |
AnnotationSorter testee = new AnnotationSorter(alignment, false); |
335 |
3 |
testee.sort(annotations, SequenceAnnotationOrder.SEQUENCE_AND_LABEL); |
336 |
3 |
long endTime = System.currentTimeMillis(); |
337 |
3 |
final long elapsed = endTime - startTime; |
338 |
3 |
System.out.println( |
339 |
|
"Timing test for unsorted " + numSeqs + " sequences and " |
340 |
|
+ numAnns + " annotations took " + elapsed + "ms"); |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
346 |
1 |
@Test(groups = { "Functional" })... |
347 |
|
public void testSort_timingSemisorted() |
348 |
|
{ |
349 |
1 |
testTiming_semiSorted(50, 100); |
350 |
1 |
testTiming_semiSorted(500, 1000); |
351 |
1 |
testTiming_semiSorted(5000, 10000); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
@param |
365 |
|
@param |
366 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 2 |
Complexity Density: 0.08 |
|
367 |
3 |
private void testTiming_semiSorted(final int numSeqs, final int numAnns)... |
368 |
|
{ |
369 |
3 |
Alignment alignment = buildAlignment(numSeqs); |
370 |
3 |
AlignmentAnnotation[] annotations = buildAnnotations(numAnns); |
371 |
|
|
372 |
3 |
String[] labels = new String[] { "label1", "label2", "label3", "label4", |
373 |
|
"label5", "label6" }; |
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
3 |
Random r = new Random(); |
379 |
3 |
final SequenceI[] sequences = alignment.getSequencesArray(); |
380 |
11103 |
for (int i = 0; i < annotations.length; i++) |
381 |
|
{ |
382 |
11100 |
SequenceI sequenceRef = sequences[i % sequences.length]; |
383 |
11100 |
annotations[i].sequenceRef = sequenceRef; |
384 |
11100 |
annotations[i].label = labels[r.nextInt(labels.length)]; |
385 |
|
} |
386 |
3 |
long startTime = System.currentTimeMillis(); |
387 |
3 |
AnnotationSorter testee = new AnnotationSorter(alignment, false); |
388 |
3 |
testee.sort(annotations, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); |
389 |
3 |
long endTime = System.currentTimeMillis(); |
390 |
3 |
long elapsed = endTime - startTime; |
391 |
3 |
System.out.println( |
392 |
|
"Sort by label for semisorted " + numSeqs + " sequences and " |
393 |
|
+ numAnns + " annotations took " + elapsed + "ms"); |
394 |
|
|
395 |
|
|
396 |
3 |
startTime = System.currentTimeMillis(); |
397 |
3 |
testee.sort(annotations, SequenceAnnotationOrder.SEQUENCE_AND_LABEL); |
398 |
3 |
endTime = System.currentTimeMillis(); |
399 |
3 |
elapsed = endTime - startTime; |
400 |
3 |
System.out.println("Resort by sequence for semisorted " + numSeqs |
401 |
|
+ " sequences and " + numAnns + " annotations took " + elapsed |
402 |
|
+ "ms"); |
403 |
|
|
404 |
|
|
405 |
3 |
startTime = System.currentTimeMillis(); |
406 |
3 |
testee.sort(annotations, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); |
407 |
3 |
endTime = System.currentTimeMillis(); |
408 |
3 |
elapsed = endTime - startTime; |
409 |
3 |
System.out.println( |
410 |
|
"Resort by label for semisorted " + numSeqs + " sequences and " |
411 |
|
+ numAnns + " annotations took " + elapsed + "ms"); |
412 |
|
} |
413 |
|
} |