2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import jalview.datamodel.AnnotatedCollectionI;
24 import jalview.datamodel.SequenceCollectionI;
25 import jalview.datamodel.SequenceI;
27 import java.awt.Color;
28 import java.util.Hashtable;
29 import java.util.List;
31 import java.util.Vector;
33 public class ClustalxColourScheme extends ResidueColourScheme // implements
36 public static Hashtable colhash = new Hashtable();
42 ConsensusColour[] colours;
44 ConsensusColour[] ResidueColour;
48 Consensus[] conses = new Consensus[32];
50 Vector colourTable = new Vector();
52 private boolean includeGaps = true;
55 colhash.put("RED", new Color((float) 0.9, (float) 0.2, (float) 0.1));
56 colhash.put("BLUE", new Color((float) 0.5, (float) 0.7, (float) 0.9));
57 colhash.put("GREEN", new Color((float) 0.1, (float) 0.8, (float) 0.1));
58 colhash.put("ORANGE", new Color((float) 0.9, (float) 0.6, (float) 0.3));
59 colhash.put("CYAN", new Color((float) 0.1, (float) 0.7, (float) 0.7));
60 colhash.put("PINK", new Color((float) 0.9, (float) 0.5, (float) 0.5));
61 colhash.put("MAGENTA", new Color((float) 0.8, (float) 0.3, (float) 0.8));
62 colhash.put("YELLOW", new Color((float) 0.8, (float) 0.8, (float) 0.0));
65 public ClustalxColourScheme(AnnotatedCollectionI alignment,
66 Map<SequenceI, SequenceCollectionI> hiddenReps)
68 alignmentChanged(alignment, hiddenReps);
71 public void alignmentChanged(AnnotatedCollectionI alignment,
72 Map<SequenceI, SequenceCollectionI> hiddenReps)
74 int maxWidth = alignment.getWidth();
75 List<SequenceI> seqs = alignment.getSequences(hiddenReps);
76 cons2 = new int[maxWidth][24];
77 includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
78 // get the current setting of the
82 // Initialize the array
83 for (int j = 0; j < 24; j++)
85 for (int i = 0; i < maxWidth; i++)
96 for (SequenceI sq : seqs)
98 seq = sq.getSequence();
100 int end_j = seq.length - 1;
102 for (i = start; i <= end_j; i++)
104 if ((seq.length - 1) < i)
110 res = ResidueProperties.aaIndex[seq[i]];
119 this.size = seqs.size();
123 public void makeColours()
125 conses[0] = new Consensus("WLVIMAFCYHP", 60);
126 conses[1] = new Consensus("WLVIMAFCYHP", 80);
127 conses[2] = new Consensus("ED", 50);
128 conses[3] = new Consensus("KR", 60);
129 conses[4] = new Consensus("G", 50);
130 conses[5] = new Consensus("N", 50);
131 conses[6] = new Consensus("QE", 50);
132 conses[7] = new Consensus("P", 50);
133 conses[8] = new Consensus("TS", 50);
135 conses[26] = new Consensus("A", 85);
136 conses[27] = new Consensus("C", 85);
137 conses[10] = new Consensus("E", 85);
138 conses[11] = new Consensus("F", 85);
139 conses[12] = new Consensus("G", 85);
140 conses[13] = new Consensus("H", 85);
141 conses[14] = new Consensus("I", 85);
142 conses[15] = new Consensus("L", 85);
143 conses[16] = new Consensus("M", 85);
144 conses[17] = new Consensus("N", 85);
145 conses[18] = new Consensus("P", 85);
146 conses[19] = new Consensus("Q", 85);
147 conses[20] = new Consensus("R", 85);
148 conses[21] = new Consensus("S", 85);
149 conses[22] = new Consensus("T", 85);
150 conses[23] = new Consensus("V", 85);
151 conses[24] = new Consensus("W", 85);
152 conses[25] = new Consensus("Y", 85);
153 conses[28] = new Consensus("K", 85);
154 conses[29] = new Consensus("D", 85);
156 conses[30] = new Consensus("G", 0);
157 conses[31] = new Consensus("P", 0);
159 // We now construct the colours
160 colours = new ConsensusColour[11];
162 Consensus[] tmp8 = new Consensus[1];
163 tmp8[0] = conses[30]; // G
164 colours[7] = new ConsensusColour((Color) colhash.get("ORANGE"), tmp8);
166 Consensus[] tmp9 = new Consensus[1];
167 tmp9[0] = conses[31]; // P
168 colours[8] = new ConsensusColour((Color) colhash.get("YELLOW"), tmp9);
170 Consensus[] tmp10 = new Consensus[1];
171 tmp10[0] = conses[27]; // C
172 colours[9] = new ConsensusColour((Color) colhash.get("PINK"), tmp8);
174 Consensus[] tmp1 = new Consensus[14];
175 tmp1[0] = conses[0]; // %
176 tmp1[1] = conses[1]; // #
177 tmp1[2] = conses[26]; // A
178 tmp1[3] = conses[27]; // C
179 tmp1[4] = conses[11]; // F
180 tmp1[5] = conses[13]; // H
181 tmp1[6] = conses[14]; // I
182 tmp1[7] = conses[15]; // L
183 tmp1[8] = conses[16]; // M
184 tmp1[9] = conses[23]; // V
185 tmp1[10] = conses[24]; // W
186 tmp1[11] = conses[25]; // Y
187 tmp1[12] = conses[18]; // P
188 tmp1[13] = conses[19]; // p
189 colours[0] = new ConsensusColour((Color) colhash.get("BLUE"), tmp1);
191 colours[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1);
193 Consensus[] tmp2 = new Consensus[5];
194 tmp2[0] = conses[8]; // t
195 tmp2[1] = conses[21]; // S
196 tmp2[2] = conses[22]; // T
197 tmp2[3] = conses[0]; // %
198 tmp2[4] = conses[1]; // #
199 colours[1] = new ConsensusColour((Color) colhash.get("GREEN"), tmp2);
201 Consensus[] tmp3 = new Consensus[3];
203 tmp3[0] = conses[17]; // N
204 tmp3[1] = conses[29]; // D
205 tmp3[2] = conses[5]; // n
206 colours[2] = new ConsensusColour((Color) colhash.get("GREEN"), tmp3);
208 Consensus[] tmp4 = new Consensus[6];
209 tmp4[0] = conses[6]; // q = QE
210 tmp4[1] = conses[19]; // Q
211 tmp4[2] = conses[22]; // E
212 tmp4[3] = conses[3]; // +
213 tmp4[4] = conses[28]; // K
214 tmp4[5] = conses[20]; // R
215 colours[3] = new ConsensusColour((Color) colhash.get("GREEN"), tmp4);
217 Consensus[] tmp5 = new Consensus[4];
218 tmp5[0] = conses[3]; // +
219 tmp5[1] = conses[28]; // K
220 tmp5[2] = conses[20]; // R
221 tmp5[3] = conses[19]; // Q
222 colours[4] = new ConsensusColour((Color) colhash.get("RED"), tmp5);
224 Consensus[] tmp6 = new Consensus[6];
225 tmp6[0] = conses[3]; // -
226 tmp6[1] = conses[29]; // D
227 tmp6[2] = conses[10]; // E
228 tmp6[3] = conses[6]; // QE
229 tmp6[4] = conses[19]; // Q
230 tmp6[5] = conses[2]; // DE
231 colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6);
233 Consensus[] tmp7 = new Consensus[5];
234 tmp7[0] = conses[3]; // -
235 tmp7[1] = conses[29]; // D
236 tmp7[2] = conses[10]; // E
237 tmp7[3] = conses[17]; // N
238 tmp7[4] = conses[2]; // DE
239 colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7);
241 // Now attach the ConsensusColours to the residue letters
242 ResidueColour = new ConsensusColour[20];
243 ResidueColour[0] = colours[0]; // A
244 ResidueColour[1] = colours[4]; // R
245 ResidueColour[2] = colours[2]; // N
246 ResidueColour[3] = colours[6]; // D
247 ResidueColour[4] = colours[0]; // C
248 ResidueColour[5] = colours[3]; // Q
249 ResidueColour[6] = colours[5]; // E
250 ResidueColour[7] = colours[7]; // G
251 ResidueColour[8] = colours[10]; // H
252 ResidueColour[9] = colours[0]; // I
253 ResidueColour[10] = colours[0]; // L
254 ResidueColour[11] = colours[4]; // K
255 ResidueColour[12] = colours[0]; // M
256 ResidueColour[13] = colours[0]; // F
257 ResidueColour[14] = colours[8]; // P
258 ResidueColour[15] = colours[1]; // S
259 ResidueColour[16] = colours[1]; // T
260 ResidueColour[17] = colours[0]; // W
261 ResidueColour[18] = colours[10]; // Y
262 ResidueColour[19] = colours[0]; // V
266 public Color findColour(char c)
272 public Color findColour(char c, int j, SequenceI seq)
276 if (cons2.length <= j
277 || (includeGaps && threshold != 0 && !aboveThreshold(c, j)))
282 int i = ResidueProperties.aaIndex[c];
284 currentColour = Color.white;
288 return currentColour;
291 for (int k = 0; k < ResidueColour[i].conses.length; k++)
293 if (ResidueColour[i].conses[k].isConserved(cons2, j, size,
296 currentColour = ResidueColour[i].c;
302 if (conses[27].isConserved(cons2, j, size, includeGaps))
304 currentColour = (Color) colhash.get("PINK");
308 if (conservationColouring)
310 currentColour = applyConservation(currentColour, j);
313 return currentColour;
317 * @return the includeGaps
319 protected boolean isIncludeGaps()
326 * the includeGaps to set
328 protected void setIncludeGaps(boolean includeGaps)
330 this.includeGaps = includeGaps;
334 public ColourSchemeI applyTo(AnnotatedCollectionI sg,
335 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
337 ClustalxColourScheme css = new ClustalxColourScheme(sg,
339 css.includeGaps = includeGaps;
344 class ConsensusColour
350 public ConsensusColour(Color c, Consensus[] conses)
352 this.conses = conses;