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
38 boolean consensusColouring = false;
\r
43 /* Set when threshold colouring to either pid_gaps or pid_nogaps*/
\r
44 protected String ignoreGaps = AAFrequency.PID_GAPS;
\r
46 /** Consenus as a hashtable array */
\r
47 Hashtable [] consensus;
\r
49 /** Conservation string as a char array */
\r
50 char [] conservation;
\r
52 /** DOCUMENT ME!! */
\r
57 * Creates a new ResidueColourScheme object.
\r
59 * @param colors DOCUMENT ME!
\r
60 * @param threshold DOCUMENT ME!
\r
62 public ResidueColourScheme(Color[] colours, int threshold)
\r
64 this.colors = colours;
\r
65 this.threshold = threshold;
\r
69 * Creates a new ResidueColourScheme object.
\r
71 public ResidueColourScheme()
\r
76 * Find a colour without an index in a sequence
\r
78 public Color findColour(char c)
\r
80 return colors[ResidueProperties.aaIndex[c]];
\r
85 public Color findColour(char c, int j)
\r
87 Color currentColour;
\r
89 if ((threshold == 0) || aboveThreshold(c, j))
\r
91 currentColour = colors[ResidueProperties.aaIndex[c]];
\r
95 currentColour = Color.white;
\r
98 if(conservationColouring)
\r
99 currentColour = applyConservation(currentColour, j);
\r
102 return currentColour;
\r
107 * Get the percentage threshold for this colour scheme
\r
109 * @return Returns the percentage threshold
\r
111 public int getThreshold()
\r
119 * @param ct DOCUMENT ME!
\r
121 public void setThreshold(int ct, boolean ignoreGaps)
\r
125 this.ignoreGaps = AAFrequency.PID_NOGAPS;
\r
127 this.ignoreGaps = AAFrequency.PID_GAPS;
\r
133 * @param s DOCUMENT ME!
\r
134 * @param j DOCUMENT ME!
\r
136 * @return DOCUMENT ME!
\r
138 public boolean aboveThreshold(char c, int j)
\r
140 if ('a' <= c && c <= 'z')
\r
142 // TO UPPERCASE !!!
\r
143 //Faster than toUpperCase
\r
147 if (consensus == null || consensus[j] == null)
\r
150 if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&
\r
151 consensus[j].contains(String.valueOf(c)))
\r
153 if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
\r
163 public boolean conservationApplied()
\r
165 return conservationColouring;
\r
168 public void setConservationInc(int i)
\r
173 public int getConservationInc()
\r
181 * @param consensus DOCUMENT ME!
\r
183 public void setConsensus(Hashtable [] consensus)
\r
185 if(consensus==null)
\r
188 this.consensus = consensus;
\r
193 public void setConservation(Conservation cons)
\r
197 conservationColouring = false;
\r
198 conservation = null;
\r
202 conservationColouring = true;
\r
203 int i, iSize = cons.getConsSequence().getLength();
\r
204 conservation = new char[iSize];
\r
205 for (i = 0; i < iSize; i++)
\r
206 conservation[i] = cons.getConsSequence().getCharAt(i);
\r
215 * @param s DOCUMENT ME!
\r
216 * @param i DOCUMENT ME!
\r
218 * @return DOCUMENT ME!
\r
221 Color applyConservation(Color currentColour, int i)
\r
224 if ((conservation[i] != '*') && (conservation[i] != '+'))
\r
226 if(jalview.util.Comparison.isGap(conservation[i]))
\r
228 currentColour = Color.white;
\r
232 float t = 11 - (conservation[i] - '0');
\r
235 return Color.white;
\r
238 int red = currentColour.getRed();
\r
239 int green = currentColour.getGreen();
\r
240 int blue = currentColour.getBlue();
\r
242 int dr = 255 - red;
\r
243 int dg = 255 - green;
\r
244 int db = 255 - blue;
\r
250 red += (inc / 20f) * dr;
\r
251 green += (inc / 20f) * dg;
\r
252 blue += (inc / 20f) * db;
\r
254 if (red > 255 || green > 255 || blue > 255)
\r
255 currentColour = Color.white;
\r
257 currentColour = new Color(red, green, blue);
\r
260 return currentColour;
\r