2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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;
25 import jalview.datamodel.*;
27 public class ClustalxColourScheme
28 extends ResidueColourScheme // implements IParameterizable
30 public static Hashtable colhash = new Hashtable();
33 ConsensusColour[] colours;
34 ConsensusColour[] ResidueColour;
36 Consensus[] conses = new Consensus[32];
37 Vector colourTable = new Vector();
38 private boolean includeGaps=true;
41 colhash.put("RED", new Color( (float) 0.9, (float) 0.2, (float) 0.1));
42 colhash.put("BLUE", new Color( (float) 0.5, (float) 0.7, (float) 0.9));
43 colhash.put("GREEN", new Color( (float) 0.1, (float) 0.8, (float) 0.1));
44 colhash.put("ORANGE", new Color( (float) 0.9, (float) 0.6, (float) 0.3));
45 colhash.put("CYAN", new Color( (float) 0.1, (float) 0.7, (float) 0.7));
46 colhash.put("PINK", new Color( (float) 0.9, (float) 0.5, (float) 0.5));
47 colhash.put("MAGENTA", new Color( (float) 0.8, (float) 0.3, (float) 0.8));
48 colhash.put("YELLOW", new Color( (float) 0.8, (float) 0.8, (float) 0.0));
51 public ClustalxColourScheme(Vector seqs, int maxWidth)
53 resetClustalX(seqs, maxWidth);
56 public void resetClustalX(Vector seqs, int maxWidth)
58 cons2 = new int[maxWidth][24];
59 includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to get the current setting of the includeGaps param.
62 // Initialize the array
63 for (int j = 0; j < 24; j++)
65 for (int i = 0; i < maxWidth; i++)
76 while (j < seqs.size())
78 seq = ( (SequenceI) seqs.elementAt(j)).getSequence();
80 int end_j = seq.length - 1;
82 for (i = start; i <= end_j; i++)
84 if ( (seq.length - 1) < i)
90 res = ResidueProperties.aaIndex[seq[i]];
99 this.size = seqs.size();
103 public void makeColours()
105 conses[0] = new Consensus("WLVIMAFCYHP", 60);
106 conses[1] = new Consensus("WLVIMAFCYHP", 80);
107 conses[2] = new Consensus("ED", 50);
108 conses[3] = new Consensus("KR", 60);
109 conses[4] = new Consensus("G", 50);
110 conses[5] = new Consensus("N", 50);
111 conses[6] = new Consensus("QE", 50);
112 conses[7] = new Consensus("P", 50);
113 conses[8] = new Consensus("TS", 50);
115 conses[26] = new Consensus("A", 85);
116 conses[27] = new Consensus("C", 85);
117 conses[10] = new Consensus("E", 85);
118 conses[11] = new Consensus("F", 85);
119 conses[12] = new Consensus("G", 85);
120 conses[13] = new Consensus("H", 85);
121 conses[14] = new Consensus("I", 85);
122 conses[15] = new Consensus("L", 85);
123 conses[16] = new Consensus("M", 85);
124 conses[17] = new Consensus("N", 85);
125 conses[18] = new Consensus("P", 85);
126 conses[19] = new Consensus("Q", 85);
127 conses[20] = new Consensus("R", 85);
128 conses[21] = new Consensus("S", 85);
129 conses[22] = new Consensus("T", 85);
130 conses[23] = new Consensus("V", 85);
131 conses[24] = new Consensus("W", 85);
132 conses[25] = new Consensus("Y", 85);
133 conses[28] = new Consensus("K", 85);
134 conses[29] = new Consensus("D", 85);
136 conses[30] = new Consensus("G", 0);
137 conses[31] = new Consensus("P", 0);
139 // We now construct the colours
140 colours = new ConsensusColour[11];
142 Consensus[] tmp8 = new Consensus[1];
143 tmp8[0] = conses[30]; //G
144 colours[7] = new ConsensusColour( (Color) colhash.get("ORANGE"), tmp8);
146 Consensus[] tmp9 = new Consensus[1];
147 tmp9[0] = conses[31]; //P
148 colours[8] = new ConsensusColour( (Color) colhash.get("YELLOW"), tmp9);
150 Consensus[] tmp10 = new Consensus[1];
151 tmp10[0] = conses[27]; //C
152 colours[9] = new ConsensusColour( (Color) colhash.get("PINK"), tmp8);
154 Consensus[] tmp1 = new Consensus[14];
155 tmp1[0] = conses[0]; //%
156 tmp1[1] = conses[1]; //#
157 tmp1[2] = conses[26]; //A
158 tmp1[3] = conses[27]; //C
159 tmp1[4] = conses[11]; //F
160 tmp1[5] = conses[13]; //H
161 tmp1[6] = conses[14]; //I
162 tmp1[7] = conses[15]; //L
163 tmp1[8] = conses[16]; //M
164 tmp1[9] = conses[23]; //V
165 tmp1[10] = conses[24]; //W
166 tmp1[11] = conses[25]; //Y
167 tmp1[12] = conses[18]; //P
168 tmp1[13] = conses[19]; //p
169 colours[0] = new ConsensusColour( (Color) colhash.get("BLUE"), tmp1);
171 colours[10] = new ConsensusColour( (Color) colhash.get("CYAN"), tmp1);
173 Consensus[] tmp2 = new Consensus[5];
174 tmp2[0] = conses[8]; //t
175 tmp2[1] = conses[21]; //S
176 tmp2[2] = conses[22]; //T
177 tmp2[3] = conses[0]; //%
178 tmp2[4] = conses[1]; //#
179 colours[1] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp2);
181 Consensus[] tmp3 = new Consensus[3];
183 tmp3[0] = conses[17]; //N
184 tmp3[1] = conses[29]; //D
185 tmp3[2] = conses[5]; //n
186 colours[2] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp3);
188 Consensus[] tmp4 = new Consensus[6];
189 tmp4[0] = conses[6]; // q = QE
190 tmp4[1] = conses[19]; //Q
191 tmp4[2] = conses[22]; //E
192 tmp4[3] = conses[3]; //+
193 tmp4[4] = conses[28]; //K
194 tmp4[5] = conses[20]; //R
195 colours[3] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp4);
197 Consensus[] tmp5 = new Consensus[4];
198 tmp5[0] = conses[3]; //+
199 tmp5[1] = conses[28]; //K
200 tmp5[2] = conses[20]; //R
201 tmp5[3] = conses[19]; //Q
202 colours[4] = new ConsensusColour( (Color) colhash.get("RED"), tmp5);
204 Consensus[] tmp6 = new Consensus[5];
205 tmp6[0] = conses[3]; //-
206 tmp6[1] = conses[29]; //D
207 tmp6[2] = conses[10]; //E
208 tmp6[3] = conses[6]; //q
209 tmp6[4] = conses[19]; //Q
210 colours[5] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp6);
212 Consensus[] tmp7 = new Consensus[5];
213 tmp7[0] = conses[3]; //-
214 tmp7[1] = conses[29]; //D
215 tmp7[2] = conses[10]; //E
216 tmp7[3] = conses[17]; //N
217 tmp7[4] = conses[2]; //DE
218 colours[6] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp7);
220 // Now attach the ConsensusColours to the residue letters
221 ResidueColour = new ConsensusColour[20];
222 ResidueColour[0] = colours[0]; // A
223 ResidueColour[1] = colours[4]; // R
224 ResidueColour[2] = colours[2]; // N
225 ResidueColour[3] = colours[6]; // D
226 ResidueColour[4] = colours[0]; // C
227 ResidueColour[5] = colours[3]; // Q
228 ResidueColour[6] = colours[5]; // E
229 ResidueColour[7] = colours[7]; // G
230 ResidueColour[8] = colours[10]; // H
231 ResidueColour[9] = colours[0]; // I
232 ResidueColour[10] = colours[0]; // L
233 ResidueColour[11] = colours[4]; // K
234 ResidueColour[12] = colours[0]; // M
235 ResidueColour[13] = colours[0]; // F
236 ResidueColour[14] = colours[8]; // P
237 ResidueColour[15] = colours[1]; // S
238 ResidueColour[16] = colours[1]; // T
239 ResidueColour[17] = colours[0]; // W
240 ResidueColour[18] = colours[10]; // Y
241 ResidueColour[19] = colours[0]; // V
244 public Color findColour(char c)
249 public Color findColour(char c, int j)
253 if (cons2.length <= j || (includeGaps && threshold != 0 && !aboveThreshold(c, j)))
258 int i = ResidueProperties.aaIndex[c];
260 currentColour = Color.white;
264 return currentColour;
267 for (int k = 0; k < ResidueColour[i].conses.length; k++)
269 if (ResidueColour[i].conses[k].isConserved(cons2, j, size, includeGaps))
271 currentColour = ResidueColour[i].c;
277 if (conses[27].isConserved(cons2, j, size, includeGaps))
279 currentColour = (Color) colhash.get("PINK");
283 if (conservationColouring)
285 currentColour = applyConservation(currentColour, j);
288 return currentColour;
292 * @return the includeGaps
294 protected boolean isIncludeGaps()
300 * @param includeGaps the includeGaps to set
302 protected void setIncludeGaps(boolean includeGaps)
304 this.includeGaps = includeGaps;
308 class ConsensusColour
313 public ConsensusColour(Color c, Consensus[] conses)
315 this.conses = conses;