2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
26 * @version $Revision$
\r
28 public class AlignmentAnnotation
\r
30 public SequenceI sequenceRef;
\r
32 /** DOCUMENT ME!! */
\r
33 public String label;
\r
35 /** DOCUMENT ME!! */
\r
36 public String description;
\r
38 /** DOCUMENT ME!! */
\r
39 public Annotation[] annotations;
\r
41 public java.util.Hashtable sequenceMapping;
\r
43 /** DOCUMENT ME!! */
\r
44 public float graphMin;
\r
46 /** DOCUMENT ME!! */
\r
47 public float graphMax;
\r
49 public GraphLine threshold;
\r
51 // Graphical hints and tips
\r
53 /** DOCUMENT ME!! */
\r
54 public boolean editable = false;
\r
56 /** DOCUMENT ME!! */
\r
57 public boolean hasIcons; //
\r
59 /** DOCUMENT ME!! */
\r
60 public boolean hasText;
\r
62 /** DOCUMENT ME!! */
\r
63 public boolean visible = true;
\r
65 public int graphGroup = -1;
\r
67 /** DOCUMENT ME!! */
\r
68 public int height = 0;
\r
70 public int graph = 0;
\r
72 public int graphHeight = 40;
\r
74 public static final int NO_GRAPH = 0;
\r
76 public static final int BAR_GRAPH = 1;
\r
78 public static final int LINE_GRAPH = 2;
\r
80 public static int getGraphValueFromString(String string)
\r
82 if(string.equalsIgnoreCase("BAR_GRAPH"))
\r
84 else if(string.equalsIgnoreCase("LINE_GRAPH"))
\r
91 * Creates a new AlignmentAnnotation object.
\r
93 * @param label DOCUMENT ME!
\r
94 * @param description DOCUMENT ME!
\r
95 * @param annotations DOCUMENT ME!
\r
97 public AlignmentAnnotation(String label, String description,
\r
98 Annotation[] annotations)
\r
100 // always editable?
\r
102 this.label = label;
\r
103 this.description = description;
\r
104 this.annotations = annotations;
\r
106 for (int i = 0; i < annotations.length; i++)
\r
108 if ((annotations[i] != null) &&
\r
109 ((annotations[i].secondaryStructure == 'H') ||
\r
110 (annotations[i].secondaryStructure == 'E')))
\r
115 if ((annotations[i] != null) &&
\r
116 (annotations[i].displayCharacter.length() > 0))
\r
124 * Creates a new AlignmentAnnotation object.
\r
126 * @param label DOCUMENT ME!
\r
127 * @param description DOCUMENT ME!
\r
128 * @param annotations DOCUMENT ME!
\r
129 * @param min DOCUMENT ME!
\r
130 * @param max DOCUMENT ME!
\r
131 * @param winLength DOCUMENT ME!
\r
133 public AlignmentAnnotation(String label, String description,
\r
134 Annotation[] annotations, float min, float max, int graphType)
\r
136 // graphs are not editable
\r
137 this.label = label;
\r
138 this.description = description;
\r
139 this.annotations = annotations;
\r
142 boolean drawValues = true;
\r
147 for (int i = 0; i < annotations.length; i++)
\r
149 if (annotations[i] == null)
\r
154 if(drawValues && annotations[i].displayCharacter.length() > 1 )
\r
156 drawValues = false;
\r
159 if (annotations[i].value > max)
\r
161 max = annotations[i].value;
\r
164 if (annotations[i].value < min)
\r
166 min = annotations[i].value;
\r
174 for (int i = 0; i < annotations.length; i++)
\r
177 && annotations[i] != null
\r
178 && ((annotations[i].secondaryStructure == 'H') ||
\r
179 (annotations[i].secondaryStructure == 'E')))
\r
185 && annotations[i]!=null
\r
186 && annotations[i].displayCharacter.length() > 0)
\r
192 if(!drawValues && graphType!=NO_GRAPH)
\r
194 for (int i = 0; i < annotations.length; i++)
\r
196 if (annotations[i] != null)
\r
197 annotations[i].displayCharacter = "";
\r
205 * @return DOCUMENT ME!
\r
207 public String toString()
\r
209 StringBuffer buffer = new StringBuffer();
\r
211 for (int i = 0; i < annotations.length; i++)
\r
213 if (annotations[i] != null)
\r
217 buffer.append(annotations[i].value);
\r
221 buffer.append(annotations[i].secondaryStructure);
\r
225 buffer.append(annotations[i].displayCharacter);
\r
229 buffer.append(", ");
\r
232 if (label.equals("Consensus"))
\r
234 buffer.append("\n");
\r
236 for (int i = 0; i < annotations.length; i++)
\r
238 if (annotations[i] != null)
\r
240 buffer.append(annotations[i].description);
\r
243 buffer.append(", ");
\r
247 return buffer.toString();
\r
250 public void setThreshold(GraphLine line)
\r
255 public GraphLine getThreshold()
\r
263 public void createSequenceMapping(SequenceI seqRef, int startRes)
\r
268 sequenceMapping = new java.util.Hashtable();
\r
270 sequenceRef = seqRef;
\r
272 if(startRes < sequenceRef.getStart())
\r
273 startRes = sequenceRef.getStart();
\r
277 int fileOffset = 0;
\r
278 if(startRes > sequenceRef.getStart())
\r
280 fileOffset = startRes - sequenceRef.getStart();
\r
283 for(int i = 0; i < annotations.length; i++)
\r
285 seqPos = sequenceRef.findPosition(i + fileOffset);
\r
286 if(seqPos<annotations.length)
\r
288 if (annotations[i] != null)
\r
290 sequenceMapping.put(new Integer(seqPos),
\r
296 adjustForAlignment();
\r
300 public void adjustForAlignment()
\r
302 int a=0, aSize = sequenceRef.getLength();
\r
311 Annotation[] temp = new Annotation[aSize];
\r
314 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
\r
316 index = new Integer(a);
\r
317 if(sequenceMapping.containsKey(index))
\r
319 position = sequenceRef.findIndex(a)-1;
\r
321 temp[position] = (Annotation)sequenceMapping.get(index);
\r
325 annotations = temp;
\r