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
56 * The colour to be calculated, manipulated and returned
\r
58 Color currentColour = null;
\r
63 * Creates a new ResidueColourScheme object.
\r
65 * @param colors DOCUMENT ME!
\r
66 * @param threshold DOCUMENT ME!
\r
68 public ResidueColourScheme(Color[] colours, int threshold)
\r
70 this.colors = colours;
\r
71 this.threshold = threshold;
\r
75 * Creates a new ResidueColourScheme object.
\r
77 public ResidueColourScheme()
\r
82 * Find a colour without an index in a sequence
\r
84 public Color findColour(String aa)
\r
86 return colors[ResidueProperties.aaIndex[aa.charAt(0)]];
\r
91 public Color findColour(String s, int j)
\r
94 int index = ResidueProperties.aaIndex[s.charAt(0)];
\r
96 if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
\r
98 currentColour = colors[index];
\r
102 currentColour = Color.white;
\r
105 if(conservationColouring)
\r
106 applyConservation(j);
\r
109 return currentColour;
\r
114 * Get the percentage threshold for this colour scheme
\r
116 * @return Returns the percentage threshold
\r
118 public int getThreshold()
\r
126 * @param ct DOCUMENT ME!
\r
128 public void setThreshold(int ct, boolean ignoreGaps)
\r
132 this.ignoreGaps = AAFrequency.PID_NOGAPS;
\r
134 this.ignoreGaps = AAFrequency.PID_GAPS;
\r
140 * @param s DOCUMENT ME!
\r
141 * @param j DOCUMENT ME!
\r
143 * @return DOCUMENT ME!
\r
145 public boolean aboveThreshold(String s, int j)
\r
147 char c = s.charAt(0);
\r
148 if ('a' <= c && c <= 'z')
\r
150 // TO UPPERCASE !!!
\r
151 //Faster than toUpperCase
\r
153 s = String.valueOf(c);
\r
156 if (consensus == null || consensus[j] == null)
\r
159 if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&
\r
160 consensus[j].contains(s))
\r
162 if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
\r
172 public boolean conservationApplied()
\r
174 return conservationColouring;
\r
177 public void setConservationInc(int i)
\r
182 public int getConservationInc()
\r
190 * @param consensus DOCUMENT ME!
\r
192 public void setConsensus(Hashtable [] consensus)
\r
194 if(consensus==null)
\r
197 this.consensus = consensus;
\r
202 public void setConservation(Conservation cons)
\r
206 conservationColouring = false;
\r
207 conservation = null;
\r
211 conservationColouring = true;
\r
212 int i, iSize = cons.getConsSequence().getLength();
\r
213 conservation = new char[iSize];
\r
214 for (i = 0; i < iSize; i++)
\r
215 conservation[i] = cons.getConsSequence().getCharAt(i);
\r
224 * @param s DOCUMENT ME!
\r
225 * @param i DOCUMENT ME!
\r
227 * @return DOCUMENT ME!
\r
230 void applyConservation(int i)
\r
233 if ((conservation[i] != '*') && (conservation[i] != '+'))
\r
235 if(jalview.util.Comparison.isGap(conservation[i]))
\r
237 currentColour = Color.white;
\r
241 float t = 11 - (conservation[i] - '0');
\r
244 currentColour = Color.white;
\r
248 int red = currentColour.getRed();
\r
249 int green = currentColour.getGreen();
\r
250 int blue = currentColour.getBlue();
\r
252 int dr = 255 - red;
\r
253 int dg = 255 - green;
\r
254 int db = 255 - blue;
\r
260 red += (inc / 20f) * dr;
\r
261 green += (inc / 20f) * dg;
\r
262 blue += (inc / 20f) * db;
\r
264 if (red > 255 || green > 255 || blue > 255)
\r
265 currentColour = Color.white;
\r
267 currentColour = new Color(red, green, blue);
\r