1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.schemes; |
22 |
|
|
23 |
|
import jalview.api.AlignViewportI; |
24 |
|
import jalview.datamodel.AlignmentAnnotation; |
25 |
|
import jalview.datamodel.AlignmentI; |
26 |
|
import jalview.datamodel.AnnotatedCollectionI; |
27 |
|
import jalview.datamodel.Annotation; |
28 |
|
import jalview.datamodel.GraphLine; |
29 |
|
import jalview.datamodel.SequenceCollectionI; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
import jalview.renderer.AnnotationRenderer; |
32 |
|
import jalview.util.Comparison; |
33 |
|
|
34 |
|
import java.awt.Color; |
35 |
|
import java.util.IdentityHashMap; |
36 |
|
import java.util.Map; |
37 |
|
|
|
|
| 50.7% |
Uncovered Elements: 101 (205) |
Complexity: 82 |
Complexity Density: 0.69 |
|
38 |
|
public class AnnotationColourGradient extends FollowerColourScheme |
39 |
|
{ |
40 |
|
public static final int NO_THRESHOLD = -1; |
41 |
|
|
42 |
|
public static final int BELOW_THRESHOLD = 0; |
43 |
|
|
44 |
|
public static final int ABOVE_THRESHOLD = 1; |
45 |
|
|
46 |
|
private final AlignmentAnnotation annotation; |
47 |
|
|
48 |
|
private final int aboveAnnotationThreshold; |
49 |
|
|
50 |
|
public boolean thresholdIsMinMax = false; |
51 |
|
|
52 |
|
private GraphLine annotationThreshold; |
53 |
|
|
54 |
|
private int redMin; |
55 |
|
|
56 |
|
private int greenMin; |
57 |
|
|
58 |
|
private int blueMin; |
59 |
|
|
60 |
|
private int redRange; |
61 |
|
|
62 |
|
private int greenRange; |
63 |
|
|
64 |
|
private int blueRange; |
65 |
|
|
66 |
|
private boolean predefinedColours = false; |
67 |
|
|
68 |
|
private boolean seqAssociated = false; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
private boolean noGradient = false; |
76 |
|
|
77 |
|
private IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null; |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
79 |
4 |
@Override... |
80 |
|
public ColourSchemeI getInstance(AlignViewportI view, |
81 |
|
AnnotatedCollectionI sg) |
82 |
|
{ |
83 |
4 |
AnnotationColourGradient acg = new AnnotationColourGradient(annotation, |
84 |
|
getColourScheme(), aboveAnnotationThreshold); |
85 |
4 |
acg.thresholdIsMinMax = thresholdIsMinMax; |
86 |
4 |
acg.annotationThreshold = (annotationThreshold == null) ? null |
87 |
|
: new GraphLine(annotationThreshold); |
88 |
4 |
acg.redMin = redMin; |
89 |
4 |
acg.greenMin = greenMin; |
90 |
4 |
acg.blueMin = blueMin; |
91 |
4 |
acg.redRange = redRange; |
92 |
4 |
acg.greenRange = greenRange; |
93 |
4 |
acg.blueRange = blueRange; |
94 |
4 |
acg.predefinedColours = predefinedColours; |
95 |
4 |
acg.seqAssociated = seqAssociated; |
96 |
4 |
acg.noGradient = noGradient; |
97 |
4 |
return acg; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
103 |
4 |
public AnnotationColourGradient(AlignmentAnnotation annotation,... |
104 |
|
ColourSchemeI originalColour, int aboveThreshold) |
105 |
|
{ |
106 |
4 |
if (originalColour instanceof AnnotationColourGradient) |
107 |
|
{ |
108 |
0 |
setColourScheme(((AnnotationColourGradient) originalColour) |
109 |
|
.getColourScheme()); |
110 |
|
} |
111 |
|
else |
112 |
|
{ |
113 |
4 |
setColourScheme(originalColour); |
114 |
|
} |
115 |
|
|
116 |
4 |
this.annotation = annotation; |
117 |
|
|
118 |
4 |
aboveAnnotationThreshold = aboveThreshold; |
119 |
|
|
120 |
4 |
if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null) |
121 |
|
{ |
122 |
2 |
annotationThreshold = annotation.threshold; |
123 |
|
} |
124 |
|
|
125 |
4 |
redMin = 254; |
126 |
4 |
greenMin = 254; |
127 |
4 |
blueMin = 254; |
128 |
4 |
redRange = 0; |
129 |
4 |
greenRange = 0; |
130 |
4 |
blueRange = 0; |
131 |
|
|
132 |
4 |
noGradient = true; |
133 |
4 |
checkLimits(); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
139 |
7 |
public AnnotationColourGradient(AlignmentAnnotation annotation,... |
140 |
|
Color minColour, Color maxColour, int aboveThreshold) |
141 |
|
{ |
142 |
7 |
this.annotation = annotation; |
143 |
|
|
144 |
7 |
aboveAnnotationThreshold = aboveThreshold; |
145 |
|
|
146 |
7 |
if (aboveThreshold != NO_THRESHOLD && annotation.threshold != null) |
147 |
|
{ |
148 |
4 |
annotationThreshold = annotation.threshold; |
149 |
|
} |
150 |
|
|
151 |
7 |
redMin = minColour.getRed(); |
152 |
7 |
greenMin = minColour.getGreen(); |
153 |
7 |
blueMin = minColour.getBlue(); |
154 |
|
|
155 |
7 |
redRange = maxColour.getRed() - redMin; |
156 |
7 |
greenRange = maxColour.getGreen() - greenMin; |
157 |
7 |
blueRange = maxColour.getBlue() - blueMin; |
158 |
|
|
159 |
7 |
noGradient = false; |
160 |
7 |
checkLimits(); |
161 |
|
} |
162 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
163 |
11 |
private void checkLimits()... |
164 |
|
{ |
165 |
11 |
aamax = annotation.graphMax; |
166 |
11 |
aamin = annotation.graphMin; |
167 |
11 |
if (annotation.isRNA()) |
168 |
|
{ |
169 |
|
|
170 |
0 |
ColourSchemeProperty.resetRnaHelicesShading(); |
171 |
0 |
ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); |
172 |
|
} |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 16 |
Complexity Density: 0.84 |
|
175 |
0 |
@Override... |
176 |
|
public void alignmentChanged(AnnotatedCollectionI alignment, |
177 |
|
Map<SequenceI, SequenceCollectionI> hiddenReps) |
178 |
|
{ |
179 |
0 |
super.alignmentChanged(alignment, hiddenReps); |
180 |
|
|
181 |
0 |
if (seqAssociated && annotation.getCalcId() != null) |
182 |
|
{ |
183 |
0 |
if (seqannot != null) |
184 |
|
{ |
185 |
0 |
seqannot.clear(); |
186 |
|
} |
187 |
|
else |
188 |
|
{ |
189 |
0 |
seqannot = new IdentityHashMap<>(); |
190 |
|
} |
191 |
|
|
192 |
0 |
AnnotatedCollectionI alcontext = alignment instanceof AlignmentI |
193 |
|
? alignment |
194 |
|
: alignment.getContext(); |
195 |
0 |
boolean f = true, rna = false; |
196 |
0 |
for (AlignmentAnnotation alan : alcontext |
197 |
|
.findAnnotation(annotation.getCalcId())) |
198 |
|
{ |
199 |
0 |
if (alan.sequenceRef != null |
200 |
|
&& (alan.label != null && annotation != null |
201 |
|
&& alan.label.equals(annotation.label))) |
202 |
|
{ |
203 |
0 |
if (!rna && alan.isRNA()) |
204 |
|
{ |
205 |
0 |
rna = true; |
206 |
|
} |
207 |
0 |
seqannot.put(alan.sequenceRef, alan); |
208 |
0 |
if (f || alan.graphMax > aamax) |
209 |
|
{ |
210 |
0 |
aamax = alan.graphMax; |
211 |
|
} |
212 |
0 |
if (f || alan.graphMin < aamin) |
213 |
|
{ |
214 |
0 |
aamin = alan.graphMin; |
215 |
|
} |
216 |
0 |
f = false; |
217 |
|
} |
218 |
|
} |
219 |
0 |
if (rna) |
220 |
|
{ |
221 |
0 |
ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); |
222 |
|
} |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
|
float aamin = 0f, aamax = 0f; |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
0 |
public AlignmentAnnotation getAnnotation()... |
229 |
|
{ |
230 |
0 |
return annotation; |
231 |
|
} |
232 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
0 |
public int getAboveThreshold()... |
234 |
|
{ |
235 |
0 |
return aboveAnnotationThreshold; |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
238 |
0 |
public float getAnnotationThreshold()... |
239 |
|
{ |
240 |
0 |
if (annotationThreshold == null) |
241 |
|
{ |
242 |
0 |
return 0; |
243 |
|
} |
244 |
|
else |
245 |
|
{ |
246 |
0 |
return annotationThreshold.value; |
247 |
|
} |
248 |
|
} |
249 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
250 |
0 |
public Color getMinColour()... |
251 |
|
{ |
252 |
0 |
return new Color(redMin, greenMin, blueMin); |
253 |
|
} |
254 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
255 |
0 |
public Color getMaxColour()... |
256 |
|
{ |
257 |
0 |
return new Color(redMin + redRange, greenMin + greenRange, |
258 |
|
blueMin + blueRange); |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
@param |
265 |
|
|
266 |
|
|
267 |
|
@return |
268 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
269 |
0 |
@Override... |
270 |
|
public Color findColour(char c) |
271 |
|
{ |
272 |
0 |
return Color.red; |
273 |
|
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
@param |
279 |
|
|
280 |
|
@param |
281 |
|
|
282 |
|
@param |
283 |
|
|
284 |
|
@return |
285 |
|
|
|
|
| 43.4% |
Uncovered Elements: 30 (53) |
Complexity: 28 |
Complexity Density: 1.12 |
|
286 |
66 |
@Override... |
287 |
|
public Color findColour(char c, int j, SequenceI seq) |
288 |
|
{ |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
66 |
AlignmentAnnotation ann = (seqAssociated && seqannot != null |
293 |
|
? seqannot.get(seq) |
294 |
|
: this.annotation); |
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
66 |
if (ann == null || ann.annotations == null |
300 |
|
|| j >= ann.annotations.length || ann.annotations[j] == null |
301 |
|
|| Comparison.isGap(c)) |
302 |
|
{ |
303 |
0 |
return Color.white; |
304 |
|
} |
305 |
|
|
306 |
66 |
Annotation aj = ann.annotations[j]; |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
66 |
if (annotationThreshold != null) |
321 |
|
{ |
322 |
44 |
if ((aboveAnnotationThreshold == ABOVE_THRESHOLD |
323 |
|
&& aj.value <= annotationThreshold.value) |
324 |
|
|| (aboveAnnotationThreshold == BELOW_THRESHOLD |
325 |
|
&& aj.value >= annotationThreshold.value)) |
326 |
|
{ |
327 |
24 |
return Color.white; |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
42 |
if (predefinedColours && aj.colour != null |
336 |
|
&& !aj.colour.equals(Color.black)) |
337 |
|
{ |
338 |
10 |
return aj.colour; |
339 |
|
} |
340 |
|
|
341 |
32 |
Color result = Color.white; |
342 |
32 |
if (ann.hasIcons && ann.graph == AlignmentAnnotation.NO_GRAPH) |
343 |
|
{ |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
0 |
if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.' |
348 |
|
&& aj.secondaryStructure != '-') |
349 |
|
{ |
350 |
0 |
if (getColourScheme() != null) |
351 |
|
{ |
352 |
0 |
result = getColourScheme().findColour(c, j, seq, null, 0f); |
353 |
|
} |
354 |
|
else |
355 |
|
{ |
356 |
0 |
if (ann.isRNA()) |
357 |
|
{ |
358 |
0 |
result = ColourSchemeProperty.rnaHelices[(int) aj.value]; |
359 |
|
} |
360 |
|
else |
361 |
|
{ |
362 |
0 |
result = ann.annotations[j].secondaryStructure == 'H' |
363 |
|
? AnnotationRenderer.HELIX_COLOUR |
364 |
0 |
: ann.annotations[j].secondaryStructure == 'E' |
365 |
|
? AnnotationRenderer.SHEET_COLOUR |
366 |
|
: AnnotationRenderer.STEM_COLOUR; |
367 |
|
} |
368 |
|
} |
369 |
|
} |
370 |
|
else |
371 |
|
{ |
372 |
0 |
return Color.white; |
373 |
|
} |
374 |
|
} |
375 |
32 |
else if (noGradient) |
376 |
|
{ |
377 |
0 |
if (getColourScheme() != null) |
378 |
|
{ |
379 |
0 |
result = getColourScheme().findColour(c, j, seq, null, 0f); |
380 |
|
} |
381 |
|
else |
382 |
|
{ |
383 |
0 |
if (aj.colour != null) |
384 |
|
{ |
385 |
0 |
result = aj.colour; |
386 |
|
} |
387 |
|
} |
388 |
|
} |
389 |
|
else |
390 |
|
{ |
391 |
32 |
result = shadeCalculation(ann, j); |
392 |
|
} |
393 |
|
|
394 |
32 |
return result; |
395 |
|
} |
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
@param |
407 |
|
@param |
408 |
|
@return |
409 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 12 |
Complexity Density: 0.92 |
|
410 |
91 |
Color shadeCalculation(AlignmentAnnotation ann, int col)... |
411 |
|
{ |
412 |
91 |
float range = 1f; |
413 |
91 |
float value = ann.annotations[col].value; |
414 |
91 |
if (thresholdIsMinMax && ann.threshold != null |
415 |
|
&& aboveAnnotationThreshold == ABOVE_THRESHOLD |
416 |
|
&& value >= ann.threshold.value) |
417 |
|
{ |
418 |
12 |
range = ann.graphMax == ann.threshold.value ? 1f |
419 |
|
: (value - ann.threshold.value) |
420 |
|
/ (ann.graphMax - ann.threshold.value); |
421 |
|
} |
422 |
79 |
else if (thresholdIsMinMax && ann.threshold != null |
423 |
|
&& aboveAnnotationThreshold == BELOW_THRESHOLD |
424 |
|
&& value <= ann.threshold.value) |
425 |
|
{ |
426 |
12 |
range = ann.graphMin == ann.threshold.value ? 0f |
427 |
|
: (value - ann.graphMin) |
428 |
|
/ (ann.threshold.value - ann.graphMin); |
429 |
|
} |
430 |
|
else |
431 |
|
{ |
432 |
67 |
if (ann.graphMax != ann.graphMin) |
433 |
|
{ |
434 |
67 |
range = (value - ann.graphMin) / (ann.graphMax - ann.graphMin); |
435 |
|
} |
436 |
|
else |
437 |
|
{ |
438 |
0 |
range = 0f; |
439 |
|
} |
440 |
|
} |
441 |
|
|
442 |
91 |
int dr = (int) (redRange * range + redMin); |
443 |
91 |
int dg = (int) (greenRange * range + greenMin); |
444 |
91 |
int db = (int) (blueRange * range + blueMin); |
445 |
|
|
446 |
91 |
return new Color(dr, dg, db); |
447 |
|
} |
448 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
449 |
0 |
public boolean isPredefinedColours()... |
450 |
|
{ |
451 |
0 |
return predefinedColours; |
452 |
|
} |
453 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
454 |
1 |
public void setPredefinedColours(boolean predefinedColours)... |
455 |
|
{ |
456 |
1 |
this.predefinedColours = predefinedColours; |
457 |
|
} |
458 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
459 |
0 |
public boolean isSeqAssociated()... |
460 |
|
{ |
461 |
0 |
return seqAssociated; |
462 |
|
} |
463 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
464 |
0 |
public void setSeqAssociated(boolean sassoc)... |
465 |
|
{ |
466 |
0 |
seqAssociated = sassoc; |
467 |
|
} |
468 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
469 |
0 |
public boolean isThresholdIsMinMax()... |
470 |
|
{ |
471 |
0 |
return thresholdIsMinMax; |
472 |
|
} |
473 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
474 |
6 |
public void setThresholdIsMinMax(boolean minMax)... |
475 |
|
{ |
476 |
6 |
this.thresholdIsMinMax = minMax; |
477 |
|
} |
478 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
479 |
0 |
@Override... |
480 |
|
public String getSchemeName() |
481 |
|
{ |
482 |
0 |
return ANNOTATION_COLOUR; |
483 |
|
} |
484 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
485 |
0 |
@Override... |
486 |
|
public boolean isSimple() |
487 |
|
{ |
488 |
0 |
return false; |
489 |
|
} |
490 |
|
} |