Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.schemes

File ClustalxColourScheme.java

 

Coverage histogram

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

Code metrics

18
161
14
3
365
271
24
0.15
11.5
4.67
1.71

Classes

Class Line # Actions
ClustalxColourScheme 33 158 22
0.957446895.7%
ClustalxColourScheme.ClustalColour 43 1 1
1.0100%
ClustalxColourScheme.ConsensusColour 58 2 1
1.0100%
 

Contributing tests

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