bugfix todo for the 'edit sequence' command
[jalview.git] / src / jalview / commands / EditCommand.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.commands;
20
21 import java.util.*;
22
23 import jalview.datamodel.*;
24
25 /**
26  *
27  * <p>Title: EditCommmand</p>
28  *
29  * <p>Description: Essential information for performing
30  * undo and redo for cut/paste insert/delete gap
31  * which can be stored in the HistoryList </p>
32  *
33  * <p>Copyright: Copyright (c) 2006</p>
34  *
35  * <p>Company: Dundee University</p>
36  *
37  * @author not attributable
38  * @version 1.0
39  */
40 public class EditCommand
41     implements CommandI
42 {
43   public static final int INSERT_GAP = 0;
44   public static final int DELETE_GAP = 1;
45   public static final int CUT = 2;
46   public static final int PASTE = 3;
47   public static final int REPLACE = 4;
48
49   Edit[] edits;
50
51   String description;
52
53   public EditCommand()
54   {}
55
56   public EditCommand(String description)
57   {
58     this.description = description;
59   }
60
61   public EditCommand(String description,
62                      int command,
63                      SequenceI[] seqs,
64                      int position,
65                      int number,
66                      AlignmentI al)
67   {
68     this.description = description;
69     if (command == CUT || command == PASTE)
70     {
71       edits = new Edit[]
72           {
73           new Edit(command, seqs, position, number, al)};
74     }
75
76     performEdit(0, null);
77   }
78
79   public EditCommand(String description,
80                      int command,
81                      String replace,
82                      SequenceI[] seqs,
83                      int position,
84                      int number,
85                      AlignmentI al)
86   {
87     this.description = description;
88     if (command == REPLACE)
89     {
90       edits = new Edit[]
91           { new Edit(command, seqs, position, number, al, replace)};
92     }
93
94     performEdit(0, null);
95   }
96
97   final public String getDescription()
98   {
99     return description;
100   }
101
102   public int getSize()
103   {
104     return edits == null ? 0 : edits.length;
105   }
106
107   final public AlignmentI getAlignment()
108   {
109     return edits[0].al;
110   }
111
112   /**
113    * append a new editCommand
114    * Note. this shouldn't be called if the edit is an operation affects more alignment objects than the one referenced
115    * in al (for example, cut or pasting whole sequences). Use the form with an additional AlignmentI[] views parameter.
116    * @param command
117    * @param seqs
118    * @param position
119    * @param number
120    * @param al
121    * @param performEdit
122    */
123   final public void appendEdit(int command,
124           SequenceI[] seqs,
125           int position,
126           int number,
127           AlignmentI al,
128           boolean performEdit)
129   {
130     appendEdit(command, seqs, position, number, al, performEdit, null);
131   }
132   /**
133    * append a new edit command with a set of alignment views that may be operated on
134    * @param command
135    * @param seqs
136    * @param position
137    * @param number
138    * @param al
139    * @param performEdit
140    * @param views
141    */
142   final public void appendEdit(int command,
143                                SequenceI[] seqs,
144                                int position,
145                                int number,
146                                AlignmentI al,
147                                boolean performEdit, AlignmentI[] views)
148   {
149     Edit edit = new Edit(command, seqs, position, number, al.getGapCharacter());
150     if (al.getHeight() == seqs.length)
151     {
152       edit.al = al;
153       edit.fullAlignmentHeight = true;
154     }
155
156     if (edits != null)
157     {
158       Edit[] temp = new Edit[edits.length + 1];
159       System.arraycopy(edits, 0, temp, 0, edits.length);
160       edits = temp;
161       edits[edits.length - 1] = edit;
162     }
163     else
164     {
165       edits = new Edit[]
166           {
167           edit};
168     }
169
170     if (performEdit)
171     {
172       performEdit(edits.length - 1, views);
173     }
174   }
175
176   final void performEdit(int commandIndex, AlignmentI[] views)
177   {
178     int eSize = edits.length;
179     for (int e = commandIndex; e < eSize; e++)
180     {
181       switch(edits[e].command)
182       {
183         case INSERT_GAP:
184         insertGap(edits[e]);
185           break;
186         case DELETE_GAP:
187         deleteGap(edits[e]);
188           break;
189         case CUT:
190         cut(edits[e], views);
191           break;
192         case PASTE:
193         paste(edits[e], views);
194           break;
195         case REPLACE:
196           replace(edits[e]);
197           break;
198       }
199     }
200   }
201
202   final public void doCommand(AlignmentI[] views)
203   {
204     performEdit(0,views);
205   }
206
207   final public void undoCommand(AlignmentI[] views)
208   {
209     int e = 0, eSize = edits.length;
210     for (e = eSize - 1; e > -1; e--)
211     {
212       switch (edits[e].command)
213       {
214         case INSERT_GAP:
215         deleteGap(edits[e]);
216           break;
217         case DELETE_GAP:
218         insertGap(edits[e]);
219           break;
220         case CUT:
221         paste(edits[e], views);
222           break;
223         case PASTE:
224         cut(edits[e], views);
225           break;
226         case REPLACE:
227           replace(edits[e]);
228           break;
229       }
230     }
231   }
232
233   final void insertGap(Edit command)
234   {
235
236     for (int s = 0; s < command.seqs.length; s++)
237     {
238       command.seqs[s].insertCharAt(command.position,
239                                    command.number,
240                                    command.gapChar);
241     }
242
243     adjustAnnotations(command, true, false, null);
244   }
245
246   final void deleteGap(Edit command)
247   {
248     for (int s = 0; s < command.seqs.length; s++)
249     {
250       command.seqs[s].deleteChars(command.position,
251                                   command.position + command.number);
252     }
253
254     adjustAnnotations(command, false, false, null);
255   }
256
257   void cut(Edit command, AlignmentI[] views)
258   {
259     boolean seqDeleted=false;
260     command.string = new char[command.seqs.length][];
261
262     for (int i = 0; i < command.seqs.length; i++)
263     {
264       if (command.seqs[i].getLength() > command.position)
265       {
266         command.string[i] = command.seqs[i].getSequence(command.position,
267             command.position + command.number);
268         SequenceI oldds = command.seqs[i].getDatasetSequence();
269         if (command.oldds!=null && command.oldds[i]!=null)
270         {
271           // we are redoing an undone cut.
272           command.seqs[i].setDatasetSequence(null);
273         }
274         command.seqs[i].deleteChars(command.position,
275                 command.position + command.number);
276         if (command.oldds!=null && command.oldds[i]!=null)
277         {
278           // oldds entry contains the cut dataset sequence.
279           command.seqs[i].setDatasetSequence(command.oldds[i]);
280           command.oldds[i] = oldds;
281         } else {
282           // modify the oldds if necessary
283           if (oldds!=command.seqs[i].getDatasetSequence()
284             || command.seqs[i].getSequenceFeatures() != null)
285           {
286             if (command.oldds==null)
287             {
288               command.oldds = new SequenceI[command.seqs.length];
289             }
290             command.oldds[i] = oldds;
291             adjustFeatures(command, i,
292                     command.seqs[i].findPosition(command.position),
293                     command.seqs[i].findPosition(command.position +
294                             command.number),
295                             false);
296           }
297         }
298       }
299
300       if (command.seqs[i].getLength() < 1)
301       {
302         command.al.deleteSequence(command.seqs[i]);
303         seqDeleted=true;
304       }
305     }
306
307     adjustAnnotations(command, false, seqDeleted, views);
308   }
309
310   void paste(Edit command, AlignmentI[] views)
311   {
312     StringBuffer tmp;
313     boolean newDSNeeded;
314     boolean newDSWasNeeded;
315     int newstart,newend;
316     boolean seqWasDeleted=false;
317     int start = 0, end = 0;
318
319     for (int i = 0; i < command.seqs.length; i++)
320     {
321       newDSNeeded = false;
322       newDSWasNeeded = command.oldds!=null && command.oldds[i]!=null;
323       if (command.seqs[i].getLength() < 1)
324       {
325         // ie this sequence was deleted, we need to
326         // read it to the alignment
327         if (command.alIndex[i] < command.al.getHeight())
328         {
329           command.al.getSequences().insertElementAt(command.seqs[i],
330               command.alIndex[i]);
331         }
332         else
333         {
334           command.al.addSequence(command.seqs[i]);
335         }
336         seqWasDeleted=true;
337       }
338       newstart = command.seqs[i].getStart();
339       newend = command.seqs[i].getEnd();
340
341       tmp = new StringBuffer();
342       tmp.append(command.seqs[i].getSequence());
343       //Undo of a delete does not replace original dataset sequence on to alignment sequence.
344       
345       if (command.string != null && command.string[i] != null)
346       {
347         if (command.position >= tmp.length())
348         {
349           //This occurs if padding is on, and residues
350           //are removed from end of alignment
351           int length = command.position - tmp.length();
352           while (length > 0)
353           {
354             tmp.append(command.gapChar);
355             length--;
356           }
357         }
358         tmp.insert(command.position, command.string[i]);
359         for (int s = 0; s < command.string[i].length; s++)
360         {
361           if (jalview.schemes.ResidueProperties.aaIndex[command.string[i][s]] !=
362               23)
363           {
364             if (!newDSNeeded)
365             {
366               newDSNeeded = true;
367               start = command.seqs[i].findPosition(command.position);
368               end = command.seqs[i].findPosition(command.position +
369                                                command.number);
370             }
371             if (command.seqs[i].getStart()==start)
372               newstart--;
373             else
374               newend++;
375           }
376         }
377         command.string[i] = null;
378       }
379
380       command.seqs[i].setSequence(tmp.toString());
381       command.seqs[i].setStart(newstart);
382       command.seqs[i].setEnd(newend);
383       if (newDSNeeded)
384       {
385         if (command.seqs[i].getDatasetSequence() != null)
386         { 
387           SequenceI ds;
388           if (newDSWasNeeded)
389           {
390             ds = command.oldds[i];
391           } else {
392             // make a new DS sequence
393             // use new ds mechanism here
394             ds= new Sequence(command.seqs[i].getName(),
395                                      jalview.analysis.AlignSeq.extractGaps(
396                                          jalview.util.Comparison.GapChars,
397                                          command.seqs[i].getSequenceAsString()
398                                      ),
399                                      command.seqs[i].getStart(),
400                                      command.seqs[i].getEnd());
401             ds.setDescription(command.seqs[i].getDescription());
402           }
403           if (command.oldds==null)
404           {
405             command.oldds = new SequenceI[command.seqs.length];
406           }
407           command.oldds[i]=command.seqs[i].getDatasetSequence();
408           command.seqs[i].setDatasetSequence(ds);
409         }
410         adjustFeatures(command, i, start, end, true);
411       }
412     }
413     adjustAnnotations(command, true, seqWasDeleted, views);
414
415     command.string = null;
416   }
417
418   void replace(Edit command)
419   {
420     StringBuffer tmp;
421     String oldstring;
422     int start = command.position;
423     int end = command.number;
424     // TODO TUTORIAL - Fix for replacement with different length of sequence (or whole sequence)
425     // TODO Jalview 2.4 bugfix change to an aggregate command - original sequence string is cut, new string is pasted in.
426     command.number = start + command.string[0].length;
427     for (int i = 0; i < command.seqs.length; i++)
428     {
429       /**  cut
430        *     addHistoryItem(new EditCommand("Cut Sequences",
431                                       EditCommand.CUT,
432                                       cut,
433                                       sg.getStartRes(),
434                                       sg.getEndRes()-sg.getStartRes()+1,
435                                       viewport.alignment));
436
437        */
438       /** then
439        *        addHistoryItem(new EditCommand(
440                "Add sequences",
441                EditCommand.PASTE,
442                sequences,
443                0,
444                alignment.getWidth(),
445                alignment)
446               );
447
448        */
449       oldstring = command.seqs[i].getSequenceAsString();
450       tmp = new StringBuffer(oldstring.substring(0, start));
451       tmp.append(command.string[i]);
452       tmp.append(oldstring.substring(end));
453       command.seqs[i].setSequence(tmp.toString());
454       command.string[i] = oldstring.substring(start, end).toCharArray();
455       tmp = null;
456       oldstring = null;
457     }
458   }
459
460   final void adjustAnnotations(Edit command, boolean insert, boolean modifyVisibility, AlignmentI[] views)
461   {
462     AlignmentAnnotation[] annotations = null;
463
464     if (modifyVisibility && !insert)
465     {
466       // only occurs if a sequence was added or deleted.
467       command.deletedAnnotationRows = new Hashtable();
468     }
469     if (command.fullAlignmentHeight)
470     {
471       annotations = command.al.getAlignmentAnnotation();
472     }
473     else
474     {
475       int aSize = 0;
476       AlignmentAnnotation[] tmp;
477       for (int s = 0; s < command.seqs.length; s++)
478       {
479         if (modifyVisibility)
480         {
481           // Rows are only removed or added to sequence object.
482           if (!insert) {
483             // remove rows
484             tmp = command.seqs[s].getAnnotation();
485             if (tmp!=null) {
486               int alen=tmp.length;
487               for (int aa =0; aa<tmp.length; aa++)
488               {
489                 if (!command.al.deleteAnnotation(tmp[aa]))
490                 {
491                   // strip out annotation not in the current al (will be put back on insert in all views)
492                   tmp[aa] = null;
493                   alen--;
494                 }
495               }
496               command.seqs[s].setAlignmentAnnotation(null);
497               if (alen!=tmp.length)
498               {
499                 // save the non-null annotation references only
500                 AlignmentAnnotation[] saved = new AlignmentAnnotation[alen];
501                 for (int aa=0,aapos=0;aa<tmp.length;aa++)
502                 {
503                   if (tmp[aa]!=null)
504                   {
505                     saved[aapos++] = tmp[aa];
506                     tmp[aa] = null;
507                   }
508                 }
509                 tmp = saved;
510                 command.deletedAnnotationRows.put(command.seqs[s], saved);
511                 // and then remove any annotation in the other views
512                 for (int alview=0; views!=null && alview<views.length; alview++)
513                 {
514                   if (views[alview]!=command.al)
515                   {
516                     AlignmentAnnotation[] toremove = views[alview].getAlignmentAnnotation();
517                     if (toremove==null || toremove.length==0)
518                     {
519                       continue;
520                     }
521                     // remove any alignment annotation on this sequence that's on that alignment view.
522                     for (int aa = 0; aa<toremove.length; aa++)
523                     {
524                       if (toremove[aa].sequenceRef==command.seqs[s])
525                       {
526                         views[alview].deleteAnnotation(toremove[aa]);
527                       }
528                     }
529                   }
530                 }
531               } else {
532                 // save all the annotation
533                 command.deletedAnnotationRows.put(command.seqs[s], tmp);
534               }
535             }
536           } else {
537             // recover rows
538             if (command.deletedAnnotationRows!=null && command.deletedAnnotationRows.containsKey(command.seqs[s]))
539             {
540               AlignmentAnnotation[] revealed = (AlignmentAnnotation[]) command.deletedAnnotationRows.get(command.seqs[s]);
541               command.seqs[s].setAlignmentAnnotation(revealed);
542               if (revealed!=null) {
543                 for (int aa =0; aa<revealed.length; aa++)
544                 {
545                   // iterate through al adding original annotation
546                   command.al.addAnnotation(revealed[aa]);
547                 }
548                 for (int aa =0; aa<revealed.length; aa++)
549                 {
550                   command.al.setAnnotationIndex(revealed[aa], aa);
551                 }
552                 // and then duplicate added annotation on every other alignment view
553                 for (int vnum=0; views!=null && vnum<views.length; vnum++)
554                 {
555                   if (views[vnum]!=command.al)
556                   {
557                     int avwidth = views[vnum].getWidth()+1;
558                     // duplicate in this view
559                     for (int a=0; a<revealed.length; a++)
560                     {
561                       AlignmentAnnotation newann = new AlignmentAnnotation(revealed[a]);
562                       command.seqs[s].addAlignmentAnnotation(newann);
563                       newann.padAnnotation(avwidth);
564                       views[vnum].addAnnotation(newann);
565                       views[vnum].setAnnotationIndex(newann, a);
566                     }
567                   }
568                 }
569               }
570             }
571           }
572           continue;
573         }
574
575         if (command.seqs[s].getAnnotation() == null)
576         {
577           continue;
578         }
579
580         if (aSize == 0)
581         {
582           annotations = command.seqs[s].getAnnotation();
583         }
584         else
585         {
586           tmp = new AlignmentAnnotation
587               [aSize + command.seqs[s].getAnnotation().length];
588
589           System.arraycopy(annotations, 0, tmp, 0, aSize);
590
591           System.arraycopy(command.seqs[s].getAnnotation(),
592                            0, tmp, aSize,
593                            command.seqs[s].getAnnotation().length);
594
595           annotations = tmp;
596         }
597         aSize = annotations.length;
598       }
599     }
600
601     if (annotations == null)
602     {
603       return;
604     }
605
606     if (!insert)
607     {
608       command.deletedAnnotations = new Hashtable();
609     }
610
611     int aSize;
612     Annotation[] temp;
613     for (int a = 0; a < annotations.length; a++)
614     {
615       if (annotations[a].autoCalculated || annotations[a].annotations == null)
616       {
617         continue;
618       }
619
620       int tSize = 0;
621
622       aSize = annotations[a].annotations.length;
623       if (insert)
624       {
625         temp = new Annotation[aSize + command.number];
626         if(annotations[a].padGaps)
627           for (int aa = 0; aa < temp.length; aa++)
628           {
629             temp[aa] = new Annotation(
630                 command.gapChar+"",
631                 null, ' ', 0);
632           }
633       }
634       else
635       {
636         if (command.position < aSize)
637         {
638           if (command.position + command.number >= aSize)
639           {
640             tSize = aSize;
641           }
642           else
643           {
644             tSize = aSize - command.number;
645           }
646         }
647         else
648         {
649           tSize = aSize;
650         }
651
652         if (tSize < 0)
653         {
654           tSize = aSize;
655         }
656         temp = new Annotation[tSize];
657       }
658
659
660       if (insert)
661       {
662         if (command.position < annotations[a].annotations.length)
663         {
664           System.arraycopy(annotations[a].annotations,
665                            0, temp, 0, command.position);
666
667           if (command.deletedAnnotations != null
668               &&
669               command.deletedAnnotations.containsKey(annotations[a].
670               annotationId))
671           {
672             Annotation[] restore = (Annotation[])
673                 command.deletedAnnotations.get(annotations[a].annotationId);
674
675             System.arraycopy(restore,
676                              0,
677                              temp,
678                              command.position,
679                              command.number);
680
681           }
682
683           System.arraycopy(annotations[a].annotations,
684                            command.position, temp,
685                            command.position + command.number,
686                            aSize - command.position);
687         }
688         else
689         {
690           if (command.deletedAnnotations != null
691               &&
692               command.deletedAnnotations.containsKey(annotations[a].
693               annotationId))
694           {
695             Annotation[] restore = (Annotation[])
696                 command.deletedAnnotations.get(annotations[a].annotationId);
697
698             temp = new Annotation[annotations[a].annotations.length +
699                 restore.length];
700             System.arraycopy(annotations[a].annotations,
701                              0, temp, 0,
702                              annotations[a].annotations.length);
703             System.arraycopy(restore, 0, temp,
704                              annotations[a].annotations.length, restore.length);
705           }
706           else
707           {
708             temp = annotations[a].annotations;
709           }
710         }
711       }
712       else
713       {
714         if (tSize != aSize || command.position < 2)
715         {
716           int copylen = Math.min(command.position, annotations[a].annotations.length);
717           if (copylen>0)
718             System.arraycopy(annotations[a].annotations,
719                            0, temp, 0, copylen); //command.position);
720
721           Annotation[] deleted = new Annotation[command.number];
722           if (copylen>=command.position) {
723             copylen = Math.min(command.number, annotations[a].annotations.length-command.position);
724             if (copylen>0)
725             {
726               System.arraycopy(annotations[a].annotations,
727                       command.position, deleted, 0, copylen); // command.number);
728             }
729           }
730
731           command.deletedAnnotations.put(annotations[a].annotationId,
732                                          deleted);
733           if (annotations[a].annotations.length>command.position+command.number) {
734             System.arraycopy(annotations[a].annotations,
735                            command.position + command.number,
736                            temp, command.position,
737                            annotations[a].annotations.length - command.position - command.number); // aSize
738           }
739         }
740         else
741         {
742           int dSize = aSize - command.position;
743
744           if (dSize > 0)
745           {
746             Annotation[] deleted = new Annotation[command.number];
747             System.arraycopy(annotations[a].annotations,
748                              command.position, deleted, 0, dSize);
749
750             command.deletedAnnotations.put(annotations[a].annotationId,
751                                            deleted);
752
753             tSize = Math.min(annotations[a].annotations.length,
754                              command.position);
755             temp = new Annotation[tSize];
756             System.arraycopy(annotations[a].annotations,
757                              0, temp, 0, tSize);
758           }
759           else
760           {
761             temp = annotations[a].annotations;
762           }
763         }
764       }
765
766       annotations[a].annotations = temp;
767     }
768   }
769
770   final void adjustFeatures(Edit command, int index, int i, int j,
771                             boolean insert)
772   {
773     SequenceI seq = command.seqs[index];
774     SequenceI sequence = seq.getDatasetSequence();
775     if (sequence == null)
776     {
777       sequence = seq;
778     }
779
780     if (insert)
781     {
782       if (command.editedFeatures != null
783           && command.editedFeatures.containsKey(seq))
784       {
785         sequence.setSequenceFeatures(
786             (SequenceFeature[]) command.editedFeatures.get(seq)
787             );
788       }
789
790       return;
791     }
792
793     SequenceFeature[] sf = sequence.getSequenceFeatures();
794
795     if (sf == null)
796     {
797       return;
798     }
799
800     SequenceFeature[] oldsf = new SequenceFeature[sf.length];
801
802     int cSize = j - i;
803
804     for (int s = 0; s < sf.length; s++)
805     {
806       SequenceFeature copy = new SequenceFeature(sf[s]);
807
808       oldsf[s] = copy;
809
810       if (sf[s].getEnd() < i)
811       {
812         continue;
813       }
814
815       if (sf[s].getBegin() > j)
816       {
817         sf[s].setBegin(copy.getBegin() - cSize);
818         sf[s].setEnd(copy.getEnd() - cSize);
819         continue;
820       }
821
822       if (sf[s].getBegin() >= i)
823       {
824         sf[s].setBegin(i);
825       }
826
827       if (sf[s].getEnd() < j)
828       {
829         sf[s].setEnd(j - 1);
830       }
831
832       sf[s].setEnd(sf[s].getEnd() - (cSize));
833
834       if (sf[s].getBegin() > sf[s].getEnd())
835       {
836         sequence.deleteFeature(sf[s]);
837       }
838     }
839
840     if (command.editedFeatures == null)
841     {
842       command.editedFeatures = new Hashtable();
843     }
844
845     command.editedFeatures.put(seq, oldsf);
846
847   }
848
849   class Edit
850   {
851     public SequenceI[] oldds;
852     boolean fullAlignmentHeight = false;
853     Hashtable deletedAnnotationRows;
854     Hashtable deletedAnnotations;
855     Hashtable editedFeatures;
856     AlignmentI al;
857     int command;
858     char[][] string;
859     SequenceI[] seqs;
860     int[] alIndex;
861     int position, number;
862     char gapChar;
863
864     Edit(int command,
865          SequenceI[] seqs,
866          int position,
867          int number,
868          char gapChar)
869     {
870       this.command = command;
871       this.seqs = seqs;
872       this.position = position;
873       this.number = number;
874       this.gapChar = gapChar;
875     }
876
877     Edit(int command,
878          SequenceI[] seqs,
879          int position,
880          int number,
881          AlignmentI al)
882     {
883       this.gapChar = al.getGapCharacter();
884       this.command = command;
885       this.seqs = seqs;
886       this.position = position;
887       this.number = number;
888       this.al = al;
889
890       alIndex = new int[seqs.length];
891       for (int i = 0; i < seqs.length; i++)
892       {
893         alIndex[i] = al.findIndex(seqs[i]);
894       }
895
896       fullAlignmentHeight = (al.getHeight() == seqs.length);
897     }
898
899     Edit(int command,
900          SequenceI[] seqs,
901          int position,
902          int number,
903          AlignmentI al,
904          String replace)
905     {
906       this.command = command;
907       this.seqs = seqs;
908       this.position = position;
909       this.number = number;
910       this.al = al;
911       this.gapChar = al.getGapCharacter();
912       string = new char[seqs.length][];
913       for (int i = 0; i < seqs.length; i++)
914       {
915         string[i] = replace.toCharArray();
916       }
917
918       fullAlignmentHeight = (al.getHeight() == seqs.length);
919     }
920   }
921 }