Not used in Jalview
[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 public class AlignmentAnnotation {\r
22     public String label;\r
23     public String description;\r
24     public Annotation[] annotations;\r
25     public boolean isGraph = false;\r
26     public float graphMin;\r
27     public float graphMax;\r
28     public int windowLength;\r
29 \r
30     // Graphical hints and tips\r
31     public boolean editable = false;\r
32     public boolean hasIcons; //\r
33     public boolean hasText;\r
34     public boolean visible = true;\r
35     public int height = 0;\r
36 \r
37     public AlignmentAnnotation(String label, String description,\r
38         Annotation[] annotations) {\r
39         // always editable?\r
40         editable = true;\r
41         this.label = label;\r
42         this.description = description;\r
43         this.annotations = annotations;\r
44 \r
45         for (int i = 0; i < annotations.length; i++) {\r
46             if ((annotations[i] != null) &&\r
47                     ((annotations[i].secondaryStructure == 'H') ||\r
48                     (annotations[i].secondaryStructure == 'E'))) {\r
49                 hasIcons = true;\r
50             }\r
51 \r
52             if ((annotations[i] != null) &&\r
53                     (annotations[i].displayCharacter.length() > 0)) {\r
54                 hasText = true;\r
55             }\r
56         }\r
57     }\r
58 \r
59     public AlignmentAnnotation(String label, String description,\r
60         Annotation[] annotations, float min, float max, int winLength) {\r
61         // graphs are not editable\r
62         this.label = label;\r
63         this.description = description;\r
64         this.annotations = annotations;\r
65         isGraph = true;\r
66 \r
67         if (min == max) {\r
68             for (int i = 0; i < annotations.length; i++) {\r
69                 if (annotations[i] == null) {\r
70                     continue;\r
71                 }\r
72 \r
73                 if (annotations[i].value > max) {\r
74                     max = annotations[i].value;\r
75                 }\r
76 \r
77                 if (annotations[i].value < min) {\r
78                     min = annotations[i].value;\r
79                 }\r
80             }\r
81         }\r
82 \r
83         graphMin = min;\r
84         graphMax = max;\r
85         windowLength = winLength;\r
86 \r
87         for (int i = 0; i < annotations.length; i++) {\r
88             if ((annotations[i] != null) &&\r
89                     ((annotations[i].secondaryStructure == 'H') ||\r
90                     (annotations[i].secondaryStructure == 'E'))) {\r
91                 hasIcons = true;\r
92             }\r
93 \r
94             if ((annotations[i] != null) &&\r
95                     (annotations[i].displayCharacter.length() > 0)) {\r
96                 hasText = true;\r
97             }\r
98         }\r
99     }\r
100 \r
101     public String toString() {\r
102         StringBuffer buffer = new StringBuffer();\r
103 \r
104         for (int i = 0; i < annotations.length; i++) {\r
105             if (annotations[i] != null) {\r
106                 if (isGraph) {\r
107                     buffer.append(annotations[i].value);\r
108                 } else if (hasIcons) {\r
109                     buffer.append(annotations[i].secondaryStructure);\r
110                 } else {\r
111                     buffer.append(annotations[i].displayCharacter);\r
112                 }\r
113             }\r
114 \r
115             buffer.append(", ");\r
116         }\r
117 \r
118         if (label.equals("Consensus")) {\r
119             buffer.append("\n");\r
120 \r
121             for (int i = 0; i < annotations.length; i++) {\r
122                 if (annotations[i] != null) {\r
123                     buffer.append(annotations[i].description);\r
124                 }\r
125 \r
126                 buffer.append(", ");\r
127             }\r
128         }\r
129 \r
130         return buffer.toString();\r
131     }\r
132 }\r