2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
28 public class AlignmentAnnotation
30 public SequenceI sequenceRef;
36 public String description;
39 public Annotation[] annotations;
41 public java.util.Hashtable sequenceMapping;
44 public float graphMin;
47 public float graphMax;
49 public GraphLine threshold;
51 // Graphical hints and tips
54 public boolean editable = false;
57 public boolean hasIcons; //
60 public boolean hasText;
63 public boolean visible = true;
65 public int graphGroup = -1;
68 public int height = 0;
72 public int graphHeight = 40;
74 public static final int NO_GRAPH = 0;
76 public static final int BAR_GRAPH = 1;
78 public static final int LINE_GRAPH = 2;
80 public static int getGraphValueFromString(String string)
82 if(string.equalsIgnoreCase("BAR_GRAPH"))
84 else if(string.equalsIgnoreCase("LINE_GRAPH"))
91 * Creates a new AlignmentAnnotation object.
93 * @param label DOCUMENT ME!
94 * @param description DOCUMENT ME!
95 * @param annotations DOCUMENT ME!
97 public AlignmentAnnotation(String label, String description,
98 Annotation[] annotations)
103 this.description = description;
104 this.annotations = annotations;
106 areLabelsSecondaryStructure();
109 void areLabelsSecondaryStructure()
111 boolean nonSSLabel = false;
112 for (int i = 0; i < annotations.length; i++)
114 if(annotations[i]==null)
117 if (annotations[i].secondaryStructure == 'H' ||
118 annotations[i].secondaryStructure == 'E')
123 if (annotations[i].secondaryStructure != 'H'
124 && annotations[i].secondaryStructure != 'E'
125 && annotations[i].secondaryStructure != '-')
130 if (annotations[i].displayCharacter.length() > 0)
139 for (int j = 0; j < annotations.length; j++)
141 if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
143 annotations[j].displayCharacter
144 =String.valueOf(annotations[j].secondaryStructure);
145 annotations[j].secondaryStructure = ' ';
146 if(annotations[j].description.length()<1)
147 annotations[j].description = annotations[j].displayCharacter;
157 * Creates a new AlignmentAnnotation object.
159 * @param label DOCUMENT ME!
160 * @param description DOCUMENT ME!
161 * @param annotations DOCUMENT ME!
162 * @param min DOCUMENT ME!
163 * @param max DOCUMENT ME!
164 * @param winLength DOCUMENT ME!
166 public AlignmentAnnotation(String label, String description,
167 Annotation[] annotations, float min, float max, int graphType)
169 // graphs are not editable
171 this.description = description;
172 this.annotations = annotations;
175 boolean drawValues = true;
180 for (int i = 0; i < annotations.length; i++)
182 if (annotations[i] == null)
187 if(drawValues && annotations[i].displayCharacter.length() > 1 )
192 if (annotations[i].value > max)
194 max = annotations[i].value;
197 if (annotations[i].value < min)
199 min = annotations[i].value;
207 areLabelsSecondaryStructure();
209 if(!drawValues && graphType!=NO_GRAPH)
211 for (int i = 0; i < annotations.length; i++)
213 if (annotations[i] != null)
214 annotations[i].displayCharacter = "";
222 * @return DOCUMENT ME!
224 public String toString()
226 StringBuffer buffer = new StringBuffer();
228 for (int i = 0; i < annotations.length; i++)
230 if (annotations[i] != null)
234 buffer.append(annotations[i].value);
238 buffer.append(annotations[i].secondaryStructure);
242 buffer.append(annotations[i].displayCharacter);
249 if (label.equals("Consensus"))
253 for (int i = 0; i < annotations.length; i++)
255 if (annotations[i] != null)
257 buffer.append(annotations[i].description);
264 return buffer.toString();
267 public void setThreshold(GraphLine line)
272 public GraphLine getThreshold()
278 * Attach the annotation to seqRef, starting from startRes position. If alreadyMapped is true then the indices of the annotation[] array are sequence positions rather than alignment column positions.
281 * @param alreadyMapped
283 public void createSequenceMapping(SequenceI seqRef,
285 boolean alreadyMapped)
290 sequenceMapping = new java.util.Hashtable();
292 sequenceRef = seqRef;
295 for(int i = 0; i < annotations.length; i++)
297 if (annotations[i] != null)
300 seqPos = seqRef.findPosition(i);
304 sequenceMapping.put(new Integer(seqPos), annotations[i]);
308 adjustForAlignment();
311 public void adjustForAlignment()
313 int a=0, aSize = sequenceRef.getLength();
322 Annotation[] temp = new Annotation[aSize];
325 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
327 index = new Integer(a);
328 if(sequenceMapping.containsKey(index))
330 position = sequenceRef.findIndex(a)-1;
332 temp[position] = (Annotation)sequenceMapping.get(index);