JAL-1432 updated copyright notices
[jalview.git] / src / jalview / datamodel / Annotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.datamodel;
20
21 import java.awt.Color;
22
23 /**
24  * Holds all annotation values for a position in an AlignmentAnnotation row
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public class Annotation
30 {
31   /** Character label - also shown below histogram */
32   public String displayCharacter = "";
33
34   /**
35    * Text label for position: shown in mouse over and displayed on secondary
36    * structure glyphs
37    */
38   public String description = "";
39
40   /**
41    * Secondary structure symbol: Protein symbols are H, E and S(?), RNA are
42    * WUSS/Vienna plus extended pseudoknot symbols
43    */
44   public char secondaryStructure = ' ';
45
46   /** Score for the position - used in histograms, line graphs and for shading */
47   public float value;
48
49   /** Colour for position */
50   public Color colour;
51
52   /**
53    * Creates a new Annotation object.
54    * 
55    * @param displayChar
56    *          DOCUMENT ME!
57    * @param desc
58    *          DOCUMENT ME!
59    * @param ss
60    *          DOCUMENT ME!
61    * @param val
62    *          DOCUMENT ME!
63    */
64   public Annotation(String displayChar, String desc, char ss, float val)
65   {
66     displayCharacter = displayChar;
67     description = desc;
68     secondaryStructure = ss;
69     value = val;
70   }
71
72   /**
73    * Creates a new Annotation object.
74    * 
75    * @param displayChar
76    *          DOCUMENT ME!
77    * @param desc
78    *          DOCUMENT ME!
79    * @param ss
80    *          DOCUMENT ME!
81    * @param val
82    *          DOCUMENT ME!
83    * @param colour
84    *          DOCUMENT ME!
85    */
86   public Annotation(String displayChar, String desc, char ss, float val,
87           Color colour)
88   {
89     this(displayChar, desc, ss, val);
90     this.colour = colour;
91   }
92
93   /**
94    * Copy constructor New annotation takes on the same (or duplicated)
95    * attributes as the given template
96    * 
97    * @param that
98    *          template annotation
99    */
100   public Annotation(Annotation that)
101   {
102     if (that == null || this == that)
103     {
104       return;
105     }
106     if (that.displayCharacter != null)
107       displayCharacter = new String(that.displayCharacter);
108     if (that.description != null)
109       description = new String(that.description);
110     secondaryStructure = that.secondaryStructure;
111     value = that.value;
112     colour = that.colour;
113   }
114
115   /**
116    * Value only annotation.
117    * 
118    * @param val
119    *          value at this annotation position
120    */
121   public Annotation(float val)
122   {
123     this(null, null, ' ', val);
124   }
125
126   /**
127    * human readable representation of an annotation row element.
128    *
129    * Format is 'display Char','secondary Structure
130    * Char',"description",score,[colourstring]
131    *
132    * fields may be missing if they are null, whitespace, or equivalent to
133    * Float.NaN
134    */
135   @Override
136   public String toString()
137   {
138     StringBuffer sb = new StringBuffer();
139     if (displayCharacter != null)
140     {
141       sb.append("\'");
142       sb.append(displayCharacter);
143       sb.append("\'");
144     }
145     {
146       sb.append(",");
147     }
148     if (secondaryStructure != 0
149             && !("" + displayCharacter).equals("" + secondaryStructure))
150     {
151       sb.append("\'");
152       sb.append(secondaryStructure);
153       sb.append("\'");
154     }
155     {
156       sb.append(",");
157     }
158     if (description != null && description.length() > 0)
159     {
160       sb.append("\"");
161       sb.append(description);
162       sb.append("\"");
163     }
164     {
165       sb.append(",");
166     }
167     if (value != Float.NaN)
168     {
169       sb.append(value);
170     }
171     if (colour != null)
172     {
173       if (sb.length() > 0)
174       {
175         sb.append(",");
176       }
177       sb.append("[");
178       sb.append(colour.getRed());
179       sb.append(",");
180       sb.append(colour.getGreen());
181       sb.append(",");
182       sb.append(colour.getBlue());
183       sb.append("]");
184     }
185     return sb.toString();
186   }
187 }