2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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;
27 public class AlignmentAnnotation
29 /** If true, this annotations is calculated every edit,
30 * eg consensus, quality or conservation graphs */
31 public boolean autoCalculated = false;
33 public String annotationId;
35 public SequenceI sequenceRef;
41 public String description;
44 public Annotation[] annotations;
46 public java.util.Hashtable sequenceMapping;
49 public float graphMin;
52 public float graphMax;
54 public GraphLine threshold;
56 // Graphical hints and tips
59 public boolean editable = false;
62 public boolean hasIcons; //
65 public boolean hasText;
68 public boolean visible = true;
70 public int graphGroup = -1;
73 public int height = 0;
77 public int graphHeight = 40;
79 public static final int NO_GRAPH = 0;
81 public static final int BAR_GRAPH = 1;
83 public static final int LINE_GRAPH = 2;
85 public static int getGraphValueFromString(String string)
87 if (string.equalsIgnoreCase("BAR_GRAPH"))
91 else if (string.equalsIgnoreCase("LINE_GRAPH"))
102 * Creates a new AlignmentAnnotation object.
104 * @param label DOCUMENT ME!
105 * @param description DOCUMENT ME!
106 * @param annotations DOCUMENT ME!
108 public AlignmentAnnotation(String label, String description,
109 Annotation[] annotations)
114 this.description = description;
115 this.annotations = annotations;
117 areLabelsSecondaryStructure();
120 void areLabelsSecondaryStructure()
122 boolean nonSSLabel = false;
123 for (int i = 0; i < annotations.length; i++)
125 if (annotations[i] == null)
130 if (annotations[i].secondaryStructure == 'H' ||
131 annotations[i].secondaryStructure == 'E')
136 if (annotations[i].displayCharacter.length() == 1
137 && !annotations[i].displayCharacter.equals("H")
138 && !annotations[i].displayCharacter.equals("E")
139 && !annotations[i].displayCharacter.equals("-")
140 && !annotations[i].displayCharacter.equals("."))
142 if (jalview.schemes.ResidueProperties.aaIndex
143 [annotations[i].displayCharacter.charAt(0)] < 23)
149 if (annotations[i].displayCharacter.length() > 0)
158 for (int j = 0; j < annotations.length; j++)
160 if (annotations[j] != null && annotations[j].secondaryStructure != ' ')
162 annotations[j].displayCharacter
163 = String.valueOf(annotations[j].secondaryStructure);
164 annotations[j].secondaryStructure = ' ';
171 annotationId = this.hashCode() + "";
175 * Creates a new AlignmentAnnotation object.
177 * @param label DOCUMENT ME!
178 * @param description DOCUMENT ME!
179 * @param annotations DOCUMENT ME!
180 * @param min DOCUMENT ME!
181 * @param max DOCUMENT ME!
182 * @param winLength DOCUMENT ME!
184 public AlignmentAnnotation(String label, String description,
185 Annotation[] annotations, float min, float max,
188 // graphs are not editable
190 this.description = description;
191 this.annotations = annotations;
194 boolean drawValues = true;
199 for (int i = 0; i < annotations.length; i++)
201 if (annotations[i] == null)
206 if (drawValues && annotations[i].displayCharacter.length() > 1)
211 if (annotations[i].value > max)
213 max = annotations[i].value;
216 if (annotations[i].value < min)
218 min = annotations[i].value;
226 areLabelsSecondaryStructure();
228 if (!drawValues && graphType != NO_GRAPH)
230 for (int i = 0; i < annotations.length; i++)
232 if (annotations[i] != null)
234 annotations[i].displayCharacter = "";
243 * @return DOCUMENT ME!
245 public String toString()
247 StringBuffer buffer = new StringBuffer();
249 for (int i = 0; i < annotations.length; i++)
251 if (annotations[i] != null)
255 buffer.append(annotations[i].value);
259 buffer.append(annotations[i].secondaryStructure);
263 buffer.append(annotations[i].displayCharacter);
270 if (label.equals("Consensus"))
274 for (int i = 0; i < annotations.length; i++)
276 if (annotations[i] != null)
278 buffer.append(annotations[i].description);
285 return buffer.toString();
288 public void setThreshold(GraphLine line)
293 public GraphLine getThreshold()
299 * 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.
302 * @param alreadyMapped
304 public void createSequenceMapping(SequenceI seqRef,
306 boolean alreadyMapped)
314 sequenceMapping = new java.util.Hashtable();
316 sequenceRef = seqRef;
319 for (int i = 0; i < annotations.length; i++)
321 if (annotations[i] != null)
325 seqPos = seqRef.findPosition(i);
329 seqPos = i + startRes;
332 sequenceMapping.put(new Integer(seqPos), annotations[i]);
338 public void adjustForAlignment()
340 int a = 0, aSize = sequenceRef.getLength();
349 Annotation[] temp = new Annotation[aSize];
352 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
354 index = new Integer(a);
355 if (sequenceMapping.containsKey(index))
357 position = sequenceRef.findIndex(a) - 1;
359 temp[position] = (Annotation) sequenceMapping.get(index);