X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fcommands%2FEditCommand.java;h=83ba5367cf3af0ae9d73c630944cd47898c2d4b6;hb=095d07c7765f6925736c41896b9bdff8df369f4e;hp=9321524dc230a46bf64ed37d5539d65d49b8beeb;hpb=f52f7b378972cc884b5d3e5cc250f89667f558f7;p=jalview.git diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 9321524..83ba536 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -1,19 +1,22 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) - * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle - * + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * * This file is part of Jalview. - * + * * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.commands; @@ -22,24 +25,24 @@ import java.util.*; import jalview.datamodel.*; /** - * + * *

* Title: EditCommmand *

- * + * *

* Description: Essential information for performing undo and redo for cut/paste * insert/delete gap which can be stored in the HistoryList *

- * + * *

* Copyright: Copyright (c) 2006 *

- * + * *

* Company: Dundee University *

- * + * * @author not attributable * @version 1.0 */ @@ -55,7 +58,7 @@ public class EditCommand implements CommandI public static final int REPLACE = 4; - public static final int INSERT_NUC=5; + public static final int INSERT_NUC = 5; Edit[] edits; @@ -118,7 +121,7 @@ public class EditCommand implements CommandI * operation affects more alignment objects than the one referenced in al (for * example, cut or pasting whole sequences). Use the form with an additional * AlignmentI[] views parameter. - * + * * @param command * @param seqs * @param position @@ -135,7 +138,7 @@ public class EditCommand implements CommandI /** * append a new edit command with a set of alignment views that may be * operated on - * + * * @param command * @param seqs * @param position @@ -196,10 +199,10 @@ public class EditCommand implements CommandI case REPLACE: replace(edits[e]); break; - //TODO:add deleteNuc for UNDO -// case INSERT_NUC: -// insertNuc(edits[e]); -// break; + // TODO:add deleteNuc for UNDO + // case INSERT_NUC: + // insertNuc(edits[e]); + // break; } } } @@ -233,7 +236,7 @@ public class EditCommand implements CommandI case REPLACE: replace(edits[e]); break; - } + } } } @@ -244,23 +247,24 @@ public class EditCommand implements CommandI { command.seqs[s].insertCharAt(command.position, command.number, command.gapChar); -// System.out.println("pos: "+command.position+" number: "+command.number); + // System.out.println("pos: "+command.position+" number: "+command.number); } adjustAnnotations(command, true, false, null); } -// -// final void insertNuc(Edit command) -// { -// -// for (int s = 0; s < command.seqs.length; s++) -// { -// System.out.println("pos: "+command.position+" number: "+command.number); -// command.seqs[s].insertCharAt(command.position, command.number,'A'); -// } -// -// adjustAnnotations(command, true, false, null); -// } + + // + // final void insertNuc(Edit command) + // { + // + // for (int s = 0; s < command.seqs.length; s++) + // { + // System.out.println("pos: "+command.position+" number: "+command.number); + // command.seqs[s].insertCharAt(command.position, command.number,'A'); + // } + // + // adjustAnnotations(command, true, false, null); + // } final void deleteGap(Edit command) { @@ -349,7 +353,8 @@ public class EditCommand implements CommandI if (command.alIndex[i] < command.al.getHeight()) { List sequences; - synchronized (sequences=command.al.getSequences()) { + synchronized (sequences = command.al.getSequences()) + { sequences.add(command.alIndex[i], command.seqs[i]); } } @@ -452,23 +457,65 @@ 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, * viewport.alignment)); - * + * */ /** * then addHistoryItem(new EditCommand( "Add sequences", * EditCommand.PASTE, sequences, 0, alignment.getWidth(), alignment) ); - * + * */ 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: JAL-1131 ensure newly created dataset sequence is added to + // the set of + // dataset sequences associated with the alignment. + // TODO: JAL-1131 fix up any annotation associated with new dataset + // sequence to ensure that original sequence/annotation relationships + // are preserved. + command.seqs[i].setDatasetSequence(newds); + + } + } tmp = null; oldstring = null; }