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(String aa)
\r
80 return colors[ResidueProperties.aaIndex[aa.charAt(0)]];
\r
85 public Color findColour(String s, int j)
\r
87 Color currentColour;
\r
88 int index = ResidueProperties.aaIndex[s.charAt(0)];
\r
90 if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
\r
92 currentColour = colors[index];
\r
96 currentColour = Color.white;
\r
99 if(conservationColouring)
\r
100 currentColour = applyConservation(currentColour, j);
\r
103 return currentColour;
\r
108 * Get the percentage threshold for this colour scheme
\r
110 * @return Returns the percentage threshold
\r
112 public int getThreshold()
\r
120 * @param ct DOCUMENT ME!
\r
122 public void setThreshold(int ct, boolean ignoreGaps)
\r
126 this.ignoreGaps = AAFrequency.PID_NOGAPS;
\r
128 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(String s, int j)
\r
141 char c = s.charAt(0);
\r
142 if ('a' <= c && c <= 'z')
\r
144 // TO UPPERCASE !!!
\r
145 //Faster than toUpperCase
\r
147 s = String.valueOf(c);
\r
150 if (consensus == null || consensus[j] == null)
\r
153 if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&
\r
154 consensus[j].contains(s))
\r
156 if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
\r
166 public boolean conservationApplied()
\r
168 return conservationColouring;
\r
171 public void setConservationInc(int i)
\r
176 public int getConservationInc()
\r
184 * @param consensus DOCUMENT ME!
\r
186 public void setConsensus(Hashtable [] consensus)
\r
188 if(consensus==null)
\r
191 this.consensus = consensus;
\r
196 public void setConservation(Conservation cons)
\r
200 conservationColouring = false;
\r
201 conservation = null;
\r
205 conservationColouring = true;
\r
206 int i, iSize = cons.getConsSequence().getLength();
\r
207 conservation = new char[iSize];
\r
208 for (i = 0; i < iSize; i++)
\r
209 conservation[i] = cons.getConsSequence().getCharAt(i);
\r
218 * @param s DOCUMENT ME!
\r
219 * @param i DOCUMENT ME!
\r
221 * @return DOCUMENT ME!
\r
224 Color applyConservation(Color currentColour, int i)
\r
227 if ((conservation[i] != '*') && (conservation[i] != '+'))
\r
229 if(jalview.util.Comparison.isGap(conservation[i]))
\r
231 currentColour = Color.white;
\r
235 float t = 11 - (conservation[i] - '0');
\r
238 return Color.white;
\r
241 int red = currentColour.getRed();
\r
242 int green = currentColour.getGreen();
\r
243 int blue = currentColour.getBlue();
\r
245 int dr = 255 - red;
\r
246 int dg = 255 - green;
\r
247 int db = 255 - blue;
\r
253 red += (inc / 20f) * dr;
\r
254 green += (inc / 20f) * dg;
\r
255 blue += (inc / 20f) * db;
\r
257 if (red > 255 || green > 255 || blue > 255)
\r
258 currentColour = Color.white;
\r
260 currentColour = new Color(red, green, blue);
\r
263 return currentColour;
\r