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.
21 package jalview.datamodel;
23 import java.awt.Color;
26 * Holds all annotation values for a position in an AlignmentAnnotation row
31 public class Annotation
34 * the empty annotation - proxy for null entries in annotation row
36 public static final Annotation EMPTY_ANNOTATION = new Annotation("", "",
39 /** Character label - also shown below histogram */
40 public String displayCharacter = "";
43 * Text label for position: shown in mouse over and displayed on secondary
46 public String description = "";
49 * Secondary structure symbol: Protein symbols are H, E and S(?), RNA are
50 * WUSS/Vienna plus extended pseudoknot symbols
52 public char secondaryStructure = ' ';
55 * Score for the position - used in histograms, line graphs and for shading
59 /** Colour for position */
63 * Creates a new Annotation object.
74 public Annotation(String displayChar, String desc, char ss, float val)
76 displayCharacter = displayChar;
78 secondaryStructure = ss;
84 * Creates a new Annotation object.
97 public Annotation(String displayChar, String desc, char ss, float val,
100 this(displayChar, desc, ss, val);
101 this.colour = colour;
105 * Copy constructor New annotation takes on the same (or duplicated)
106 * attributes as the given template
109 * template annotation
111 public Annotation(Annotation that)
113 if (that == null || this == that)
117 if (that.displayCharacter != null)
119 displayCharacter = new String(that.displayCharacter);
121 if (that.description != null)
123 description = new String(that.description);
125 secondaryStructure = that.secondaryStructure;
127 colour = that.colour;
132 * Value only annotation.
135 * value at this annotation position
137 public Annotation(float val)
139 this(null, null, ' ', val, null);
143 * human readable representation of an annotation row element.
145 * Format is 'display Char','secondary Structure
146 * Char',"description",score,[colourstring]
148 * fields may be missing if they are null, whitespace, or equivalent to
152 public String toString()
154 StringBuffer sb = new StringBuffer();
155 if (displayCharacter != null)
158 sb.append(displayCharacter);
164 if (secondaryStructure != 0
165 && !("" + displayCharacter).equals("" + secondaryStructure))
168 sb.append(secondaryStructure);
174 if (description != null && description.length() > 0)
177 sb.append(description);
183 if (!Float.isNaN(value))
194 sb.append(colour.getRed());
196 sb.append(colour.getGreen());
198 sb.append(colour.getBlue());
201 return sb.toString();
205 * @return true if annot is 'whitespace' annotation (zero score, whitespace or
206 * zero length display character, label, description
208 public boolean isWhitespace()
210 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
217 && (secondaryStructure == '\0' || (secondaryStructure == ' '))