1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.renderer.seqfeatures; |
22 |
|
|
23 |
|
import java.awt.AlphaComposite; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.FontMetrics; |
26 |
|
import java.awt.Graphics; |
27 |
|
import java.awt.Graphics2D; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
import jalview.api.AlignViewportI; |
31 |
|
import jalview.api.FeatureColourI; |
32 |
|
import jalview.datamodel.ContiguousI; |
33 |
|
import jalview.datamodel.MappedFeatures; |
34 |
|
import jalview.datamodel.SequenceFeature; |
35 |
|
import jalview.datamodel.SequenceI; |
36 |
|
import jalview.gui.AlignFrame; |
37 |
|
import jalview.gui.Desktop; |
38 |
|
import jalview.util.Comparison; |
39 |
|
import jalview.util.ReverseListIterator; |
40 |
|
import jalview.viewmodel.seqfeatures.FeatureRendererModel; |
41 |
|
|
|
|
| 53.2% |
Uncovered Elements: 124 (265) |
Complexity: 70 |
Complexity Density: 0.44 |
|
42 |
|
public class FeatureRenderer extends FeatureRendererModel |
43 |
|
{ |
44 |
|
private static final AlphaComposite NO_TRANSPARENCY = AlphaComposite |
45 |
|
.getInstance(AlphaComposite.SRC_OVER, 1.0f); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@param |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
549 |
public FeatureRenderer(AlignViewportI viewport)... |
53 |
|
{ |
54 |
549 |
this.av = viewport; |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@param |
63 |
|
@param |
64 |
|
@param |
65 |
|
@param |
66 |
|
@param |
67 |
|
@param |
68 |
|
@param |
69 |
|
@param |
70 |
|
@param |
71 |
|
@return |
72 |
|
|
|
|
| 82.9% |
Uncovered Elements: 6 (35) |
Complexity: 9 |
Complexity Density: 0.39 |
|
73 |
12733 |
boolean renderFeature(Graphics g, SequenceI seq, int featureStart,... |
74 |
|
int featureEnd, Color featureColour, int start, int end, int y1, |
75 |
|
boolean colourOnly) |
76 |
|
{ |
77 |
12733 |
int charHeight = av.getCharHeight(); |
78 |
12733 |
int charWidth = av.getCharWidth(); |
79 |
12733 |
boolean validCharWidth = av.isValidCharWidth(); |
80 |
|
|
81 |
12733 |
if (featureStart > end || featureEnd < start) |
82 |
|
{ |
83 |
0 |
return false; |
84 |
|
} |
85 |
|
|
86 |
12733 |
if (featureStart < start) |
87 |
|
{ |
88 |
0 |
featureStart = start; |
89 |
|
} |
90 |
12733 |
if (featureEnd >= end) |
91 |
|
{ |
92 |
347 |
featureEnd = end; |
93 |
|
} |
94 |
12733 |
int pady = (y1 + charHeight) - charHeight / 5; |
95 |
|
|
96 |
12733 |
FontMetrics fm = g.getFontMetrics(); |
97 |
34075 |
for (int i = featureStart; i <= featureEnd; i++) |
98 |
|
{ |
99 |
21342 |
char s = seq.getCharAt(i); |
100 |
|
|
101 |
21342 |
if (Comparison.isGap(s)) |
102 |
|
{ |
103 |
0 |
continue; |
104 |
|
} |
105 |
|
|
106 |
21342 |
g.setColor(featureColour); |
107 |
|
|
108 |
21342 |
g.fillRect((i - start) * charWidth, y1, charWidth, charHeight); |
109 |
|
|
110 |
21342 |
if (colourOnly || !validCharWidth) |
111 |
|
{ |
112 |
6 |
continue; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
21336 |
g.setColor(Color.white); |
120 |
21336 |
int charOffset = (charWidth - fm.charWidth(s)) / 2; |
121 |
21336 |
g.drawString(String.valueOf(s), |
122 |
|
charOffset + (charWidth * (i - start)), pady); |
123 |
|
} |
124 |
12733 |
return true; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
@param |
133 |
|
@param |
134 |
|
@param |
135 |
|
@param |
136 |
|
@param |
137 |
|
@param |
138 |
|
@param |
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@return |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 11 |
Complexity Density: 0.33 |
|
144 |
0 |
boolean renderScoreFeature(Graphics g, SequenceI seq, int fstart,... |
145 |
|
int fend, Color featureColour, int start, int end, int y1, |
146 |
|
byte[] bs, boolean colourOnly) |
147 |
|
{ |
148 |
0 |
if (fstart > end || fend < start) |
149 |
|
{ |
150 |
0 |
return false; |
151 |
|
} |
152 |
|
|
153 |
0 |
if (fstart < start) |
154 |
|
{ |
155 |
0 |
fstart = start; |
156 |
|
} |
157 |
|
|
158 |
0 |
if (fend >= end) |
159 |
|
{ |
160 |
0 |
fend = end; |
161 |
|
} |
162 |
0 |
int charHeight = av.getCharHeight(); |
163 |
0 |
int pady = (y1 + charHeight) - charHeight / 5; |
164 |
0 |
int ystrt = 0, yend = charHeight; |
165 |
0 |
if (bs[0] != 0) |
166 |
|
{ |
167 |
|
|
168 |
0 |
if (bs[1] < 128) |
169 |
|
{ |
170 |
0 |
yend = charHeight * (128 - bs[1]) / 512; |
171 |
0 |
ystrt = charHeight - yend / 2; |
172 |
|
} |
173 |
|
else |
174 |
|
{ |
175 |
0 |
ystrt = charHeight / 2; |
176 |
0 |
yend = charHeight * (bs[1] - 128) / 512; |
177 |
|
} |
178 |
|
} |
179 |
|
else |
180 |
|
{ |
181 |
0 |
yend = charHeight * bs[1] / 255; |
182 |
0 |
ystrt = charHeight - yend; |
183 |
|
|
184 |
|
} |
185 |
|
|
186 |
0 |
FontMetrics fm = g.getFontMetrics(); |
187 |
0 |
int charWidth = av.getCharWidth(); |
188 |
|
|
189 |
0 |
for (int i = fstart; i <= fend; i++) |
190 |
|
{ |
191 |
0 |
char s = seq.getCharAt(i); |
192 |
|
|
193 |
0 |
if (Comparison.isGap(s)) |
194 |
|
{ |
195 |
0 |
continue; |
196 |
|
} |
197 |
|
|
198 |
0 |
g.setColor(featureColour); |
199 |
0 |
int x = (i - start) * charWidth; |
200 |
0 |
g.drawRect(x, y1, charWidth, charHeight); |
201 |
0 |
g.fillRect(x, y1 + ystrt, charWidth, yend); |
202 |
|
|
203 |
0 |
if (colourOnly || !av.isValidCharWidth()) |
204 |
|
{ |
205 |
0 |
continue; |
206 |
|
} |
207 |
|
|
208 |
0 |
g.setColor(Color.black); |
209 |
0 |
int charOffset = (charWidth - fm.charWidth(s)) / 2; |
210 |
0 |
g.drawString(String.valueOf(s), |
211 |
|
charOffset + (charWidth * (i - start)), pady); |
212 |
|
} |
213 |
0 |
return true; |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
@inheritDoc |
218 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
219 |
25443 |
@Override... |
220 |
|
public Color findFeatureColour(SequenceI seq, int column, Graphics g) |
221 |
|
{ |
222 |
25442 |
if (!av.isShowSequenceFeatures()) |
223 |
|
{ |
224 |
0 |
return null; |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
25444 |
if (Comparison.isGap(seq.getCharAt(column - 1))) |
229 |
|
{ |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
3209 |
return null; |
235 |
|
} |
236 |
|
|
237 |
22235 |
Color renderedColour = null; |
238 |
22235 |
if (transparency == 1.0f) |
239 |
|
{ |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
22231 |
renderedColour = findFeatureColour(seq, column); |
244 |
|
} |
245 |
|
else |
246 |
|
{ |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
4 |
renderedColour = drawSequence(g, seq, column, column, 0, true); |
252 |
|
} |
253 |
22235 |
return renderedColour; |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
@param |
263 |
|
|
264 |
|
@param |
265 |
|
@param |
266 |
|
|
267 |
|
@param |
268 |
|
|
269 |
|
@param |
270 |
|
|
271 |
|
@param |
272 |
|
|
273 |
|
|
274 |
|
@return |
275 |
|
|
|
|
| 79.7% |
Uncovered Elements: 16 (79) |
Complexity: 25 |
Complexity Density: 0.56 |
|
276 |
807 |
public synchronized Color drawSequence(final Graphics g,... |
277 |
|
final SequenceI seq, int start, int end, int y1, |
278 |
|
boolean colourOnly) |
279 |
|
{ |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
807 |
ContiguousI visiblePositions = seq.findPositions(start + 1, end + 1); |
284 |
807 |
if (visiblePositions == null || !seq.getFeatures().hasFeatures() |
285 |
|
&& !av.isShowComplementFeatures()) |
286 |
|
{ |
287 |
115 |
return null; |
288 |
|
} |
289 |
|
|
290 |
692 |
updateFeatures(); |
291 |
|
|
292 |
692 |
if (transparency != 1f && g != null) |
293 |
|
{ |
294 |
4 |
Graphics2D g2 = (Graphics2D) g; |
295 |
4 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, |
296 |
|
transparency)); |
297 |
|
} |
298 |
|
|
299 |
692 |
Color drawnColour = null; |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
692 |
if (av.isShowComplementFeatures() |
305 |
|
&& !av.isShowComplementFeaturesOnTop()) |
306 |
|
{ |
307 |
0 |
drawnColour = drawComplementFeatures(g, seq, start, end, y1, |
308 |
|
colourOnly, visiblePositions, drawnColour); |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
19227 |
for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) |
315 |
|
{ |
316 |
18535 |
String type = renderOrder[renderIndex]; |
317 |
18535 |
if (!showFeatureOfType(type)) |
318 |
|
{ |
319 |
13675 |
continue; |
320 |
|
} |
321 |
|
|
322 |
4860 |
FeatureColourI fc = getFeatureStyle(type); |
323 |
4860 |
List<SequenceFeature> overlaps = seq.getFeatures().findFeatures( |
324 |
|
visiblePositions.getBegin(), visiblePositions.getEnd(), type); |
325 |
|
|
326 |
4860 |
if (overlaps.size() > 1 && fc.isSimpleColour()) |
327 |
|
{ |
328 |
1016 |
filterFeaturesForDisplay(overlaps); |
329 |
|
} |
330 |
|
|
331 |
4860 |
for (SequenceFeature sf : overlaps) |
332 |
|
{ |
333 |
12733 |
Color featureColour = getColor(sf, fc); |
334 |
12733 |
if (featureColour == null) |
335 |
|
{ |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
0 |
continue; |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
12733 |
int visibleStart = sf.getBegin(); |
348 |
12733 |
if (visibleStart < visiblePositions.getBegin()) |
349 |
|
{ |
350 |
75 |
visibleStart = sf.isContactFeature() ? sf.getEnd() |
351 |
|
: visiblePositions.getBegin(); |
352 |
|
} |
353 |
12733 |
int visibleEnd = sf.getEnd(); |
354 |
12733 |
if (visibleEnd > visiblePositions.getEnd()) |
355 |
|
{ |
356 |
13 |
visibleEnd = sf.isContactFeature() ? sf.getBegin() |
357 |
|
: visiblePositions.getEnd(); |
358 |
|
} |
359 |
|
|
360 |
12733 |
int featureStartCol = seq.findIndex(visibleStart); |
361 |
12733 |
int featureEndCol = sf.begin == sf.end ? featureStartCol |
362 |
|
: seq.findIndex(visibleEnd); |
363 |
|
|
364 |
|
|
365 |
|
|
366 |
12733 |
boolean isContactFeature = sf.isContactFeature(); |
367 |
|
|
368 |
12733 |
if (isContactFeature) |
369 |
|
{ |
370 |
0 |
boolean drawn = renderFeature(g, seq, featureStartCol - 1, |
371 |
|
featureStartCol - 1, featureColour, start, end, y1, |
372 |
|
colourOnly); |
373 |
0 |
drawn |= renderFeature(g, seq, featureEndCol - 1, |
374 |
|
featureEndCol - 1, featureColour, start, end, y1, |
375 |
|
colourOnly); |
376 |
0 |
if (drawn) |
377 |
|
{ |
378 |
0 |
drawnColour = featureColour; |
379 |
|
} |
380 |
|
} |
381 |
|
else |
382 |
|
{ |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
12733 |
boolean drawn = renderFeature(g, seq, featureStartCol - 1, |
404 |
|
featureEndCol - 1, featureColour, start, end, y1, |
405 |
|
colourOnly); |
406 |
12733 |
if (drawn) |
407 |
|
{ |
408 |
12733 |
drawnColour = featureColour; |
409 |
|
} |
410 |
|
|
411 |
|
} |
412 |
|
} |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
692 |
if (av.isShowComplementFeatures() && av.isShowComplementFeaturesOnTop()) |
419 |
|
{ |
420 |
0 |
drawnColour = drawComplementFeatures(g, seq, start, end, y1, |
421 |
|
colourOnly, visiblePositions, drawnColour); |
422 |
|
} |
423 |
|
|
424 |
692 |
if (transparency != 1.0f && g != null) |
425 |
|
{ |
426 |
|
|
427 |
|
|
428 |
|
|
429 |
4 |
Graphics2D g2 = (Graphics2D) g; |
430 |
4 |
g2.setComposite(NO_TRANSPARENCY); |
431 |
|
} |
432 |
|
|
433 |
692 |
return drawnColour; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
|
@param |
442 |
|
@param |
443 |
|
@param |
444 |
|
@param |
445 |
|
@param |
446 |
|
@param |
447 |
|
@param |
448 |
|
@param |
449 |
|
@return |
450 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
451 |
0 |
Color drawComplementFeatures(final Graphics g, final SequenceI seq,... |
452 |
|
int start, int end, int y1, boolean colourOnly, |
453 |
|
ContiguousI visiblePositions, Color drawnColour) |
454 |
|
{ |
455 |
0 |
AlignViewportI comp = av.getCodingComplement(); |
456 |
0 |
FeatureRenderer fr2 = Desktop.getAlignFrameFor(comp) |
457 |
|
.getFeatureRenderer(); |
458 |
|
|
459 |
0 |
final int visibleStart = visiblePositions.getBegin(); |
460 |
0 |
final int visibleEnd = visiblePositions.getEnd(); |
461 |
|
|
462 |
0 |
for (int pos = visibleStart; pos <= visibleEnd; pos++) |
463 |
|
{ |
464 |
0 |
int column = seq.findIndex(pos); |
465 |
0 |
MappedFeatures mf = fr2.findComplementFeaturesAtResidue(seq, pos); |
466 |
0 |
if (mf != null) |
467 |
|
{ |
468 |
0 |
for (SequenceFeature sf : mf.features) |
469 |
|
{ |
470 |
0 |
FeatureColourI fc = fr2.getFeatureStyle(sf.getType()); |
471 |
0 |
Color featureColour = fr2.getColor(sf, fc); |
472 |
0 |
renderFeature(g, seq, column - 1, column - 1, featureColour, |
473 |
|
start, end, y1, colourOnly); |
474 |
0 |
drawnColour = featureColour; |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
0 |
return drawnColour; |
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
486 |
19 |
@Override... |
487 |
|
public void featuresAdded() |
488 |
|
{ |
489 |
19 |
findAllFeatures(); |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
@param |
504 |
|
@param |
505 |
|
|
506 |
|
@return |
507 |
|
|
|
|
| 77.8% |
Uncovered Elements: 8 (36) |
Complexity: 11 |
Complexity Density: 0.55 |
|
508 |
22231 |
Color findFeatureColour(SequenceI seq, int column)... |
509 |
|
{ |
510 |
|
|
511 |
|
|
512 |
|
|
513 |
22231 |
updateFeatures(); |
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
22231 |
if (av.isShowComplementFeatures() && av.isShowComplementFeaturesOnTop()) |
519 |
|
{ |
520 |
0 |
Color col = findComplementFeatureColour(seq, column); |
521 |
0 |
if (col != null) |
522 |
|
{ |
523 |
0 |
return col; |
524 |
|
} |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
22231 |
for (int renderIndex = renderOrder.length |
532 |
647490 |
- 1; renderIndex >= 0; renderIndex--) |
533 |
|
{ |
534 |
633830 |
String type = renderOrder[renderIndex]; |
535 |
634039 |
if (!showFeatureOfType(type)) |
536 |
|
{ |
537 |
416234 |
continue; |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
217824 |
List<SequenceFeature> overlaps = seq.findFeatures(column, column, |
545 |
|
type); |
546 |
217761 |
for (int i = overlaps.size() - 1; i >= 0; i--) |
547 |
|
{ |
548 |
8165 |
SequenceFeature sequenceFeature = overlaps.get(i); |
549 |
8165 |
if (!featureGroupNotShown(sequenceFeature)) |
550 |
|
{ |
551 |
8164 |
Color col = getColour(sequenceFeature); |
552 |
8164 |
if (col != null) |
553 |
|
{ |
554 |
8160 |
return col; |
555 |
|
} |
556 |
|
} |
557 |
|
} |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
14071 |
Color col = null; |
564 |
14071 |
if (av.isShowComplementFeatures() |
565 |
|
&& !av.isShowComplementFeaturesOnTop()) |
566 |
|
{ |
567 |
0 |
col = findComplementFeatureColour(seq, column); |
568 |
|
} |
569 |
|
|
570 |
14071 |
return col; |
571 |
|
} |
572 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.36 |
|
573 |
0 |
Color findComplementFeatureColour(SequenceI seq, int column)... |
574 |
|
{ |
575 |
0 |
AlignViewportI complement = av.getCodingComplement(); |
576 |
0 |
AlignFrame af = Desktop.getAlignFrameFor(complement); |
577 |
0 |
FeatureRendererModel fr2 = af.getFeatureRenderer(); |
578 |
0 |
MappedFeatures mf = fr2.findComplementFeaturesAtResidue(seq, |
579 |
|
seq.findPosition(column - 1)); |
580 |
0 |
if (mf == null) |
581 |
|
{ |
582 |
0 |
return null; |
583 |
|
} |
584 |
0 |
ReverseListIterator<SequenceFeature> it = new ReverseListIterator<>( |
585 |
|
mf.features); |
586 |
0 |
while (it.hasNext()) |
587 |
|
{ |
588 |
0 |
SequenceFeature sf = it.next(); |
589 |
0 |
if (!fr2.featureGroupNotShown(sf)) |
590 |
|
{ |
591 |
0 |
Color col = fr2.getColour(sf); |
592 |
0 |
if (col != null) |
593 |
|
{ |
594 |
0 |
return col; |
595 |
|
} |
596 |
|
} |
597 |
|
} |
598 |
0 |
return null; |
599 |
|
} |
600 |
|
} |