From: Jim Procter Date: Fri, 29 May 2020 17:25:41 +0000 (+0100) Subject: JAL-518 quick and dirty groovy script implementing undo/redo left justify (or right... X-Git-Tag: Release_2_11_4_0~45^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cfba86992cd64bb0df6105bbf5dfc076ba8a93b2;p=jalview.git JAL-518 quick and dirty groovy script implementing undo/redo left justify (or right if the flag is disabled) --- diff --git a/examples/groovy/justifyRegionQuick.groovy b/examples/groovy/justifyRegionQuick.groovy new file mode 100644 index 0000000..7316b5e --- /dev/null +++ b/examples/groovy/justifyRegionQuick.groovy @@ -0,0 +1,84 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + +// Prototype Right/Left Justify Script +boolean left=true; + +import jalview.datamodel.*; + +def msaf = jalview.bin.Jalview.getCurrentAlignFrame(); +if (msaf==null) +{ + return; +} + +def al = msaf.getViewport().getAlignment(); +al.padGaps(); +def reg = msaf.getViewport().getSelectionGroup(); +int from,to; +SequenceI[] seqs; + +from=0; +to=al.getWidth()-1; +seqs = al.getSequences(); +if (reg!=null) { + seqs = reg.getSequences(); + from=reg.getStartRes(); + to=reg.getEndRes(); +} + +if ((to-from)<1) { + return; +} + +jalview.commands.EditCommand[] edits=new jalview.commands.EditCommand[seqs.length]; +int s=0; +for (SequenceI seq:seqs) { + ContiguousI cont = seq.findPositions(from+1,to+1); + if (cont==null) { continue; } + int dsstart=seq.getDatasetSequence().getStart(); + char[] sqchar=seq.getDatasetSequence().getSequence(-dsstart+cont.getBegin(),-dsstart+cont.getEnd()+1); + println sqchar; + char[] alseq = new char[to-from+1]; + int sqstart = left ? 0 : alseq.length-sqchar.length; + int gaps = alseq.length-sqchar.length; + int gapstart=left ? sqchar.length : 0; + char gc = al.getGapCharacter(); + for (int gp=0;gp