2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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;
20 import jalview.datamodel.AnnotatedCollectionI;
21 import jalview.datamodel.SequenceCollectionI;
22 import jalview.datamodel.SequenceI;
24 import java.awt.Color;
25 import java.util.Hashtable;
26 import java.util.List;
28 import java.util.Vector;
30 public class ClustalxColourScheme extends ResidueColourScheme // implements
33 public static Hashtable colhash = new Hashtable();
39 ConsensusColour[] colours;
41 ConsensusColour[] ResidueColour;
45 Consensus[] conses = new Consensus[32];
47 Vector colourTable = new Vector();
49 private boolean includeGaps = true;
52 colhash.put("RED", new Color((float) 0.9, (float) 0.2, (float) 0.1));
53 colhash.put("BLUE", new Color((float) 0.5, (float) 0.7, (float) 0.9));
54 colhash.put("GREEN", new Color((float) 0.1, (float) 0.8, (float) 0.1));
55 colhash.put("ORANGE", new Color((float) 0.9, (float) 0.6, (float) 0.3));
56 colhash.put("CYAN", new Color((float) 0.1, (float) 0.7, (float) 0.7));
57 colhash.put("PINK", new Color((float) 0.9, (float) 0.5, (float) 0.5));
58 colhash.put("MAGENTA", new Color((float) 0.8, (float) 0.3, (float) 0.8));
59 colhash.put("YELLOW", new Color((float) 0.8, (float) 0.8, (float) 0.0));
62 public ClustalxColourScheme(AnnotatedCollectionI alignment,
63 Map<SequenceI, SequenceCollectionI> hiddenReps)
65 alignmentChanged(alignment, hiddenReps);
68 public void alignmentChanged(AnnotatedCollectionI alignment,
69 Map<SequenceI, SequenceCollectionI> hiddenReps)
71 int maxWidth = alignment.getWidth();
72 List<SequenceI> seqs = alignment.getSequences(hiddenReps);
73 cons2 = new int[maxWidth][24];
74 includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
75 // get the current setting of the
79 // Initialize the array
80 for (int j = 0; j < 24; j++)
82 for (int i = 0; i < maxWidth; i++)
93 for (SequenceI sq : seqs)
95 seq = sq.getSequence();
97 int end_j = seq.length - 1;
99 for (i = start; i <= end_j; i++)
101 if ((seq.length - 1) < i)
107 res = ResidueProperties.aaIndex[seq[i]];
116 this.size = seqs.size();
120 public void makeColours()
122 conses[0] = new Consensus("WLVIMAFCYHP", 60);
123 conses[1] = new Consensus("WLVIMAFCYHP", 80);
124 conses[2] = new Consensus("ED", 50);
125 conses[3] = new Consensus("KR", 60);
126 conses[4] = new Consensus("G", 50);
127 conses[5] = new Consensus("N", 50);
128 conses[6] = new Consensus("QE", 50);
129 conses[7] = new Consensus("P", 50);
130 conses[8] = new Consensus("TS", 50);
132 conses[26] = new Consensus("A", 85);
133 conses[27] = new Consensus("C", 85);
134 conses[10] = new Consensus("E", 85);
135 conses[11] = new Consensus("F", 85);
136 conses[12] = new Consensus("G", 85);
137 conses[13] = new Consensus("H", 85);
138 conses[14] = new Consensus("I", 85);
139 conses[15] = new Consensus("L", 85);
140 conses[16] = new Consensus("M", 85);
141 conses[17] = new Consensus("N", 85);
142 conses[18] = new Consensus("P", 85);
143 conses[19] = new Consensus("Q", 85);
144 conses[20] = new Consensus("R", 85);
145 conses[21] = new Consensus("S", 85);
146 conses[22] = new Consensus("T", 85);
147 conses[23] = new Consensus("V", 85);
148 conses[24] = new Consensus("W", 85);
149 conses[25] = new Consensus("Y", 85);
150 conses[28] = new Consensus("K", 85);
151 conses[29] = new Consensus("D", 85);
153 conses[30] = new Consensus("G", 0);
154 conses[31] = new Consensus("P", 0);
156 // We now construct the colours
157 colours = new ConsensusColour[11];
159 Consensus[] tmp8 = new Consensus[1];
160 tmp8[0] = conses[30]; // G
161 colours[7] = new ConsensusColour((Color) colhash.get("ORANGE"), tmp8);
163 Consensus[] tmp9 = new Consensus[1];
164 tmp9[0] = conses[31]; // P
165 colours[8] = new ConsensusColour((Color) colhash.get("YELLOW"), tmp9);
167 Consensus[] tmp10 = new Consensus[1];
168 tmp10[0] = conses[27]; // C
169 colours[9] = new ConsensusColour((Color) colhash.get("PINK"), tmp8);
171 Consensus[] tmp1 = new Consensus[14];
172 tmp1[0] = conses[0]; // %
173 tmp1[1] = conses[1]; // #
174 tmp1[2] = conses[26]; // A
175 tmp1[3] = conses[27]; // C
176 tmp1[4] = conses[11]; // F
177 tmp1[5] = conses[13]; // H
178 tmp1[6] = conses[14]; // I
179 tmp1[7] = conses[15]; // L
180 tmp1[8] = conses[16]; // M
181 tmp1[9] = conses[23]; // V
182 tmp1[10] = conses[24]; // W
183 tmp1[11] = conses[25]; // Y
184 tmp1[12] = conses[18]; // P
185 tmp1[13] = conses[19]; // p
186 colours[0] = new ConsensusColour((Color) colhash.get("BLUE"), tmp1);
188 colours[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1);
190 Consensus[] tmp2 = new Consensus[5];
191 tmp2[0] = conses[8]; // t
192 tmp2[1] = conses[21]; // S
193 tmp2[2] = conses[22]; // T
194 tmp2[3] = conses[0]; // %
195 tmp2[4] = conses[1]; // #
196 colours[1] = new ConsensusColour((Color) colhash.get("GREEN"), tmp2);
198 Consensus[] tmp3 = new Consensus[3];
200 tmp3[0] = conses[17]; // N
201 tmp3[1] = conses[29]; // D
202 tmp3[2] = conses[5]; // n
203 colours[2] = new ConsensusColour((Color) colhash.get("GREEN"), tmp3);
205 Consensus[] tmp4 = new Consensus[6];
206 tmp4[0] = conses[6]; // q = QE
207 tmp4[1] = conses[19]; // Q
208 tmp4[2] = conses[22]; // E
209 tmp4[3] = conses[3]; // +
210 tmp4[4] = conses[28]; // K
211 tmp4[5] = conses[20]; // R
212 colours[3] = new ConsensusColour((Color) colhash.get("GREEN"), tmp4);
214 Consensus[] tmp5 = new Consensus[4];
215 tmp5[0] = conses[3]; // +
216 tmp5[1] = conses[28]; // K
217 tmp5[2] = conses[20]; // R
218 tmp5[3] = conses[19]; // Q
219 colours[4] = new ConsensusColour((Color) colhash.get("RED"), tmp5);
221 Consensus[] tmp6 = new Consensus[6];
222 tmp6[0] = conses[3]; // -
223 tmp6[1] = conses[29]; // D
224 tmp6[2] = conses[10]; // E
225 tmp6[3] = conses[6]; // QE
226 tmp6[4] = conses[19]; // Q
227 tmp6[5] = conses[2]; // DE
228 colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6);
230 Consensus[] tmp7 = new Consensus[5];
231 tmp7[0] = conses[3]; // -
232 tmp7[1] = conses[29]; // D
233 tmp7[2] = conses[10]; // E
234 tmp7[3] = conses[17]; // N
235 tmp7[4] = conses[2]; // DE
236 colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7);
238 // Now attach the ConsensusColours to the residue letters
239 ResidueColour = new ConsensusColour[20];
240 ResidueColour[0] = colours[0]; // A
241 ResidueColour[1] = colours[4]; // R
242 ResidueColour[2] = colours[2]; // N
243 ResidueColour[3] = colours[6]; // D
244 ResidueColour[4] = colours[0]; // C
245 ResidueColour[5] = colours[3]; // Q
246 ResidueColour[6] = colours[5]; // E
247 ResidueColour[7] = colours[7]; // G
248 ResidueColour[8] = colours[10]; // H
249 ResidueColour[9] = colours[0]; // I
250 ResidueColour[10] = colours[0]; // L
251 ResidueColour[11] = colours[4]; // K
252 ResidueColour[12] = colours[0]; // M
253 ResidueColour[13] = colours[0]; // F
254 ResidueColour[14] = colours[8]; // P
255 ResidueColour[15] = colours[1]; // S
256 ResidueColour[16] = colours[1]; // T
257 ResidueColour[17] = colours[0]; // W
258 ResidueColour[18] = colours[10]; // Y
259 ResidueColour[19] = colours[0]; // V
263 public Color findColour(char c)
269 public Color findColour(char c, int j, SequenceI seq)
273 if (cons2.length <= j
274 || (includeGaps && threshold != 0 && !aboveThreshold(c, j)))
279 int i = ResidueProperties.aaIndex[c];
281 currentColour = Color.white;
285 return currentColour;
288 for (int k = 0; k < ResidueColour[i].conses.length; k++)
290 if (ResidueColour[i].conses[k].isConserved(cons2, j, size,
293 currentColour = ResidueColour[i].c;
299 if (conses[27].isConserved(cons2, j, size, includeGaps))
301 currentColour = (Color) colhash.get("PINK");
305 if (conservationColouring)
307 currentColour = applyConservation(currentColour, j);
310 return currentColour;
314 * @return the includeGaps
316 protected boolean isIncludeGaps()
323 * the includeGaps to set
325 protected void setIncludeGaps(boolean includeGaps)
327 this.includeGaps = includeGaps;
331 class ConsensusColour
337 public ConsensusColour(Color c, Consensus[] conses)
339 this.conses = conses;