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