From: amwaterhouse Date: Thu, 25 Jan 2007 18:45:46 +0000 (+0000) Subject: Annotation adjustment moved to EditCommand X-Git-Tag: Release_2_3~436 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=714af52b3db1dfa2420b0782ef64248b7404adf9;p=jalview.git Annotation adjustment moved to EditCommand --- diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index c1b4daf..ed356dc 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -20,6 +20,8 @@ package jalview.commands; import jalview.datamodel.*; +import java.util.Hashtable; + /** * *

Title: EditCommmand

@@ -91,10 +93,15 @@ public class EditCommand implements CommandI SequenceI[] seqs, int position, int number, - char gapChar, + AlignmentI al, boolean performEdit) { - Edit edit = new Edit(command, seqs, position, number, gapChar); + Edit edit = new Edit(command, seqs, position, number, al.getGapCharacter()); + if(al.getHeight()==seqs.length) + { + edit.al = al; + edit.fullAlignmentHeight = true; + } if (edits != null) { @@ -171,6 +178,11 @@ public class EditCommand implements CommandI command.number, command.gapChar); } + + if (command.fullAlignmentHeight) + { + adjustAnnotations(command, true); + } } void deleteGap(Edit command) @@ -179,6 +191,11 @@ public class EditCommand implements CommandI { command.seqs[s].deleteChars(command.position, command.position+command.number); } + + if (command.fullAlignmentHeight) + { + adjustAnnotations(command, false); + } } void cut(Edit command) @@ -200,9 +217,13 @@ public class EditCommand implements CommandI { command.al.deleteSequence(command.seqs[i]); } + } - + if (command.fullAlignmentHeight) + { + adjustAnnotations(command, false); } + } void paste(Edit command) @@ -240,16 +261,99 @@ public class EditCommand implements CommandI command.string[i] = null; } command.seqs[i].setSequence(tmp.toString()); + } - - + if (command.fullAlignmentHeight) + { + adjustAnnotations(command, true); } command.string = null; } + + void adjustAnnotations(Edit command, boolean insert) + { + AlignmentAnnotation [] annotations = command.al.getAlignmentAnnotation(); + if(annotations!=null) + { + if(!insert) + command.deletedAnnotations = new Hashtable(); + + int aSize, tSize; + Annotation [] temp; + for (int a = 0; a < annotations.length; a++) + { + if(annotations[a].autoCalculated) + { + continue; + } + + aSize = annotations[a].annotations.length; + if(insert) + tSize = aSize + command.number; + else + tSize = aSize - command.number; + + temp = new Annotation[tSize]; + + if(insert) + { + System.arraycopy(annotations[a].annotations, + 0, temp, 0, command.position); + + if(command.deletedAnnotations!=null + && command.deletedAnnotations.containsKey(annotations[a].annotationId)) + { + Annotation [] restore = (Annotation []) + command.deletedAnnotations.get(annotations[a].annotationId); + + System.arraycopy(restore, + 0, + temp, + command.position, + command.number); + + } + + System.arraycopy(annotations[a].annotations, + command.position, temp, + command.position+command.number, + aSize - command.position); + } + else + { + if(command.position < annotations[a].annotations.length) + { + System.arraycopy(annotations[a].annotations, + 0, temp, 0, command.position); + + Annotation[] deleted = new Annotation[command.number]; + System.arraycopy(annotations[a].annotations, + command.position, deleted, 0, command.number); + + command.deletedAnnotations.put(annotations[a].annotationId, + deleted); + + System.arraycopy(annotations[a].annotations, + command.position + command.number, + temp, command.position, + aSize - command.position - command.number); + } + else + temp = annotations[a].annotations; + } + + annotations[a].annotations = temp; + } + } + } + + class Edit { + boolean fullAlignmentHeight = false; + Hashtable deletedAnnotations; AlignmentI al; int command; char [][] string; @@ -288,6 +392,9 @@ public class EditCommand implements CommandI alIndex = new int[seqs.length]; for(int i=0; iwidth) width = seqs[i].getLength(); - findGaps(seqs, 0, width, gapChar); + findGaps(seqs, 0, width, al); } public RemoveGapsCommand( String description, SequenceI[] seqs, - int start, int end, char gapChar) + int start, int end, AlignmentI al) { this.description = description; - findGaps(seqs, start, end, gapChar); + findGaps(seqs, start, end, al); } - void findGaps(SequenceI [] seqs, int start, int end, char gapChar) + void findGaps(SequenceI [] seqs, int start, int end, AlignmentI al) { int startCol = -1, endCol = -1; @@ -87,7 +87,7 @@ public class RemoveGapsCommand extends EditCommand this.appendEdit(DELETE_GAP, new SequenceI[]{seqs[s]}, start + startCol - deletedCols, endCol - startCol, - gapChar, + al, false); deletedCols += (endCol - startCol); @@ -100,7 +100,7 @@ public class RemoveGapsCommand extends EditCommand this.appendEdit(DELETE_GAP, new SequenceI[]{seqs[s]}, start + startCol - deletedCols, jSize - startCol, - gapChar, + al, false); } diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index f255ab5..2ad0588 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -470,58 +470,6 @@ public class Alignment implements AlignmentI } - public void adjustSequenceAnnotations(int position, - int number, - boolean insert) - { - if(annotations!=null) - { - int aSize, tSize; - Annotation [] temp; - for (int a = 0; a < annotations.length; a++) - { - if(annotations[a].autoCalculated) - { - System.out.println("ignore "+annotations[a].label); - continue; - } - aSize = annotations[a].annotations.length; - if(insert) - tSize = aSize + number; - else - tSize = aSize - number; - - temp = new Annotation[tSize]; - - if(insert) - { - System.arraycopy(annotations[a].annotations, - 0, temp, 0, position); - - System.arraycopy(annotations[a].annotations, - position, temp, position+number, aSize - position); - } - else - { - System.arraycopy(annotations[a].annotations, - 0, temp, 0, position); - - System.arraycopy(annotations[a].annotations, - position + number, temp, position, - aSize - position - number); - } - - annotations[a].annotations = temp; - - - // if (annotations[a].sequenceRef != null) - { - // annotations[a].adjustForAlignment(); - } - } - } - } - /** * DOCUMENT ME! * diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 4a3cad6..6803e9f 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -31,6 +31,8 @@ public class AlignmentAnnotation * eg consensus, quality or conservation graphs */ public boolean autoCalculated = false; + public String annotationId = Math.random() +""; + public SequenceI sequenceRef; /** DOCUMENT ME!! */ diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index bf1614b..baaebc2 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -228,10 +228,6 @@ public interface AlignmentI */ public boolean padGaps(); - public void adjustSequenceAnnotations(int position, - int number, - boolean insert); - public HiddenSequences getHiddenSequences(); /**