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.
22 // Prototype Right/Left Justify Script
25 import jalview.datamodel.*;
27 def msaf = jalview.bin.Jalview.getCurrentAlignFrame();
33 def al = msaf.getViewport().getAlignment();
35 def reg = msaf.getViewport().getSelectionGroup();
41 seqs = al.getSequences();
43 seqs = reg.getSequences();
44 from=reg.getStartRes();
52 jalview.commands.EditCommand[] edits=new jalview.commands.EditCommand[seqs.length];
54 for (SequenceI seq:seqs) {
55 ContiguousI cont = seq.findPositions(from+1,to+1);
56 if (cont==null) { continue; }
57 int dsstart=seq.getDatasetSequence().getStart();
58 char[] sqchar=seq.getDatasetSequence().getSequence(-dsstart+cont.getBegin(),-dsstart+cont.getEnd()+1);
60 char[] alseq = new char[to-from+1];
61 int sqstart = left ? 0 : alseq.length-sqchar.length;
62 int gaps = alseq.length-sqchar.length;
63 int gapstart=left ? sqchar.length : 0;
64 char gc = al.getGapCharacter();
65 for (int gp=0;gp<gaps;gp++) {
66 alseq[gapstart+gp]=gc;
69 for (int sqp=0;sqp<sqchar.length;sqp++) {
70 alseq[sqp+sqstart]=sqchar[sqp];
72 SequenceI[] sqa=new SequenceI[1];
74 // cant do this because the edit command isn't visible.
75 // edits[s++]=new jalview.commands.EditCommand.Edit(jalview.commands.EditCommand.Action.REPLACE,sqa,(from).intValue(),(int)alseq.length,al, new String(alseq));
76 edits[s++]=new jalview.commands.EditCommand("justify",jalview.commands.EditCommand.Action.REPLACE, new String(alseq),sqa,(from).intValue(),(to).intValue()+1,al);
79 jalview.commands.EditCommand finalEdit=new jalview.commands.EditCommand("Justify "+(left ? "Left" : "Right"));
80 for (jalview.commands.EditCommand edit:edits) {
81 if (edit!=null) {finalEdit.addEdit(edit.getEdits().get(0)); }
83 msaf.addHistoryItem(finalEdit);
84 msaf.getViewport().firePropertyChange("alignment",null,seqs);