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 jalview.api.AlignViewportI; |
24 |
|
import jalview.api.FeatureColourI; |
25 |
|
import jalview.datamodel.Range; |
26 |
|
import jalview.datamodel.SequenceFeature; |
27 |
|
import jalview.datamodel.SequenceI; |
28 |
|
import jalview.util.Comparison; |
29 |
|
import jalview.viewmodel.seqfeatures.FeatureRendererModel; |
30 |
|
|
31 |
|
import java.awt.AlphaComposite; |
32 |
|
import java.awt.Color; |
33 |
|
import java.awt.FontMetrics; |
34 |
|
import java.awt.Graphics; |
35 |
|
import java.awt.Graphics2D; |
36 |
|
import java.util.List; |
37 |
|
|
|
|
| 63.3% |
Uncovered Elements: 73 (199) |
Complexity: 50 |
Complexity Density: 0.42 |
|
38 |
|
public class FeatureRenderer extends FeatureRendererModel |
39 |
|
{ |
40 |
|
private static final AlphaComposite NO_TRANSPARENCY = AlphaComposite |
41 |
|
.getInstance(AlphaComposite.SRC_OVER, 1.0f); |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@param |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
235 |
public FeatureRenderer(AlignViewportI viewport)... |
49 |
|
{ |
50 |
235 |
this.av = viewport; |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
@param |
60 |
|
@param |
61 |
|
@param |
62 |
|
@param |
63 |
|
@param |
64 |
|
@param |
65 |
|
@param |
66 |
|
@param |
67 |
|
@return |
68 |
|
|
|
|
| 82.9% |
Uncovered Elements: 6 (35) |
Complexity: 9 |
Complexity Density: 0.39 |
|
69 |
25891 |
boolean renderFeature(Graphics g, SequenceI seq, int featureStart,... |
70 |
|
int featureEnd, Color featureColour, int start, int end, int y1, |
71 |
|
boolean colourOnly) |
72 |
|
{ |
73 |
25891 |
int charHeight = av.getCharHeight(); |
74 |
25891 |
int charWidth = av.getCharWidth(); |
75 |
25891 |
boolean validCharWidth = av.isValidCharWidth(); |
76 |
|
|
77 |
25891 |
if (featureStart > end || featureEnd < start) |
78 |
|
{ |
79 |
0 |
return false; |
80 |
|
} |
81 |
|
|
82 |
25891 |
if (featureStart < start) |
83 |
|
{ |
84 |
0 |
featureStart = start; |
85 |
|
} |
86 |
25891 |
if (featureEnd >= end) |
87 |
|
{ |
88 |
613 |
featureEnd = end; |
89 |
|
} |
90 |
25891 |
int pady = (y1 + charHeight) - charHeight / 5; |
91 |
|
|
92 |
25891 |
FontMetrics fm = g.getFontMetrics(); |
93 |
64858 |
for (int i = featureStart; i <= featureEnd; i++) |
94 |
|
{ |
95 |
38967 |
char s = seq.getCharAt(i); |
96 |
|
|
97 |
38967 |
if (Comparison.isGap(s)) |
98 |
|
{ |
99 |
0 |
continue; |
100 |
|
} |
101 |
|
|
102 |
38967 |
g.setColor(featureColour); |
103 |
|
|
104 |
38967 |
g.fillRect((i - start) * charWidth, y1, charWidth, charHeight); |
105 |
|
|
106 |
38967 |
if (colourOnly || !validCharWidth) |
107 |
|
{ |
108 |
6 |
continue; |
109 |
|
} |
110 |
|
|
111 |
38961 |
g.setColor(Color.white); |
112 |
38961 |
int charOffset = (charWidth - fm.charWidth(s)) / 2; |
113 |
38961 |
g.drawString(String.valueOf(s), |
114 |
|
charOffset + (charWidth * (i - start)), pady); |
115 |
|
} |
116 |
25891 |
return true; |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
@param |
126 |
|
@param |
127 |
|
@param |
128 |
|
@param |
129 |
|
@param |
130 |
|
@param |
131 |
|
@param |
132 |
|
@param |
133 |
|
@param |
134 |
|
@return |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 11 |
Complexity Density: 0.33 |
|
136 |
0 |
boolean renderScoreFeature(Graphics g, SequenceI seq, int fstart,... |
137 |
|
int fend, Color featureColour, int start, int end, int y1, |
138 |
|
byte[] bs, boolean colourOnly) |
139 |
|
{ |
140 |
0 |
if (fstart > end || fend < start) |
141 |
|
{ |
142 |
0 |
return false; |
143 |
|
} |
144 |
|
|
145 |
0 |
if (fstart < start) |
146 |
|
{ |
147 |
0 |
fstart = start; |
148 |
|
} |
149 |
|
|
150 |
0 |
if (fend >= end) |
151 |
|
{ |
152 |
0 |
fend = end; |
153 |
|
} |
154 |
0 |
int charHeight = av.getCharHeight(); |
155 |
0 |
int pady = (y1 + charHeight) - charHeight / 5; |
156 |
0 |
int ystrt = 0, yend = charHeight; |
157 |
0 |
if (bs[0] != 0) |
158 |
|
{ |
159 |
|
|
160 |
0 |
if (bs[1] < 128) |
161 |
|
{ |
162 |
0 |
yend = charHeight * (128 - bs[1]) / 512; |
163 |
0 |
ystrt = charHeight - yend / 2; |
164 |
|
} |
165 |
|
else |
166 |
|
{ |
167 |
0 |
ystrt = charHeight / 2; |
168 |
0 |
yend = charHeight * (bs[1] - 128) / 512; |
169 |
|
} |
170 |
|
} |
171 |
|
else |
172 |
|
{ |
173 |
0 |
yend = charHeight * bs[1] / 255; |
174 |
0 |
ystrt = charHeight - yend; |
175 |
|
|
176 |
|
} |
177 |
|
|
178 |
0 |
FontMetrics fm = g.getFontMetrics(); |
179 |
0 |
int charWidth = av.getCharWidth(); |
180 |
|
|
181 |
0 |
for (int i = fstart; i <= fend; i++) |
182 |
|
{ |
183 |
0 |
char s = seq.getCharAt(i); |
184 |
|
|
185 |
0 |
if (Comparison.isGap(s)) |
186 |
|
{ |
187 |
0 |
continue; |
188 |
|
} |
189 |
|
|
190 |
0 |
g.setColor(featureColour); |
191 |
0 |
int x = (i - start) * charWidth; |
192 |
0 |
g.drawRect(x, y1, charWidth, charHeight); |
193 |
0 |
g.fillRect(x, y1 + ystrt, charWidth, yend); |
194 |
|
|
195 |
0 |
if (colourOnly || !av.isValidCharWidth()) |
196 |
|
{ |
197 |
0 |
continue; |
198 |
|
} |
199 |
|
|
200 |
0 |
g.setColor(Color.black); |
201 |
0 |
int charOffset = (charWidth - fm.charWidth(s)) / 2; |
202 |
0 |
g.drawString(String.valueOf(s), |
203 |
|
charOffset + (charWidth * (i - start)), pady); |
204 |
|
} |
205 |
0 |
return true; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
@inheritDoc |
210 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
211 |
30 |
@Override... |
212 |
|
public Color findFeatureColour(SequenceI seq, int column, Graphics g) |
213 |
|
{ |
214 |
30 |
if (!av.isShowSequenceFeatures()) |
215 |
|
{ |
216 |
0 |
return null; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
30 |
if (Comparison.isGap(seq.getCharAt(column - 1))) |
221 |
|
{ |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
1 |
return null; |
227 |
|
} |
228 |
|
|
229 |
29 |
Color renderedColour = null; |
230 |
29 |
if (transparency == 1.0f) |
231 |
|
{ |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
25 |
renderedColour = findFeatureColour(seq, column); |
236 |
|
} |
237 |
|
else |
238 |
|
{ |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
4 |
renderedColour = drawSequence(g, seq, column, column, 0, true); |
244 |
|
} |
245 |
29 |
return renderedColour; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
@param |
255 |
|
|
256 |
|
@param |
257 |
|
@param |
258 |
|
|
259 |
|
@param |
260 |
|
|
261 |
|
@param |
262 |
|
|
263 |
|
@param |
264 |
|
|
265 |
|
|
266 |
|
@return |
267 |
|
|
|
|
| 78.9% |
Uncovered Elements: 15 (71) |
Complexity: 19 |
Complexity Density: 0.46 |
|
268 |
1034 |
public synchronized Color drawSequence(final Graphics g,... |
269 |
|
final SequenceI seq, int start, int end, int y1, |
270 |
|
boolean colourOnly) |
271 |
|
{ |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
1034 |
Range visiblePositions = seq.findPositions(start+1, end+1); |
276 |
1034 |
if (visiblePositions == null || !seq.getFeatures().hasFeatures()) |
277 |
|
{ |
278 |
0 |
return null; |
279 |
|
} |
280 |
|
|
281 |
1034 |
updateFeatures(); |
282 |
|
|
283 |
1034 |
if (transparency != 1f && g != null) |
284 |
|
{ |
285 |
4 |
Graphics2D g2 = (Graphics2D) g; |
286 |
4 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, |
287 |
|
transparency)); |
288 |
|
} |
289 |
|
|
290 |
1034 |
Color drawnColour = null; |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
29973 |
for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) |
296 |
|
{ |
297 |
28939 |
String type = renderOrder[renderIndex]; |
298 |
28939 |
if (!showFeatureOfType(type)) |
299 |
|
{ |
300 |
21405 |
continue; |
301 |
|
} |
302 |
|
|
303 |
7534 |
FeatureColourI fc = getFeatureStyle(type); |
304 |
7534 |
List<SequenceFeature> overlaps = seq.getFeatures().findFeatures( |
305 |
|
visiblePositions.getBegin(), visiblePositions.getEnd(), type); |
306 |
|
|
307 |
7534 |
if (fc.isSimpleColour()) |
308 |
|
{ |
309 |
7534 |
filterFeaturesForDisplay(overlaps); |
310 |
|
} |
311 |
|
|
312 |
7534 |
for (SequenceFeature sf : overlaps) |
313 |
|
{ |
314 |
25891 |
Color featureColour = getColor(sf, fc); |
315 |
25891 |
if (featureColour == null) |
316 |
|
{ |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
0 |
continue; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
25891 |
int visibleStart = sf.getBegin(); |
329 |
25891 |
if (visibleStart < visiblePositions.getBegin()) |
330 |
|
{ |
331 |
55 |
visibleStart = sf.isContactFeature() ? sf.getEnd() |
332 |
|
: visiblePositions.getBegin(); |
333 |
|
} |
334 |
25891 |
int visibleEnd = sf.getEnd(); |
335 |
25891 |
if (visibleEnd > visiblePositions.getEnd()) |
336 |
|
{ |
337 |
7 |
visibleEnd = sf.isContactFeature() ? sf.getBegin() |
338 |
|
: visiblePositions.getEnd(); |
339 |
|
} |
340 |
|
|
341 |
25891 |
int featureStartCol = seq.findIndex(visibleStart); |
342 |
25891 |
int featureEndCol = sf.begin == sf.end ? featureStartCol : seq |
343 |
|
.findIndex(visibleEnd); |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
25891 |
boolean isContactFeature = sf.isContactFeature(); |
348 |
|
|
349 |
25891 |
if (isContactFeature) |
350 |
|
{ |
351 |
0 |
boolean drawn = renderFeature(g, seq, featureStartCol - 1, |
352 |
|
featureStartCol - 1, featureColour, start, end, y1, |
353 |
|
colourOnly); |
354 |
0 |
drawn |= renderFeature(g, seq, featureEndCol - 1, |
355 |
|
featureEndCol - 1, featureColour, start, end, y1, |
356 |
|
colourOnly); |
357 |
0 |
if (drawn) |
358 |
|
{ |
359 |
0 |
drawnColour = featureColour; |
360 |
|
} |
361 |
|
} |
362 |
|
else |
363 |
|
{ |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
25891 |
boolean drawn = renderFeature(g, seq, |
385 |
|
featureStartCol - 1, |
386 |
|
featureEndCol - 1, featureColour, |
387 |
|
start, end, y1, colourOnly); |
388 |
25891 |
if (drawn) |
389 |
|
{ |
390 |
25891 |
drawnColour = featureColour; |
391 |
|
} |
392 |
|
|
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
|
|
397 |
1034 |
if (transparency != 1.0f && g != null) |
398 |
|
{ |
399 |
|
|
400 |
|
|
401 |
|
|
402 |
4 |
Graphics2D g2 = (Graphics2D) g; |
403 |
4 |
g2.setComposite(NO_TRANSPARENCY); |
404 |
|
} |
405 |
|
|
406 |
1034 |
return drawnColour; |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
414 |
17 |
@Override... |
415 |
|
public void featuresAdded() |
416 |
|
{ |
417 |
17 |
findAllFeatures(); |
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
@param |
432 |
|
@param |
433 |
|
|
434 |
|
@return |
435 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
436 |
25 |
Color findFeatureColour(SequenceI seq, int column)... |
437 |
|
{ |
438 |
|
|
439 |
|
|
440 |
|
|
441 |
25 |
updateFeatures(); |
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
25 |
for (int renderIndex = renderOrder.length |
448 |
37 |
- 1; renderIndex >= 0; renderIndex--) |
449 |
|
{ |
450 |
30 |
String type = renderOrder[renderIndex]; |
451 |
30 |
if (!showFeatureOfType(type)) |
452 |
|
{ |
453 |
1 |
continue; |
454 |
|
} |
455 |
|
|
456 |
29 |
List<SequenceFeature> overlaps = seq.findFeatures(column, column, |
457 |
|
type); |
458 |
29 |
for (SequenceFeature sequenceFeature : overlaps) |
459 |
|
{ |
460 |
23 |
if (!featureGroupNotShown(sequenceFeature)) |
461 |
|
{ |
462 |
22 |
Color col = getColour(sequenceFeature); |
463 |
22 |
if (col != null) |
464 |
|
{ |
465 |
18 |
return col; |
466 |
|
} |
467 |
|
} |
468 |
|
} |
469 |
|
} |
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
7 |
return null; |
475 |
|
} |
476 |
|
} |