2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
21 import jalview.analysis.*;
\r
32 * @version $Revision$
\r
34 public class ResidueColourScheme 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
51 /** 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
84 public Color findColour(char c, int j)
\r
86 Color currentColour;
\r
88 if ((threshold == 0) || aboveThreshold(c, j))
\r
90 currentColour = colors[ResidueProperties.aaIndex[c]];
\r
94 currentColour = Color.white;
\r
97 if(conservationColouring)
\r
98 currentColour = applyConservation(currentColour, j);
\r
101 return currentColour;
\r
106 * Get the percentage threshold for this colour scheme
\r
108 * @return Returns the percentage threshold
\r
110 public int getThreshold()
\r
118 * @param ct DOCUMENT ME!
\r
120 public void setThreshold(int ct, boolean ignoreGaps)
\r
124 this.ignoreGaps = AAFrequency.PID_NOGAPS;
\r
126 this.ignoreGaps = AAFrequency.PID_GAPS;
\r
132 * @param s DOCUMENT ME!
\r
133 * @param j DOCUMENT ME!
\r
135 * @return DOCUMENT ME!
\r
137 public boolean aboveThreshold(char c, int j)
\r
139 if ('a' <= c && c <= 'z')
\r
141 // TO UPPERCASE !!!
\r
142 //Faster than toUpperCase
\r
146 if (consensus == null || consensus[j] == null)
\r
149 if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&
\r
150 consensus[j].contains(String.valueOf(c)))
\r
152 if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
\r
162 public boolean conservationApplied()
\r
164 return conservationColouring;
\r
167 public void setConservationInc(int i)
\r
172 public int getConservationInc()
\r
180 * @param consensus DOCUMENT ME!
\r
182 public void setConsensus(Hashtable [] consensus)
\r
184 if(consensus==null)
\r
187 this.consensus = consensus;
\r
192 public void setConservation(Conservation cons)
\r
196 conservationColouring = false;
\r
197 conservation = null;
\r
201 conservationColouring = true;
\r
202 int i, iSize = cons.getConsSequence().getLength();
\r
203 conservation = new char[iSize];
\r
204 for (i = 0; i < iSize; i++)
\r
205 conservation[i] = cons.getConsSequence().getCharAt(i);
\r
214 * @param s DOCUMENT ME!
\r
215 * @param i DOCUMENT ME!
\r
217 * @return DOCUMENT ME!
\r
220 Color applyConservation(Color currentColour, int i)
\r
223 if ((conservation[i] != '*') && (conservation[i] != '+'))
\r
225 if(jalview.util.Comparison.isGap(conservation[i]))
\r
227 currentColour = Color.white;
\r
231 float t = 11 - (conservation[i] - '0');
\r
234 return Color.white;
\r
237 int red = currentColour.getRed();
\r
238 int green = currentColour.getGreen();
\r
239 int blue = currentColour.getBlue();
\r
241 int dr = 255 - red;
\r
242 int dg = 255 - green;
\r
243 int db = 255 - blue;
\r
249 red += (inc / 20f) * dr;
\r
250 green += (inc / 20f) * dg;
\r
251 blue += (inc / 20f) * db;
\r
253 if (red > 255 || green > 255 || blue > 255)
\r
254 currentColour = Color.white;
\r
256 currentColour = new Color(red, green, blue);
\r
259 return currentColour;
\r