2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
25 import jalview.analysis.*;
33 public class ResidueColourScheme implements ColourSchemeI
36 boolean conservationColouring = false;
42 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
43 protected String ignoreGaps = AAFrequency.PID_GAPS;
45 /** Consenus as a hashtable array */
46 Hashtable[] consensus;
48 /** Conservation string as a char array */
51 int conservationLength = 0;
57 * Creates a new ResidueColourScheme object.
64 public ResidueColourScheme(Color[] colours, int threshold)
66 this.colors = colours;
67 this.threshold = threshold;
71 * Creates a new ResidueColourScheme object.
73 public ResidueColourScheme()
78 * Find a colour without an index in a sequence
80 public Color findColour(char c)
82 return colors[ResidueProperties.aaIndex[c]];
85 public Color findColour(char c, int j)
89 if ((threshold == 0) || aboveThreshold(c, j))
91 currentColour = colors[ResidueProperties.aaIndex[c]];
95 currentColour = Color.white;
98 if (conservationColouring)
100 currentColour = applyConservation(currentColour, j);
103 return currentColour;
107 * Get the percentage threshold for this colour scheme
109 * @return Returns the percentage threshold
111 public int getThreshold()
122 public void setThreshold(int ct, boolean ignoreGaps)
127 this.ignoreGaps = AAFrequency.PID_NOGAPS;
131 this.ignoreGaps = AAFrequency.PID_GAPS;
143 * @return DOCUMENT ME!
145 public boolean aboveThreshold(char c, int j)
147 if ('a' <= c && c <= 'z')
150 // Faster than toUpperCase
154 if (consensus == null || consensus.length < j || consensus[j] == null)
159 if ((((Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1)
160 && consensus[j].contains(String.valueOf(c)))
162 if (((Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
171 public boolean conservationApplied()
173 return conservationColouring;
176 public void setConservationInc(int i)
181 public int getConservationInc()
192 public void setConsensus(Hashtable[] consensus)
194 if (consensus == null)
199 this.consensus = consensus;
202 public void setConservation(Conservation cons)
206 conservationColouring = false;
211 conservationColouring = true;
212 int i, iSize = cons.getConsSequence().getLength();
213 conservation = new char[iSize];
214 for (i = 0; i < iSize; i++)
216 conservation[i] = cons.getConsSequence().getCharAt(i);
218 conservationLength = conservation.length;
231 * @return DOCUMENT ME!
234 Color applyConservation(Color currentColour, int i)
237 if ((conservationLength > i) && (conservation[i] != '*')
238 && (conservation[i] != '+'))
240 if (jalview.util.Comparison.isGap(conservation[i]))
242 currentColour = Color.white;
246 float t = 11 - (conservation[i] - '0');
252 int red = currentColour.getRed();
253 int green = currentColour.getGreen();
254 int blue = currentColour.getBlue();
257 int dg = 255 - green;
264 red += (inc / 20f) * dr;
265 green += (inc / 20f) * dg;
266 blue += (inc / 20f) * db;
268 if (red > 255 || green > 255 || blue > 255)
270 currentColour = Color.white;
274 currentColour = new Color(red, green, blue);
278 return currentColour;