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