2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
24 import jalview.analysis.*;
32 public class ResidueColourScheme implements ColourSchemeI
35 boolean conservationColouring = false;
37 Color[] colors = null;
41 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
42 protected String ignoreGaps = AAFrequency.PID_GAPS;
44 /** Consenus as a hashtable array */
45 Hashtable[] consensus;
47 /** Conservation string as a char array */
50 int conservationLength = 0;
56 * Creates a new ResidueColourScheme object.
63 public ResidueColourScheme(Color[] colours, int threshold)
65 this.colors = colours;
66 this.threshold = threshold;
70 * Creates a new ResidueColourScheme object.
72 public ResidueColourScheme()
77 * Find a colour without an index in a sequence
79 public Color findColour(char c)
81 return colors == null ? Color.white
82 : colors[ResidueProperties.aaIndex[c]];
85 public Color findColour(char c, int j)
89 if ((threshold == 0) || aboveThreshold(c, j))
91 currentColour = colors[ResidueProperties.aaIndex[c]];
95 currentColour = Color.white;
98 if (conservationColouring)
100 currentColour = applyConservation(currentColour, j);
103 return currentColour;
107 * Get the percentage threshold for this colour scheme
109 * @return Returns the percentage threshold
111 public int getThreshold()
122 public void setThreshold(int ct, boolean ignoreGaps)
127 this.ignoreGaps = AAFrequency.PID_NOGAPS;
131 this.ignoreGaps = AAFrequency.PID_GAPS;
143 * @return DOCUMENT ME!
145 public boolean aboveThreshold(char c, int j)
147 if ('a' <= c && c <= 'z')
150 // Faster than toUpperCase
154 if (consensus == null || consensus.length < j || consensus[j] == null)
159 if ((((Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1)
160 && consensus[j].contains(String.valueOf(c)))
162 if (((Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
171 public boolean conservationApplied()
173 return conservationColouring;
176 public void setConservationInc(int i)
181 public int getConservationInc()
192 public void setConsensus(Hashtable[] consensus)
194 if (consensus == null)
199 this.consensus = consensus;
202 public void setConservation(Conservation cons)
206 conservationColouring = false;
211 conservationColouring = true;
212 int i, iSize = cons.getConsSequence().getLength();
213 conservation = new char[iSize];
214 for (i = 0; i < iSize; i++)
216 conservation[i] = cons.getConsSequence().getCharAt(i);
218 conservationLength = conservation.length;
231 * @return DOCUMENT ME!
234 Color applyConservation(Color currentColour, int i)
237 if ((conservationLength > i) && (conservation[i] != '*')
238 && (conservation[i] != '+'))
240 if (jalview.util.Comparison.isGap(conservation[i]))
242 currentColour = Color.white;
246 float t = 11 - (conservation[i] - '0');
252 int red = currentColour.getRed();
253 int green = currentColour.getGreen();
254 int blue = currentColour.getBlue();
257 int dg = 255 - green;
264 red += (inc / 20f) * dr;
265 green += (inc / 20f) * dg;
266 blue += (inc / 20f) * db;
268 if (red > 255 || green > 255 || blue > 255)
270 currentColour = Color.white;
274 currentColour = new Color(red, green, blue);
278 return currentColour;