Clover icon

Coverage Report

  1. Project Clover database Tue Oct 29 2024 21:36:55 GMT
  2. Package jalview.renderer

File ScaleRenderer.java

 

Coverage histogram

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

Code metrics

14
38
2
2
156
84
10
0.26
19
1
5

Classes

Class Line # Actions
ScaleRenderer 37 35 9
0.9696%
ScaleRenderer.ScaleMark 42 3 1
1.0100%
 

Contributing tests

This file is covered by 100 tests. .

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.renderer;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.datamodel.HiddenColumns;
25    import jalview.datamodel.SequenceI;
26   
27    import java.util.ArrayList;
28    import java.util.Iterator;
29    import java.util.List;
30   
31    /**
32    * Calculate and display alignment rulers
33    *
34    * @author jprocter
35    *
36    */
 
37    public class ScaleRenderer
38    {
39    /**
40    * Represents one major or minor scale mark
41    */
 
42    public final class ScaleMark
43    {
44    /**
45    * true for a major scale mark, false for minor
46    */
47    public final boolean major;
48   
49    /**
50    * visible column position (0..) e.g. 19
51    */
52    public final int column;
53   
54    /**
55    * text (if any) to show e.g. "20"
56    */
57    public final String text;
58   
 
59  32728 toggle ScaleMark(boolean isMajor, int col, String txt)
60    {
61  32728 major = isMajor;
62  32728 column = col;
63  32728 text = txt;
64    }
65    }
66   
67    /**
68    * calculate positions markers on the alignment ruler
69    *
70    * @param av
71    * @param startx
72    * left-most column in visible view
73    * @param endx
74    * - right-most column in visible view
75    * @return List of ScaleMark holding boolean: true/false for major/minor mark,
76    * marker position in alignment column coords, a String to be rendered
77    * at the position (or null)
78    */
 
79  3262 toggle public List<ScaleMark> calculateMarks(AlignViewportI av, int startx,
80    int endx)
81    {
82  3262 int scalestartx = (startx / 10) * 10;
83   
84  3262 SequenceI refSeq = av.getAlignment().getSeqrep();
85  3262 int refSp = 0;
86  3262 int refStartI = 0;
87  3262 int refEndI = -1;
88   
89  3262 HiddenColumns hc = av.getAlignment().getHiddenColumns();
90   
91  3262 if (refSeq != null)
92    {
93    // find bounds and set origin appropriately
94    // locate first residue in sequence which is not hidden
95  251 Iterator<int[]> it = hc.iterator();
96  251 int index = refSeq.firstResidueOutsideIterator(it);
97  251 refSp = hc.absoluteToVisibleColumn(index);
98   
99  251 refStartI = refSeq.findIndex(refSeq.getStart()) - 1;
100   
101  251 int seqlength = refSeq.getLength();
102    // get sequence position past the end of the sequence
103  251 int pastEndPos = refSeq.findPosition(seqlength + 1);
104  251 refEndI = refSeq.findIndex(pastEndPos - 1) - 1;
105   
106  251 scalestartx = refSp + ((scalestartx - refSp) / 10) * 10;
107    }
108   
109  3262 if (refSeq == null && scalestartx % 10 == 0)
110    {
111  3011 scalestartx += 5;
112    }
113  3262 List<ScaleMark> marks = new ArrayList<>();
114  3262 String string;
115  3262 int refN, iadj;
116    // todo: add a 'reference origin column' to set column number relative to
117  35990 for (int i = scalestartx; i <= endx; i += 5)
118    {
119  32728 if (((i - refSp) % 10) == 0)
120    {
121  15522 if (refSeq == null)
122    {
123  13765 iadj = hc.visibleToAbsoluteColumn(i - 1) + 1;
124  13765 string = String.valueOf(iadj);
125    }
126    else
127    {
128  1757 iadj = hc.visibleToAbsoluteColumn(i - 1);
129  1757 refN = refSeq.findPosition(iadj);
130    // TODO show bounds if position is a gap
131    // - ie L--R -> "1L|2R" for
132    // marker
133  1757 if (iadj < refStartI)
134    {
135  19 string = String.valueOf(iadj - refStartI);
136    }
137  1738 else if (iadj > refEndI)
138    {
139  0 string = "+" + String.valueOf(iadj - refEndI);
140    }
141    else
142    {
143  1738 string = String.valueOf(refN) + refSeq.getCharAt(iadj);
144    }
145    }
146  15522 marks.add(new ScaleMark(true, i - startx - 1, string));
147    }
148    else
149    {
150  17206 marks.add(new ScaleMark(false, i - startx - 1, null));
151    }
152    }
153  3262 return marks;
154    }
155   
156    }