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;
20 import jalview.datamodel.AlignmentAnnotation;
21 import jalview.datamodel.GraphLine;
22 import jalview.datamodel.SequenceI;
24 import java.awt.Color;
26 public class AnnotationColourGradient extends ResidueColourScheme
28 public static final int NO_THRESHOLD = -1;
30 public static final int BELOW_THRESHOLD = 0;
32 public static final int ABOVE_THRESHOLD = 1;
34 public AlignmentAnnotation annotation;
36 int aboveAnnotationThreshold = -1;
38 public boolean thresholdIsMinMax = false;
40 GraphLine annotationThreshold;
42 float r1, g1, b1, rr, gg, bb, dr, dg, db;
44 ColourSchemeI colourScheme;
46 public boolean predefinedColours = false;
49 * Creates a new AnnotationColourGradient object.
51 public AnnotationColourGradient(AlignmentAnnotation annotation,
52 ColourSchemeI originalColour, int aboveThreshold)
54 if (originalColour instanceof AnnotationColourGradient)
56 colourScheme = ((AnnotationColourGradient) originalColour).colourScheme;
60 colourScheme = originalColour;
63 this.annotation = annotation;
65 aboveAnnotationThreshold = aboveThreshold;
67 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
69 annotationThreshold = annotation.threshold;
74 * Creates a new AnnotationColourGradient object.
76 public AnnotationColourGradient(AlignmentAnnotation annotation,
77 Color minColour, Color maxColour, int aboveThreshold)
79 this.annotation = annotation;
81 aboveAnnotationThreshold = aboveThreshold;
83 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
85 annotationThreshold = annotation.threshold;
88 r1 = minColour.getRed();
89 g1 = minColour.getGreen();
90 b1 = minColour.getBlue();
92 rr = maxColour.getRed() - r1;
93 gg = maxColour.getGreen() - g1;
94 bb = maxColour.getBlue() - b1;
97 public String getAnnotation()
99 return annotation.label;
102 public int getAboveThreshold()
104 return aboveAnnotationThreshold;
107 public float getAnnotationThreshold()
109 if (annotationThreshold == null)
115 return annotationThreshold.value;
119 public ColourSchemeI getBaseColour()
124 public Color getMinColour()
126 return new Color((int) r1, (int) g1, (int) b1);
129 public Color getMaxColour()
131 return new Color((int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
140 * @return DOCUMENT ME!
142 public Color findColour(char c)
155 * @return DOCUMENT ME!
158 public Color findColour(char c, int j, SequenceI seq)
160 Color currentColour = Color.white;
162 if ((threshold == 0) || aboveThreshold(c, j))
164 if (j < annotation.annotations.length
165 && annotation.annotations[j] != null
166 && !jalview.util.Comparison.isGap(c))
169 if (predefinedColours)
171 if (annotation.annotations[j].colour != null)
172 return annotation.annotations[j].colour;
174 return currentColour;
177 if (aboveAnnotationThreshold == NO_THRESHOLD
178 || (annotationThreshold != null
179 && aboveAnnotationThreshold == ABOVE_THRESHOLD && annotation.annotations[j].value >= annotationThreshold.value)
180 || (annotationThreshold != null
181 && aboveAnnotationThreshold == BELOW_THRESHOLD && annotation.annotations[j].value <= annotationThreshold.value))
185 if (thresholdIsMinMax
186 && annotation.threshold != null
187 && aboveAnnotationThreshold == ABOVE_THRESHOLD
188 && annotation.annotations[j].value > annotation.threshold.value)
190 range = (annotation.annotations[j].value - annotation.threshold.value)
191 / (annotation.graphMax - annotation.threshold.value);
193 else if (thresholdIsMinMax && annotation.threshold != null
194 && aboveAnnotationThreshold == BELOW_THRESHOLD
195 && annotation.annotations[j].value > annotation.graphMin)
197 range = (annotation.annotations[j].value - annotation.graphMin)
198 / (annotation.threshold.value - annotation.graphMin);
202 range = (annotation.annotations[j].value - annotation.graphMin)
203 / (annotation.graphMax - annotation.graphMin);
206 if (colourScheme != null)
208 currentColour = colourScheme.findColour(c, j, seq);
212 dr = rr * range + r1;
213 dg = gg * range + g1;
214 db = bb * range + b1;
216 currentColour = new Color((int) dr, (int) dg, (int) db);
222 if (conservationColouring)
224 currentColour = applyConservation(currentColour, j);
227 return currentColour;