1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.commands; |
22 |
|
|
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import static org.testng.AssertJUnit.assertEquals; |
26 |
|
import static org.testng.AssertJUnit.assertSame; |
27 |
|
import static org.testng.AssertJUnit.assertTrue; |
28 |
|
|
29 |
|
import jalview.commands.EditCommand.Action; |
30 |
|
import jalview.commands.EditCommand.Edit; |
31 |
|
import jalview.datamodel.Alignment; |
32 |
|
import jalview.datamodel.AlignmentI; |
33 |
|
import jalview.datamodel.Sequence; |
34 |
|
import jalview.datamodel.SequenceFeature; |
35 |
|
import jalview.datamodel.SequenceI; |
36 |
|
import jalview.datamodel.features.SequenceFeatures; |
37 |
|
import jalview.gui.JvOptionPane; |
38 |
|
|
39 |
|
import java.nio.charset.Charset; |
40 |
|
import java.util.Arrays; |
41 |
|
import java.util.Collections; |
42 |
|
import java.util.Comparator; |
43 |
|
import java.util.List; |
44 |
|
import java.util.Map; |
45 |
|
import java.util.spi.LocaleServiceProvider; |
46 |
|
|
47 |
|
import org.testng.Assert; |
48 |
|
import org.testng.annotations.BeforeClass; |
49 |
|
import org.testng.annotations.BeforeMethod; |
50 |
|
import org.testng.annotations.Test; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@author |
56 |
|
|
57 |
|
|
|
|
| 97.1% |
Uncovered Elements: 17 (579) |
Complexity: 54 |
Complexity Density: 0.11 |
|
58 |
|
public class EditCommandTest |
59 |
|
{ |
60 |
|
private static Comparator<SequenceFeature> BY_DESCRIPTION = new Comparator<SequenceFeature>() |
61 |
|
{ |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
1144 |
@Override... |
64 |
|
public int compare(SequenceFeature o1, SequenceFeature o2) |
65 |
|
{ |
66 |
1144 |
return o1.getDescription().compareTo(o2.getDescription()); |
67 |
|
} |
68 |
|
}; |
69 |
|
|
70 |
|
private EditCommand testee; |
71 |
|
|
72 |
|
private SequenceI[] seqs; |
73 |
|
|
74 |
|
private Alignment al; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
58 |
private static int func(int i)... |
81 |
|
{ |
82 |
58 |
return i * (i + 1) / 2; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
85 |
1 |
@BeforeClass(alwaysRun = true)... |
86 |
|
public void setUpJvOptionPane() |
87 |
|
{ |
88 |
1 |
JvOptionPane.setInteractiveMode(false); |
89 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
92 |
26 |
@BeforeMethod(alwaysRun = true)... |
93 |
|
public void setUp() |
94 |
|
{ |
95 |
26 |
testee = new EditCommand(); |
96 |
26 |
seqs = new SequenceI[4]; |
97 |
26 |
seqs[0] = new Sequence("seq0", "abcdefghjk"); |
98 |
26 |
seqs[0].setDatasetSequence(new Sequence("seq0ds", "ABCDEFGHJK")); |
99 |
26 |
seqs[1] = new Sequence("seq1", "fghjklmnopq"); |
100 |
26 |
seqs[1].setDatasetSequence(new Sequence("seq1ds", "FGHJKLMNOPQ")); |
101 |
26 |
seqs[2] = new Sequence("seq2", "qrstuvwxyz"); |
102 |
26 |
seqs[2].setDatasetSequence(new Sequence("seq2ds", "QRSTUVWXYZ")); |
103 |
26 |
seqs[3] = new Sequence("seq3", "1234567890"); |
104 |
26 |
seqs[3].setDatasetSequence(new Sequence("seq3ds", "1234567890")); |
105 |
26 |
al = new Alignment(seqs); |
106 |
26 |
al.setGapCharacter('?'); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
112 |
1 |
@Test(groups = { "Functional" })... |
113 |
|
public void testAppendEdit_insertGap() |
114 |
|
{ |
115 |
|
|
116 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true); |
117 |
1 |
assertEquals("abcd???efghjk", seqs[0].getSequenceAsString()); |
118 |
1 |
assertEquals("fghj???klmnopq", seqs[1].getSequenceAsString()); |
119 |
1 |
assertEquals("qrst???uvwxyz", seqs[2].getSequenceAsString()); |
120 |
1 |
assertEquals("1234???567890", seqs[3].getSequenceAsString()); |
121 |
|
|
122 |
|
|
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
129 |
1 |
@Test(groups = { "Functional" })... |
130 |
|
public void testAppendEdit_deleteGap() |
131 |
|
{ |
132 |
1 |
testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true); |
133 |
1 |
assertEquals("abcdhjk", seqs[0].getSequenceAsString()); |
134 |
1 |
assertEquals("fghjnopq", seqs[1].getSequenceAsString()); |
135 |
1 |
assertEquals("qrstxyz", seqs[2].getSequenceAsString()); |
136 |
1 |
assertEquals("1234890", seqs[3].getSequenceAsString()); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
143 |
1 |
@Test(groups = { "Functional" })... |
144 |
|
public void testCut() |
145 |
|
{ |
146 |
1 |
Edit ec = testee.new Edit(Action.CUT, seqs, 4, 3, al); |
147 |
1 |
EditCommand.cut(ec, new AlignmentI[] { al }); |
148 |
1 |
assertEquals("abcdhjk", seqs[0].getSequenceAsString()); |
149 |
1 |
assertEquals("fghjnopq", seqs[1].getSequenceAsString()); |
150 |
1 |
assertEquals("qrstxyz", seqs[2].getSequenceAsString()); |
151 |
1 |
assertEquals("1234890", seqs[3].getSequenceAsString()); |
152 |
|
|
153 |
1 |
assertEquals("efg", new String(ec.string[0])); |
154 |
1 |
assertEquals("klm", new String(ec.string[1])); |
155 |
1 |
assertEquals("uvw", new String(ec.string[2])); |
156 |
1 |
assertEquals("567", new String(ec.string[3])); |
157 |
|
|
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
163 |
0 |
@Test(groups = { "Functional" }, enabled = false)... |
164 |
|
public void testPaste_undo_redo() |
165 |
|
{ |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
0 |
SequenceI[] newSeqs = new SequenceI[2]; |
174 |
0 |
newSeqs[0] = new Sequence("newseq0", "ACEFKL"); |
175 |
0 |
newSeqs[1] = new Sequence("newseq1", "JWMPDH"); |
176 |
|
|
177 |
0 |
new EditCommand("Paste", Action.PASTE, newSeqs, 0, al.getWidth(), al); |
178 |
0 |
assertEquals(6, al.getSequences().size()); |
179 |
0 |
assertEquals("1234567890", seqs[3].getSequenceAsString()); |
180 |
0 |
assertEquals("ACEFKL", seqs[4].getSequenceAsString()); |
181 |
0 |
assertEquals("JWMPDH", seqs[5].getSequenceAsString()); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
187 |
1 |
@Test(groups = { "Functional" })... |
188 |
|
public void testUndo_insertGap() |
189 |
|
{ |
190 |
|
|
191 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true); |
192 |
|
|
193 |
1 |
assertEquals("abcd???efghjk", seqs[0].getSequenceAsString()); |
194 |
1 |
testee.undoCommand(new AlignmentI[] { al }); |
195 |
1 |
assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); |
196 |
1 |
assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); |
197 |
1 |
assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); |
198 |
1 |
assertEquals("1234567890", seqs[3].getSequenceAsString()); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
204 |
1 |
@Test(groups = { "Functional" })... |
205 |
|
public void testUndo_deleteGap() |
206 |
|
{ |
207 |
1 |
testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true); |
208 |
|
|
209 |
1 |
assertEquals("abcdhjk", seqs[0].getSequenceAsString()); |
210 |
1 |
testee.undoCommand(new AlignmentI[] { al }); |
211 |
|
|
212 |
1 |
assertEquals("abcd???hjk", seqs[0].getSequenceAsString()); |
213 |
1 |
assertEquals("fghj???nopq", seqs[1].getSequenceAsString()); |
214 |
1 |
assertEquals("qrst???xyz", seqs[2].getSequenceAsString()); |
215 |
1 |
assertEquals("1234???890", seqs[3].getSequenceAsString()); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
221 |
1 |
@Test(groups = { "Functional" })... |
222 |
|
public void testUndo_multipleCommands() |
223 |
|
{ |
224 |
|
|
225 |
1 |
testee.appendEdit(Action.DELETE_GAP, seqs, 2, 3, al, true); |
226 |
1 |
assertEquals("abfghjk", seqs[0].getSequenceAsString()); |
227 |
1 |
assertEquals("1267890", seqs[3].getSequenceAsString()); |
228 |
|
|
229 |
|
|
230 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 2, 2, al, true); |
231 |
1 |
assertEquals("ab??fghjk", seqs[0].getSequenceAsString()); |
232 |
1 |
assertEquals("12??67890", seqs[3].getSequenceAsString()); |
233 |
|
|
234 |
|
|
235 |
1 |
testee.appendEdit(Action.DELETE_GAP, seqs, 3, 3, al, true); |
236 |
1 |
assertEquals("ab?hjk", seqs[0].getSequenceAsString()); |
237 |
1 |
assertEquals("12?890", seqs[3].getSequenceAsString()); |
238 |
|
|
239 |
|
|
240 |
1 |
testee.undoCommand(new AlignmentI[] { al }); |
241 |
1 |
assertEquals("ab?????hjk", seqs[0].getSequenceAsString()); |
242 |
1 |
assertEquals("12?????890", seqs[3].getSequenceAsString()); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
249 |
1 |
@Test(groups = { "Functional" })... |
250 |
|
public void testUndo_multipleInsertGaps() |
251 |
|
{ |
252 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 4, 1, al, true); |
253 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 5, 1, al, true); |
254 |
1 |
testee.appendEdit(Action.INSERT_GAP, seqs, 6, 1, al, true); |
255 |
|
|
256 |
|
|
257 |
1 |
testee.undoCommand(new AlignmentI[] { al }); |
258 |
1 |
assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); |
259 |
1 |
assertEquals("1234567890", seqs[3].getSequenceAsString()); |
260 |
|
|
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
266 |
1 |
@Test(groups = { "Functional" })... |
267 |
|
public void testUndo_cut() |
268 |
|
{ |
269 |
1 |
testee.appendEdit(Action.CUT, seqs, 4, 3, al, true); |
270 |
|
|
271 |
1 |
assertEquals("abcdhjk", seqs[0].getSequenceAsString()); |
272 |
1 |
testee.undoCommand(new AlignmentI[] { al }); |
273 |
1 |
assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); |
274 |
1 |
assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); |
275 |
1 |
assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); |
276 |
1 |
assertEquals("1234567890", seqs[3].getSequenceAsString()); |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
282 |
1 |
@Test(groups = { "Functional" })... |
283 |
|
public void testReplace() |
284 |
|
{ |
285 |
|
|
286 |
1 |
seqs[1].createDatasetSequence(); |
287 |
1 |
assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); |
288 |
|
|
289 |
1 |
new EditCommand("", Action.REPLACE, "Z-xY", new SequenceI[] { seqs[1] }, |
290 |
|
4, 8, al); |
291 |
1 |
assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); |
292 |
1 |
assertEquals("fghjZ-xYopq", seqs[1].getSequenceAsString()); |
293 |
|
|
294 |
1 |
assertEquals("fghjZxYopq".toUpperCase(Locale.ROOT), |
295 |
|
seqs[1].getDatasetSequence().getSequenceAsString()); |
296 |
1 |
assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); |
297 |
1 |
assertEquals("1234567890", seqs[3].getSequenceAsString()); |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
303 |
1 |
@Test(groups = { "Functional" })... |
304 |
|
public void testReplace_withGaps() |
305 |
|
{ |
306 |
1 |
SequenceI seq = new Sequence("seq", "ABC--DEF"); |
307 |
1 |
seq.createDatasetSequence(); |
308 |
1 |
assertEquals("ABCDEF", seq.getDatasetSequence().getSequenceAsString()); |
309 |
1 |
assertEquals(1, seq.getStart()); |
310 |
1 |
assertEquals(6, seq.getEnd()); |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
1 |
EditCommand edit = new EditCommand("", Action.REPLACE, "xyZ", |
318 |
|
new SequenceI[] |
319 |
|
{ seq }, 2, 4, al); |
320 |
1 |
assertEquals("ABxyZ-DEF", seq.getSequenceAsString()); |
321 |
1 |
assertEquals(1, seq.getStart()); |
322 |
1 |
assertEquals(8, seq.getEnd()); |
323 |
|
|
324 |
1 |
assertEquals("ABxyZDEF".toUpperCase(Locale.ROOT), |
325 |
|
seq.getDatasetSequence().getSequenceAsString()); |
326 |
1 |
assertEquals(8, seq.getDatasetSequence().getEnd()); |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
1 |
AlignmentI[] views = new AlignmentI[] { |
332 |
|
new Alignment(new SequenceI[] |
333 |
|
{ seq }) }; |
334 |
1 |
edit.undoCommand(views); |
335 |
|
|
336 |
1 |
assertEquals("ABC--DEF", seq.getSequenceAsString()); |
337 |
1 |
assertEquals("ABCDEF", seq.getDatasetSequence().getSequenceAsString()); |
338 |
1 |
assertEquals(1, seq.getStart()); |
339 |
1 |
assertEquals(6, seq.getEnd()); |
340 |
1 |
assertEquals(6, seq.getDatasetSequence().getEnd()); |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
1 |
edit.doCommand(views); |
346 |
|
|
347 |
1 |
assertEquals("ABxyZ-DEF", seq.getSequenceAsString()); |
348 |
1 |
assertEquals(1, seq.getStart()); |
349 |
1 |
assertEquals(8, seq.getEnd()); |
350 |
|
|
351 |
1 |
assertEquals("ABxyZDEF".toUpperCase(Locale.ROOT), |
352 |
|
seq.getDatasetSequence().getSequenceAsString()); |
353 |
1 |
assertEquals(8, seq.getDatasetSequence().getEnd()); |
354 |
|
|
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
360 |
1 |
@Test(groups = { "Functional" })... |
361 |
|
public void testReplaceFirstResiduesWithGaps() |
362 |
|
{ |
363 |
|
|
364 |
|
|
365 |
1 |
SequenceI dsseq = seqs[1].getDatasetSequence(); |
366 |
1 |
EditCommand edit = new EditCommand("", Action.REPLACE, "----", |
367 |
|
new SequenceI[] |
368 |
|
{ seqs[1] }, 0, 4, al); |
369 |
|
|
370 |
|
|
371 |
1 |
assertEquals("----klmnopq", seqs[1].getSequenceAsString()); |
372 |
|
|
373 |
1 |
assertTrue(dsseq == seqs[1].getDatasetSequence()); |
374 |
|
|
375 |
1 |
assertEquals("fghjklmnopq".toUpperCase(Locale.ROOT), |
376 |
|
dsseq.getSequenceAsString()); |
377 |
|
|
378 |
1 |
assertEquals(5, seqs[1].getStart()); |
379 |
1 |
assertEquals(11, seqs[1].getEnd()); |
380 |
|
|
381 |
1 |
AlignmentI[] views = new AlignmentI[] { new Alignment(seqs) }; |
382 |
|
|
383 |
1 |
edit.undoCommand(views); |
384 |
|
|
385 |
|
|
386 |
1 |
assertTrue(dsseq == seqs[1].getDatasetSequence()); |
387 |
|
|
388 |
1 |
assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); |
389 |
|
|
390 |
1 |
assertEquals(1, seqs[1].getStart()); |
391 |
1 |
assertEquals(11, seqs[1].getEnd()); |
392 |
|
|
393 |
|
|
394 |
1 |
edit.undoCommand(views); |
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
1 |
assertEquals("----klmnopq", seqs[1].getSequenceAsString()); |
400 |
|
|
401 |
1 |
assertTrue(dsseq == seqs[1].getDatasetSequence()); |
402 |
|
|
403 |
1 |
assertEquals("fghjklmnopq".toUpperCase(Locale.ROOT), |
404 |
|
dsseq.getSequenceAsString()); |
405 |
|
|
406 |
1 |
assertEquals(5, seqs[1].getStart()); |
407 |
1 |
assertEquals(11, seqs[1].getEnd()); |
408 |
|
|
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
415 |
1 |
@Test(groups = { "Functional" })... |
416 |
|
public void testAddEdit_multipleInsertGap() |
417 |
|
{ |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
1 |
Edit e = new EditCommand().new Edit(Action.INSERT_GAP, |
422 |
|
new SequenceI[] |
423 |
|
{ seqs[0] }, 1, 1, al); |
424 |
1 |
testee.addEdit(e); |
425 |
1 |
SequenceI edited = new Sequence("seq0", "a?bcdefghjk"); |
426 |
1 |
edited.setDatasetSequence(seqs[0].getDatasetSequence()); |
427 |
1 |
e = new EditCommand().new Edit(Action.INSERT_GAP, |
428 |
|
new SequenceI[] |
429 |
|
{ edited }, 2, 1, al); |
430 |
1 |
testee.addEdit(e); |
431 |
1 |
edited = new Sequence("seq0", "a??bcdefghjk"); |
432 |
1 |
edited.setDatasetSequence(seqs[0].getDatasetSequence()); |
433 |
1 |
e = new EditCommand().new Edit(Action.INSERT_GAP, |
434 |
|
new SequenceI[] |
435 |
|
{ edited }, 3, 1, al); |
436 |
1 |
testee.addEdit(e); |
437 |
1 |
assertEquals(1, testee.getSize()); |
438 |
1 |
assertEquals(Action.INSERT_GAP, testee.getEdit(0).getAction()); |
439 |
1 |
assertEquals(1, testee.getEdit(0).getPosition()); |
440 |
1 |
assertEquals(3, testee.getEdit(0).getNumber()); |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
1 |
e = new EditCommand().new Edit(Action.INSERT_GAP, |
446 |
|
new SequenceI[] |
447 |
|
{ edited }, 5, 2, al); |
448 |
1 |
testee.addEdit(e); |
449 |
1 |
assertEquals(2, testee.getSize()); |
450 |
1 |
assertEquals(5, testee.getEdit(1).getPosition()); |
451 |
1 |
assertEquals(2, testee.getEdit(1).getNumber()); |
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
1 |
e = new EditCommand().new Edit(Action.DELETE_GAP, |
457 |
|
new SequenceI[] |
458 |
|
{ edited }, 6, 2, al); |
459 |
1 |
testee.addEdit(e); |
460 |
1 |
assertEquals(3, testee.getSize()); |
461 |
1 |
assertEquals(Action.DELETE_GAP, testee.getEdit(2).getAction()); |
462 |
1 |
assertEquals(6, testee.getEdit(2).getPosition()); |
463 |
1 |
assertEquals(2, testee.getEdit(2).getNumber()); |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
470 |
1 |
@Test(groups = { "Functional" })... |
471 |
|
public void testAddEdit_multipleDeleteGap() |
472 |
|
{ |
473 |
|
|
474 |
|
|
475 |
|
|
476 |
1 |
seqs[0].setSequence("a???bcdefghjk"); |
477 |
1 |
Edit e = new EditCommand().new Edit(Action.DELETE_GAP, |
478 |
|
new SequenceI[] |
479 |
|
{ seqs[0] }, 4, 1, al); |
480 |
1 |
testee.addEdit(e); |
481 |
1 |
assertEquals(1, testee.getSize()); |
482 |
|
|
483 |
1 |
SequenceI edited = new Sequence("seq0", "a??bcdefghjk"); |
484 |
1 |
edited.setDatasetSequence(seqs[0].getDatasetSequence()); |
485 |
1 |
e = new EditCommand().new Edit(Action.DELETE_GAP, |
486 |
|
new SequenceI[] |
487 |
|
{ edited }, 3, 1, al); |
488 |
1 |
testee.addEdit(e); |
489 |
1 |
assertEquals(1, testee.getSize()); |
490 |
|
|
491 |
1 |
edited = new Sequence("seq0", "a?bcdefghjk"); |
492 |
1 |
edited.setDatasetSequence(seqs[0].getDatasetSequence()); |
493 |
1 |
e = new EditCommand().new Edit(Action.DELETE_GAP, |
494 |
|
new SequenceI[] |
495 |
|
{ edited }, 2, 1, al); |
496 |
1 |
testee.addEdit(e); |
497 |
1 |
assertEquals(1, testee.getSize()); |
498 |
1 |
assertEquals(Action.DELETE_GAP, testee.getEdit(0).getAction()); |
499 |
1 |
assertEquals(2, testee.getEdit(0).getPosition()); |
500 |
1 |
assertEquals(3, testee.getEdit(0).getNumber()); |
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
1 |
e = new EditCommand().new Edit(Action.DELETE_GAP, |
506 |
|
new SequenceI[] |
507 |
|
{ edited }, 2, 1, al); |
508 |
1 |
testee.addEdit(e); |
509 |
1 |
assertEquals(2, testee.getSize()); |
510 |
1 |
assertEquals(Action.DELETE_GAP, testee.getEdit(0).getAction()); |
511 |
1 |
assertEquals(2, testee.getEdit(1).getPosition()); |
512 |
1 |
assertEquals(1, testee.getEdit(1).getNumber()); |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
1 |
e = new EditCommand().new Edit(Action.INSERT_GAP, |
518 |
|
new SequenceI[] |
519 |
|
{ edited }, 1, 1, al); |
520 |
1 |
testee.addEdit(e); |
521 |
1 |
assertEquals(3, testee.getSize()); |
522 |
1 |
assertEquals(Action.INSERT_GAP, testee.getEdit(2).getAction()); |
523 |
1 |
assertEquals(1, testee.getEdit(2).getPosition()); |
524 |
1 |
assertEquals(1, testee.getEdit(2).getNumber()); |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
532 |
1 |
@Test(groups = { "Functional" })... |
533 |
|
public void testAddEdit_removeAllGaps() |
534 |
|
{ |
535 |
1 |
seqs[0].setSequence("a???bcdefghjk"); |
536 |
1 |
Edit e = new EditCommand().new Edit(Action.DELETE_GAP, |
537 |
|
new SequenceI[] |
538 |
|
{ seqs[0] }, 4, 1, al); |
539 |
1 |
testee.addEdit(e); |
540 |
|
|
541 |
1 |
seqs[1].setSequence("f??ghjklmnopq"); |
542 |
1 |
Edit e2 = new EditCommand().new Edit(Action.DELETE_GAP, |
543 |
|
new SequenceI[] |
544 |
|
{ seqs[1] }, 3, 1, al); |
545 |
1 |
testee.addEdit(e2); |
546 |
1 |
assertEquals(2, testee.getSize()); |
547 |
1 |
assertSame(e, testee.getEdit(0)); |
548 |
1 |
assertSame(e2, testee.getEdit(1)); |
549 |
|
} |
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
555 |
1 |
@Test(groups = { "Functional" })... |
556 |
|
public void testAddEdit_groupInsertGaps() |
557 |
|
{ |
558 |
|
|
559 |
|
|
560 |
|
|
561 |
1 |
Edit e = new EditCommand().new Edit(Action.INSERT_GAP, |
562 |
|
new SequenceI[] |
563 |
|
{ seqs[0], seqs[1] }, 1, 1, al); |
564 |
1 |
testee.addEdit(e); |
565 |
1 |
SequenceI seq1edited = new Sequence("seq0", "a?bcdefghjk"); |
566 |
1 |
seq1edited.setDatasetSequence(seqs[0].getDatasetSequence()); |
567 |
1 |
SequenceI seq2edited = new Sequence("seq1", "f?ghjklmnopq"); |
568 |
1 |
seq2edited.setDatasetSequence(seqs[1].getDatasetSequence()); |
569 |
1 |
e = new EditCommand().new Edit(Action.INSERT_GAP, |
570 |
|
new SequenceI[] |
571 |
|
{ seq1edited, seq2edited }, 2, 1, al); |
572 |
1 |
testee.addEdit(e); |
573 |
|
|
574 |
1 |
assertEquals(1, testee.getSize()); |
575 |
1 |
assertEquals(Action.INSERT_GAP, testee.getEdit(0).getAction()); |
576 |
1 |
assertEquals(1, testee.getEdit(0).getPosition()); |
577 |
1 |
assertEquals(2, testee.getEdit(0).getNumber()); |
578 |
1 |
assertEquals(seqs[0].getDatasetSequence(), |
579 |
|
testee.getEdit(0).getSequences()[0].getDatasetSequence()); |
580 |
1 |
assertEquals(seqs[1].getDatasetSequence(), |
581 |
|
testee.getEdit(0).getSequences()[1].getDatasetSequence()); |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
593 |
1 |
@Test(groups = { "Functional" })... |
594 |
|
public void testPriorState_multipleInserts() |
595 |
|
{ |
596 |
1 |
EditCommand command = new EditCommand(); |
597 |
1 |
SequenceI seq = new Sequence("", "--A--B-CDEF"); |
598 |
1 |
SequenceI ds = new Sequence("", "ABCDEF"); |
599 |
1 |
seq.setDatasetSequence(ds); |
600 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
601 |
1 |
Edit e = command.new Edit(Action.INSERT_GAP, sqs, 1, 2, '-'); |
602 |
1 |
command.addEdit(e); |
603 |
1 |
e = command.new Edit(Action.INSERT_GAP, sqs, 4, 1, '-'); |
604 |
1 |
command.addEdit(e); |
605 |
1 |
e = command.new Edit(Action.INSERT_GAP, sqs, 0, 2, '-'); |
606 |
1 |
command.addEdit(e); |
607 |
|
|
608 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
609 |
1 |
assertEquals("ABCDEF", unwound.get(ds).getSequenceAsString()); |
610 |
|
} |
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
620 |
1 |
@Test(groups = { "Functional" })... |
621 |
|
public void testPriorState_removeAllGaps() |
622 |
|
{ |
623 |
1 |
EditCommand command = new EditCommand(); |
624 |
1 |
SequenceI seq = new Sequence("", "ABC"); |
625 |
1 |
SequenceI ds = new Sequence("", "ABC"); |
626 |
1 |
seq.setDatasetSequence(ds); |
627 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
628 |
1 |
Edit e = command.new Edit(Action.DELETE_GAP, sqs, 1, 1, '-'); |
629 |
1 |
command.addEdit(e); |
630 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 2, 1, '-'); |
631 |
1 |
command.addEdit(e); |
632 |
|
|
633 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
634 |
1 |
assertEquals("A-B-C", unwound.get(ds).getSequenceAsString()); |
635 |
|
} |
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
640 |
1 |
@Test(groups = { "Functional" })... |
641 |
|
public void testPriorState_singleDelete() |
642 |
|
{ |
643 |
1 |
EditCommand command = new EditCommand(); |
644 |
1 |
SequenceI seq = new Sequence("", "ABCDEF"); |
645 |
1 |
SequenceI ds = new Sequence("", "ABCDEF"); |
646 |
1 |
seq.setDatasetSequence(ds); |
647 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
648 |
1 |
Edit e = command.new Edit(Action.DELETE_GAP, sqs, 2, 2, '-'); |
649 |
1 |
command.addEdit(e); |
650 |
|
|
651 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
652 |
1 |
assertEquals("AB--CDEF", unwound.get(ds).getSequenceAsString()); |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
658 |
1 |
@Test(groups = { "Functional" })... |
659 |
|
public void testPriorState_singleInsert() |
660 |
|
{ |
661 |
1 |
EditCommand command = new EditCommand(); |
662 |
1 |
SequenceI seq = new Sequence("", "AB---CDEF"); |
663 |
1 |
SequenceI ds = new Sequence("", "ABCDEF"); |
664 |
1 |
seq.setDatasetSequence(ds); |
665 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
666 |
1 |
Edit e = command.new Edit(Action.INSERT_GAP, sqs, 2, 3, '-'); |
667 |
1 |
command.addEdit(e); |
668 |
|
|
669 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
670 |
1 |
SequenceI prior = unwound.get(ds); |
671 |
1 |
assertEquals("ABCDEF", prior.getSequenceAsString()); |
672 |
1 |
assertEquals(1, prior.getStart()); |
673 |
1 |
assertEquals(6, prior.getEnd()); |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
680 |
1 |
@Test(groups = { "Functional" })... |
681 |
|
public void testPriorState_singleInsertWithOffset() |
682 |
|
{ |
683 |
1 |
EditCommand command = new EditCommand(); |
684 |
1 |
SequenceI seq = new Sequence("", "AB---CDEF", 8, 13); |
685 |
|
|
686 |
|
|
687 |
1 |
seq.createDatasetSequence(); |
688 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
689 |
1 |
Edit e = command.new Edit(Action.INSERT_GAP, sqs, 2, 3, '-'); |
690 |
1 |
command.addEdit(e); |
691 |
|
|
692 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
693 |
1 |
SequenceI prior = unwound.get(seq.getDatasetSequence()); |
694 |
1 |
assertEquals("ABCDEF", prior.getSequenceAsString()); |
695 |
1 |
assertEquals(8, prior.getStart()); |
696 |
1 |
assertEquals(13, prior.getEnd()); |
697 |
|
} |
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
703 |
1 |
@Test(groups = { "Functional" })... |
704 |
|
public void testPriorState_removeGapsMultipleSeqs() |
705 |
|
{ |
706 |
1 |
EditCommand command = new EditCommand(); |
707 |
1 |
String original1 = "--ABC-DEF"; |
708 |
1 |
String original2 = "FG-HI--J"; |
709 |
1 |
String original3 = "M-NOPQ"; |
710 |
|
|
711 |
|
|
712 |
|
|
713 |
|
|
714 |
1 |
SequenceI seq = new Sequence("", "ABC-DEF"); |
715 |
1 |
SequenceI ds1 = new Sequence("", "ABCDEF"); |
716 |
1 |
seq.setDatasetSequence(ds1); |
717 |
1 |
SequenceI[] sqs = new SequenceI[] { seq }; |
718 |
1 |
Edit e = command.new Edit(Action.DELETE_GAP, sqs, 0, 2, '-'); |
719 |
1 |
command.addEdit(e); |
720 |
1 |
seq = new Sequence("", "ABCDEF"); |
721 |
1 |
seq.setDatasetSequence(ds1); |
722 |
1 |
sqs = new SequenceI[] { seq }; |
723 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 3, 1, '-'); |
724 |
1 |
command.addEdit(e); |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
1 |
seq = new Sequence("", "FGHI--J"); |
730 |
1 |
SequenceI ds2 = new Sequence("", "FGHIJ"); |
731 |
1 |
seq.setDatasetSequence(ds2); |
732 |
1 |
sqs = new SequenceI[] { seq }; |
733 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 2, 1, '-'); |
734 |
1 |
command.addEdit(e); |
735 |
1 |
seq = new Sequence("", "FGHIJ"); |
736 |
1 |
seq.setDatasetSequence(ds2); |
737 |
1 |
sqs = new SequenceI[] { seq }; |
738 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 4, 2, '-'); |
739 |
1 |
command.addEdit(e); |
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
1 |
seq = new Sequence("", "MNOPQ"); |
745 |
1 |
SequenceI ds3 = new Sequence("", "MNOPQ"); |
746 |
1 |
seq.setDatasetSequence(ds3); |
747 |
1 |
sqs = new SequenceI[] { seq }; |
748 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 1, 1, '-'); |
749 |
1 |
command.addEdit(e); |
750 |
|
|
751 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
752 |
1 |
assertEquals(original1, unwound.get(ds1).getSequenceAsString()); |
753 |
1 |
assertEquals(original2, unwound.get(ds2).getSequenceAsString()); |
754 |
1 |
assertEquals(original3, unwound.get(ds3).getSequenceAsString()); |
755 |
|
} |
756 |
|
|
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
|
761 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
762 |
1 |
@Test(groups = { "Functional" })... |
763 |
|
public void testPriorState_removeGappedCols() |
764 |
|
{ |
765 |
1 |
EditCommand command = new EditCommand(); |
766 |
1 |
String original1 = "--ABC--DEF"; |
767 |
1 |
String original2 = "-G-HI--J"; |
768 |
1 |
String original3 = "-M-NO--PQ"; |
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
|
773 |
1 |
SequenceI seq1 = new Sequence("", "-ABC--DEF"); |
774 |
1 |
SequenceI ds1 = new Sequence("", "ABCDEF"); |
775 |
1 |
seq1.setDatasetSequence(ds1); |
776 |
1 |
SequenceI seq2 = new Sequence("", "G-HI--J"); |
777 |
1 |
SequenceI ds2 = new Sequence("", "GHIJ"); |
778 |
1 |
seq2.setDatasetSequence(ds2); |
779 |
1 |
SequenceI seq3 = new Sequence("", "M-NO--PQ"); |
780 |
1 |
SequenceI ds3 = new Sequence("", "MNOPQ"); |
781 |
1 |
seq3.setDatasetSequence(ds3); |
782 |
1 |
SequenceI[] sqs = new SequenceI[] { seq1, seq2, seq3 }; |
783 |
1 |
Edit e = command.new Edit(Action.DELETE_GAP, sqs, 0, 1, '-'); |
784 |
1 |
command.addEdit(e); |
785 |
|
|
786 |
|
|
787 |
|
|
788 |
|
|
789 |
1 |
seq1 = new Sequence("", "-ABCDEF"); |
790 |
1 |
seq1.setDatasetSequence(ds1); |
791 |
1 |
seq2 = new Sequence("", "G-HIJ"); |
792 |
1 |
seq2.setDatasetSequence(ds2); |
793 |
1 |
seq3 = new Sequence("", "M-NOPQ"); |
794 |
1 |
seq3.setDatasetSequence(ds3); |
795 |
1 |
sqs = new SequenceI[] { seq1, seq2, seq3 }; |
796 |
1 |
e = command.new Edit(Action.DELETE_GAP, sqs, 4, 2, '-'); |
797 |
1 |
command.addEdit(e); |
798 |
|
|
799 |
1 |
Map<SequenceI, SequenceI> unwound = command.priorState(false); |
800 |
1 |
assertEquals(original1, unwound.get(ds1).getSequenceAsString()); |
801 |
1 |
assertEquals(original2, unwound.get(ds2).getSequenceAsString()); |
802 |
1 |
assertEquals(original3, unwound.get(ds3).getSequenceAsString()); |
803 |
1 |
assertEquals(ds1, unwound.get(ds1).getDatasetSequence()); |
804 |
1 |
assertEquals(ds2, unwound.get(ds2).getDatasetSequence()); |
805 |
1 |
assertEquals(ds3, unwound.get(ds3).getDatasetSequence()); |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
811 |
1 |
@Test(groups = { "Functional" })... |
812 |
|
public void testCut_withFeatures() |
813 |
|
{ |
814 |
|
|
815 |
|
|
816 |
|
|
817 |
|
|
818 |
1 |
SequenceI seq0 = seqs[0]; |
819 |
1 |
seq0.addSequenceFeature( |
820 |
|
new SequenceFeature("before", "", 1, 3, 0f, null)); |
821 |
1 |
seq0.addSequenceFeature( |
822 |
|
new SequenceFeature("overlap left", "", 2, 6, 0f, null)); |
823 |
1 |
seq0.addSequenceFeature( |
824 |
|
new SequenceFeature("internal", "", 5, 6, 0f, null)); |
825 |
1 |
seq0.addSequenceFeature( |
826 |
|
new SequenceFeature("overlap right", "", 7, 8, 0f, null)); |
827 |
1 |
seq0.addSequenceFeature( |
828 |
|
new SequenceFeature("after", "", 8, 10, 0f, null)); |
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
|
833 |
1 |
SequenceFeature internalContact = new SequenceFeature("disulphide bond", |
834 |
|
"", 5, 6, 0f, null); |
835 |
1 |
seq0.addSequenceFeature(internalContact); |
836 |
1 |
SequenceFeature overlapLeftContact = new SequenceFeature( |
837 |
|
"disulphide bond", "", 2, 6, 0f, null); |
838 |
1 |
seq0.addSequenceFeature(overlapLeftContact); |
839 |
1 |
SequenceFeature overlapRightContact = new SequenceFeature( |
840 |
|
"disulphide bond", "", 5, 8, 0f, null); |
841 |
1 |
seq0.addSequenceFeature(overlapRightContact); |
842 |
1 |
SequenceFeature spanningContact = new SequenceFeature("disulphide bond", |
843 |
|
"", 2, 9, 0f, null); |
844 |
1 |
seq0.addSequenceFeature(spanningContact); |
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
1 |
Edit ec = testee.new Edit(Action.CUT, seqs, 3, 4, al); |
850 |
1 |
EditCommand.cut(ec, new AlignmentI[] { al }); |
851 |
|
|
852 |
1 |
List<SequenceFeature> sfs = seq0.getSequenceFeatures(); |
853 |
1 |
SequenceFeatures.sortFeatures(sfs, true); |
854 |
|
|
855 |
1 |
assertEquals(5, sfs.size()); |
856 |
1 |
SequenceFeature sf = sfs.get(0); |
857 |
1 |
assertEquals("before", sf.getType()); |
858 |
1 |
assertEquals(1, sf.getBegin()); |
859 |
1 |
assertEquals(3, sf.getEnd()); |
860 |
1 |
sf = sfs.get(1); |
861 |
1 |
assertEquals("disulphide bond", sf.getType()); |
862 |
1 |
assertEquals(2, sf.getBegin()); |
863 |
1 |
assertEquals(5, sf.getEnd()); |
864 |
1 |
sf = sfs.get(2); |
865 |
1 |
assertEquals("overlap left", sf.getType()); |
866 |
1 |
assertEquals(2, sf.getBegin()); |
867 |
1 |
assertEquals(3, sf.getEnd()); |
868 |
1 |
sf = sfs.get(3); |
869 |
1 |
assertEquals("after", sf.getType()); |
870 |
1 |
assertEquals(4, sf.getBegin()); |
871 |
1 |
assertEquals(6, sf.getEnd()); |
872 |
1 |
sf = sfs.get(4); |
873 |
1 |
assertEquals("overlap right", sf.getType()); |
874 |
1 |
assertEquals(4, sf.getBegin()); |
875 |
1 |
assertEquals(4, sf.getEnd()); |
876 |
|
} |
877 |
|
|
878 |
|
|
879 |
|
|
880 |
|
|
881 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (55) |
Complexity: 7 |
Complexity Density: 0.16 |
1PASS
|
|
882 |
1 |
@Test(groups = { "Functional" })... |
883 |
|
public void testCut_withFeatures_exhaustive() |
884 |
|
{ |
885 |
|
|
886 |
|
|
887 |
|
|
888 |
1 |
SequenceI seq0 = new Sequence("seq", "ABCDE"); |
889 |
1 |
int start = 8; |
890 |
1 |
int end = 12; |
891 |
1 |
seq0.setStart(start); |
892 |
1 |
seq0.setEnd(end); |
893 |
1 |
AlignmentI alignment = new Alignment(new SequenceI[] { seq0 }); |
894 |
1 |
alignment.setDataset(null); |
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
1 |
AlignmentI copy = new Alignment( |
900 |
|
new SequenceI[] |
901 |
|
{ alignment.getDataset().getSequenceAt(0).deriveSequence() }); |
902 |
1 |
SequenceI copySeq0 = copy.getSequenceAt(0); |
903 |
|
|
904 |
6 |
for (int from = start; from <= end; from++) |
905 |
|
{ |
906 |
20 |
for (int to = from; to <= end; to++) |
907 |
|
{ |
908 |
15 |
String desc = String.format("%d-%d", from, to); |
909 |
15 |
SequenceFeature sf = new SequenceFeature("test", desc, from, to, 0f, |
910 |
|
null); |
911 |
15 |
sf.setValue("from", Integer.valueOf(from)); |
912 |
15 |
sf.setValue("to", Integer.valueOf(to)); |
913 |
15 |
seq0.addSequenceFeature(sf); |
914 |
|
} |
915 |
|
} |
916 |
|
|
917 |
1 |
List<SequenceFeature> sfs = seq0.getSequenceFeatures(); |
918 |
1 |
assertEquals(func(5), sfs.size()); |
919 |
1 |
assertEquals(sfs, copySeq0.getSequenceFeatures()); |
920 |
1 |
String copySequenceFeatures = copySeq0.getSequenceFeatures().toString(); |
921 |
|
|
922 |
|
|
923 |
|
|
924 |
|
|
925 |
|
|
926 |
1 |
SequenceI[] sqs = new SequenceI[] { seq0 }; |
927 |
|
|
928 |
6 |
for (int from = 0; from < seq0.getLength(); from++) |
929 |
|
{ |
930 |
20 |
for (int to = from; to < seq0.getLength(); to++) |
931 |
|
{ |
932 |
15 |
EditCommand ec = new EditCommand("Cut", Action.CUT, sqs, from, |
933 |
|
(to - from + 1), alignment); |
934 |
15 |
final String msg = String.format("Cut %d-%d ", from + 1, to + 1); |
935 |
15 |
boolean newDatasetSequence = copySeq0.getDatasetSequence() != seq0 |
936 |
|
.getDatasetSequence(); |
937 |
|
|
938 |
15 |
verifyCut(seq0, from, to, msg, start); |
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
15 |
assertEquals("Original dataset sequence was modified", |
944 |
|
copySequenceFeatures, |
945 |
|
copySeq0.getSequenceFeatures().toString()); |
946 |
|
|
947 |
|
|
948 |
|
|
949 |
|
|
950 |
|
|
951 |
15 |
assertEquals("Wrong Dataset size after " + msg, |
952 |
15 |
newDatasetSequence ? 2 : 1, |
953 |
|
alignment.getDataset().getHeight()); |
954 |
|
|
955 |
|
|
956 |
|
|
957 |
|
|
958 |
15 |
AlignmentI[] views = new AlignmentI[] { alignment }; |
959 |
15 |
ec.undoCommand(views); |
960 |
15 |
sfs = seq0.getSequenceFeatures(); |
961 |
15 |
assertEquals("After undo of " + msg, func(5), sfs.size()); |
962 |
15 |
verifyUndo(from, to, sfs); |
963 |
|
|
964 |
|
|
965 |
|
|
966 |
|
|
967 |
|
|
968 |
15 |
assertEquals("Original dataset sequence was modified", |
969 |
|
copySequenceFeatures, |
970 |
|
copySeq0.getSequenceFeatures().toString()); |
971 |
15 |
assertEquals("Wrong Dataset size after Undo of " + msg, 1, |
972 |
|
alignment.getDataset().getHeight()); |
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
15 |
ec.doCommand(views); |
978 |
15 |
verifyCut(seq0, from, to, msg, start); |
979 |
|
|
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
15 |
assertEquals("Original dataset sequence was modified", |
985 |
|
copySequenceFeatures, |
986 |
|
copySeq0.getSequenceFeatures().toString()); |
987 |
15 |
assertEquals("Wrong Dataset size after Redo of " + msg, |
988 |
15 |
newDatasetSequence ? 2 : 1, |
989 |
|
alignment.getDataset().getHeight()); |
990 |
|
|
991 |
|
|
992 |
|
|
993 |
|
|
994 |
15 |
ec.undoCommand(views); |
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
15 |
assertEquals("Original dataset sequence was modified", |
1001 |
|
copySequenceFeatures, |
1002 |
|
copySeq0.getSequenceFeatures().toString()); |
1003 |
15 |
assertEquals("Wrong Dataset size after final Undo of " + msg, 1, |
1004 |
|
alignment.getDataset().getHeight()); |
1005 |
|
} |
1006 |
|
} |
1007 |
|
} |
1008 |
|
|
1009 |
|
|
1010 |
|
|
1011 |
|
|
1012 |
|
|
1013 |
|
|
1014 |
|
@param |
1015 |
|
@param |
1016 |
|
@param |
1017 |
|
@param |
1018 |
|
@param |
1019 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
1020 |
30 |
protected void verifyCut(SequenceI seq0, int from, int to,... |
1021 |
|
final String msg, int seqStart) |
1022 |
|
{ |
1023 |
30 |
List<SequenceFeature> sfs; |
1024 |
30 |
sfs = seq0.getSequenceFeatures(); |
1025 |
|
|
1026 |
30 |
Collections.sort(sfs, BY_DESCRIPTION); |
1027 |
|
|
1028 |
|
|
1029 |
|
|
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
|
|
1035 |
30 |
boolean datasetRetained = from == 0 || to == 4; |
1036 |
30 |
if (datasetRetained) |
1037 |
|
{ |
1038 |
|
|
1039 |
18 |
assertEquals(msg, func(5), sfs.size()); |
1040 |
|
} |
1041 |
12 |
else if (to - from == 4) |
1042 |
|
{ |
1043 |
|
|
1044 |
0 |
assertTrue(sfs.isEmpty()); |
1045 |
|
} |
1046 |
|
else |
1047 |
|
{ |
1048 |
|
|
1049 |
12 |
assertEquals(msg + "wrong number of features left", |
1050 |
|
func(5) - func(to - from + 1), sfs.size()); |
1051 |
|
} |
1052 |
|
|
1053 |
|
|
1054 |
|
|
1055 |
|
|
1056 |
30 |
for (SequenceFeature sf : sfs) |
1057 |
|
{ |
1058 |
420 |
verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained, |
1059 |
|
seqStart); |
1060 |
|
} |
1061 |
|
} |
1062 |
|
|
1063 |
|
|
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
@param |
1068 |
|
@param |
1069 |
|
@param |
1070 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
1071 |
15 |
protected void verifyUndo(int from, int to, List<SequenceFeature> sfs)... |
1072 |
|
{ |
1073 |
15 |
for (SequenceFeature sf : sfs) |
1074 |
|
{ |
1075 |
225 |
final int oldFrom = ((Integer) sf.getValue("from")).intValue(); |
1076 |
225 |
final int oldTo = ((Integer) sf.getValue("to")).intValue(); |
1077 |
225 |
String msg = String.format("Undo cut of [%d-%d], feature at [%d-%d] ", |
1078 |
|
from + 1, to + 1, oldFrom, oldTo); |
1079 |
225 |
assertEquals(msg + "start", oldFrom, sf.getBegin()); |
1080 |
225 |
assertEquals(msg + "end", oldTo, sf.getEnd()); |
1081 |
|
} |
1082 |
|
} |
1083 |
|
|
1084 |
|
|
1085 |
|
|
1086 |
|
|
1087 |
|
@param |
1088 |
|
@param |
1089 |
|
|
1090 |
|
@param |
1091 |
|
|
1092 |
|
@param |
1093 |
|
@param |
1094 |
|
|
|
|
| 86.4% |
Uncovered Elements: 6 (44) |
Complexity: 12 |
Complexity Density: 0.5 |
|
1095 |
420 |
private void verifyFeatureRelocation(SequenceFeature sf, int from, int to,... |
1096 |
|
boolean newDataset, int seqStart) |
1097 |
|
{ |
1098 |
|
|
1099 |
420 |
int cutSize = to - from + 1; |
1100 |
420 |
final int oldFrom = ((Integer) sf.getValue("from")).intValue(); |
1101 |
420 |
final int oldTo = ((Integer) sf.getValue("to")).intValue(); |
1102 |
420 |
final int oldFromPosition = oldFrom - seqStart + 1; |
1103 |
420 |
final int oldToPosition = oldTo - seqStart + 1; |
1104 |
|
|
1105 |
420 |
String msg = String.format( |
1106 |
|
"Feature %s relocated to %d-%d after cut of %d-%d", |
1107 |
|
sf.getDescription(), sf.getBegin(), sf.getEnd(), from, to); |
1108 |
420 |
if (!newDataset) |
1109 |
|
{ |
1110 |
|
|
1111 |
270 |
assertEquals("0: " + msg, oldFrom, sf.getBegin()); |
1112 |
270 |
assertEquals("0: " + msg, oldTo, sf.getEnd()); |
1113 |
|
} |
1114 |
150 |
else if (oldToPosition < from) |
1115 |
|
{ |
1116 |
|
|
1117 |
30 |
assertEquals("1: " + msg, oldFrom, sf.getBegin()); |
1118 |
30 |
assertEquals("2: " + msg, oldTo, sf.getEnd()); |
1119 |
|
} |
1120 |
120 |
else if (oldFromPosition > to) |
1121 |
|
{ |
1122 |
|
|
1123 |
30 |
assertEquals("3: " + msg, newDataset ? oldFrom - cutSize : oldFrom, |
1124 |
|
sf.getBegin()); |
1125 |
30 |
assertEquals("4: " + msg, newDataset ? oldTo - cutSize : oldTo, |
1126 |
|
sf.getEnd()); |
1127 |
|
} |
1128 |
90 |
else if (oldFromPosition < from && oldToPosition > to) |
1129 |
|
{ |
1130 |
|
|
1131 |
30 |
assertEquals("5: " + msg, oldFrom, sf.getBegin()); |
1132 |
30 |
assertEquals("6: " + msg, oldTo - cutSize, sf.getEnd()); |
1133 |
|
} |
1134 |
60 |
else if (oldFromPosition < from) |
1135 |
|
{ |
1136 |
|
|
1137 |
30 |
assertEquals("7: " + msg, from - 1 + seqStart - 1, sf.getEnd()); |
1138 |
|
} |
1139 |
30 |
else if (oldToPosition > to) |
1140 |
|
{ |
1141 |
|
|
1142 |
30 |
assertEquals("8: " + msg, newDataset ? from + seqStart - 1 : to + 1, |
1143 |
|
sf.getBegin()); |
1144 |
30 |
assertEquals("9: " + msg, newDataset ? from + oldTo - to - 1 : oldTo, |
1145 |
|
sf.getEnd()); |
1146 |
|
} |
1147 |
|
else |
1148 |
|
{ |
1149 |
|
|
1150 |
0 |
Assert.fail(msg + " - should have been deleted"); |
1151 |
|
} |
1152 |
|
} |
1153 |
|
|
1154 |
|
|
1155 |
|
|
1156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1157 |
1 |
@Test(groups = { "Functional" })... |
1158 |
|
public void testCut_withFeatures5prime() |
1159 |
|
{ |
1160 |
1 |
SequenceI seq0 = new Sequence("seq/8-11", "A-BCC"); |
1161 |
1 |
seq0.createDatasetSequence(); |
1162 |
1 |
assertEquals(8, seq0.getStart()); |
1163 |
1 |
seq0.addSequenceFeature(new SequenceFeature("", "", 10, 11, 0f, null)); |
1164 |
1 |
SequenceI[] seqsArray = new SequenceI[] { seq0 }; |
1165 |
1 |
AlignmentI alignment = new Alignment(seqsArray); |
1166 |
|
|
1167 |
|
|
1168 |
|
|
1169 |
|
|
1170 |
|
|
1171 |
1 |
Edit ec = testee.new Edit(Action.CUT, seqsArray, 0, 3, alignment); |
1172 |
1 |
EditCommand.cut(ec, new AlignmentI[] { alignment }); |
1173 |
|
|
1174 |
|
|
1175 |
|
|
1176 |
|
|
1177 |
1 |
assertSame(seq0, alignment.getSequenceAt(0)); |
1178 |
1 |
assertEquals(10, seq0.getStart()); |
1179 |
1 |
List<SequenceFeature> sfs = seq0.getSequenceFeatures(); |
1180 |
1 |
assertEquals(1, sfs.size()); |
1181 |
1 |
SequenceFeature sf = sfs.get(0); |
1182 |
1 |
assertEquals(10, sf.getBegin()); |
1183 |
1 |
assertEquals(11, sf.getEnd()); |
1184 |
|
} |
1185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1186 |
3 |
private SequenceI mkDs(SequenceI as)... |
1187 |
|
{ |
1188 |
3 |
SequenceI ds = as.createDatasetSequence(); |
1189 |
3 |
ds.setSequence(ds.getSequenceAsString().toUpperCase(Locale.ROOT)); |
1190 |
3 |
return ds; |
1191 |
|
} |
1192 |
|
|
1193 |
|
|
1194 |
|
|
1195 |
|
|
1196 |
|
|
1197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
1198 |
1 |
@Test(groups = { "Functional" })... |
1199 |
|
public void testLeftRight_Justify_and_preserves_gaps() |
1200 |
|
{ |
1201 |
1 |
EditCommand command = new EditCommand(); |
1202 |
1 |
String original1 = "--ABc--DEF"; |
1203 |
1 |
String original2 = "-G-Hi--J"; |
1204 |
1 |
String original3 = "-M-No--PQ"; |
1205 |
|
|
1206 |
|
|
1207 |
|
|
1208 |
|
|
1209 |
1 |
SequenceI seq1 = new Sequence("sq1", original1); |
1210 |
1 |
SequenceI ds1 = mkDs(seq1); |
1211 |
|
|
1212 |
|
|
1213 |
|
|
1214 |
1 |
assertEquals("ABCDEF", seq1.getDatasetSequence().getSequenceAsString()); |
1215 |
1 |
assertEquals(original1, seq1.getSequenceAsString()); |
1216 |
1 |
SequenceI seq2 = new Sequence("sq2", original2); |
1217 |
1 |
SequenceI ds2 = mkDs(seq2); |
1218 |
1 |
SequenceI seq3 = new Sequence("sq3", original3); |
1219 |
1 |
SequenceI ds3 = mkDs(seq3); |
1220 |
1 |
List<SequenceI> sqs = Arrays.asList(seq1, seq2, seq3); |
1221 |
1 |
Alignment al = new Alignment(sqs.toArray(new SequenceI[0])); |
1222 |
1 |
EditCommand lefj = new JustifyLeftOrRightCommand("Left J", true, sqs, 1, |
1223 |
|
7, al); |
1224 |
1 |
String exp = "-ABcD---EF"; |
1225 |
|
|
1226 |
1 |
assertEquals(exp.toUpperCase(Locale.ROOT), |
1227 |
|
seq1.getSequenceAsString().toUpperCase(Locale.ROOT)); |
1228 |
|
|
1229 |
1 |
assertEquals(exp, seq1.getSequenceAsString()); |
1230 |
|
|
1231 |
1 |
assertEquals("-GHiJ---", seq2.getSequenceAsString()); |
1232 |
1 |
assertEquals("-MNoP---Q", seq3.getSequenceAsString()); |
1233 |
1 |
lefj.undoCommand(new AlignmentI[] { al }); |
1234 |
1 |
assertEquals(original3, seq3.getSequenceAsString()); |
1235 |
1 |
assertEquals(original1, seq1.getSequenceAsString()); |
1236 |
1 |
assertEquals(original2, seq2.getSequenceAsString()); |
1237 |
|
|
1238 |
1 |
EditCommand righj = new JustifyLeftOrRightCommand("Right J", false, sqs, |
1239 |
|
2, 7, al); |
1240 |
1 |
assertEquals("----ABcDEF", seq1.getSequenceAsString()); |
1241 |
1 |
assertEquals("-G---HiJ", seq2.getSequenceAsString()); |
1242 |
1 |
assertEquals("-M---NoPQ", seq3.getSequenceAsString()); |
1243 |
1 |
righj.undoCommand(new AlignmentI[] { al }); |
1244 |
1 |
assertEquals(original3, seq3.getSequenceAsString()); |
1245 |
1 |
assertEquals(original1, seq1.getSequenceAsString()); |
1246 |
1 |
assertEquals(original2, seq2.getSequenceAsString()); |
1247 |
|
|
1248 |
|
} |
1249 |
|
} |