2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.commands;
22 * Jalview - A Sequence Alignment Editor and Viewer Copyright (C) 2007 AM
23 * Waterhouse, J Procter, G Barton, M Clamp, S Searle
25 * This program is free software; you can redistribute it and/or modify it under
26 * the terms of the GNU General Public License as published by the Free Software
27 * Foundation; either version 2 of the License, or (at your option) any later
30 * This program is distributed in the hope that it will be useful, but WITHOUT
31 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
35 * You should have received a copy of the GNU General Public License along with
36 * this program; if not, write to the Free Software Foundation, Inc., 51
37 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
40 import jalview.datamodel.*;
42 public class RemoveGapsCommand extends EditCommand
44 public RemoveGapsCommand(String description, SequenceI[] seqs,
47 this.description = description;
49 for (int i = 0; i < seqs.length; i++)
51 if (seqs[i].getLength() > width)
53 width = seqs[i].getLength();
57 findGaps(seqs, 0, width, al);
60 public RemoveGapsCommand(String description, SequenceI[] seqs, int start,
61 int end, AlignmentI al)
63 this.description = description;
64 findGaps(seqs, start, end, al);
67 void findGaps(SequenceI[] seqs, int start, int end, AlignmentI al)
70 int startCol = -1, endCol = -1;
77 boolean delete = true;
80 for (int s = 0; s < seqs.length; s++)
85 sequence = seqs[s].getSequence(start, end + 1);
87 jSize = sequence.length;
88 for (j = 0; j < jSize; j++)
92 if (!jalview.util.Comparison.isGap(sequence[j]))
102 if (delete && startCol == -1)
107 if (!delete && startCol > -1)
109 this.appendEdit(DELETE_GAP, new SequenceI[]
110 { seqs[s] }, start + startCol - deletedCols, endCol - startCol,
113 deletedCols += (endCol - startCol);
118 if (delete && startCol > -1)
120 this.appendEdit(DELETE_GAP, new SequenceI[]
121 { seqs[s] }, start + startCol - deletedCols, jSize - startCol, al,
127 performEdit(0, null);