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')
129 if (annotations[i].displayCharacter.length() > 0)
138 for (int j = 0; j < annotations.length; j++)
140 if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
142 annotations[j].displayCharacter
143 =String.valueOf(annotations[j].secondaryStructure);
144 annotations[j].secondaryStructure = ' ';
145 if(annotations[j].description.length()<1)
146 annotations[j].description = annotations[j].displayCharacter;
156 * Creates a new AlignmentAnnotation object.
158 * @param label DOCUMENT ME!
159 * @param description DOCUMENT ME!
160 * @param annotations DOCUMENT ME!
161 * @param min DOCUMENT ME!
162 * @param max DOCUMENT ME!
163 * @param winLength DOCUMENT ME!
165 public AlignmentAnnotation(String label, String description,
166 Annotation[] annotations, float min, float max, int graphType)
168 // graphs are not editable
170 this.description = description;
171 this.annotations = annotations;
174 boolean drawValues = true;
179 for (int i = 0; i < annotations.length; i++)
181 if (annotations[i] == null)
186 if(drawValues && annotations[i].displayCharacter.length() > 1 )
191 if (annotations[i].value > max)
193 max = annotations[i].value;
196 if (annotations[i].value < min)
198 min = annotations[i].value;
206 areLabelsSecondaryStructure();
208 if(!drawValues && graphType!=NO_GRAPH)
210 for (int i = 0; i < annotations.length; i++)
212 if (annotations[i] != null)
213 annotations[i].displayCharacter = "";
221 * @return DOCUMENT ME!
223 public String toString()
225 StringBuffer buffer = new StringBuffer();
227 for (int i = 0; i < annotations.length; i++)
229 if (annotations[i] != null)
233 buffer.append(annotations[i].value);
237 buffer.append(annotations[i].secondaryStructure);
241 buffer.append(annotations[i].displayCharacter);
248 if (label.equals("Consensus"))
252 for (int i = 0; i < annotations.length; i++)
254 if (annotations[i] != null)
256 buffer.append(annotations[i].description);
263 return buffer.toString();
266 public void setThreshold(GraphLine line)
271 public GraphLine getThreshold()
277 * 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.
280 * @param alreadyMapped
282 public void createSequenceMapping(SequenceI seqRef,
284 boolean alreadyMapped)
289 sequenceMapping = new java.util.Hashtable();
291 sequenceRef = seqRef;
294 for(int i = 0; i < annotations.length; i++)
296 if (annotations[i] != null)
299 seqPos = seqRef.findPosition(i);
303 sequenceMapping.put(new Integer(seqPos), annotations[i]);
307 adjustForAlignment();
310 public void adjustForAlignment()
312 int a=0, aSize = sequenceRef.getLength();
321 Annotation[] temp = new Annotation[aSize];
324 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
326 index = new Integer(a);
327 if(sequenceMapping.containsKey(index))
329 position = sequenceRef.findIndex(a)-1;
331 temp[position] = (Annotation)sequenceMapping.get(index);