1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.renderer; |
22 |
|
|
23 |
|
import jalview.analysis.Conservation; |
24 |
|
import jalview.api.ViewStyleI; |
25 |
|
import jalview.datamodel.AnnotatedCollectionI; |
26 |
|
import jalview.datamodel.ProfileI; |
27 |
|
import jalview.datamodel.ProfilesI; |
28 |
|
import jalview.datamodel.SequenceCollectionI; |
29 |
|
import jalview.datamodel.SequenceI; |
30 |
|
import jalview.schemes.ColourSchemeI; |
31 |
|
import jalview.util.ColorUtils; |
32 |
|
import jalview.util.Comparison; |
33 |
|
|
34 |
|
import java.awt.Color; |
35 |
|
import java.util.Map; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@author |
48 |
|
|
49 |
|
|
|
|
| 0% |
Uncovered Elements: 140 (140) |
Complexity: 50 |
Complexity Density: 0.68 |
|
50 |
|
public class ResidueShader implements ResidueShaderI |
51 |
|
{ |
52 |
|
private static final int INITIAL_CONSERVATION = 30; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private ColourSchemeI colourScheme; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private ProfilesI consensus; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private ProfilesI ssConsensus; |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
public ProfilesI getSsConsensus()... |
71 |
|
{ |
72 |
0 |
return ssConsensus; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
public void setSsConsensus(ProfilesI ssConsensus)... |
76 |
|
{ |
77 |
0 |
this.ssConsensus = ssConsensus; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
private boolean conservationColouring; |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
private char[] conservation; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
private int pidThreshold; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
private boolean ignoreGaps; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
private int conservationIncrement = INITIAL_CONSERVATION; |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
0 |
public ResidueShader(ColourSchemeI cs)... |
110 |
|
{ |
111 |
0 |
colourScheme = cs; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
117 |
0 |
public ResidueShader()... |
118 |
|
{ |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
126 |
0 |
public ResidueShader(ViewStyleI viewStyle)... |
127 |
|
{ |
128 |
|
|
129 |
0 |
this(); |
130 |
0 |
setConservationApplied(viewStyle.isConservationColourSelected()); |
131 |
|
|
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
137 |
0 |
public ResidueShader(ResidueShader rs)... |
138 |
|
{ |
139 |
0 |
this.colourScheme = rs.colourScheme; |
140 |
0 |
this.consensus = rs.consensus; |
141 |
0 |
this.conservation = rs.conservation; |
142 |
0 |
this.conservationColouring = rs.conservationColouring; |
143 |
0 |
this.conservationIncrement = rs.conservationIncrement; |
144 |
0 |
this.ignoreGaps = rs.ignoreGaps; |
145 |
0 |
this.pidThreshold = rs.pidThreshold; |
146 |
0 |
this.ssConsensus = rs.ssConsensus; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
@see |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
@Override... |
153 |
|
public void setConsensus(ProfilesI cons) |
154 |
|
{ |
155 |
0 |
consensus = cons; |
156 |
|
|
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
@see |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0 |
@Override... |
163 |
|
public boolean conservationApplied() |
164 |
|
{ |
165 |
0 |
return conservationColouring; |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
@see |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
0 |
@Override... |
172 |
|
public void setConservationApplied(boolean conservationApplied) |
173 |
|
{ |
174 |
0 |
conservationColouring = conservationApplied; |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
@see |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
180 |
0 |
@Override... |
181 |
|
public void setConservation(Conservation cons) |
182 |
|
{ |
183 |
0 |
if (cons == null) |
184 |
|
{ |
185 |
0 |
conservationColouring = false; |
186 |
0 |
conservation = null; |
187 |
|
} |
188 |
|
else |
189 |
|
{ |
190 |
0 |
conservationColouring = true; |
191 |
0 |
conservation = cons.getConsSequence().getSequenceAsString() |
192 |
|
.toCharArray(); |
193 |
|
} |
194 |
|
|
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
@see |
199 |
|
|
200 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
201 |
0 |
@Override... |
202 |
|
public void alignmentChanged(AnnotatedCollectionI alignment, |
203 |
|
Map<SequenceI, SequenceCollectionI> hiddenReps) |
204 |
|
{ |
205 |
0 |
if (colourScheme != null) |
206 |
|
{ |
207 |
0 |
colourScheme.alignmentChanged(alignment, hiddenReps); |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
@see |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
214 |
0 |
@Override... |
215 |
|
public void setThreshold(int consensusThreshold, boolean ignoreGaps) |
216 |
|
{ |
217 |
0 |
pidThreshold = consensusThreshold; |
218 |
0 |
this.ignoreGaps = ignoreGaps; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
@see |
223 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
0 |
@Override... |
225 |
|
public void setConservationInc(int i) |
226 |
|
{ |
227 |
0 |
conservationIncrement = i; |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
@see |
232 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
0 |
@Override... |
234 |
|
public int getConservationInc() |
235 |
|
{ |
236 |
0 |
return conservationIncrement; |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
@see |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
242 |
0 |
@Override... |
243 |
|
public int getThreshold() |
244 |
|
{ |
245 |
0 |
return pidThreshold; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
@see |
250 |
|
|
251 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.67 |
|
252 |
0 |
@Override... |
253 |
|
public Color findColour(char symbol, int position, SequenceI seq) |
254 |
|
{ |
255 |
0 |
if (colourScheme == null) |
256 |
|
{ |
257 |
0 |
return Color.white; |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
0 |
ProfileI profile = consensus == null ? null : consensus.get(position); |
264 |
0 |
String modalResidue = profile == null ? null |
265 |
|
: profile.getModalResidue(); |
266 |
0 |
float pid = profile == null ? 0f |
267 |
|
: profile.getPercentageIdentity(ignoreGaps); |
268 |
0 |
Color colour = colourScheme.findColour(symbol, position, seq, |
269 |
|
modalResidue, pid); |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
0 |
if (!Comparison.isGap(symbol)) |
275 |
|
{ |
276 |
0 |
colour = adjustColour(symbol, position, colour); |
277 |
|
} |
278 |
|
|
279 |
0 |
return colour; |
280 |
|
} |
281 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.67 |
|
282 |
0 |
@Override... |
283 |
|
public Color findSSColour(char symbol, int position, SequenceI seq) |
284 |
|
{ |
285 |
0 |
if (colourScheme == null) |
286 |
|
{ |
287 |
0 |
return Color.white; |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
0 |
ProfileI profile = ssConsensus == null ? null |
294 |
|
: ssConsensus.get(position); |
295 |
0 |
String modalSS = profile == null ? null : profile.getModalSS(); |
296 |
0 |
float pid = profile == null ? 0f |
297 |
|
: profile.getSSPercentageIdentity(ignoreGaps); |
298 |
0 |
Color colour = colourScheme.findColour(symbol, position, seq, modalSS, |
299 |
|
pid); |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
0 |
if (!Comparison.isGap(symbol)) |
305 |
|
{ |
306 |
0 |
colour = adjustColour(symbol, position, colour); |
307 |
|
} |
308 |
|
|
309 |
0 |
return colour; |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
@param |
325 |
|
@param |
326 |
|
@param |
327 |
|
@return |
328 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
329 |
0 |
protected Color adjustColour(char symbol, int column, Color colour)... |
330 |
|
{ |
331 |
0 |
if (!aboveThreshold(symbol, column)) |
332 |
|
{ |
333 |
0 |
colour = Color.white; |
334 |
|
} |
335 |
|
|
336 |
0 |
if (conservationColouring) |
337 |
|
{ |
338 |
0 |
colour = applyConservation(colour, column); |
339 |
|
} |
340 |
0 |
return colour; |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
@param |
351 |
|
@param |
352 |
|
|
353 |
|
|
354 |
|
@return |
355 |
|
@see |
356 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 8 |
Complexity Density: 0.73 |
|
357 |
0 |
protected boolean aboveThreshold(char residue, int column)... |
358 |
|
{ |
359 |
0 |
if (pidThreshold == 0) |
360 |
|
{ |
361 |
0 |
return true; |
362 |
|
} |
363 |
0 |
if ('a' <= residue && residue <= 'z') |
364 |
|
{ |
365 |
|
|
366 |
|
|
367 |
0 |
residue -= ('a' - 'A'); |
368 |
|
} |
369 |
|
|
370 |
0 |
if (consensus == null) |
371 |
|
{ |
372 |
0 |
return false; |
373 |
|
} |
374 |
|
|
375 |
0 |
ProfileI profile = consensus.get(column); |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
0 |
if (profile != null |
381 |
|
&& profile.getModalResidue().contains(String.valueOf(residue))) |
382 |
|
{ |
383 |
0 |
if (profile.getPercentageIdentity(ignoreGaps) >= pidThreshold) |
384 |
|
{ |
385 |
0 |
return true; |
386 |
|
} |
387 |
|
} |
388 |
|
|
389 |
0 |
return false; |
390 |
|
} |
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
@param |
405 |
|
@param |
406 |
|
|
407 |
|
@return |
408 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 8 |
Complexity Density: 0.8 |
|
409 |
0 |
protected Color applyConservation(Color currentColour, int column)... |
410 |
|
{ |
411 |
0 |
if (conservation == null || conservation.length <= column) |
412 |
|
{ |
413 |
0 |
return currentColour; |
414 |
|
} |
415 |
0 |
char conservationScore = conservation[column]; |
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
0 |
if (conservationScore == '*' || conservationScore == '+' |
422 |
|
|| conservationScore == (char) 10 |
423 |
|
|| conservationScore == (char) 11) |
424 |
|
{ |
425 |
0 |
return currentColour; |
426 |
|
} |
427 |
|
|
428 |
0 |
if (Comparison.isGap(conservationScore)) |
429 |
|
{ |
430 |
0 |
return Color.white; |
431 |
|
} |
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
0 |
float bleachFactor = (11 - (conservationScore - '0')) / 10f; |
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
0 |
bleachFactor *= (conservationIncrement / 20f); |
444 |
|
|
445 |
0 |
return ColorUtils.bleachColour(currentColour, bleachFactor); |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
@see |
450 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
451 |
0 |
@Override... |
452 |
|
public ColourSchemeI getColourScheme() |
453 |
|
{ |
454 |
0 |
return this.colourScheme; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
|
@see |
459 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
460 |
0 |
@Override... |
461 |
|
public void setColourScheme(ColourSchemeI cs) |
462 |
|
{ |
463 |
0 |
colourScheme = cs; |
464 |
|
} |
465 |
|
} |