AddAnnotation with start index
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package jalview.datamodel;\r
20 \r
21 \r
22 /**\r
23  * DOCUMENT ME!\r
24  *\r
25  * @author $author$\r
26  * @version $Revision$\r
27  */\r
28 public class AlignmentAnnotation\r
29 {\r
30     public SequenceI refSequence;\r
31 \r
32     /** DOCUMENT ME!! */\r
33     public String label;\r
34 \r
35     /** DOCUMENT ME!! */\r
36     public String description;\r
37 \r
38     /** DOCUMENT ME!! */\r
39     public Annotation[] annotations;\r
40 \r
41 \r
42     /** DOCUMENT ME!! */\r
43     public float graphMin;\r
44 \r
45     /** DOCUMENT ME!! */\r
46     public float graphMax;\r
47 \r
48     public java.util.Vector graphLines;\r
49 \r
50     // Graphical hints and tips\r
51 \r
52     /** DOCUMENT ME!! */\r
53     public boolean editable = false;\r
54 \r
55     /** DOCUMENT ME!! */\r
56     public boolean hasIcons; //\r
57 \r
58     /** DOCUMENT ME!! */\r
59     public boolean hasText;\r
60 \r
61     /** DOCUMENT ME!! */\r
62     public boolean visible = true;\r
63 \r
64     public int graphGroup = -1;\r
65 \r
66     /** DOCUMENT ME!! */\r
67     public int height = 0;\r
68 \r
69     public int graph = 0;\r
70 \r
71     public int graphHeight = 40;\r
72 \r
73     public static final int NO_GRAPH = 0;\r
74 \r
75     public static final int BAR_GRAPH = 1;\r
76 \r
77     public static final int LINE_GRAPH = 2;\r
78 \r
79     public static int getGraphValueFromString(String string)\r
80     {\r
81       if(string.equalsIgnoreCase("BAR_GRAPH"))\r
82         return BAR_GRAPH;\r
83       else if(string.equalsIgnoreCase("LINE_GRAPH"))\r
84         return LINE_GRAPH;\r
85       else\r
86         return NO_GRAPH;\r
87     }\r
88 \r
89     /**\r
90      * Creates a new AlignmentAnnotation object.\r
91      *\r
92      * @param label DOCUMENT ME!\r
93      * @param description DOCUMENT ME!\r
94      * @param annotations DOCUMENT ME!\r
95      */\r
96     public AlignmentAnnotation(String label, String description,\r
97         Annotation[] annotations)\r
98     {\r
99         // always editable?\r
100         editable = true;\r
101         this.label = label;\r
102         this.description = description;\r
103         this.annotations = annotations;\r
104 \r
105         for (int i = 0; i < annotations.length; i++)\r
106         {\r
107             if ((annotations[i] != null) &&\r
108                     ((annotations[i].secondaryStructure == 'H') ||\r
109                     (annotations[i].secondaryStructure == 'E')))\r
110             {\r
111                 hasIcons = true;\r
112             }\r
113 \r
114             if ((annotations[i] != null) &&\r
115                     (annotations[i].displayCharacter.length() > 0))\r
116             {\r
117                 hasText = true;\r
118             }\r
119         }\r
120     }\r
121 \r
122     /**\r
123      * Creates a new AlignmentAnnotation object.\r
124      *\r
125      * @param label DOCUMENT ME!\r
126      * @param description DOCUMENT ME!\r
127      * @param annotations DOCUMENT ME!\r
128      * @param min DOCUMENT ME!\r
129      * @param max DOCUMENT ME!\r
130      * @param winLength DOCUMENT ME!\r
131      */\r
132     public AlignmentAnnotation(String label, String description,\r
133         Annotation[] annotations, float min, float max, int graphType)\r
134     {\r
135         // graphs are not editable\r
136         this.label = label;\r
137         this.description = description;\r
138         this.annotations = annotations;\r
139         graph = graphType;\r
140 \r
141         if (min == max)\r
142         {\r
143             min = 999999999;\r
144             for (int i = 0; i < annotations.length; i++)\r
145             {\r
146                 if (annotations[i] == null)\r
147                 {\r
148                     continue;\r
149                 }\r
150 \r
151                 if (annotations[i].value > max)\r
152                 {\r
153                     max = annotations[i].value;\r
154                 }\r
155 \r
156                 if (annotations[i].value < min)\r
157                 {\r
158                     min = annotations[i].value;\r
159                 }\r
160             }\r
161         }\r
162 \r
163         graphMin = min;\r
164         graphMax = max;\r
165 \r
166         for (int i = 0; i < annotations.length; i++)\r
167         {\r
168             if ((annotations[i] != null) &&\r
169                     ((annotations[i].secondaryStructure == 'H') ||\r
170                     (annotations[i].secondaryStructure == 'E')))\r
171             {\r
172                 hasIcons = true;\r
173             }\r
174 \r
175             if ((annotations[i] != null) &&\r
176                     (annotations[i].displayCharacter.length() > 0))\r
177             {\r
178                 hasText = true;\r
179             }\r
180         }\r
181     }\r
182 \r
183     /**\r
184      * DOCUMENT ME!\r
185      *\r
186      * @return DOCUMENT ME!\r
187      */\r
188     public String toString()\r
189     {\r
190         StringBuffer buffer = new StringBuffer();\r
191 \r
192         for (int i = 0; i < annotations.length; i++)\r
193         {\r
194             if (annotations[i] != null)\r
195             {\r
196                 if (graph!=0)\r
197                 {\r
198                     buffer.append(annotations[i].value);\r
199                 }\r
200                 else if (hasIcons)\r
201                 {\r
202                     buffer.append(annotations[i].secondaryStructure);\r
203                 }\r
204                 else\r
205                 {\r
206                     buffer.append(annotations[i].displayCharacter);\r
207                 }\r
208             }\r
209 \r
210             buffer.append(", ");\r
211         }\r
212 \r
213         if (label.equals("Consensus"))\r
214         {\r
215             buffer.append("\n");\r
216 \r
217             for (int i = 0; i < annotations.length; i++)\r
218             {\r
219                 if (annotations[i] != null)\r
220                 {\r
221                     buffer.append(annotations[i].description);\r
222                 }\r
223 \r
224                 buffer.append(", ");\r
225             }\r
226         }\r
227 \r
228         return buffer.toString();\r
229       }\r
230 \r
231       public void addGraphLine(GraphLine line)\r
232       {\r
233         if(graphLines==null)\r
234           graphLines = new java.util.Vector();\r
235 \r
236         graphLines.add(line);\r
237       }\r
238 \r
239       public GraphLine getGraphLine(int index)\r
240       {\r
241         if(graphLines!=null && index<graphLines.size())\r
242           return (GraphLine)graphLines.elementAt(index);\r
243 \r
244         else\r
245           return null;\r
246       }\r
247 }\r
248 \r
249 \r