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 /** If true, this annotations is calculated every edit,
31 * eg consensus, quality or conservation graphs */
32 public boolean autoCalculated = false;
34 public String annotationId;
36 public SequenceI sequenceRef;
42 public String description;
45 public Annotation[] annotations;
47 public java.util.Hashtable sequenceMapping;
50 public float graphMin;
53 public float graphMax;
55 public GraphLine threshold;
57 // Graphical hints and tips
60 public boolean editable = false;
63 public boolean hasIcons; //
66 public boolean hasText;
69 public boolean visible = true;
71 public int graphGroup = -1;
74 public int height = 0;
78 public int graphHeight = 40;
80 public static final int NO_GRAPH = 0;
82 public static final int BAR_GRAPH = 1;
84 public static final int LINE_GRAPH = 2;
86 public static int getGraphValueFromString(String string)
88 if(string.equalsIgnoreCase("BAR_GRAPH"))
90 else if(string.equalsIgnoreCase("LINE_GRAPH"))
97 * Creates a new AlignmentAnnotation object.
99 * @param label DOCUMENT ME!
100 * @param description DOCUMENT ME!
101 * @param annotations DOCUMENT ME!
103 public AlignmentAnnotation(String label, String description,
104 Annotation[] annotations)
109 this.description = description;
110 this.annotations = annotations;
112 areLabelsSecondaryStructure();
115 void areLabelsSecondaryStructure()
117 boolean nonSSLabel = false;
118 for (int i = 0; i < annotations.length; i++)
120 if(annotations[i]==null)
123 if (annotations[i].secondaryStructure == 'H' ||
124 annotations[i].secondaryStructure == 'E')
129 if (annotations[i].displayCharacter.length()==1
130 && !annotations[i].displayCharacter.equals("H")
131 && !annotations[i].displayCharacter.equals("E")
132 && !annotations[i].displayCharacter.equals("-")
133 && !annotations[i].displayCharacter.equals("."))
135 if(jalview.schemes.ResidueProperties.aaIndex
136 [annotations[i].displayCharacter.charAt(0)]<23)
142 if (annotations[i].displayCharacter.length() > 0)
151 for (int j = 0; j < annotations.length; j++)
153 if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
155 annotations[j].displayCharacter
156 =String.valueOf(annotations[j].secondaryStructure);
157 annotations[j].secondaryStructure = ' ';
164 annotationId = this.hashCode()+"";
168 * Creates a new AlignmentAnnotation object.
170 * @param label DOCUMENT ME!
171 * @param description DOCUMENT ME!
172 * @param annotations DOCUMENT ME!
173 * @param min DOCUMENT ME!
174 * @param max DOCUMENT ME!
175 * @param winLength DOCUMENT ME!
177 public AlignmentAnnotation(String label, String description,
178 Annotation[] annotations, float min, float max, int graphType)
180 // graphs are not editable
182 this.description = description;
183 this.annotations = annotations;
186 boolean drawValues = true;
191 for (int i = 0; i < annotations.length; i++)
193 if (annotations[i] == null)
198 if(drawValues && annotations[i].displayCharacter.length() > 1 )
203 if (annotations[i].value > max)
205 max = annotations[i].value;
208 if (annotations[i].value < min)
210 min = annotations[i].value;
218 areLabelsSecondaryStructure();
220 if(!drawValues && graphType!=NO_GRAPH)
222 for (int i = 0; i < annotations.length; i++)
224 if (annotations[i] != null)
225 annotations[i].displayCharacter = "";
233 * @return DOCUMENT ME!
235 public String toString()
237 StringBuffer buffer = new StringBuffer();
239 for (int i = 0; i < annotations.length; i++)
241 if (annotations[i] != null)
245 buffer.append(annotations[i].value);
249 buffer.append(annotations[i].secondaryStructure);
253 buffer.append(annotations[i].displayCharacter);
260 if (label.equals("Consensus"))
264 for (int i = 0; i < annotations.length; i++)
266 if (annotations[i] != null)
268 buffer.append(annotations[i].description);
275 return buffer.toString();
278 public void setThreshold(GraphLine line)
283 public GraphLine getThreshold()
289 * 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.
292 * @param alreadyMapped
294 public void createSequenceMapping(SequenceI seqRef,
296 boolean alreadyMapped)
303 sequenceMapping = new java.util.Hashtable();
305 sequenceRef = seqRef;
308 for(int i = 0; i < annotations.length; i++)
310 if (annotations[i] != null)
313 seqPos = seqRef.findPosition(i);
317 sequenceMapping.put(new Integer(seqPos), annotations[i]);
323 public void adjustForAlignment()
325 int a=0, aSize = sequenceRef.getLength();
334 Annotation[] temp = new Annotation[aSize];
337 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
339 index = new Integer(a);
340 if(sequenceMapping.containsKey(index))
342 position = sequenceRef.findIndex(a)-1;
344 temp[position] = (Annotation)sequenceMapping.get(index);