2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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.schemes;
23 import jalview.datamodel.*;
25 public class AnnotationColourGradient extends ResidueColourScheme
27 public static int NO_THRESHOLD = -1;
29 public static int BELOW_THRESHOLD = 0;
31 public static int ABOVE_THRESHOLD = 1;
33 public AlignmentAnnotation annotation;
35 int aboveAnnotationThreshold = -1;
37 public boolean thresholdIsMinMax = false;
39 GraphLine annotationThreshold;
41 float r1, g1, b1, rr, gg, bb, dr, dg, db;
43 ColourSchemeI colourScheme;
45 public boolean predefinedColours = false;
48 * Creates a new AnnotationColourGradient object.
50 public AnnotationColourGradient(AlignmentAnnotation annotation,
51 ColourSchemeI originalColour, int aboveThreshold)
53 if (originalColour instanceof AnnotationColourGradient)
55 colourScheme = ((AnnotationColourGradient) originalColour).colourScheme;
59 colourScheme = originalColour;
62 this.annotation = annotation;
64 aboveAnnotationThreshold = aboveThreshold;
66 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
68 annotationThreshold = annotation.threshold;
73 * Creates a new AnnotationColourGradient object.
75 public AnnotationColourGradient(AlignmentAnnotation annotation,
76 Color minColour, Color maxColour, int aboveThreshold)
78 this.annotation = annotation;
80 aboveAnnotationThreshold = aboveThreshold;
82 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
84 annotationThreshold = annotation.threshold;
87 r1 = minColour.getRed();
88 g1 = minColour.getGreen();
89 b1 = minColour.getBlue();
91 rr = maxColour.getRed() - r1;
92 gg = maxColour.getGreen() - g1;
93 bb = maxColour.getBlue() - b1;
96 public String getAnnotation()
98 return annotation.label;
101 public int getAboveThreshold()
103 return aboveAnnotationThreshold;
106 public float getAnnotationThreshold()
108 if (annotationThreshold == null)
114 return annotationThreshold.value;
118 public ColourSchemeI getBaseColour()
123 public Color getMinColour()
125 return new Color((int) r1, (int) g1, (int) b1);
128 public Color getMaxColour()
130 return new Color((int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
139 * @return DOCUMENT ME!
141 public Color findColour(char c)
154 * @return DOCUMENT ME!
156 public Color findColour(char c, int j)
158 Color currentColour = Color.white;
160 if ((threshold == 0) || aboveThreshold(c, j))
162 if (j < annotation.annotations.length
163 && annotation.annotations[j] != null
164 && !jalview.util.Comparison.isGap(c))
167 if (predefinedColours)
169 if (annotation.annotations[j].colour != null)
170 return annotation.annotations[j].colour;
172 return currentColour;
175 if (aboveAnnotationThreshold == NO_THRESHOLD
176 || (annotationThreshold != null
177 && aboveAnnotationThreshold == ABOVE_THRESHOLD && annotation.annotations[j].value >= annotationThreshold.value)
178 || (annotationThreshold != null
179 && aboveAnnotationThreshold == BELOW_THRESHOLD && annotation.annotations[j].value <= annotationThreshold.value))
183 if (thresholdIsMinMax
184 && annotation.threshold != null
185 && aboveAnnotationThreshold == ABOVE_THRESHOLD
186 && annotation.annotations[j].value > annotation.threshold.value)
188 range = (annotation.annotations[j].value - annotation.threshold.value)
189 / (annotation.graphMax - annotation.threshold.value);
191 else if (thresholdIsMinMax && annotation.threshold != null
192 && aboveAnnotationThreshold == BELOW_THRESHOLD
193 && annotation.annotations[j].value > annotation.graphMin)
195 range = (annotation.annotations[j].value - annotation.graphMin)
196 / (annotation.threshold.value - annotation.graphMin);
200 range = (annotation.annotations[j].value - annotation.graphMin)
201 / (annotation.graphMax - annotation.graphMin);
204 if (colourScheme != null)
206 currentColour = colourScheme.findColour(c, j);
210 dr = rr * range + r1;
211 dg = gg * range + g1;
212 db = bb * range + b1;
214 currentColour = new Color((int) dr, (int) dg, (int) db);
220 if (conservationColouring)
222 currentColour = applyConservation(currentColour, j);
225 return currentColour;