Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.datamodel

File Annotation.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

18
46
6
1
220
109
18
0.39
7.67
6
3

Classes

Class Line # Actions
Annotation 31 46 18
0.7142857371.4%
 

Contributing tests

This file is covered by 234 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.datamodel;
22   
23    import java.awt.Color;
24   
25    /**
26    * Holds all annotation values for a position in an AlignmentAnnotation row
27    *
28    * @author $author$
29    * @version $Revision$
30    */
 
31    public class Annotation
32    {
33    /**
34    * the empty annotation - proxy for null entries in annotation row
35    */
36    public static final Annotation EMPTY_ANNOTATION = new Annotation("", "",
37    ' ', 0f);
38   
39    /** Character label - also shown below histogram */
40    public String displayCharacter = "";
41   
42    /**
43    * Text label for position: shown in mouse over and displayed on secondary
44    * structure glyphs
45    */
46    public String description = "";
47   
48    /**
49    * Secondary structure symbol: Protein symbols are H, E and S(?), RNA are
50    * WUSS/Vienna plus extended pseudoknot symbols
51    */
52    public char secondaryStructure = ' ';
53   
54    /**
55    * Score for the position - used in histograms, line graphs and for shading
56    */
57    public float value;
58   
59    /** Colour for position */
60    public Color colour;
61   
62    /**
63    * Creates a new Annotation object.
64    *
65    * @param displayChar
66    * DOCUMENT ME!
67    * @param desc
68    * DOCUMENT ME!
69    * @param ss
70    * DOCUMENT ME!
71    * @param val
72    * DOCUMENT ME!
73    */
 
74  2119260 toggle public Annotation(String displayChar, String desc, char ss, float val)
75    {
76  2119363 displayCharacter = displayChar;
77  2119675 description = desc;
78  2119689 secondaryStructure = ss;
79  2119546 value = val;
80   
81    }
82   
83    /**
84    * Creates a new Annotation object.
85    *
86    * @param displayChar
87    * DOCUMENT ME!
88    * @param desc
89    * DOCUMENT ME!
90    * @param ss
91    * DOCUMENT ME!
92    * @param val
93    * DOCUMENT ME!
94    * @param colour
95    * DOCUMENT ME!
96    */
 
97  1082104 toggle public Annotation(String displayChar, String desc, char ss, float val,
98    Color colour)
99    {
100  1082118 this(displayChar, desc, ss, val);
101  1082107 this.colour = colour;
102    }
103   
104    /**
105    * Copy constructor New annotation takes on the same (or duplicated)
106    * attributes as the given template
107    *
108    * @param that
109    * template annotation
110    */
 
111  69760 toggle public Annotation(Annotation that)
112    {
113  69760 if (that == null || this == that)
114    {
115  0 return;
116    }
117  69760 if (that.displayCharacter != null)
118    {
119  40021 displayCharacter = new String(that.displayCharacter);
120    }
121  69760 if (that.description != null)
122    {
123  39705 description = new String(that.description);
124    }
125  69760 secondaryStructure = that.secondaryStructure;
126  69760 value = that.value;
127  69760 colour = that.colour;
128   
129    }
130   
131    /**
132    * Value only annotation.
133    *
134    * @param val
135    * value at this annotation position
136    */
 
137  109814 toggle public Annotation(float val)
138    {
139  109814 this(null, null, ' ', val, null);
140    }
141   
142    /**
143    * human readable representation of an annotation row element.
144    *
145    * Format is 'display Char','secondary Structure
146    * Char',"description",score,[colourstring]
147    *
148    * fields may be missing if they are null, whitespace, or equivalent to
149    * Float.NaN
150    */
 
151  46 toggle @Override
152    public String toString()
153    {
154  46 StringBuffer sb = new StringBuffer();
155  46 if (displayCharacter != null)
156    {
157  46 sb.append("\'");
158  46 sb.append(displayCharacter);
159  46 sb.append("\'");
160    }
161    {
162  46 sb.append(",");
163    }
164  46 if (secondaryStructure != 0
165    && !("" + displayCharacter).equals("" + secondaryStructure))
166    {
167  30 sb.append("\'");
168  30 sb.append(secondaryStructure);
169  30 sb.append("\'");
170    }
171    {
172  46 sb.append(",");
173    }
174  46 if (description != null && description.length() > 0)
175    {
176  0 sb.append("\"");
177  0 sb.append(description);
178  0 sb.append("\"");
179    }
180    {
181  46 sb.append(",");
182    }
183  46 if (!Float.isNaN(value))
184    {
185  46 sb.append(value);
186    }
187  46 if (colour != null)
188    {
189  0 if (sb.length() > 0)
190    {
191  0 sb.append(",");
192    }
193  0 sb.append("[");
194  0 sb.append(colour.getRed());
195  0 sb.append(",");
196  0 sb.append(colour.getGreen());
197  0 sb.append(",");
198  0 sb.append(colour.getBlue());
199  0 sb.append("]");
200    }
201  46 return sb.toString();
202    }
203   
204    /**
205    * @return true if annot is 'whitespace' annotation (zero score, whitespace or
206    * zero length display character, label, description
207    */
 
208  39359 toggle public boolean isWhitespace()
209    {
210  39359 return ((value == 0f)
211    && ((description == null) || (description.trim().length() == 0))
212    && ((displayCharacter == null)
213    || (displayCharacter.trim().length() == 0)
214    || (displayCharacter.equals(" ."))) // RNA Stockholm blank
215    // displayCharacter can
216    // end up like this
217    && (secondaryStructure == '\0' || (secondaryStructure == ' '))
218    && colour == null);
219    }
220    }