2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
25 import jalview.datamodel.*;
\r
27 public class ClustalxColourScheme
\r
28 extends ResidueColourScheme
\r
30 public static Hashtable colhash = new Hashtable();
\r
33 ConsensusColour[] colours;
\r
34 ConsensusColour[] ResidueColour;
\r
36 Consensus[] conses = new Consensus[32];
\r
37 Vector colourTable = new Vector();
\r
40 colhash.put("RED", new Color( (float) 0.9, (float) 0.2, (float) 0.1));
\r
41 colhash.put("BLUE", new Color( (float) 0.5, (float) 0.7, (float) 0.9));
\r
42 colhash.put("GREEN", new Color( (float) 0.1, (float) 0.8, (float) 0.1));
\r
43 colhash.put("ORANGE", new Color( (float) 0.9, (float) 0.6, (float) 0.3));
\r
44 colhash.put("CYAN", new Color( (float) 0.1, (float) 0.7, (float) 0.7));
\r
45 colhash.put("PINK", new Color( (float) 0.9, (float) 0.5, (float) 0.5));
\r
46 colhash.put("MAGENTA", new Color( (float) 0.8, (float) 0.3, (float) 0.8));
\r
47 colhash.put("YELLOW", new Color( (float) 0.8, (float) 0.8, (float) 0.0));
\r
50 public ClustalxColourScheme(Vector seqs, int maxWidth)
\r
52 resetClustalX(seqs, maxWidth);
\r
55 public void resetClustalX(Vector seqs, int maxWidth)
\r
57 cons2 = new int[maxWidth][24];
\r
61 // Initialize the array
\r
62 for (int j = 0; j < 24; j++)
\r
64 for (int i = 0; i < maxWidth; i++)
\r
75 while (j < seqs.size())
\r
77 seq = ( (SequenceI) seqs.elementAt(j)).getSequence();
\r
79 int end_j = seq.length - 1;
\r
81 for (i = start; i <= end_j; i++)
\r
83 if ( (seq.length - 1) < i)
\r
89 res = ResidueProperties.aaIndex[seq[i]];
\r
98 this.size = seqs.size();
\r
102 public void makeColours()
\r
104 conses[0] = new Consensus("WLVIMAFCYHP", 60);
\r
105 conses[1] = new Consensus("WLVIMAFCYHP", 80);
\r
106 conses[2] = new Consensus("ED", 50);
\r
107 conses[3] = new Consensus("KR", 60);
\r
108 conses[4] = new Consensus("G", 50);
\r
109 conses[5] = new Consensus("N", 50);
\r
110 conses[6] = new Consensus("QE", 50);
\r
111 conses[7] = new Consensus("P", 50);
\r
112 conses[8] = new Consensus("TS", 50);
\r
114 conses[26] = new Consensus("A", 85);
\r
115 conses[27] = new Consensus("C", 85);
\r
116 conses[10] = new Consensus("E", 85);
\r
117 conses[11] = new Consensus("F", 85);
\r
118 conses[12] = new Consensus("G", 85);
\r
119 conses[13] = new Consensus("H", 85);
\r
120 conses[14] = new Consensus("I", 85);
\r
121 conses[15] = new Consensus("L", 85);
\r
122 conses[16] = new Consensus("M", 85);
\r
123 conses[17] = new Consensus("N", 85);
\r
124 conses[18] = new Consensus("P", 85);
\r
125 conses[19] = new Consensus("Q", 85);
\r
126 conses[20] = new Consensus("R", 85);
\r
127 conses[21] = new Consensus("S", 85);
\r
128 conses[22] = new Consensus("T", 85);
\r
129 conses[23] = new Consensus("V", 85);
\r
130 conses[24] = new Consensus("W", 85);
\r
131 conses[25] = new Consensus("Y", 85);
\r
132 conses[28] = new Consensus("K", 85);
\r
133 conses[29] = new Consensus("D", 85);
\r
135 conses[30] = new Consensus("G", 0);
\r
136 conses[31] = new Consensus("P", 0);
\r
138 // We now construct the colours
\r
139 colours = new ConsensusColour[11];
\r
141 Consensus[] tmp8 = new Consensus[1];
\r
142 tmp8[0] = conses[30]; //G
\r
143 colours[7] = new ConsensusColour( (Color) colhash.get("ORANGE"), tmp8);
\r
145 Consensus[] tmp9 = new Consensus[1];
\r
146 tmp9[0] = conses[31]; //P
\r
147 colours[8] = new ConsensusColour( (Color) colhash.get("YELLOW"), tmp9);
\r
149 Consensus[] tmp10 = new Consensus[1];
\r
150 tmp10[0] = conses[27]; //C
\r
151 colours[9] = new ConsensusColour( (Color) colhash.get("PINK"), tmp8);
\r
153 Consensus[] tmp1 = new Consensus[14];
\r
154 tmp1[0] = conses[0]; //%
\r
155 tmp1[1] = conses[1]; //#
\r
156 tmp1[2] = conses[26]; //A
\r
157 tmp1[3] = conses[27]; //C
\r
158 tmp1[4] = conses[11]; //F
\r
159 tmp1[5] = conses[13]; //H
\r
160 tmp1[6] = conses[14]; //I
\r
161 tmp1[7] = conses[15]; //L
\r
162 tmp1[8] = conses[16]; //M
\r
163 tmp1[9] = conses[23]; //V
\r
164 tmp1[10] = conses[24]; //W
\r
165 tmp1[11] = conses[25]; //Y
\r
166 tmp1[12] = conses[18]; //P
\r
167 tmp1[13] = conses[19]; //p
\r
168 colours[0] = new ConsensusColour( (Color) colhash.get("BLUE"), tmp1);
\r
170 colours[10] = new ConsensusColour( (Color) colhash.get("CYAN"), tmp1);
\r
172 Consensus[] tmp2 = new Consensus[5];
\r
173 tmp2[0] = conses[8]; //t
\r
174 tmp2[1] = conses[21]; //S
\r
175 tmp2[2] = conses[22]; //T
\r
176 tmp2[3] = conses[0]; //%
\r
177 tmp2[4] = conses[1]; //#
\r
178 colours[1] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp2);
\r
180 Consensus[] tmp3 = new Consensus[3];
\r
182 tmp3[0] = conses[17]; //N
\r
183 tmp3[1] = conses[29]; //D
\r
184 tmp3[2] = conses[5]; //n
\r
185 colours[2] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp3);
\r
187 Consensus[] tmp4 = new Consensus[6];
\r
188 tmp4[0] = conses[6]; // q = QE
\r
189 tmp4[1] = conses[19]; //Q
\r
190 tmp4[2] = conses[22]; //E
\r
191 tmp4[3] = conses[3]; //+
\r
192 tmp4[4] = conses[28]; //K
\r
193 tmp4[5] = conses[20]; //R
\r
194 colours[3] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp4);
\r
196 Consensus[] tmp5 = new Consensus[4];
\r
197 tmp5[0] = conses[3]; //+
\r
198 tmp5[1] = conses[28]; //K
\r
199 tmp5[2] = conses[20]; //R
\r
200 tmp5[3] = conses[19]; //Q
\r
201 colours[4] = new ConsensusColour( (Color) colhash.get("RED"), tmp5);
\r
203 Consensus[] tmp6 = new Consensus[5];
\r
204 tmp6[0] = conses[3]; //-
\r
205 tmp6[1] = conses[29]; //D
\r
206 tmp6[2] = conses[10]; //E
\r
207 tmp6[3] = conses[6]; //q
\r
208 tmp6[4] = conses[19]; //Q
\r
209 colours[5] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp6);
\r
211 Consensus[] tmp7 = new Consensus[5];
\r
212 tmp7[0] = conses[3]; //-
\r
213 tmp7[1] = conses[29]; //D
\r
214 tmp7[2] = conses[10]; //E
\r
215 tmp7[3] = conses[17]; //N
\r
216 tmp7[4] = conses[2]; //DE
\r
217 colours[6] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp7);
\r
219 // Now attach the ConsensusColours to the residue letters
\r
220 ResidueColour = new ConsensusColour[20];
\r
221 ResidueColour[0] = colours[0]; // A
\r
222 ResidueColour[1] = colours[4]; // R
\r
223 ResidueColour[2] = colours[2]; // N
\r
224 ResidueColour[3] = colours[6]; // D
\r
225 ResidueColour[4] = colours[0]; // C
\r
226 ResidueColour[5] = colours[3]; // Q
\r
227 ResidueColour[6] = colours[5]; // E
\r
228 ResidueColour[7] = colours[7]; // G
\r
229 ResidueColour[8] = colours[10]; // H
\r
230 ResidueColour[9] = colours[0]; // I
\r
231 ResidueColour[10] = colours[0]; // L
\r
232 ResidueColour[11] = colours[4]; // K
\r
233 ResidueColour[12] = colours[0]; // M
\r
234 ResidueColour[13] = colours[0]; // F
\r
235 ResidueColour[14] = colours[8]; // P
\r
236 ResidueColour[15] = colours[1]; // S
\r
237 ResidueColour[16] = colours[1]; // T
\r
238 ResidueColour[17] = colours[0]; // W
\r
239 ResidueColour[18] = colours[10]; // Y
\r
240 ResidueColour[19] = colours[0]; // V
\r
243 public Color findColour(char c)
\r
248 public Color findColour(char c, int j)
\r
250 Color currentColour;
\r
252 if (cons2.length <= j || (threshold != 0 && !aboveThreshold(c, j)))
\r
254 return Color.white;
\r
257 int i = ResidueProperties.aaIndex[c];
\r
259 currentColour = Color.white;
\r
263 return currentColour;
\r
266 for (int k = 0; k < ResidueColour[i].conses.length; k++)
\r
268 if (ResidueColour[i].conses[k].isConserved(cons2, j, size))
\r
270 currentColour = ResidueColour[i].c;
\r
276 if (conses[27].isConserved(cons2, j, size))
\r
278 currentColour = (Color) colhash.get("PINK");
\r
282 if (conservationColouring)
\r
284 currentColour = applyConservation(currentColour, j);
\r
287 return currentColour;
\r
291 class ConsensusColour
\r
293 Consensus[] conses;
\r
296 public ConsensusColour(Color c, Consensus[] conses)
\r
298 this.conses = conses;
\r
300 // this.list = list;
\r