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].displayCharacter.length()==1
124 && !annotations[i].displayCharacter.equals("H")
125 && !annotations[i].displayCharacter.equals("E")
126 && !annotations[i].displayCharacter.equals("-"))
128 if(jalview.schemes.ResidueProperties.aaIndex
129 [annotations[i].displayCharacter.charAt(0)]>0)
135 if (annotations[i].displayCharacter.length() > 0)
144 for (int j = 0; j < annotations.length; j++)
146 if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
148 annotations[j].displayCharacter
149 =String.valueOf(annotations[j].secondaryStructure);
150 annotations[j].secondaryStructure = ' ';
160 * Creates a new AlignmentAnnotation object.
162 * @param label DOCUMENT ME!
163 * @param description DOCUMENT ME!
164 * @param annotations DOCUMENT ME!
165 * @param min DOCUMENT ME!
166 * @param max DOCUMENT ME!
167 * @param winLength DOCUMENT ME!
169 public AlignmentAnnotation(String label, String description,
170 Annotation[] annotations, float min, float max, int graphType)
172 // graphs are not editable
174 this.description = description;
175 this.annotations = annotations;
178 boolean drawValues = true;
183 for (int i = 0; i < annotations.length; i++)
185 if (annotations[i] == null)
190 if(drawValues && annotations[i].displayCharacter.length() > 1 )
195 if (annotations[i].value > max)
197 max = annotations[i].value;
200 if (annotations[i].value < min)
202 min = annotations[i].value;
210 areLabelsSecondaryStructure();
212 if(!drawValues && graphType!=NO_GRAPH)
214 for (int i = 0; i < annotations.length; i++)
216 if (annotations[i] != null)
217 annotations[i].displayCharacter = "";
225 * @return DOCUMENT ME!
227 public String toString()
229 StringBuffer buffer = new StringBuffer();
231 for (int i = 0; i < annotations.length; i++)
233 if (annotations[i] != null)
237 buffer.append(annotations[i].value);
241 buffer.append(annotations[i].secondaryStructure);
245 buffer.append(annotations[i].displayCharacter);
252 if (label.equals("Consensus"))
256 for (int i = 0; i < annotations.length; i++)
258 if (annotations[i] != null)
260 buffer.append(annotations[i].description);
267 return buffer.toString();
270 public void setThreshold(GraphLine line)
275 public GraphLine getThreshold()
281 * 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.
284 * @param alreadyMapped
286 public void createSequenceMapping(SequenceI seqRef,
288 boolean alreadyMapped)
293 sequenceMapping = new java.util.Hashtable();
295 sequenceRef = seqRef;
298 for(int i = 0; i < annotations.length; i++)
300 if (annotations[i] != null)
303 seqPos = seqRef.findPosition(i);
307 sequenceMapping.put(new Integer(seqPos), annotations[i]);
311 adjustForAlignment();
314 public void adjustForAlignment()
316 int a=0, aSize = sequenceRef.getLength();
325 Annotation[] temp = new Annotation[aSize];
328 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
330 index = new Integer(a);
331 if(sequenceMapping.containsKey(index))
333 position = sequenceRef.findIndex(a)-1;
335 temp[position] = (Annotation)sequenceMapping.get(index);