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 = ' ';
54 /** Score for the position - used in histograms, line graphs and for shading */
57 /** Colour for position */
61 * Creates a new Annotation object.
72 public Annotation(String displayChar, String desc, char ss, float val)
74 displayCharacter = displayChar;
76 secondaryStructure = ss;
82 * Creates a new Annotation object.
95 public Annotation(String displayChar, String desc, char ss, float val,
98 this(displayChar, desc, ss, val);
103 * Copy constructor New annotation takes on the same (or duplicated)
104 * attributes as the given template
107 * template annotation
109 public Annotation(Annotation that)
111 if (that == null || this == that)
115 if (that.displayCharacter != null)
117 displayCharacter = new String(that.displayCharacter);
119 if (that.description != null)
121 description = new String(that.description);
123 secondaryStructure = that.secondaryStructure;
125 colour = that.colour;
130 * Value only annotation.
133 * value at this annotation position
135 public Annotation(float val)
137 this(null, null, ' ', val, null);
141 * human readable representation of an annotation row element.
143 * Format is 'display Char','secondary Structure
144 * Char',"description",score,[colourstring]
146 * fields may be missing if they are null, whitespace, or equivalent to
150 public String toString()
152 StringBuffer sb = new StringBuffer();
153 if (displayCharacter != null)
156 sb.append(displayCharacter);
162 if (secondaryStructure != 0
163 && !("" + displayCharacter).equals("" + secondaryStructure))
166 sb.append(secondaryStructure);
172 if (description != null && description.length() > 0)
175 sb.append(description);
181 if (!Float.isNaN(value))
192 sb.append(colour.getRed());
194 sb.append(colour.getGreen());
196 sb.append(colour.getBlue());
199 return sb.toString();
203 * @return true if annot is 'whitespace' annotation (zero score, whitespace or
204 * zero length display character, label, description
206 public boolean isWhitespace()
208 return ((value == 0f)
209 && ((description == null) || (description.trim()
211 && ((displayCharacter == null) || (displayCharacter
212 .trim().length() == 0))
213 && (secondaryStructure == '\0' || (secondaryStructure == ' ')) && colour == null);