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 SequenceI sequenceRef;
40 public String description;
43 public Annotation[] annotations;
45 public java.util.Hashtable sequenceMapping;
48 public float graphMin;
51 public float graphMax;
53 public GraphLine threshold;
55 // Graphical hints and tips
58 public boolean editable = false;
61 public boolean hasIcons; //
64 public boolean hasText;
67 public boolean visible = true;
69 public int graphGroup = -1;
72 public int height = 0;
76 public int graphHeight = 40;
78 public static final int NO_GRAPH = 0;
80 public static final int BAR_GRAPH = 1;
82 public static final int LINE_GRAPH = 2;
84 public static int getGraphValueFromString(String string)
86 if(string.equalsIgnoreCase("BAR_GRAPH"))
88 else if(string.equalsIgnoreCase("LINE_GRAPH"))
95 * Creates a new AlignmentAnnotation object.
97 * @param label DOCUMENT ME!
98 * @param description DOCUMENT ME!
99 * @param annotations DOCUMENT ME!
101 public AlignmentAnnotation(String label, String description,
102 Annotation[] annotations)
107 this.description = description;
108 this.annotations = annotations;
110 areLabelsSecondaryStructure();
113 void areLabelsSecondaryStructure()
115 boolean nonSSLabel = false;
116 for (int i = 0; i < annotations.length; i++)
118 if(annotations[i]==null)
121 if (annotations[i].secondaryStructure == 'H' ||
122 annotations[i].secondaryStructure == 'E')
127 if (annotations[i].displayCharacter.length()==1
128 && !annotations[i].displayCharacter.equals("H")
129 && !annotations[i].displayCharacter.equals("E")
130 && !annotations[i].displayCharacter.equals("-"))
132 if(jalview.schemes.ResidueProperties.aaIndex
133 [annotations[i].displayCharacter.charAt(0)]>0)
139 if (annotations[i].displayCharacter.length() > 0)
148 for (int j = 0; j < annotations.length; j++)
150 if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
152 annotations[j].displayCharacter
153 =String.valueOf(annotations[j].secondaryStructure);
154 annotations[j].secondaryStructure = ' ';
164 * Creates a new AlignmentAnnotation object.
166 * @param label DOCUMENT ME!
167 * @param description DOCUMENT ME!
168 * @param annotations DOCUMENT ME!
169 * @param min DOCUMENT ME!
170 * @param max DOCUMENT ME!
171 * @param winLength DOCUMENT ME!
173 public AlignmentAnnotation(String label, String description,
174 Annotation[] annotations, float min, float max, int graphType)
176 // graphs are not editable
178 this.description = description;
179 this.annotations = annotations;
182 boolean drawValues = true;
187 for (int i = 0; i < annotations.length; i++)
189 if (annotations[i] == null)
194 if(drawValues && annotations[i].displayCharacter.length() > 1 )
199 if (annotations[i].value > max)
201 max = annotations[i].value;
204 if (annotations[i].value < min)
206 min = annotations[i].value;
214 areLabelsSecondaryStructure();
216 if(!drawValues && graphType!=NO_GRAPH)
218 for (int i = 0; i < annotations.length; i++)
220 if (annotations[i] != null)
221 annotations[i].displayCharacter = "";
229 * @return DOCUMENT ME!
231 public String toString()
233 StringBuffer buffer = new StringBuffer();
235 for (int i = 0; i < annotations.length; i++)
237 if (annotations[i] != null)
241 buffer.append(annotations[i].value);
245 buffer.append(annotations[i].secondaryStructure);
249 buffer.append(annotations[i].displayCharacter);
256 if (label.equals("Consensus"))
260 for (int i = 0; i < annotations.length; i++)
262 if (annotations[i] != null)
264 buffer.append(annotations[i].description);
271 return buffer.toString();
274 public void setThreshold(GraphLine line)
279 public GraphLine getThreshold()
285 * 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.
288 * @param alreadyMapped
290 public void createSequenceMapping(SequenceI seqRef,
292 boolean alreadyMapped)
297 sequenceMapping = new java.util.Hashtable();
299 sequenceRef = seqRef;
302 for(int i = 0; i < annotations.length; i++)
304 if (annotations[i] != null)
307 seqPos = seqRef.findPosition(i);
311 sequenceMapping.put(new Integer(seqPos), annotations[i]);
315 adjustForAlignment();
318 public void adjustForAlignment()
320 int a=0, aSize = sequenceRef.getLength();
329 Annotation[] temp = new Annotation[aSize];
332 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
334 index = new Integer(a);
335 if(sequenceMapping.containsKey(index))
337 position = sequenceRef.findIndex(a)-1;
339 temp[position] = (Annotation)sequenceMapping.get(index);