2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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.schemes;
\r
23 import jalview.datamodel.*;
\r
25 public class AnnotationColourGradient
\r
26 extends ResidueColourScheme
\r
28 public static int NO_THRESHOLD = -1;
\r
29 public static int BELOW_THRESHOLD = 0;
\r
30 public static int ABOVE_THRESHOLD = 1;
\r
32 public AlignmentAnnotation annotation;
\r
33 int aboveAnnotationThreshold = -1;
\r
34 public boolean thresholdIsMinMax = false;
\r
36 GraphLine annotationThreshold;
\r
38 float r1, g1, b1, rr, gg, bb, dr, dg, db;
\r
40 ColourSchemeI colourScheme;
\r
42 public boolean predefinedColours = false;
\r
45 * Creates a new AnnotationColourGradient object.
\r
47 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
48 ColourSchemeI originalColour,
\r
51 if (originalColour instanceof AnnotationColourGradient)
\r
53 colourScheme = ( (AnnotationColourGradient) originalColour).colourScheme;
\r
57 colourScheme = originalColour;
\r
60 this.annotation = annotation;
\r
62 aboveAnnotationThreshold = aboveThreshold;
\r
64 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
\r
66 annotationThreshold = annotation.threshold;
\r
71 * Creates a new AnnotationColourGradient object.
\r
73 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
74 Color minColour, Color maxColour,
\r
77 this.annotation = annotation;
\r
79 aboveAnnotationThreshold = aboveThreshold;
\r
81 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
\r
83 annotationThreshold = annotation.threshold;
\r
86 r1 = minColour.getRed();
\r
87 g1 = minColour.getGreen();
\r
88 b1 = minColour.getBlue();
\r
90 rr = maxColour.getRed() - r1;
\r
91 gg = maxColour.getGreen() - g1;
\r
92 bb = maxColour.getBlue() - b1;
\r
95 public String getAnnotation()
\r
97 return annotation.label;
\r
100 public int getAboveThreshold()
\r
102 return aboveAnnotationThreshold;
\r
105 public float getAnnotationThreshold()
\r
107 if (annotationThreshold == null)
\r
113 return annotationThreshold.value;
\r
117 public ColourSchemeI getBaseColour()
\r
119 return colourScheme;
\r
122 public Color getMinColour()
\r
124 return new Color( (int) r1, (int) g1, (int) b1);
\r
127 public Color getMaxColour()
\r
129 return new Color( (int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
\r
135 * @param n DOCUMENT ME!
\r
137 * @return DOCUMENT ME!
\r
139 public Color findColour(char c)
\r
147 * @param n DOCUMENT ME!
\r
148 * @param j DOCUMENT ME!
\r
150 * @return DOCUMENT ME!
\r
152 public Color findColour(char c, int j)
\r
154 Color currentColour = Color.white;
\r
156 if ( (threshold == 0) || aboveThreshold(c, j))
\r
158 if (j < annotation.annotations.length
\r
159 && annotation.annotations[j] != null
\r
160 && !jalview.util.Comparison.isGap(c))
\r
163 if (predefinedColours)
\r
165 if(annotation.annotations[j].colour != null)
\r
166 return annotation.annotations[j].colour;
\r
168 return currentColour;
\r
171 if (aboveAnnotationThreshold == NO_THRESHOLD
\r
173 (annotationThreshold != null && aboveAnnotationThreshold == ABOVE_THRESHOLD &&
\r
174 annotation.annotations[j].value >= annotationThreshold.value)
\r
176 (annotationThreshold != null && aboveAnnotationThreshold == BELOW_THRESHOLD &&
\r
177 annotation.annotations[j].value <= annotationThreshold.value))
\r
181 if (thresholdIsMinMax
\r
182 && annotation.threshold != null
\r
183 && aboveAnnotationThreshold == ABOVE_THRESHOLD
\r
184 && annotation.annotations[j].value>annotation.threshold.value)
\r
187 (annotation.annotations[j].value - annotation.threshold.value) /
\r
188 (annotation.graphMax - annotation.threshold.value);
\r
190 else if (thresholdIsMinMax
\r
191 && annotation.threshold != null
\r
192 && aboveAnnotationThreshold == BELOW_THRESHOLD
\r
193 && annotation.annotations[j].value > annotation.graphMin)
\r
196 ( annotation.annotations[j].value - annotation.graphMin ) /
\r
197 (annotation.threshold.value - annotation.graphMin );
\r
201 range = (annotation.annotations[j].value -
\r
202 annotation.graphMin) /
\r
203 (annotation.graphMax - annotation.graphMin);
\r
207 if (colourScheme != null)
\r
209 currentColour = colourScheme.findColour(c, j);
\r
211 else if (range != 0)
\r
213 dr = rr * range + r1;
\r
214 dg = gg * range + g1;
\r
215 db = bb * range + b1;
\r
217 currentColour = new Color( (int) dr, (int) dg, (int) db);
\r
223 if (conservationColouring)
\r
225 currentColour = applyConservation(currentColour, j);
\r
228 return currentColour;
\r