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 for (int i = 0; i < annotations.length; i++)
108 if ((annotations[i] != null) &&
109 ((annotations[i].secondaryStructure == 'H') ||
110 (annotations[i].secondaryStructure == 'E')))
115 if ((annotations[i] != null) &&
116 (annotations[i].displayCharacter.length() > 0))
124 * Creates a new AlignmentAnnotation object.
126 * @param label DOCUMENT ME!
127 * @param description DOCUMENT ME!
128 * @param annotations DOCUMENT ME!
129 * @param min DOCUMENT ME!
130 * @param max DOCUMENT ME!
131 * @param winLength DOCUMENT ME!
133 public AlignmentAnnotation(String label, String description,
134 Annotation[] annotations, float min, float max, int graphType)
136 // graphs are not editable
138 this.description = description;
139 this.annotations = annotations;
142 boolean drawValues = true;
147 for (int i = 0; i < annotations.length; i++)
149 if (annotations[i] == null)
154 if(drawValues && annotations[i].displayCharacter.length() > 1 )
159 if (annotations[i].value > max)
161 max = annotations[i].value;
164 if (annotations[i].value < min)
166 min = annotations[i].value;
174 for (int i = 0; i < annotations.length; i++)
177 && annotations[i] != null
178 && ((annotations[i].secondaryStructure == 'H') ||
179 (annotations[i].secondaryStructure == 'E')))
185 && annotations[i]!=null
186 && annotations[i].displayCharacter.length() > 0)
192 if(!drawValues && graphType!=NO_GRAPH)
194 for (int i = 0; i < annotations.length; i++)
196 if (annotations[i] != null)
197 annotations[i].displayCharacter = "";
205 * @return DOCUMENT ME!
207 public String toString()
209 StringBuffer buffer = new StringBuffer();
211 for (int i = 0; i < annotations.length; i++)
213 if (annotations[i] != null)
217 buffer.append(annotations[i].value);
221 buffer.append(annotations[i].secondaryStructure);
225 buffer.append(annotations[i].displayCharacter);
232 if (label.equals("Consensus"))
236 for (int i = 0; i < annotations.length; i++)
238 if (annotations[i] != null)
240 buffer.append(annotations[i].description);
247 return buffer.toString();
250 public void setThreshold(GraphLine line)
255 public GraphLine getThreshold()
261 * 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.
264 * @param alreadyMapped
266 public void createSequenceMapping(SequenceI seqRef,
268 boolean alreadyMapped)
273 sequenceMapping = new java.util.Hashtable();
275 sequenceRef = seqRef;
278 for(int i = 0; i < annotations.length; i++)
280 if (annotations[i] != null)
283 seqPos = seqRef.findPosition(i);
287 sequenceMapping.put(new Integer(seqPos), annotations[i]);
291 adjustForAlignment();
294 public void adjustForAlignment()
296 int a=0, aSize = sequenceRef.getLength();
305 Annotation[] temp = new Annotation[aSize];
308 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
310 index = new Integer(a);
311 if(sequenceMapping.containsKey(index))
313 position = sequenceRef.findIndex(a)-1;
315 temp[position] = (Annotation)sequenceMapping.get(index);