Known bugs fixed
[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   public RemoveGapColCommand(String description,\r
26                              SequenceI[] seqs,\r
27                              int start, int end, char gapChar)\r
28   {\r
29     this.description = description;\r
30 \r
31     int j, jSize = seqs.length;\r
32 \r
33     int startCol = -1, endCol = -1;\r
34     int deletedCols = 0;\r
35 \r
36     edits = new Edit[0];\r
37 \r
38     boolean delete = true;\r
39     for (int i = start; i < end; i++)\r
40     {\r
41       delete = true;\r
42 \r
43       for (j = 0; j < jSize; j++)\r
44       {\r
45         if (seqs[j].getLength() > i)\r
46         {\r
47           if (!jalview.util.Comparison.isGap(seqs[j].getCharAt(i)))\r
48           {\r
49             if (delete)\r
50               endCol = i;\r
51 \r
52             delete = false;\r
53             break;\r
54           }\r
55         }\r
56       }\r
57 \r
58       if (delete && startCol == -1)\r
59       {\r
60         startCol = i;\r
61       }\r
62 \r
63       if (!delete && startCol > -1)\r
64       {\r
65         this.appendEdit(DELETE_GAP, seqs,\r
66                         startCol - deletedCols,\r
67                         endCol - startCol,\r
68                         gapChar,\r
69                         false);\r
70 \r
71         deletedCols += (endCol - startCol);\r
72         startCol = -1;\r
73         endCol = -1;\r
74       }\r
75     }\r
76 \r
77     if (delete && startCol > -1)\r
78     {\r
79        //This is for empty columns at the\r
80        //end of the alignment\r
81       this.appendEdit(DELETE_GAP, seqs,\r
82                         startCol - deletedCols,\r
83                         end-startCol+1,\r
84                         gapChar,\r
85                         false);\r
86     }\r
87 \r
88     performEdit(0);\r
89   }\r
90 \r
91 }\r