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 AlignmentAnnotation annotation;
\r
33 int aboveAnnotationThreshold = -1;
\r
35 GraphLine annotationThreshold;
\r
37 float r1, g1, b1, rr, gg, bb, dr, dg, db;
\r
40 ColourSchemeI colourScheme;
\r
43 * Creates a new AnnotationColourGradient object.
\r
45 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
46 ColourSchemeI originalColour,
\r
49 if (originalColour instanceof AnnotationColourGradient)
\r
51 colourScheme = ( (AnnotationColourGradient) originalColour).colourScheme;
\r
55 colourScheme = originalColour;
\r
58 this.annotation = annotation;
\r
60 aboveAnnotationThreshold = aboveThreshold;
\r
62 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
\r
64 annotationThreshold = annotation.threshold;
\r
69 * Creates a new AnnotationColourGradient object.
\r
71 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
72 Color minColour, Color maxColour,
\r
75 this.annotation = annotation;
\r
77 aboveAnnotationThreshold = aboveThreshold;
\r
79 if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null)
\r
81 annotationThreshold = annotation.threshold;
\r
84 r1 = minColour.getRed();
\r
85 g1 = minColour.getGreen();
\r
86 b1 = minColour.getBlue();
\r
88 rr = maxColour.getRed() - r1;
\r
89 gg = maxColour.getGreen() - g1;
\r
90 bb = maxColour.getBlue() - b1;
\r
92 range = annotation.graphMax - annotation.graphMin;
\r
96 public String getAnnotation()
\r
98 return annotation.label;
\r
101 public int getAboveThreshold()
\r
103 return aboveAnnotationThreshold;
\r
106 public float getAnnotationThreshold()
\r
108 if (annotationThreshold == null)
\r
114 return annotationThreshold.value;
\r
118 public ColourSchemeI getBaseColour()
\r
120 return colourScheme;
\r
123 public Color getMinColour()
\r
125 return new Color( (int) r1, (int) g1, (int) b1);
\r
128 public Color getMaxColour()
\r
130 return new Color( (int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
\r
136 * @param n DOCUMENT ME!
\r
138 * @return DOCUMENT ME!
\r
140 public Color findColour(char c)
\r
148 * @param n DOCUMENT ME!
\r
149 * @param j DOCUMENT ME!
\r
151 * @return DOCUMENT ME!
\r
153 public Color findColour(char c, int j)
\r
155 Color currentColour = Color.white;
\r
157 if ( (threshold == 0) || aboveThreshold(c, j))
\r
159 if (j < annotation.annotations.length
\r
160 && annotation.annotations[j] != null
\r
161 && !jalview.util.Comparison.isGap(c))
\r
163 if (aboveAnnotationThreshold == NO_THRESHOLD
\r
165 (annotationThreshold != null && aboveAnnotationThreshold == ABOVE_THRESHOLD &&
\r
166 annotation.annotations[j].value >= annotationThreshold.value)
\r
168 (annotationThreshold != null && aboveAnnotationThreshold == BELOW_THRESHOLD &&
\r
169 annotation.annotations[j].value <= annotationThreshold.value))
\r
171 if (colourScheme != null)
\r
173 currentColour = colourScheme.findColour(c, j);
\r
175 else if (range != 0)
\r
178 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
182 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
186 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
190 currentColour = new Color( (int) dr, (int) dg, (int) db);
\r
196 if (conservationColouring)
\r
198 currentColour = applyConservation(currentColour, j);
\r
201 return currentColour;
\r