Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.schemes

File ClustalxColourScheme.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

16
161
14
3
364
270
23
0.14
11.5
4.67
1.64

Classes

Class Line # Actions
ClustalxColourScheme 32 158 21 8
0.956989295.7%
ClustalxColourScheme.ClustalColour 42 1 1 0
1.0100%
ClustalxColourScheme.ConsensusColour 57 2 1 0
1.0100%
 

Contributing tests

This file is covered by 79 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.schemes;
22   
23    import jalview.datamodel.AnnotatedCollectionI;
24    import jalview.datamodel.SequenceCollectionI;
25    import jalview.datamodel.SequenceI;
26    import jalview.util.Comparison;
27   
28    import java.awt.Color;
29    import java.util.List;
30    import java.util.Map;
31   
 
32    public class ClustalxColourScheme extends ResidueColourScheme
33    {
34    private static final int EIGHTY_FIVE = 85;
35   
36    private static final int FIFTY = 50;
37   
38    private static final int EIGHTY = 80;
39   
40    private static final int SIXTY = 60;
41   
 
42    enum ClustalColour
43    {
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),
47    YELLOW(0.8f, 0.8f, 0.0f);
48   
49    final Color colour;
50   
 
51  8 toggle ClustalColour(float r, float g, float b)
52    {
53  8 colour = new Color(r, g, b);
54    }
55    }
56   
 
57    private class ConsensusColour
58    {
59    Consensus[] cons;
60   
61    Color c;
62   
 
63  132 toggle public ConsensusColour(ClustalColour col, Consensus[] conses)
64    {
65  132 this.cons = conses;
66  132 this.c = col.colour;
67    }
68    }
69   
70    private int[][] cons2;
71   
72    private ConsensusColour[] colours;
73   
74    private ConsensusColour[] residueColour;
75   
76    private int size;
77   
78    private Consensus[] conses = new Consensus[32];
79   
80    private boolean includeGaps = true;
81   
82    /**
83    * Default constructor (required for Class.newInstance())
84    */
 
85  1 toggle public ClustalxColourScheme()
86    {
87   
88    }
89   
 
90  11 toggle public ClustalxColourScheme(AnnotatedCollectionI alignment,
91    Map<SequenceI, SequenceCollectionI> hiddenReps)
92    {
93  11 alignmentChanged(alignment, hiddenReps);
94    }
95   
 
96  12 toggle @Override
97    public void alignmentChanged(AnnotatedCollectionI alignment,
98    Map<SequenceI, SequenceCollectionI> hiddenReps)
99    {
100  12 int maxWidth = alignment.getWidth();
101  12 List<SequenceI> seqs = alignment.getSequences(hiddenReps);
102  12 cons2 = new int[maxWidth][24];
103  12 includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
104    // get the current setting of the
105    // includeGaps param.
106  12 int res = 0;
107   
108  12 for (SequenceI sq : seqs)
109    {
110  67 int end_j = sq.getLength() - 1;
111  67 int length = sq.getLength();
112   
113  7271 for (int i = 0; i <= end_j; i++)
114    {
115  7204 if (length - 1 < i)
116    {
117  0 res = 23;
118    }
119    else
120    {
121  7204 res = ResidueProperties.aaIndex[sq.getCharAt(i)];
122    }
123  7204 cons2[i][res]++;
124    }
125    }
126   
127  12 this.size = seqs.size();
128  12 makeColours();
129    }
130   
 
131  12 toggle void makeColours()
132    {
133  12 conses[0] = new Consensus("WLVIMAFCYHP", SIXTY);
134  12 conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
135  12 conses[2] = new Consensus("ED", FIFTY);
136  12 conses[3] = new Consensus("KR", SIXTY);
137  12 conses[4] = new Consensus("G", FIFTY);
138  12 conses[5] = new Consensus("N", FIFTY);
139  12 conses[6] = new Consensus("QE", FIFTY);
140  12 conses[7] = new Consensus("P", FIFTY);
141  12 conses[8] = new Consensus("TS", FIFTY);
142   
143  12 conses[26] = new Consensus("A", EIGHTY_FIVE);
144  12 conses[27] = new Consensus("C", EIGHTY_FIVE);
145  12 conses[10] = new Consensus("E", EIGHTY_FIVE);
146  12 conses[11] = new Consensus("F", EIGHTY_FIVE);
147  12 conses[12] = new Consensus("G", EIGHTY_FIVE);
148  12 conses[13] = new Consensus("H", EIGHTY_FIVE);
149  12 conses[14] = new Consensus("I", EIGHTY_FIVE);
150  12 conses[15] = new Consensus("L", EIGHTY_FIVE);
151  12 conses[16] = new Consensus("M", EIGHTY_FIVE);
152  12 conses[17] = new Consensus("N", EIGHTY_FIVE);
153  12 conses[18] = new Consensus("P", EIGHTY_FIVE);
154  12 conses[19] = new Consensus("Q", EIGHTY_FIVE);
155  12 conses[20] = new Consensus("R", EIGHTY_FIVE);
156  12 conses[21] = new Consensus("S", EIGHTY_FIVE);
157  12 conses[22] = new Consensus("T", EIGHTY_FIVE);
158  12 conses[23] = new Consensus("V", EIGHTY_FIVE);
159  12 conses[24] = new Consensus("W", EIGHTY_FIVE);
160  12 conses[25] = new Consensus("Y", EIGHTY_FIVE);
161  12 conses[28] = new Consensus("K", EIGHTY_FIVE);
162  12 conses[29] = new Consensus("D", EIGHTY_FIVE);
163   
164  12 conses[30] = new Consensus("G", 0);
165  12 conses[31] = new Consensus("P", 0);
166   
167    // We now construct the colours
168  12 colours = new ConsensusColour[11];
169   
170  12 Consensus[] tmp8 = new Consensus[1];
171  12 tmp8[0] = conses[30]; // G
172  12 colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8);
173   
174  12 Consensus[] tmp9 = new Consensus[1];
175  12 tmp9[0] = conses[31]; // P
176  12 colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9);
177   
178  12 Consensus[] tmp10 = new Consensus[1];
179  12 tmp10[0] = conses[27]; // C
180  12 colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8);
181   
182  12 Consensus[] tmp1 = new Consensus[14];
183  12 tmp1[0] = conses[0]; // %
184  12 tmp1[1] = conses[1]; // #
185  12 tmp1[2] = conses[26]; // A
186  12 tmp1[3] = conses[27]; // C
187  12 tmp1[4] = conses[11]; // F
188  12 tmp1[5] = conses[13]; // H
189  12 tmp1[6] = conses[14]; // I
190  12 tmp1[7] = conses[15]; // L
191  12 tmp1[8] = conses[16]; // M
192  12 tmp1[9] = conses[23]; // V
193  12 tmp1[10] = conses[24]; // W
194  12 tmp1[11] = conses[25]; // Y
195  12 tmp1[12] = conses[18]; // P
196  12 tmp1[13] = conses[19]; // p
197  12 colours[0] = new ConsensusColour(ClustalColour.BLUE, tmp1);
198   
199  12 colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1);
200   
201  12 Consensus[] tmp2 = new Consensus[5];
202  12 tmp2[0] = conses[8]; // t
203  12 tmp2[1] = conses[21]; // S
204  12 tmp2[2] = conses[22]; // T
205  12 tmp2[3] = conses[0]; // %
206  12 tmp2[4] = conses[1]; // #
207  12 colours[1] = new ConsensusColour(ClustalColour.GREEN, tmp2);
208   
209  12 Consensus[] tmp3 = new Consensus[3];
210   
211  12 tmp3[0] = conses[17]; // N
212  12 tmp3[1] = conses[29]; // D
213  12 tmp3[2] = conses[5]; // n
214  12 colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3);
215   
216  12 Consensus[] tmp4 = new Consensus[6];
217  12 tmp4[0] = conses[6]; // q = QE
218  12 tmp4[1] = conses[19]; // Q
219  12 tmp4[2] = conses[22]; // E
220  12 tmp4[3] = conses[3]; // +
221  12 tmp4[4] = conses[28]; // K
222  12 tmp4[5] = conses[20]; // R
223  12 colours[3] = new ConsensusColour(ClustalColour.GREEN, tmp4);
224   
225  12 Consensus[] tmp5 = new Consensus[4];
226  12 tmp5[0] = conses[3]; // +
227  12 tmp5[1] = conses[28]; // K
228  12 tmp5[2] = conses[20]; // R
229  12 tmp5[3] = conses[19]; // Q
230  12 colours[4] = new ConsensusColour(ClustalColour.RED, tmp5);
231   
232  12 Consensus[] tmp6 = new Consensus[6];
233  12 tmp6[0] = conses[3]; // -
234  12 tmp6[1] = conses[29]; // D
235  12 tmp6[2] = conses[10]; // E
236  12 tmp6[3] = conses[6]; // QE
237  12 tmp6[4] = conses[19]; // Q
238  12 tmp6[5] = conses[2]; // DE
239  12 colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6);
240   
241  12 Consensus[] tmp7 = new Consensus[5];
242  12 tmp7[0] = conses[3]; // -
243  12 tmp7[1] = conses[29]; // D
244  12 tmp7[2] = conses[10]; // E
245  12 tmp7[3] = conses[17]; // N
246  12 tmp7[4] = conses[2]; // DE
247  12 colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7);
248   
249    // Now attach the ConsensusColours to the residue letters
250  12 residueColour = new ConsensusColour[20];
251  12 residueColour[0] = colours[0]; // A
252  12 residueColour[1] = colours[4]; // R
253  12 residueColour[2] = colours[2]; // N
254  12 residueColour[3] = colours[6]; // D
255  12 residueColour[4] = colours[0]; // C
256  12 residueColour[5] = colours[3]; // Q
257  12 residueColour[6] = colours[5]; // E
258  12 residueColour[7] = colours[7]; // G
259  12 residueColour[8] = colours[10]; // H
260  12 residueColour[9] = colours[0]; // I
261  12 residueColour[10] = colours[0]; // L
262  12 residueColour[11] = colours[4]; // K
263  12 residueColour[12] = colours[0]; // M
264  12 residueColour[13] = colours[0]; // F
265  12 residueColour[14] = colours[8]; // P
266  12 residueColour[15] = colours[1]; // S
267  12 residueColour[16] = colours[1]; // T
268  12 residueColour[17] = colours[0]; // W
269  12 residueColour[18] = colours[10]; // Y
270  12 residueColour[19] = colours[0]; // V
271    }
272   
 
273  0 toggle @Override
274    public Color findColour(char c)
275    {
276  0 return Color.pink;
277    }
278   
 
279  19 toggle @Override
280    protected Color findColour(char c, int j, SequenceI seq)
281    {
282    // TODO why the test for includeGaps here?
283  19 if (cons2.length <= j || Comparison.isGap(c)
284    /*|| (includeGaps && threshold != 0 && !aboveThreshold(c, j))*/)
285    {
286  0 return Color.white;
287    }
288   
289  19 int i = ResidueProperties.aaIndex[c];
290   
291  19 Color colour = Color.white;
292   
293  19 if (i > 19)
294    {
295  0 return colour;
296    }
297   
298  170 for (int k = 0; k < residueColour[i].cons.length; k++)
299    {
300  151 if (residueColour[i].cons[k].isConserved(cons2, j, size, includeGaps))
301    {
302  22 colour = residueColour[i].c;
303    }
304    }
305   
306  19 if (i == 4)
307    {
308    /*
309    * override to colour C pink if >85% conserved
310    */
311  3 if (conses[27].isConserved(cons2, j, size, includeGaps))
312    {
313  1 colour = ClustalColour.PINK.colour;
314    }
315    }
316   
317  19 return colour;
318    }
319   
320    /**
321    * @return the includeGaps
322    */
 
323  12 toggle protected boolean isIncludeGaps()
324    {
325  12 return includeGaps;
326    }
327   
328    /**
329    * @param includeGaps
330    * the includeGaps to set
331    */
 
332  2 toggle protected void setIncludeGaps(boolean includeGaps)
333    {
334  2 this.includeGaps = includeGaps;
335    }
336   
 
337  5 toggle @Override
338    public ColourSchemeI getInstance(AnnotatedCollectionI sg,
339    Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
340    {
341  5 ClustalxColourScheme css = new ClustalxColourScheme(sg,
342    hiddenRepSequences);
343  5 css.includeGaps = includeGaps;
344  5 return css;
345    }
346   
 
347  390 toggle @Override
348    public boolean isPeptideSpecific()
349    {
350  390 return true;
351    }
352   
 
353  202 toggle @Override
354    public String getSchemeName()
355    {
356  202 return JalviewColourScheme.Clustal.toString();
357    }
358   
 
359  10 toggle @Override
360    public boolean isSimple()
361    {
362  10 return false;
363    }
364    }