Typo
[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 sequenceRef;\r
31 \r
32     /** This annotation is the original loaded annotation\r
33      *  without any gaps. It is necessary to adjust the annotation\r
34      *  if sequences are updated */\r
35     public AlignmentAnnotation datasetAnnotation;\r
36 \r
37     /** DOCUMENT ME!! */\r
38     public String label;\r
39 \r
40     /** DOCUMENT ME!! */\r
41     public String description;\r
42 \r
43     /** DOCUMENT ME!! */\r
44     public Annotation[] annotations;\r
45 \r
46 \r
47     /** DOCUMENT ME!! */\r
48     public float graphMin;\r
49 \r
50     /** DOCUMENT ME!! */\r
51     public float graphMax;\r
52 \r
53     public GraphLine threshold;\r
54 \r
55     // Graphical hints and tips\r
56 \r
57     /** DOCUMENT ME!! */\r
58     public boolean editable = false;\r
59 \r
60     /** DOCUMENT ME!! */\r
61     public boolean hasIcons; //\r
62 \r
63     /** DOCUMENT ME!! */\r
64     public boolean hasText;\r
65 \r
66     /** DOCUMENT ME!! */\r
67     public boolean visible = true;\r
68 \r
69     public int graphGroup = -1;\r
70 \r
71     /** DOCUMENT ME!! */\r
72     public int height = 0;\r
73 \r
74     public int graph = 0;\r
75 \r
76     public int graphHeight = 40;\r
77 \r
78     public static final int NO_GRAPH = 0;\r
79 \r
80     public static final int BAR_GRAPH = 1;\r
81 \r
82     public static final int LINE_GRAPH = 2;\r
83 \r
84     public static int getGraphValueFromString(String string)\r
85     {\r
86       if(string.equalsIgnoreCase("BAR_GRAPH"))\r
87         return BAR_GRAPH;\r
88       else if(string.equalsIgnoreCase("LINE_GRAPH"))\r
89         return LINE_GRAPH;\r
90       else\r
91         return NO_GRAPH;\r
92     }\r
93 \r
94     /**\r
95      * Creates a new AlignmentAnnotation object.\r
96      *\r
97      * @param label DOCUMENT ME!\r
98      * @param description DOCUMENT ME!\r
99      * @param annotations DOCUMENT ME!\r
100      */\r
101     public AlignmentAnnotation(String label, String description,\r
102         Annotation[] annotations)\r
103     {\r
104         // always editable?\r
105         editable = true;\r
106         this.label = label;\r
107         this.description = description;\r
108         this.annotations = annotations;\r
109 \r
110         for (int i = 0; i < annotations.length; i++)\r
111         {\r
112             if ((annotations[i] != null) &&\r
113                     ((annotations[i].secondaryStructure == 'H') ||\r
114                     (annotations[i].secondaryStructure == 'E')))\r
115             {\r
116                 hasIcons = true;\r
117             }\r
118 \r
119             if ((annotations[i] != null) &&\r
120                     (annotations[i].displayCharacter.length() > 0))\r
121             {\r
122                 hasText = true;\r
123             }\r
124         }\r
125     }\r
126 \r
127     /**\r
128      * Creates a new AlignmentAnnotation object.\r
129      *\r
130      * @param label DOCUMENT ME!\r
131      * @param description DOCUMENT ME!\r
132      * @param annotations DOCUMENT ME!\r
133      * @param min DOCUMENT ME!\r
134      * @param max DOCUMENT ME!\r
135      * @param winLength DOCUMENT ME!\r
136      */\r
137     public AlignmentAnnotation(String label, String description,\r
138         Annotation[] annotations, float min, float max, int graphType)\r
139     {\r
140         // graphs are not editable\r
141         this.label = label;\r
142         this.description = description;\r
143         this.annotations = annotations;\r
144         graph = graphType;\r
145 \r
146         if (min == max)\r
147         {\r
148             min = 999999999;\r
149             for (int i = 0; i < annotations.length; i++)\r
150             {\r
151                 if (annotations[i] == null)\r
152                 {\r
153                     continue;\r
154                 }\r
155 \r
156                 if (annotations[i].value > max)\r
157                 {\r
158                     max = annotations[i].value;\r
159                 }\r
160 \r
161                 if (annotations[i].value < min)\r
162                 {\r
163                     min = annotations[i].value;\r
164                 }\r
165             }\r
166         }\r
167 \r
168         graphMin = min;\r
169         graphMax = max;\r
170 \r
171         for (int i = 0; i < annotations.length; i++)\r
172         {\r
173             if ((annotations[i] != null) &&\r
174                     ((annotations[i].secondaryStructure == 'H') ||\r
175                     (annotations[i].secondaryStructure == 'E')))\r
176             {\r
177                 hasIcons = true;\r
178             }\r
179 \r
180             if ((annotations[i] != null) &&\r
181                     (annotations[i].displayCharacter.length() > 0))\r
182             {\r
183                 hasText = true;\r
184             }\r
185         }\r
186     }\r
187 \r
188     /**\r
189      * DOCUMENT ME!\r
190      *\r
191      * @return DOCUMENT ME!\r
192      */\r
193     public String toString()\r
194     {\r
195         StringBuffer buffer = new StringBuffer();\r
196 \r
197         for (int i = 0; i < annotations.length; i++)\r
198         {\r
199             if (annotations[i] != null)\r
200             {\r
201                 if (graph!=0)\r
202                 {\r
203                     buffer.append(annotations[i].value);\r
204                 }\r
205                 else if (hasIcons)\r
206                 {\r
207                     buffer.append(annotations[i].secondaryStructure);\r
208                 }\r
209                 else\r
210                 {\r
211                     buffer.append(annotations[i].displayCharacter);\r
212                 }\r
213             }\r
214 \r
215             buffer.append(", ");\r
216         }\r
217 \r
218         if (label.equals("Consensus"))\r
219         {\r
220             buffer.append("\n");\r
221 \r
222             for (int i = 0; i < annotations.length; i++)\r
223             {\r
224                 if (annotations[i] != null)\r
225                 {\r
226                     buffer.append(annotations[i].description);\r
227                 }\r
228 \r
229                 buffer.append(", ");\r
230             }\r
231         }\r
232 \r
233         return buffer.toString();\r
234       }\r
235 \r
236       public void setThreshold(GraphLine line)\r
237       {\r
238         threshold = line;\r
239       }\r
240 \r
241       public GraphLine getThreshold()\r
242       {\r
243           return threshold;\r
244       }\r
245 \r
246       public void adjustForAlignment()\r
247       {\r
248           int a=0, aSize = sequenceRef.getLength();\r
249 \r
250           int index = 0;\r
251           Annotation[] temp = new Annotation[aSize];\r
252 \r
253           for (a = 0; a < aSize; a++)\r
254           {\r
255             if (!jalview.util.Comparison.isGap(sequenceRef.getCharAt(a)))\r
256             {\r
257               index = sequenceRef.findPosition(a);\r
258               if(datasetAnnotation.annotations.length>index)\r
259                 temp[a] = datasetAnnotation.annotations[index];\r
260             }\r
261           }\r
262 \r
263           annotations = temp;\r
264       }\r
265 }\r
266 \r
267 \r