JAL-1517 update copyright to version 2.8.2
[jalview.git] / src / jalview / datamodel / Annotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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   /**
74    * Creates a new Annotation object.
75    * 
76    * @param displayChar
77    *          DOCUMENT ME!
78    * @param desc
79    *          DOCUMENT ME!
80    * @param ss
81    *          DOCUMENT ME!
82    * @param val
83    *          DOCUMENT ME!
84    * @param colour
85    *          DOCUMENT ME!
86    */
87   public Annotation(String displayChar, String desc, char ss, float val,
88           Color colour)
89   {
90     this(displayChar, desc, ss, val);
91     this.colour = colour;
92   }
93
94   /**
95    * Copy constructor New annotation takes on the same (or duplicated)
96    * attributes as the given template
97    * 
98    * @param that
99    *          template annotation
100    */
101   public Annotation(Annotation that)
102   {
103     if (that == null || this == that)
104     {
105       return;
106     }
107     if (that.displayCharacter != null)
108       displayCharacter = new String(that.displayCharacter);
109     if (that.description != null)
110       description = new String(that.description);
111     secondaryStructure = that.secondaryStructure;
112     value = that.value;
113     colour = that.colour;
114
115   }
116
117   /**
118    * Value only annotation.
119    * 
120    * @param val
121    *          value at this annotation position
122    */
123   public Annotation(float val)
124   {
125     this(null, null, ' ', val,null);
126   }
127
128   /**
129    * human readable representation of an annotation row element.
130    *
131    * Format is 'display Char','secondary Structure
132    * Char',"description",score,[colourstring]
133    *
134    * fields may be missing if they are null, whitespace, or equivalent to
135    * Float.NaN
136    */
137   @Override
138   public String toString()
139   {
140     StringBuffer sb = new StringBuffer();
141     if (displayCharacter != null)
142     {
143       sb.append("\'");
144       sb.append(displayCharacter);
145       sb.append("\'");
146     }
147     {
148       sb.append(",");
149     }
150     if (secondaryStructure != 0
151             && !("" + displayCharacter).equals("" + secondaryStructure))
152     {
153       sb.append("\'");
154       sb.append(secondaryStructure);
155       sb.append("\'");
156     }
157     {
158       sb.append(",");
159     }
160     if (description != null && description.length() > 0)
161     {
162       sb.append("\"");
163       sb.append(description);
164       sb.append("\"");
165     }
166     {
167       sb.append(",");
168     }
169     if (value != Float.NaN)
170     {
171       sb.append(value);
172     }
173     if (colour != null)
174     {
175       if (sb.length() > 0)
176       {
177         sb.append(",");
178       }
179       sb.append("[");
180       sb.append(colour.getRed());
181       sb.append(",");
182       sb.append(colour.getGreen());
183       sb.append(",");
184       sb.append(colour.getBlue());
185       sb.append("]");
186     }
187     return sb.toString();
188   }
189 }