2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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;
20 import jalview.datamodel.AlignmentAnnotation;
21 import jalview.datamodel.GraphLine;
23 import java.awt.Color;
25 public class AnnotationColourGradient extends ResidueColourScheme
27 public static final int NO_THRESHOLD = -1;
29 public static final int BELOW_THRESHOLD = 0;
31 public static final 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!
157 public Color findColour(char c, int j, int sequenceIndex)
159 Color currentColour = Color.white;
161 if ((threshold == 0) || aboveThreshold(c, j))
163 if (j < annotation.annotations.length
164 && annotation.annotations[j] != null
165 && !jalview.util.Comparison.isGap(c))
168 if (predefinedColours)
170 if (annotation.annotations[j].colour != null)
171 return annotation.annotations[j].colour;
173 return currentColour;
176 if (aboveAnnotationThreshold == NO_THRESHOLD
177 || (annotationThreshold != null
178 && aboveAnnotationThreshold == ABOVE_THRESHOLD && annotation.annotations[j].value >= annotationThreshold.value)
179 || (annotationThreshold != null
180 && aboveAnnotationThreshold == BELOW_THRESHOLD && annotation.annotations[j].value <= annotationThreshold.value))
184 if (thresholdIsMinMax
185 && annotation.threshold != null
186 && aboveAnnotationThreshold == ABOVE_THRESHOLD
187 && annotation.annotations[j].value > annotation.threshold.value)
189 range = (annotation.annotations[j].value - annotation.threshold.value)
190 / (annotation.graphMax - annotation.threshold.value);
192 else if (thresholdIsMinMax && annotation.threshold != null
193 && aboveAnnotationThreshold == BELOW_THRESHOLD
194 && annotation.annotations[j].value > annotation.graphMin)
196 range = (annotation.annotations[j].value - annotation.graphMin)
197 / (annotation.threshold.value - annotation.graphMin);
201 range = (annotation.annotations[j].value - annotation.graphMin)
202 / (annotation.graphMax - annotation.graphMin);
205 if (colourScheme != null)
207 currentColour = colourScheme.findColour(c, j, sequenceIndex);
211 dr = rr * range + r1;
212 dg = gg * range + g1;
213 db = bb * range + b1;
215 currentColour = new Color((int) dr, (int) dg, (int) db);
221 if (conservationColouring)
223 currentColour = applyConservation(currentColour, j);
226 return currentColour;