1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.api.AlignViewportI; |
24 |
|
import jalview.datamodel.SequenceGroup; |
25 |
|
import jalview.datamodel.SequenceI; |
26 |
|
import jalview.renderer.ResidueColourFinder; |
27 |
|
import jalview.renderer.seqfeatures.FeatureColourFinder; |
28 |
|
|
29 |
|
import java.awt.Color; |
30 |
|
import java.awt.FontMetrics; |
31 |
|
import java.awt.Graphics; |
32 |
|
|
33 |
|
import org.jfree.graphics2d.svg.SVGGraphics2D; |
34 |
|
import org.jibble.epsgraphics.EpsGraphics2D; |
35 |
|
|
|
|
| 60.6% |
Uncovered Elements: 82 (208) |
Complexity: 62 |
Complexity Density: 0.51 |
|
36 |
|
public class SequenceRenderer implements jalview.api.SequenceRenderer |
37 |
|
{ |
38 |
|
final static int CHAR_TO_UPPER = 'A' - 'a'; |
39 |
|
|
40 |
|
AlignViewportI av; |
41 |
|
|
42 |
|
FontMetrics fm; |
43 |
|
|
44 |
|
boolean renderGaps = true; |
45 |
|
|
46 |
|
SequenceGroup[] allGroups = null; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
Graphics graphics; |
51 |
|
|
52 |
|
boolean monospacedFont; |
53 |
|
|
54 |
|
ResidueColourFinder resColourFinder; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
61 |
838 |
public SequenceRenderer(AlignViewportI viewport)... |
62 |
|
{ |
63 |
838 |
this.av = viewport; |
64 |
838 |
resColourFinder = new ResidueColourFinder(); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@param |
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
73 |
3140 |
@Override... |
74 |
|
public void prepare(Graphics g, boolean renderGaps) |
75 |
|
{ |
76 |
3140 |
graphics = g; |
77 |
3140 |
fm = g.getFontMetrics(); |
78 |
|
|
79 |
|
|
80 |
3140 |
double dwidth = fm.getStringBounds("M", g).getWidth(); |
81 |
|
|
82 |
3140 |
monospacedFont = (dwidth == fm.getStringBounds("|", g).getWidth() |
83 |
|
&& av.getCharWidth() == dwidth); |
84 |
|
|
85 |
3140 |
this.renderGaps = renderGaps; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
@param |
94 |
|
@param |
95 |
|
@param |
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
98 |
32459 |
@Override... |
99 |
|
public Color getResidueColour(final SequenceI seq, int position, |
100 |
|
FeatureColourFinder finder) |
101 |
|
{ |
102 |
32459 |
allGroups = av.getAlignment().findAllGroups(seq); |
103 |
32459 |
return resColourFinder.getResidueColour(av.getShowBoxes(), |
104 |
|
av.getResidueShading(), allGroups, seq, position, finder); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
|
112 |
|
@param |
113 |
|
|
114 |
|
@param |
115 |
|
|
116 |
|
@param |
117 |
|
|
118 |
|
@param |
119 |
|
|
120 |
|
@param |
121 |
|
|
122 |
|
@param |
123 |
|
|
124 |
|
@param |
125 |
|
|
126 |
|
@param |
127 |
|
|
128 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
129 |
15723 |
public void drawSequence(SequenceI seq, SequenceGroup[] sg, int start,... |
130 |
|
int end, int y1) |
131 |
|
{ |
132 |
15723 |
allGroups = sg; |
133 |
|
|
134 |
15723 |
drawBoxes(seq, start, end, y1); |
135 |
|
|
136 |
15723 |
if (av.isValidCharWidth()) |
137 |
|
{ |
138 |
15723 |
drawText(seq, start, end, y1); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
@param |
148 |
|
|
149 |
|
@param |
150 |
|
|
151 |
|
@param |
152 |
|
|
153 |
|
@param |
154 |
|
|
155 |
|
@param |
156 |
|
|
157 |
|
@param |
158 |
|
|
159 |
|
|
|
|
| 90.7% |
Uncovered Elements: 4 (43) |
Complexity: 9 |
Complexity Density: 0.33 |
|
160 |
15723 |
public synchronized void drawBoxes(SequenceI seq, int start, int end,... |
161 |
|
int y1) |
162 |
|
{ |
163 |
15723 |
Color resBoxColour = Color.white; |
164 |
|
|
165 |
15723 |
if (seq == null) |
166 |
|
{ |
167 |
0 |
return; |
168 |
|
} |
169 |
15723 |
int i = start; |
170 |
15723 |
int length = seq.getLength(); |
171 |
|
|
172 |
15723 |
int curStart = -1; |
173 |
15723 |
int curWidth = av.getCharWidth(), avWidth = av.getCharWidth(), |
174 |
|
avHeight = av.getCharHeight(); |
175 |
|
|
176 |
15723 |
Color tempColour = null; |
177 |
|
|
178 |
873737 |
while (i <= end) |
179 |
|
{ |
180 |
858014 |
resBoxColour = Color.white; |
181 |
|
|
182 |
858014 |
if (i < length) |
183 |
|
{ |
184 |
857419 |
SequenceGroup currentSequenceGroup = resColourFinder |
185 |
|
.getCurrentSequenceGroup(allGroups, i); |
186 |
857419 |
if (currentSequenceGroup != null) |
187 |
|
{ |
188 |
457183 |
if (currentSequenceGroup.getDisplayBoxes()) |
189 |
|
{ |
190 |
457183 |
resBoxColour = resColourFinder.getBoxColour( |
191 |
|
currentSequenceGroup.getGroupColourScheme(), seq, i); |
192 |
|
} |
193 |
|
} |
194 |
400236 |
else if (av.getShowBoxes()) |
195 |
|
{ |
196 |
400236 |
resBoxColour = resColourFinder |
197 |
|
.getBoxColour(av.getResidueShading(), seq, i); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
858014 |
if (resBoxColour != tempColour) |
202 |
|
{ |
203 |
408281 |
if (tempColour != null) |
204 |
|
{ |
205 |
392558 |
graphics.fillRect(avWidth * (curStart - start), y1, curWidth, |
206 |
|
avHeight); |
207 |
|
} |
208 |
|
|
209 |
408281 |
graphics.setColor(resBoxColour); |
210 |
|
|
211 |
408281 |
curStart = i; |
212 |
408281 |
curWidth = avWidth; |
213 |
408281 |
tempColour = resBoxColour; |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
449733 |
curWidth += avWidth; |
218 |
|
} |
219 |
|
|
220 |
858014 |
i++; |
221 |
|
} |
222 |
|
|
223 |
15723 |
graphics.fillRect(avWidth * (curStart - start), y1, curWidth, avHeight); |
224 |
|
|
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
@param |
231 |
|
|
232 |
|
@param |
233 |
|
|
234 |
|
@param |
235 |
|
|
236 |
|
@param |
237 |
|
|
238 |
|
@param |
239 |
|
|
240 |
|
@param |
241 |
|
|
242 |
|
@param |
243 |
|
|
244 |
|
|
|
|
| 50.5% |
Uncovered Elements: 49 (99) |
Complexity: 28 |
Complexity Density: 0.49 |
|
245 |
15723 |
public void drawText(SequenceI seq, int start, int end, int y1)... |
246 |
|
{ |
247 |
15723 |
y1 += av.getCharHeight() - av.getCharHeight() / 5; |
248 |
15723 |
int charOffset = 0; |
249 |
15723 |
char s; |
250 |
|
|
251 |
15723 |
if (end + 1 >= seq.getLength()) |
252 |
|
{ |
253 |
1554 |
end = seq.getLength() - 1; |
254 |
|
} |
255 |
15723 |
graphics.setColor(av.getTextColour()); |
256 |
|
|
257 |
15723 |
boolean drawAllText = monospacedFont && av.getShowText() |
258 |
|
&& allGroups.length == 0 && !av.getColourText() |
259 |
|
&& av.getThresholdTextColour() == 0; |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
15723 |
if (graphics instanceof EpsGraphics2D |
266 |
|
|| graphics instanceof SVGGraphics2D) |
267 |
|
{ |
268 |
210 |
drawAllText = false; |
269 |
|
} |
270 |
15723 |
if (drawAllText) |
271 |
|
{ |
272 |
0 |
if (av.isRenderGaps()) |
273 |
|
{ |
274 |
0 |
graphics.drawString(seq.getSequenceAsString(start, end + 1), 0, y1); |
275 |
|
} |
276 |
|
else |
277 |
|
{ |
278 |
0 |
char gap = av.getGapCharacter(); |
279 |
0 |
graphics.drawString( |
280 |
|
seq.getSequenceAsString(start, end + 1).replace(gap, ' '), |
281 |
|
0, y1); |
282 |
|
} |
283 |
|
} |
284 |
|
else |
285 |
|
{ |
286 |
15723 |
boolean srep = av.isDisplayReferenceSeq(); |
287 |
15723 |
boolean getboxColour = false; |
288 |
15723 |
boolean isarep = av.getAlignment().getSeqrep() == seq; |
289 |
15723 |
Color resBoxColour = Color.white; |
290 |
|
|
291 |
873142 |
for (int i = start; i <= end; i++) |
292 |
|
{ |
293 |
|
|
294 |
857419 |
graphics.setColor(av.getTextColour()); |
295 |
857419 |
getboxColour = false; |
296 |
857419 |
s = seq.getCharAt(i); |
297 |
|
|
298 |
857419 |
if (!renderGaps && jalview.util.Comparison.isGap(s)) |
299 |
|
{ |
300 |
0 |
continue; |
301 |
|
} |
302 |
|
|
303 |
857419 |
SequenceGroup currentSequenceGroup = resColourFinder |
304 |
|
.getCurrentSequenceGroup(allGroups, i); |
305 |
857419 |
if (currentSequenceGroup != null) |
306 |
|
{ |
307 |
457183 |
if (!currentSequenceGroup.getDisplayText()) |
308 |
|
{ |
309 |
0 |
continue; |
310 |
|
} |
311 |
|
|
312 |
457183 |
if (currentSequenceGroup.thresholdTextColour > 0 |
313 |
|
|| currentSequenceGroup.getColourText()) |
314 |
|
{ |
315 |
0 |
getboxColour = true; |
316 |
0 |
resBoxColour = resColourFinder.getBoxColour( |
317 |
|
currentSequenceGroup.getGroupColourScheme(), seq, i); |
318 |
|
|
319 |
0 |
if (currentSequenceGroup.getColourText()) |
320 |
|
{ |
321 |
0 |
graphics.setColor(resBoxColour.darker()); |
322 |
|
} |
323 |
|
|
324 |
0 |
if (currentSequenceGroup.thresholdTextColour > 0) |
325 |
|
{ |
326 |
0 |
if (resBoxColour.getRed() + resBoxColour.getBlue() |
327 |
|
+ resBoxColour |
328 |
|
.getGreen() < currentSequenceGroup.thresholdTextColour) |
329 |
|
{ |
330 |
0 |
graphics.setColor(currentSequenceGroup.textColour2); |
331 |
|
} |
332 |
|
} |
333 |
|
} |
334 |
|
else |
335 |
|
{ |
336 |
457183 |
graphics.setColor(currentSequenceGroup.textColour); |
337 |
|
} |
338 |
457183 |
boolean isgrep = currentSequenceGroup != null |
339 |
|
? currentSequenceGroup.getSeqrep() == seq |
340 |
|
: false; |
341 |
457183 |
if (!isarep && !isgrep |
342 |
|
&& currentSequenceGroup.getShowNonconserved()) |
343 |
|
|
344 |
|
{ |
345 |
|
|
346 |
0 |
s = getDisplayChar(srep, i, s, '.', currentSequenceGroup); |
347 |
|
|
348 |
|
} |
349 |
|
|
350 |
|
} |
351 |
|
else |
352 |
|
{ |
353 |
400236 |
if (!av.getShowText()) |
354 |
|
{ |
355 |
0 |
continue; |
356 |
|
} |
357 |
|
|
358 |
400236 |
if (av.getColourText()) |
359 |
|
{ |
360 |
0 |
getboxColour = true; |
361 |
0 |
resBoxColour = resColourFinder |
362 |
|
.getBoxColour(av.getResidueShading(), seq, i); |
363 |
|
|
364 |
0 |
if (av.getShowBoxes()) |
365 |
|
{ |
366 |
0 |
graphics.setColor(resBoxColour.darker()); |
367 |
|
} |
368 |
|
else |
369 |
|
{ |
370 |
0 |
graphics.setColor(resBoxColour); |
371 |
|
} |
372 |
|
} |
373 |
|
|
374 |
400236 |
if (av.getThresholdTextColour() > 0) |
375 |
|
{ |
376 |
0 |
if (!getboxColour) |
377 |
|
{ |
378 |
0 |
resBoxColour = resColourFinder |
379 |
|
.getBoxColour(av.getResidueShading(), seq, i); |
380 |
|
} |
381 |
|
|
382 |
0 |
if (resBoxColour.getRed() + resBoxColour.getBlue() |
383 |
|
+ resBoxColour.getGreen() < av.getThresholdTextColour()) |
384 |
|
{ |
385 |
0 |
graphics.setColor(av.getTextColour2()); |
386 |
|
} |
387 |
|
} |
388 |
400236 |
if (!isarep && av.getShowUnconserved()) |
389 |
|
{ |
390 |
0 |
s = getDisplayChar(srep, i, s, '.', null); |
391 |
|
|
392 |
|
} |
393 |
|
|
394 |
|
} |
395 |
|
|
396 |
857419 |
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2; |
397 |
857419 |
graphics.drawString(String.valueOf(s), |
398 |
|
charOffset + av.getCharWidth() * (i - start), y1); |
399 |
|
|
400 |
|
} |
401 |
|
} |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
@param |
410 |
|
@param |
411 |
|
@param |
412 |
|
@param |
413 |
|
@return |
414 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 14 |
Complexity Density: 3.5 |
|
415 |
0 |
private char getDisplayChar(final boolean usesrep, int position,... |
416 |
|
char sequenceChar, char conservedChar, SequenceGroup currentGroup) |
417 |
|
{ |
418 |
|
|
419 |
|
|
420 |
0 |
char conschar = (usesrep) ? (currentGroup == null |
421 |
|
|| position < currentGroup.getStartRes() |
422 |
|
|| position > currentGroup.getEndRes() |
423 |
|
? av.getAlignment().getSeqrep().getCharAt(position) |
424 |
0 |
: (currentGroup.getSeqrep() != null |
425 |
|
? currentGroup.getSeqrep().getCharAt(position) |
426 |
|
: av.getAlignment().getSeqrep() |
427 |
|
.getCharAt(position))) |
428 |
0 |
: (currentGroup != null && currentGroup.getConsensus() != null |
429 |
|
&& position >= currentGroup.getStartRes() |
430 |
|
&& position <= currentGroup.getEndRes() |
431 |
|
&& currentGroup |
432 |
|
.getConsensus().annotations.length > position) |
433 |
|
? currentGroup |
434 |
|
.getConsensus().annotations[position].displayCharacter |
435 |
|
.charAt(0) |
436 |
|
: av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter |
437 |
|
.charAt(0); |
438 |
0 |
if (!jalview.util.Comparison.isGap(conschar) |
439 |
|
&& (sequenceChar == conschar |
440 |
|
|| sequenceChar + CHAR_TO_UPPER == conschar)) |
441 |
|
{ |
442 |
0 |
sequenceChar = conservedChar; |
443 |
|
} |
444 |
0 |
return sequenceChar; |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
@param |
451 |
|
|
452 |
|
@param |
453 |
|
|
454 |
|
@param |
455 |
|
|
456 |
|
@param |
457 |
|
|
458 |
|
@param |
459 |
|
|
460 |
|
@param |
461 |
|
|
462 |
|
@param |
463 |
|
|
464 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
465 |
17 |
public void drawHighlightedText(SequenceI seq, int start, int end, int x1,... |
466 |
|
int y1) |
467 |
|
{ |
468 |
17 |
int pady = av.getCharHeight() / 5; |
469 |
17 |
int charOffset = 0; |
470 |
17 |
graphics.setColor(Color.BLACK); |
471 |
17 |
graphics.fillRect(x1, y1, av.getCharWidth() * (end - start + 1), |
472 |
|
av.getCharHeight()); |
473 |
17 |
graphics.setColor(Color.white); |
474 |
|
|
475 |
17 |
char s = '~'; |
476 |
|
|
477 |
|
|
478 |
17 |
if (av.isValidCharWidth()) |
479 |
|
{ |
480 |
82 |
for (int i = start; i <= end; i++) |
481 |
|
{ |
482 |
65 |
if (i < seq.getLength()) |
483 |
|
{ |
484 |
65 |
s = seq.getCharAt(i); |
485 |
|
} |
486 |
|
|
487 |
65 |
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2; |
488 |
65 |
graphics.drawString(String.valueOf(s), |
489 |
|
charOffset + x1 + (av.getCharWidth() * (i - start)), |
490 |
|
(y1 + av.getCharHeight()) - pady); |
491 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
|
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
@param |
499 |
|
|
500 |
|
@param |
501 |
|
|
502 |
|
@param |
503 |
|
|
504 |
|
@param |
505 |
|
|
506 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
507 |
0 |
public void drawCursor(Graphics g, char s, int x1, int y1)... |
508 |
|
{ |
509 |
0 |
int pady = av.getCharHeight() / 5; |
510 |
0 |
int charOffset = 0; |
511 |
0 |
g.setColor(Color.black); |
512 |
0 |
g.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight()); |
513 |
|
|
514 |
0 |
if (av.isValidCharWidth()) |
515 |
|
{ |
516 |
0 |
g.setColor(Color.white); |
517 |
0 |
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2; |
518 |
0 |
g.drawString(String.valueOf(s), charOffset + x1, |
519 |
|
(y1 + av.getCharHeight()) - pady); |
520 |
|
} |
521 |
|
|
522 |
|
} |
523 |
|
} |