From c8e86c8d3d346840e826942470784b0fec66d439 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 21 Jun 2017 13:46:50 +0100 Subject: [PATCH] JAL-2541 save/Undo only 'diffs' for features with Cut command Conflicts: src/jalview/datamodel/features/SequenceFeatures.java --- src/jalview/commands/EditCommand.java | 57 ++++++++++++-------- .../datamodel/features/SequenceFeatures.java | 9 ++++ .../datamodel/features/SequenceFeaturesI.java | 7 ++- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index c46b36b..7dbcd6d 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -556,6 +556,10 @@ public class EditCommand implements CommandI command.oldds = new SequenceI[command.seqs.length]; } command.oldds[i] = oldds; + if (oldds != sequence.getDatasetSequence()) + { + oldds.getFeatures().deleteAll(); + } if (cutPositions != null) { @@ -585,22 +589,21 @@ public class EditCommand implements CommandI */ static void paste(Edit command, AlignmentI[] views) { - StringBuffer tmp; - boolean newDSNeeded; - boolean newDSWasNeeded; - int newstart, newend; boolean seqWasDeleted = false; - int start = 0, end = 0; for (int i = 0; i < command.seqs.length; i++) { - newDSNeeded = false; - newDSWasNeeded = command.oldds != null && command.oldds[i] != null; + int start = 0; + int end = 0; + boolean newDSNeeded = false; + boolean newDSWasNeeded = command.oldds != null + && command.oldds[i] != null; SequenceI sequence = command.seqs[i]; if (sequence.getLength() < 1) { - // ie this sequence was deleted, we need to - // readd it to the alignment + /* + * sequence was deleted; re-add it to the alignment + */ if (command.alIndex[i] < command.al.getHeight()) { List sequences; @@ -618,10 +621,10 @@ public class EditCommand implements CommandI } seqWasDeleted = true; } - newstart = sequence.getStart(); - newend = sequence.getEnd(); + int newStart = sequence.getStart(); + int newEnd = sequence.getEnd(); - tmp = new StringBuffer(); + StringBuilder tmp = new StringBuilder(); tmp.append(sequence.getSequence()); // Undo of a delete does not replace original dataset sequence on to // alignment sequence. @@ -653,11 +656,11 @@ public class EditCommand implements CommandI } if (sequence.getStart() == start) { - newstart--; + newStart--; } else { - newend++; + newEnd++; } } } @@ -665,8 +668,14 @@ public class EditCommand implements CommandI } sequence.setSequence(tmp.toString()); - sequence.setStart(newstart); - sequence.setEnd(newend); + sequence.setStart(newStart); + sequence.setEnd(newEnd); + + /* + * command and Undo share the same dataset sequence if cut was + * at start or end of sequence + */ + boolean sameDatasetSequence = false; if (newDSNeeded) { if (sequence.getDatasetSequence() != null) @@ -691,9 +700,11 @@ public class EditCommand implements CommandI command.oldds = new SequenceI[command.seqs.length]; } command.oldds[i] = sequence.getDatasetSequence(); + sameDatasetSequence = ds == sequence.getDatasetSequence(); + ds.setSequenceFeatures(sequence.getSequenceFeatures()); sequence.setDatasetSequence(ds); } - undoCutFeatures(command, i, start, end); + undoCutFeatures(command, i, start, end, sameDatasetSequence); } } adjustAnnotations(command, true, seqWasDeleted, views); @@ -1107,7 +1118,7 @@ public class EditCommand implements CommandI } final static void undoCutFeatures(Edit command, int index, final int i, - final int j) + final int j, boolean sameDatasetSequence) { SequenceI seq = command.seqs[index]; SequenceI sequence = seq.getDatasetSequence(); @@ -1117,10 +1128,13 @@ public class EditCommand implements CommandI } /* - * TODO: shift right features that lie to the right of the restored cut - * Currently not needed as all features restored with saved dataset sequence - * nor if no saved dataset sequence (as coordinates left unchanged by Cut) + * shift right features that lie to the right of the restored cut + * (but not if dataset sequence unchanged - coordinates left unchanged by Cut) */ + if (!sameDatasetSequence) + { + seq.getFeatures().shiftFeatures(i + 1, j - i); + } /* * restore any features that were deleted or truncated @@ -1476,7 +1490,6 @@ public class EditCommand implements CommandI * truncate left, adjust end of feature */ newBegin = cutIsInternal ? cutStartPos : cutEndPos + 1; - // newEnd = newBegin + (sfEnd - sfBegin) - overlapsBy; newEnd = newBegin + sfEnd - cutEndPos - 1; if (sf.isContactFeature()) { diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index 24f2081..217c03d 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -452,4 +452,13 @@ public class SequenceFeatures implements SequenceFeaturesI } return modified; } + + /** + * {@inheritDoc} + */ + @Override + public void deleteAll() + { + featureStore.clear(); + } } diff --git a/src/jalview/datamodel/features/SequenceFeaturesI.java b/src/jalview/datamodel/features/SequenceFeaturesI.java index 40beae3..8c30dce 100644 --- a/src/jalview/datamodel/features/SequenceFeaturesI.java +++ b/src/jalview/datamodel/features/SequenceFeaturesI.java @@ -203,4 +203,9 @@ public interface SequenceFeaturesI * @param shiftBy */ boolean shiftFeatures(int fromPosition, int shiftBy); -} \ No newline at end of file + + /** + * Deletes all positional and non-positional features + */ + void deleteAll(); +} -- 1.7.10.2