Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.commands

File JustifyLeftOrRightCommand.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

14
24
1
1
98
52
10
0.42
24
1
10

Classes

Class Line # Actions
JustifyLeftOrRightCommand 30 24 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.commands;
22   
23    import java.util.List;
24   
25    import jalview.datamodel.AlignmentI;
26    import jalview.datamodel.ContiguousI;
27    import jalview.datamodel.SequenceI;
28    import jalview.util.Comparison;
29   
 
30    public class JustifyLeftOrRightCommand extends EditCommand
31    {
32    /**
33    * Constructs and performs a trim alignment command
34    *
35    * @param description
36    * (to show in Undo/Redo menu)
37    * @param justifyLeft
38    * if true left justify, otherwise right
39    * @param seqs
40    * the sequences to justify
41    * @param start
42    * - leftmost column (base 0) to justify
43    *
44    * @param end
45    * - rightmost column (base 0) to justify
46    *
47    * @param al
48    */
 
49  0 toggle public JustifyLeftOrRightCommand(String description, boolean left,
50    List<SequenceI> seqs, int from, int to, AlignmentI al)
51    {
52  0 this.description = description;
53   
54  0 for (SequenceI seq : seqs)
55    {
56  0 ContiguousI cont = seq.findPositions(from + 1, to + 1);
57  0 if (cont == null)
58    {
59  0 continue;
60    }
61  0 char[] range = seq.getSequence(from, to + 1);
62  0 if (range == null || range.length == 0)
63    {
64  0 continue;
65    }
66  0 int dsstart = seq.getDatasetSequence().getStart();
67  0 char[] sqchar = seq.getDatasetSequence().getSequence(
68    -dsstart + cont.getBegin(), -dsstart + cont.getEnd() + 1);
69    // debug
70    // println sqchar;
71  0 char[] alseq = new char[to - from + 1];
72  0 int sqstart = left ? 0 : alseq.length - sqchar.length;
73  0 int gaps = alseq.length - sqchar.length;
74  0 int gapstart = left ? sqchar.length : 0;
75  0 char gc = al.getGapCharacter();
76  0 for (int gp = 0; gp < gaps; gp++)
77    {
78  0 alseq[gapstart + gp] = gc;
79    }
80   
81  0 for (int sqp = 0, insp = 0; sqp < alseq.length; sqp++)
82    {
83  0 if (sqp < range.length && !Comparison.isGap(range[sqp]))
84    {
85  0 alseq[insp++ + sqstart] = range[sqp];
86    }
87    }
88  0 SequenceI[] sqa = new SequenceI[1];
89  0 sqa[0] = seq;
90   
91  0 addEdit(new jalview.commands.EditCommand.Edit(
92    jalview.commands.EditCommand.Action.REPLACE, sqa, from,
93    to + 1, al, new String(alseq)));
94    }
95   
96  0 performEdit(0, null);
97    }
98    }