X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcommands%2FEditCommand.java;h=9413ba813dba59b0227c1c61ddb99f970d6f6505;hb=0d6fdcd9c4597475c09fd96da43ddcadccf78fa1;hp=9321524dc230a46bf64ed37d5539d65d49b8beeb;hpb=405da8d832cf8146ffd32f1e92aabb0109721c4c;p=jalview.git diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 9321524..9413ba8 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -452,6 +452,8 @@ public class EditCommand implements CommandI command.number = start + command.string[0].length; for (int i = 0; i < command.seqs.length; i++) { + boolean newDSWasNeeded = command.oldds != null && command.oldds[i] != null; + /** * cut addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, * cut, sg.getStartRes(), sg.getEndRes()-sg.getStartRes()+1, @@ -466,9 +468,44 @@ public class EditCommand implements CommandI oldstring = command.seqs[i].getSequenceAsString(); tmp = new StringBuffer(oldstring.substring(0, start)); tmp.append(command.string[i]); + String nogaprep = jalview.analysis.AlignSeq.extractGaps( + jalview.util.Comparison.GapChars, new String( + command.string[i])); + int ipos = command.seqs[i].findPosition(start) + - command.seqs[i].getStart(); tmp.append(oldstring.substring(end)); command.seqs[i].setSequence(tmp.toString()); command.string[i] = oldstring.substring(start, end).toCharArray(); + String nogapold = jalview.analysis.AlignSeq.extractGaps( + jalview.util.Comparison.GapChars, new String( + command.string[i])); + if (!nogaprep.toLowerCase().equals(nogapold.toLowerCase())) + { + if (newDSWasNeeded) + { + SequenceI oldds = command.seqs[i].getDatasetSequence(); + command.seqs[i].setDatasetSequence(command.oldds[i]); + command.oldds[i] = oldds; + } + else + { + if (command.oldds == null) + { + command.oldds = new SequenceI[command.seqs.length]; + } + command.oldds[i] = command.seqs[i].getDatasetSequence(); + SequenceI newds = new Sequence( + command.seqs[i].getDatasetSequence()); + String fullseq, osp = newds.getSequenceAsString(); + fullseq = osp.substring(0, ipos) + nogaprep + + osp.substring(ipos + nogaprep.length()); + newds.setSequence(fullseq.toUpperCase()); + // TODO: ensure newly created dataset sequence is added to the set of + // dataset sequences associated with the alignment. + command.seqs[i].setDatasetSequence(newds); + + } + } tmp = null; oldstring = null; }