2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.schemes;
21 import jalview.analysis.*;
34 public class ResidueColourScheme implements ColourSchemeI
37 boolean conservationColouring = false;
38 boolean consensusColouring = false;
43 /* Set when threshold colouring to either pid_gaps or pid_nogaps*/
44 protected String ignoreGaps = "pid_gaps";
46 /** Consenus as a hashtable array */
47 Hashtable [] consensus;
49 /** Conservation string as a char array */
56 * The colour to be calculated, manipulated and returned
58 Color currentColour = null;
63 * Creates a new ResidueColourScheme object.
65 * @param colors DOCUMENT ME!
66 * @param threshold DOCUMENT ME!
68 public ResidueColourScheme(Color[] colours, int threshold)
70 this.colors = colours;
71 this.threshold = threshold;
75 * Creates a new ResidueColourScheme object.
77 public ResidueColourScheme()
82 * Find a colour without an index in a sequence
84 public Color findColour(String aa)
86 return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()];
91 public Color findColour(String s, int j)
94 int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue();
96 if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
98 currentColour = colors[index];
102 currentColour = Color.white;
105 if(conservationColouring)
106 applyConservation(j);
109 return currentColour;
114 * Get the percentage threshold for this colour scheme
116 * @return Returns the percentage threshold
118 public int getThreshold()
126 * @param ct DOCUMENT ME!
128 public void setThreshold(int ct, boolean ignoreGaps)
132 this.ignoreGaps = "pid_nogaps";
134 this.ignoreGaps = "pid_gaps";
140 * @param s DOCUMENT ME!
141 * @param j DOCUMENT ME!
143 * @return DOCUMENT ME!
145 public boolean aboveThreshold(String s, int j)
147 if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) &&
148 consensus[j].contains(s))
150 if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold)
160 public boolean conservationApplied()
162 return conservationColouring;
165 public void setConservationInc(int i)
170 public int getConservationInc()
178 * @param consensus DOCUMENT ME!
180 public void setConsensus(Vector vconsensus)
185 int i, iSize=vconsensus.size();
186 consensus = new Hashtable[iSize];
187 for(i=0; i<iSize; i++)
188 consensus[i] = (Hashtable)vconsensus.elementAt(i);
192 public void setConservation(Conservation cons)
196 conservationColouring = false;
201 conservationColouring = true;
202 int i, iSize = cons.getConsSequence().getLength();
203 conservation = new char[iSize];
204 for (i = 0; i < iSize; i++)
205 conservation[i] = cons.getConsSequence().getCharAt(i);
214 * @param s DOCUMENT ME!
215 * @param i DOCUMENT ME!
217 * @return DOCUMENT ME!
220 void applyConservation(int i)
223 if ((conservation[i] != '*') && (conservation[i] != '+'))
225 if(jalview.util.Comparison.isGap(conservation[i]))
227 currentColour = Color.white;
231 float t = 11 - (conservation[i] - '0');
234 currentColour = Color.white;
238 int red = currentColour.getRed();
239 int green = currentColour.getGreen();
240 int blue = currentColour.getBlue();
243 int dg = 255 - green;
250 red += (inc / 20f) * dr;
251 green += (inc / 20f) * dg;
252 blue += (inc / 20f) * db;
254 if (red > 255 || green > 255 || blue > 255)
255 currentColour = Color.white;
257 currentColour = new Color(red, green, blue);