2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.commands;
24 * Jalview - A Sequence Alignment Editor and Viewer Copyright (C) 2007 AM
25 * Waterhouse, J Procter, G Barton, M Clamp, S Searle
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
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
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
42 import jalview.datamodel.AlignmentI;
43 import jalview.datamodel.SequenceI;
45 public class RemoveGapsCommand extends EditCommand
47 public RemoveGapsCommand(String description, SequenceI[] seqs,
50 this.description = description;
52 for (int i = 0; i < seqs.length; i++)
54 if (seqs[i].getLength() > width)
56 width = seqs[i].getLength();
60 findGaps(seqs, 0, width, al);
63 public RemoveGapsCommand(String description, SequenceI[] seqs, int start,
64 int end, AlignmentI al)
66 this.description = description;
67 findGaps(seqs, start, end, al);
70 void findGaps(SequenceI[] seqs, int start, int end, AlignmentI al)
73 int startCol = -1, endCol = -1;
80 boolean delete = true;
83 for (int s = 0; s < seqs.length; s++)
88 sequence = seqs[s].getSequence(start, end + 1);
90 jSize = sequence.length;
91 for (j = 0; j < jSize; j++)
95 if (!jalview.util.Comparison.isGap(sequence[j]))
105 if (delete && startCol == -1)
110 if (!delete && startCol > -1)
112 this.appendEdit(Action.DELETE_GAP, new SequenceI[]
113 { seqs[s] }, start + startCol - deletedCols, endCol - startCol,
116 deletedCols += (endCol - startCol);
121 if (delete && startCol > -1)
123 this.appendEdit(Action.DELETE_GAP, new SequenceI[]
124 { seqs[s] }, start + startCol - deletedCols, jSize - startCol, al,
130 performEdit(0, null);