From f9a10c9d8e8173c7387a9a2dd2547c2e9e6c6be3 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 14 Sep 2017 16:10:36 +0100 Subject: [PATCH] JAL-2541 test with seq start > 1 (and fix Undo bug this uncovered) --- src/jalview/commands/EditCommand.java | 3 +- test/jalview/commands/EditCommandTest.java | 46 +++++++++++++++++----------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 9be8d3f..8c53128 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -1163,7 +1163,8 @@ public class EditCommand implements CommandI * shift right any features that start at the cut position, * unless they were truncated */ - List sfs = seq.findFeatures(start, start); + List sfs = seq.getFeatures().findFeatures(start, + start); for (SequenceFeature sf : sfs) { if (sf.getBegin() == start) diff --git a/test/jalview/commands/EditCommandTest.java b/test/jalview/commands/EditCommandTest.java index 111adba..dbc659e 100644 --- a/test/jalview/commands/EditCommandTest.java +++ b/test/jalview/commands/EditCommandTest.java @@ -746,11 +746,15 @@ public class EditCommandTest * create a sequence features on each subrange of 1-5 */ SequenceI seq0 = new Sequence("seq", "ABCDE"); + int start = 8; + int end = 12; + seq0.setStart(start); + seq0.setEnd(end); AlignmentI alignment = new Alignment(new SequenceI[] { seq0 }); alignment.setDataset(null); - for (int from = 1; from <= seq0.getLength(); from++) + for (int from = start; from <= end; from++) { - for (int to = from; to <= seq0.getLength(); to++) + for (int to = from; to <= end; to++) { String desc = String.format("%d-%d", from, to); SequenceFeature sf = new SequenceFeature("test", desc, from, to, @@ -765,7 +769,7 @@ public class EditCommandTest assertEquals(func(5), sfs.size()); /* - * now perform all possible cuts of subranges of 1-5 (followed by Undo) + * now perform all possible cuts of subranges of columns 1-5 * and validate the resulting remaining sequence features! */ SequenceI[] sqs = new SequenceI[] { seq0 }; @@ -778,10 +782,10 @@ public class EditCommandTest - from + 1), alignment); final String msg = String.format("Cut %d-%d ", from + 1, to + 1); - verifyCut(seq0, from, to, msg); + verifyCut(seq0, from, to, msg, start); /* - * undo and verify + * undo and verify all restored */ AlignmentI[] views = new AlignmentI[] { alignment }; ec.undoCommand(views); @@ -793,7 +797,7 @@ public class EditCommandTest * redo and verify */ ec.doCommand(views); - verifyCut(seq0, from, to, msg); + verifyCut(seq0, from, to, msg, start); /* * undo ready for next cut @@ -812,9 +816,10 @@ public class EditCommandTest * @param from * @param to * @param msg + * @param seqStart */ protected void verifyCut(SequenceI seq0, int from, int to, - final String msg) + final String msg, int seqStart) { List sfs; sfs = seq0.getSequenceFeatures(); @@ -851,7 +856,8 @@ public class EditCommandTest */ for (SequenceFeature sf : sfs) { - verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained); + verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained, + seqStart); } } @@ -882,18 +888,21 @@ public class EditCommandTest * * @param sf * @param from - * start of cut (first residue cut) + * start of cut (first residue cut 1..) * @param to - * end of cut (last residue cut) + * end of cut (last residue cut 1..) * @param newDataset + * @param seqStart */ private void verifyFeatureRelocation(SequenceFeature sf, int from, int to, - boolean newDataset) + boolean newDataset, int seqStart) { // TODO handle the gapped sequence case as well int cutSize = to - from + 1; final int oldFrom = ((Integer) sf.getValue("from")).intValue(); final int oldTo = ((Integer) sf.getValue("to")).intValue(); + final int oldFromPosition = oldFrom - seqStart + 1; // 1.. + final int oldToPosition = oldTo - seqStart + 1; // 1.. String msg = String.format( "Feature %s relocated to %d-%d after cut of %d-%d", @@ -904,13 +913,13 @@ public class EditCommandTest assertEquals("0: " + msg, oldFrom, sf.getBegin()); assertEquals("0: " + msg, oldTo, sf.getEnd()); } - else if (oldTo < from) + else if (oldToPosition < from) { // before cut region so unchanged assertEquals("1: " + msg, oldFrom, sf.getBegin()); assertEquals("2: " + msg, oldTo, sf.getEnd()); } - else if (oldFrom > to) + else if (oldFromPosition > to) { // follows cut region - shift by size of cut assertEquals("3: " + msg, newDataset ? oldFrom - cutSize : oldFrom, @@ -918,21 +927,22 @@ public class EditCommandTest assertEquals("4: " + msg, newDataset ? oldTo - cutSize : oldTo, sf.getEnd()); } - else if (oldFrom < from && oldTo > to) + else if (oldFromPosition < from && oldToPosition > to) { // feature encloses cut region - shrink it right assertEquals("5: " + msg, oldFrom, sf.getBegin()); assertEquals("6: " + msg, oldTo - cutSize, sf.getEnd()); } - else if (oldFrom < from) + else if (oldFromPosition < from) { // feature overlaps left side of cut region - truncated right - assertEquals("7: " + msg, from - 1, sf.getEnd()); + assertEquals("7: " + msg, from - 1 + seqStart - 1, sf.getEnd()); } - else if (oldTo > to) + else if (oldToPosition > to) { // feature overlaps right side of cut region - truncated left - assertEquals("8: " + msg, newDataset ? from : to + 1, sf.getBegin()); + assertEquals("8: " + msg, newDataset ? from + seqStart - 1 : to + 1, + sf.getBegin()); assertEquals("9: " + msg, newDataset ? from + oldTo - to - 1 : oldTo, sf.getEnd()); } -- 1.7.10.2