2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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;
26 import jalview.util.Comparison;
28 import java.awt.Color;
29 import java.util.List;
32 public class ClustalxColourScheme extends ResidueColourScheme
34 private static final int EIGHTY_FIVE = 85;
36 private static final int FIFTY = 50;
38 private static final int EIGHTY = 80;
40 private static final int SIXTY = 60;
44 RED(0.9f, 0.2f, 0.1f), BLUE(0.5f, 0.7f, 0.9f), GREEN(0.1f, 0.8f, 0.1f),
45 ORANGE(0.9f, 0.6f, 0.3f), CYAN(0.1f, 0.7f, 0.7f),
46 PINK(0.9f, 0.5f, 0.5f), MAGENTA(0.8f, 0.3f, 0.8f), YELLOW(0.8f, 0.8f,
51 ClustalColour(float r, float g, float b)
53 colour = new Color(r, g, b);
56 private class ConsensusColour
62 public ConsensusColour(ClustalColour col, Consensus[] conses)
69 private int[][] cons2;
71 private ConsensusColour[] colours;
73 private ConsensusColour[] residueColour;
77 private Consensus[] conses = new Consensus[32];
79 private boolean includeGaps = true;
82 * Default constructor (required for Class.newInstance())
84 public ClustalxColourScheme()
89 public ClustalxColourScheme(AnnotatedCollectionI alignment,
90 Map<SequenceI, SequenceCollectionI> hiddenReps)
92 alignmentChanged(alignment, hiddenReps);
96 public void alignmentChanged(AnnotatedCollectionI alignment,
97 Map<SequenceI, SequenceCollectionI> hiddenReps)
99 int maxWidth = alignment.getWidth();
100 List<SequenceI> seqs = alignment.getSequences(hiddenReps);
101 cons2 = new int[maxWidth][24];
102 includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
103 // get the current setting of the
104 // includeGaps param.
107 for (SequenceI sq : seqs)
109 int end_j = sq.getLength() - 1;
110 int length = sq.getLength();
112 for (int i = 0; i <= end_j; i++)
120 res = ResidueProperties.aaIndex[sq.getCharAt(i)];
126 this.size = seqs.size();
132 conses[0] = new Consensus("WLVIMAFCYHP", SIXTY);
133 conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
134 conses[2] = new Consensus("ED", FIFTY);
135 conses[3] = new Consensus("KR", SIXTY);
136 conses[4] = new Consensus("G", FIFTY);
137 conses[5] = new Consensus("N", FIFTY);
138 conses[6] = new Consensus("QE", FIFTY);
139 conses[7] = new Consensus("P", FIFTY);
140 conses[8] = new Consensus("TS", FIFTY);
142 conses[26] = new Consensus("A", EIGHTY_FIVE);
143 conses[27] = new Consensus("C", EIGHTY_FIVE);
144 conses[10] = new Consensus("E", EIGHTY_FIVE);
145 conses[11] = new Consensus("F", EIGHTY_FIVE);
146 conses[12] = new Consensus("G", EIGHTY_FIVE);
147 conses[13] = new Consensus("H", EIGHTY_FIVE);
148 conses[14] = new Consensus("I", EIGHTY_FIVE);
149 conses[15] = new Consensus("L", EIGHTY_FIVE);
150 conses[16] = new Consensus("M", EIGHTY_FIVE);
151 conses[17] = new Consensus("N", EIGHTY_FIVE);
152 conses[18] = new Consensus("P", EIGHTY_FIVE);
153 conses[19] = new Consensus("Q", EIGHTY_FIVE);
154 conses[20] = new Consensus("R", EIGHTY_FIVE);
155 conses[21] = new Consensus("S", EIGHTY_FIVE);
156 conses[22] = new Consensus("T", EIGHTY_FIVE);
157 conses[23] = new Consensus("V", EIGHTY_FIVE);
158 conses[24] = new Consensus("W", EIGHTY_FIVE);
159 conses[25] = new Consensus("Y", EIGHTY_FIVE);
160 conses[28] = new Consensus("K", EIGHTY_FIVE);
161 conses[29] = new Consensus("D", EIGHTY_FIVE);
163 conses[30] = new Consensus("G", 0);
164 conses[31] = new Consensus("P", 0);
166 // We now construct the colours
167 colours = new ConsensusColour[11];
169 Consensus[] tmp8 = new Consensus[1];
170 tmp8[0] = conses[30]; // G
171 colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8);
173 Consensus[] tmp9 = new Consensus[1];
174 tmp9[0] = conses[31]; // P
175 colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9);
177 Consensus[] tmp10 = new Consensus[1];
178 tmp10[0] = conses[27]; // C
179 colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8);
181 Consensus[] tmp1 = new Consensus[14];
182 tmp1[0] = conses[0]; // %
183 tmp1[1] = conses[1]; // #
184 tmp1[2] = conses[26]; // A
185 tmp1[3] = conses[27]; // C
186 tmp1[4] = conses[11]; // F
187 tmp1[5] = conses[13]; // H
188 tmp1[6] = conses[14]; // I
189 tmp1[7] = conses[15]; // L
190 tmp1[8] = conses[16]; // M
191 tmp1[9] = conses[23]; // V
192 tmp1[10] = conses[24]; // W
193 tmp1[11] = conses[25]; // Y
194 tmp1[12] = conses[18]; // P
195 tmp1[13] = conses[19]; // p
196 colours[0] = new ConsensusColour(ClustalColour.BLUE, tmp1);
198 colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1);
200 Consensus[] tmp2 = new Consensus[5];
201 tmp2[0] = conses[8]; // t
202 tmp2[1] = conses[21]; // S
203 tmp2[2] = conses[22]; // T
204 tmp2[3] = conses[0]; // %
205 tmp2[4] = conses[1]; // #
206 colours[1] = new ConsensusColour(ClustalColour.GREEN, tmp2);
208 Consensus[] tmp3 = new Consensus[3];
210 tmp3[0] = conses[17]; // N
211 tmp3[1] = conses[29]; // D
212 tmp3[2] = conses[5]; // n
213 colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3);
215 Consensus[] tmp4 = new Consensus[6];
216 tmp4[0] = conses[6]; // q = QE
217 tmp4[1] = conses[19]; // Q
218 tmp4[2] = conses[22]; // E
219 tmp4[3] = conses[3]; // +
220 tmp4[4] = conses[28]; // K
221 tmp4[5] = conses[20]; // R
222 colours[3] = new ConsensusColour(ClustalColour.GREEN, tmp4);
224 Consensus[] tmp5 = new Consensus[4];
225 tmp5[0] = conses[3]; // +
226 tmp5[1] = conses[28]; // K
227 tmp5[2] = conses[20]; // R
228 tmp5[3] = conses[19]; // Q
229 colours[4] = new ConsensusColour(ClustalColour.RED, tmp5);
231 Consensus[] tmp6 = new Consensus[6];
232 tmp6[0] = conses[3]; // -
233 tmp6[1] = conses[29]; // D
234 tmp6[2] = conses[10]; // E
235 tmp6[3] = conses[6]; // QE
236 tmp6[4] = conses[19]; // Q
237 tmp6[5] = conses[2]; // DE
238 colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6);
240 Consensus[] tmp7 = new Consensus[5];
241 tmp7[0] = conses[3]; // -
242 tmp7[1] = conses[29]; // D
243 tmp7[2] = conses[10]; // E
244 tmp7[3] = conses[17]; // N
245 tmp7[4] = conses[2]; // DE
246 colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7);
248 // Now attach the ConsensusColours to the residue letters
249 residueColour = new ConsensusColour[20];
250 residueColour[0] = colours[0]; // A
251 residueColour[1] = colours[4]; // R
252 residueColour[2] = colours[2]; // N
253 residueColour[3] = colours[6]; // D
254 residueColour[4] = colours[0]; // C
255 residueColour[5] = colours[3]; // Q
256 residueColour[6] = colours[5]; // E
257 residueColour[7] = colours[7]; // G
258 residueColour[8] = colours[10]; // H
259 residueColour[9] = colours[0]; // I
260 residueColour[10] = colours[0]; // L
261 residueColour[11] = colours[4]; // K
262 residueColour[12] = colours[0]; // M
263 residueColour[13] = colours[0]; // F
264 residueColour[14] = colours[8]; // P
265 residueColour[15] = colours[1]; // S
266 residueColour[16] = colours[1]; // T
267 residueColour[17] = colours[0]; // W
268 residueColour[18] = colours[10]; // Y
269 residueColour[19] = colours[0]; // V
273 public Color findColour(char c)
279 protected Color findColour(char c, int j, SequenceI seq)
281 // TODO why the test for includeGaps here?
282 if (cons2.length <= j || Comparison.isGap(c)
283 /*|| (includeGaps && threshold != 0 && !aboveThreshold(c, j))*/)
288 int i = ResidueProperties.aaIndex[c];
290 Color colour = Color.white;
297 for (int k = 0; k < residueColour[i].cons.length; k++)
299 if (residueColour[i].cons[k].isConserved(cons2, j, size,
302 colour = residueColour[i].c;
309 * override to colour C pink if >85% conserved
311 if (conses[27].isConserved(cons2, j, size, includeGaps))
313 colour = ClustalColour.PINK.colour;
321 * @return the includeGaps
323 protected boolean isIncludeGaps()
330 * the includeGaps to set
332 protected void setIncludeGaps(boolean includeGaps)
334 this.includeGaps = includeGaps;
338 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
339 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
341 ClustalxColourScheme css = new ClustalxColourScheme(sg,
343 css.includeGaps = includeGaps;
348 public boolean isPeptideSpecific()
354 public String getSchemeName()
356 return JalviewColourScheme.Clustal.toString();
360 public boolean isSimple()