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;
28 import jalview.util.Comparison;
30 public class JustifyLeftOrRightCommand extends EditCommand
33 * Constructs and performs a trim alignment command
36 * (to show in Undo/Redo menu)
38 * if true left justify, otherwise right
40 * the sequences to justify
42 * - leftmost column (base 0) to justify
45 * - rightmost column (base 0) to justify
49 public JustifyLeftOrRightCommand(String description, boolean left,
50 List<SequenceI> seqs, int from, int to, AlignmentI al)
52 this.description = description;
54 for (SequenceI seq : seqs)
56 ContiguousI cont = seq.findPositions(from + 1, to + 1);
61 char[] range = seq.getSequence(from, to+1);
62 if (range==null || range.length==0)
66 int dsstart = seq.getDatasetSequence().getStart();
67 char[] sqchar = seq.getDatasetSequence().getSequence(
68 -dsstart + cont.getBegin(), -dsstart + cont.getEnd() + 1);
71 char[] alseq = new char[to - from + 1];
72 int sqstart = left ? 0 : alseq.length - sqchar.length;
73 int gaps = alseq.length - sqchar.length;
74 int gapstart = left ? sqchar.length : 0;
75 char gc = al.getGapCharacter();
76 for (int gp = 0; gp < gaps; gp++)
78 alseq[gapstart + gp] = gc;
81 for (int sqp = 0,insp=0; sqp<alseq.length; sqp++)
83 if (sqp < range.length && !Comparison.isGap(range[sqp]))
85 alseq[insp++ + sqstart] = range[sqp];
88 SequenceI[] sqa = new SequenceI[1];
91 addEdit(new jalview.commands.EditCommand.Edit(
92 jalview.commands.EditCommand.Action.REPLACE, sqa, from,
93 to + 1, al, new String(alseq)));