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
25 import jalview.analysis.*;
\r
31 * @version $Revision$
\r
33 public class ResidueColourScheme
\r
34 implements ColourSchemeI
\r
37 boolean conservationColouring = false;
\r
42 /* Set when threshold colouring to either pid_gaps or pid_nogaps*/
\r
43 protected String ignoreGaps = AAFrequency.PID_GAPS;
\r
45 /** Consenus as a hashtable array */
\r
46 Hashtable[] consensus;
\r
48 /** Conservation string as a char array */
\r
49 char[] conservation;
\r
50 int conservationLength=0;
\r
52 /** DOCUMENT ME!! */
\r
56 * Creates a new ResidueColourScheme object.
\r
58 * @param colors DOCUMENT ME!
\r
59 * @param threshold DOCUMENT ME!
\r
61 public ResidueColourScheme(Color[] colours, int threshold)
\r
63 this.colors = colours;
\r
64 this.threshold = threshold;
\r
68 * Creates a new ResidueColourScheme object.
\r
70 public ResidueColourScheme()
\r
75 * Find a colour without an index in a sequence
\r
77 public Color findColour(char c)
\r
79 return colors[ResidueProperties.aaIndex[c]];
\r
82 public Color findColour(char c, int j)
\r
84 Color currentColour;
\r
86 if ( (threshold == 0) || aboveThreshold(c, j))
\r
88 currentColour = colors[ResidueProperties.aaIndex[c]];
\r
92 currentColour = Color.white;
\r
95 if (conservationColouring)
\r
97 currentColour = applyConservation(currentColour, j);
\r
100 return currentColour;
\r
104 * Get the percentage threshold for this colour scheme
\r
106 * @return Returns the percentage threshold
\r
108 public int getThreshold()
\r
116 * @param ct DOCUMENT ME!
\r
118 public void setThreshold(int ct, boolean ignoreGaps)
\r
123 this.ignoreGaps = AAFrequency.PID_NOGAPS;
\r
127 this.ignoreGaps = AAFrequency.PID_GAPS;
\r
134 * @param s DOCUMENT ME!
\r
135 * @param j DOCUMENT ME!
\r
137 * @return DOCUMENT ME!
\r
139 public boolean aboveThreshold(char c, int j)
\r
141 if ('a' <= c && c <= 'z')
\r
143 // TO UPPERCASE !!!
\r
144 //Faster than toUpperCase
\r
148 if (consensus == null || consensus.length<j || consensus[j] == null)
\r
153 if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&
\r
154 consensus[j].contains(String.valueOf(c)))
\r
156 if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
\r
165 public boolean conservationApplied()
\r
167 return conservationColouring;
\r
170 public void setConservationInc(int i)
\r
175 public int getConservationInc()
\r
183 * @param consensus DOCUMENT ME!
\r
185 public void setConsensus(Hashtable[] consensus)
\r
187 if (consensus == null)
\r
192 this.consensus = consensus;
\r
195 public void setConservation(Conservation cons)
\r
199 conservationColouring = false;
\r
200 conservation = null;
\r
204 conservationColouring = true;
\r
205 int i, iSize = cons.getConsSequence().getLength();
\r
206 conservation = new char[iSize];
\r
207 for (i = 0; i < iSize; i++)
\r
209 conservation[i] = cons.getConsSequence().getCharAt(i);
\r
211 conservationLength = conservation.length;
\r
219 * @param s DOCUMENT ME!
\r
220 * @param i DOCUMENT ME!
\r
222 * @return DOCUMENT ME!
\r
225 Color applyConservation(Color currentColour, int i)
\r
228 if ((conservationLength>i) && (conservation[i] != '*') && (conservation[i] != '+'))
\r
230 if ( jalview.util.Comparison.isGap(conservation[i]))
\r
232 currentColour = Color.white;
\r
236 float t = 11 - (conservation[i] - '0');
\r
239 return Color.white;
\r
242 int red = currentColour.getRed();
\r
243 int green = currentColour.getGreen();
\r
244 int blue = currentColour.getBlue();
\r
246 int dr = 255 - red;
\r
247 int dg = 255 - green;
\r
248 int db = 255 - blue;
\r
254 red += (inc / 20f) * dr;
\r
255 green += (inc / 20f) * dg;
\r
256 blue += (inc / 20f) * db;
\r
258 if (red > 255 || green > 255 || blue > 255)
\r
260 currentColour = Color.white;
\r
264 currentColour = new Color(red, green, blue);
\r
268 return currentColour;
\r