Annotation adjustment moved to EditCommand
[jalview.git] / src / jalview / commands / RemoveGapColCommand.java
1 package jalview.commands;\r
2   /*\r
3  * Jalview - A Sequence Alignment Editor and Viewer\r
4  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  *\r
11  * This program is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program; if not, write to the Free Software\r
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
19  */\r
20 \r
21 import jalview.datamodel.*;\r
22 \r
23 public class RemoveGapColCommand  extends EditCommand\r
24 {\r
25   int columnsDeleted;\r
26   public RemoveGapColCommand(String description,\r
27                              SequenceI[] seqs,\r
28                              int start, int end, AlignmentI al)\r
29   {\r
30     this.description = description;\r
31 \r
32     int j, jSize = seqs.length;\r
33 \r
34     int startCol = -1, endCol = -1;\r
35     columnsDeleted=0;\r
36 \r
37     edits = new Edit[0];\r
38 \r
39     boolean delete = true;\r
40     for (int i = start; i <= end; i++)\r
41     {\r
42       delete = true;\r
43 \r
44       for (j = 0; j < jSize; j++)\r
45       {\r
46         if (seqs[j].getLength() > i)\r
47         {\r
48           if (!jalview.util.Comparison.isGap(seqs[j].getCharAt(i)))\r
49           {\r
50             if (delete)\r
51               endCol = i;\r
52 \r
53             delete = false;\r
54             break;\r
55           }\r
56         }\r
57       }\r
58 \r
59       if (delete && startCol == -1)\r
60       {\r
61         startCol = i;\r
62       }\r
63 \r
64       if (!delete && startCol > -1)\r
65       {\r
66         this.appendEdit(DELETE_GAP, seqs,\r
67                         startCol - columnsDeleted,\r
68                         endCol - startCol,\r
69                         al,\r
70                         false);\r
71 \r
72         columnsDeleted += (endCol - startCol);\r
73         startCol = -1;\r
74         endCol = -1;\r
75       }\r
76     }\r
77 \r
78     if (delete && startCol > -1)\r
79     {\r
80        //This is for empty columns at the\r
81        //end of the alignment\r
82 \r
83       this.appendEdit(DELETE_GAP, seqs,\r
84                         startCol - columnsDeleted,\r
85                         end - startCol +1,\r
86                         al,\r
87                         false);\r
88 \r
89       columnsDeleted += (end - startCol +1);\r
90     }\r
91 \r
92 \r
93     performEdit(0);\r
94   }\r
95 \r
96   public int getSize()\r
97   {\r
98     //We're interested in the number of columns deleted,\r
99     //Not the number of sequence edits.\r
100     return columnsDeleted;\r
101   }\r
102 \r
103 }\r