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