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;
23 import java.util.List;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ContiguousI;
27 import jalview.datamodel.SequenceI;
29 public class JustifyLeftOrRightCommand extends EditCommand
32 * Constructs and performs a trim alignment command
35 * (to show in Undo/Redo menu)
37 * if true left justify, otherwise right
39 * the sequences to justify
41 * - leftmost column (base 0) to justify
44 * - rightmost column (base 0) to justify
48 public JustifyLeftOrRightCommand(String description, boolean left,
49 List<SequenceI> seqs, int from, int to, AlignmentI al)
51 this.description = description;
53 for (SequenceI seq : seqs)
55 ContiguousI cont = seq.findPositions(from + 1, to + 1);
60 int dsstart = seq.getDatasetSequence().getStart();
61 char[] sqchar = seq.getDatasetSequence().getSequence(
62 -dsstart + cont.getBegin(), -dsstart + cont.getEnd() + 1);
65 char[] alseq = new char[to - from + 1];
66 int sqstart = left ? 0 : alseq.length - sqchar.length;
67 int gaps = alseq.length - sqchar.length;
68 int gapstart = left ? sqchar.length : 0;
69 char gc = al.getGapCharacter();
70 for (int gp = 0; gp < gaps; gp++)
72 alseq[gapstart + gp] = gc;
75 for (int sqp = 0; sqp < sqchar.length; sqp++)
77 alseq[sqp + sqstart] = sqchar[sqp];
79 SequenceI[] sqa = new SequenceI[1];
82 addEdit(new jalview.commands.EditCommand.Edit(
83 jalview.commands.EditCommand.Action.REPLACE, sqa, from,
84 to + 1, al, new String(alseq)));
85 // addEdit(new jalview.commands.EditCommand("justify",
86 // jalview.commands.EditCommand.Action.REPLACE,
87 // new String(alseq), sqa, from, to + 1, al).getEdit(0));