2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
22 import jalview.datamodel.*;
24 public class AnnotationColourGradient extends ResidueColourScheme
26 public static final int NO_THRESHOLD = -1;
28 public static final int BELOW_THRESHOLD = 0;
30 public static final int ABOVE_THRESHOLD = 1;
32 public AlignmentAnnotation annotation;
34 int aboveAnnotationThreshold = -1;
36 public boolean thresholdIsMinMax = false;
38 GraphLine annotationThreshold;
40 float r1, g1, b1, rr, gg, bb, dr, dg, db;
42 ColourSchemeI colourScheme;
44 public boolean predefinedColours = false;
47 * Creates a new AnnotationColourGradient object.
49 public AnnotationColourGradient(AlignmentAnnotation annotation,
50 ColourSchemeI originalColour, int aboveThreshold)
52 if (originalColour instanceof AnnotationColourGradient)
54 colourScheme = ((AnnotationColourGradient) originalColour).colourScheme;
58 colourScheme = originalColour;
61 this.annotation = annotation;
63 aboveAnnotationThreshold = aboveThreshold;
65 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
67 annotationThreshold = annotation.threshold;
72 * Creates a new AnnotationColourGradient object.
74 public AnnotationColourGradient(AlignmentAnnotation annotation,
75 Color minColour, Color maxColour, int aboveThreshold)
77 this.annotation = annotation;
79 aboveAnnotationThreshold = aboveThreshold;
81 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
83 annotationThreshold = annotation.threshold;
86 r1 = minColour.getRed();
87 g1 = minColour.getGreen();
88 b1 = minColour.getBlue();
90 rr = maxColour.getRed() - r1;
91 gg = maxColour.getGreen() - g1;
92 bb = maxColour.getBlue() - b1;
95 public String getAnnotation()
97 return annotation.label;
100 public int getAboveThreshold()
102 return aboveAnnotationThreshold;
105 public float getAnnotationThreshold()
107 if (annotationThreshold == null)
113 return annotationThreshold.value;
117 public ColourSchemeI getBaseColour()
122 public Color getMinColour()
124 return new Color((int) r1, (int) g1, (int) b1);
127 public Color getMaxColour()
129 return new Color((int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
138 * @return DOCUMENT ME!
140 public Color findColour(char c)
153 * @return DOCUMENT ME!
155 public Color findColour(char c, int j)
157 Color currentColour = Color.white;
159 if ((threshold == 0) || aboveThreshold(c, j))
161 if (j < annotation.annotations.length
162 && annotation.annotations[j] != null
163 && !jalview.util.Comparison.isGap(c))
166 if (predefinedColours)
168 if (annotation.annotations[j].colour != null)
169 return annotation.annotations[j].colour;
171 return currentColour;
174 if (aboveAnnotationThreshold == NO_THRESHOLD
175 || (annotationThreshold != null
176 && aboveAnnotationThreshold == ABOVE_THRESHOLD && annotation.annotations[j].value >= annotationThreshold.value)
177 || (annotationThreshold != null
178 && aboveAnnotationThreshold == BELOW_THRESHOLD && annotation.annotations[j].value <= annotationThreshold.value))
182 if (thresholdIsMinMax
183 && annotation.threshold != null
184 && aboveAnnotationThreshold == ABOVE_THRESHOLD
185 && annotation.annotations[j].value > annotation.threshold.value)
187 range = (annotation.annotations[j].value - annotation.threshold.value)
188 / (annotation.graphMax - annotation.threshold.value);
190 else if (thresholdIsMinMax && annotation.threshold != null
191 && aboveAnnotationThreshold == BELOW_THRESHOLD
192 && annotation.annotations[j].value > annotation.graphMin)
194 range = (annotation.annotations[j].value - annotation.graphMin)
195 / (annotation.threshold.value - annotation.graphMin);
199 range = (annotation.annotations[j].value - annotation.graphMin)
200 / (annotation.graphMax - annotation.graphMin);
203 if (colourScheme != null)
205 currentColour = colourScheme.findColour(c, j);
209 dr = rr * range + r1;
210 dg = gg * range + g1;
211 db = bb * range + b1;
213 currentColour = new Color((int) dr, (int) dg, (int) db);
219 if (conservationColouring)
221 currentColour = applyConservation(currentColour, j);
224 return currentColour;