1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.datamodel.SequenceGroup; |
24 |
|
import jalview.datamodel.SequenceI; |
25 |
|
import jalview.renderer.ResidueColourFinder; |
26 |
|
import jalview.renderer.seqfeatures.FeatureColourFinder; |
27 |
|
|
28 |
|
import java.awt.Color; |
29 |
|
import java.awt.Font; |
30 |
|
import java.awt.FontMetrics; |
31 |
|
import java.awt.Graphics; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 191 (191) |
Complexity: 54 |
Complexity Density: 0.48 |
|
33 |
|
public class SequenceRenderer implements jalview.api.SequenceRenderer |
34 |
|
{ |
35 |
|
final static int CHAR_TO_UPPER = 'A' - 'a'; |
36 |
|
|
37 |
|
AlignViewport av; |
38 |
|
|
39 |
|
FontMetrics fm; |
40 |
|
|
41 |
|
boolean renderGaps = true; |
42 |
|
|
43 |
|
SequenceGroup[] allGroups = null; |
44 |
|
|
45 |
|
Color resBoxColour; |
46 |
|
|
47 |
|
Graphics graphics; |
48 |
|
|
49 |
|
ResidueColourFinder resColourFinder; |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
0 |
public SequenceRenderer(AlignViewport av)... |
52 |
|
{ |
53 |
0 |
this.av = av; |
54 |
0 |
resColourFinder = new ResidueColourFinder(); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
63 |
0 |
public void prepare(Graphics g, boolean renderGaps)... |
64 |
|
{ |
65 |
0 |
graphics = g; |
66 |
0 |
fm = g.getFontMetrics(); |
67 |
|
|
68 |
0 |
this.renderGaps = renderGaps; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
@param |
78 |
|
@param |
79 |
|
@return |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
@Override... |
82 |
|
public Color getResidueColour(final SequenceI seq, int position, |
83 |
|
FeatureColourFinder finder) |
84 |
|
{ |
85 |
|
|
86 |
|
|
87 |
0 |
return resColourFinder.getResidueColour(av.getShowBoxes(), |
88 |
|
av.getResidueShading(), |
89 |
|
allGroups, seq, position, finder); |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
92 |
0 |
public Color findSequenceColour(SequenceI seq, int i)... |
93 |
|
{ |
94 |
0 |
allGroups = av.getAlignment().findAllGroups(seq); |
95 |
0 |
drawBoxes(seq, i, i, 0); |
96 |
0 |
return resBoxColour; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
99 |
0 |
public void drawSequence(SequenceI seq, SequenceGroup[] sg, int start,... |
100 |
|
int end, int y1) |
101 |
|
{ |
102 |
0 |
if (seq == null) |
103 |
|
{ |
104 |
0 |
return; |
105 |
|
} |
106 |
|
|
107 |
0 |
allGroups = sg; |
108 |
|
|
109 |
0 |
drawBoxes(seq, start, end, y1); |
110 |
|
|
111 |
0 |
if (av.validCharWidth) |
112 |
|
{ |
113 |
0 |
drawText(seq, start, end, y1); |
114 |
|
} |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 8 |
Complexity Density: 0.32 |
|
117 |
0 |
public void drawBoxes(SequenceI seq, int start, int end, int y1)... |
118 |
|
{ |
119 |
0 |
int i = start; |
120 |
0 |
int length = seq.getLength(); |
121 |
|
|
122 |
0 |
int curStart = -1; |
123 |
0 |
int curWidth = av.getCharWidth(), avCharWidth = av.getCharWidth(), |
124 |
|
avCharHeight = av.getCharHeight(); |
125 |
|
|
126 |
0 |
Color resBoxColour = Color.white; |
127 |
0 |
Color tempColour = null; |
128 |
0 |
while (i <= end) |
129 |
|
{ |
130 |
0 |
resBoxColour = Color.white; |
131 |
0 |
if (i < length) |
132 |
|
{ |
133 |
0 |
SequenceGroup currentSequenceGroup = resColourFinder |
134 |
|
.getCurrentSequenceGroup(allGroups, i); |
135 |
0 |
if (currentSequenceGroup != null) |
136 |
|
{ |
137 |
0 |
if (currentSequenceGroup.getDisplayBoxes()) |
138 |
|
{ |
139 |
0 |
resBoxColour = resColourFinder.getBoxColour( |
140 |
|
currentSequenceGroup.getGroupColourScheme(), seq, |
141 |
|
i); |
142 |
|
} |
143 |
|
} |
144 |
0 |
else if (av.getShowBoxes()) |
145 |
|
{ |
146 |
0 |
resBoxColour = resColourFinder |
147 |
|
.getBoxColour(av.getResidueShading(), seq, i); |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
0 |
if (resBoxColour != tempColour) |
152 |
|
{ |
153 |
0 |
if (tempColour != null) |
154 |
|
{ |
155 |
0 |
graphics.fillRect(avCharWidth * (curStart - start), y1, curWidth, |
156 |
|
avCharHeight); |
157 |
|
} |
158 |
0 |
graphics.setColor(resBoxColour); |
159 |
|
|
160 |
0 |
curStart = i; |
161 |
0 |
curWidth = avCharWidth; |
162 |
0 |
tempColour = resBoxColour; |
163 |
|
|
164 |
|
} |
165 |
|
else |
166 |
|
{ |
167 |
0 |
curWidth += avCharWidth; |
168 |
|
} |
169 |
|
|
170 |
0 |
i++; |
171 |
|
} |
172 |
|
|
173 |
0 |
graphics.fillRect(avCharWidth * (curStart - start), y1, curWidth, |
174 |
|
avCharHeight); |
175 |
|
} |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 78 (78) |
Complexity: 19 |
Complexity Density: 0.41 |
|
177 |
0 |
public void drawText(SequenceI seq, int start, int end, int y1)... |
178 |
|
{ |
179 |
0 |
int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); |
180 |
0 |
Font boldFont = null; |
181 |
0 |
boolean bold = false; |
182 |
0 |
if (av.isUpperCasebold()) |
183 |
|
{ |
184 |
0 |
boldFont = new Font(av.getFont().getName(), Font.BOLD, avCharHeight); |
185 |
|
|
186 |
0 |
graphics.setFont(av.getFont()); |
187 |
|
} |
188 |
|
|
189 |
0 |
y1 += avCharHeight - avCharHeight / 5; |
190 |
|
|
191 |
0 |
int charOffset = 0; |
192 |
|
|
193 |
|
|
194 |
0 |
if (end + 1 >= seq.getLength()) |
195 |
|
{ |
196 |
0 |
end = seq.getLength() - 1; |
197 |
|
} |
198 |
|
|
199 |
0 |
char s = ' '; |
200 |
0 |
boolean srep = av.isDisplayReferenceSeq(); |
201 |
0 |
for (int i = start; i <= end; i++) |
202 |
|
{ |
203 |
0 |
graphics.setColor(Color.black); |
204 |
|
|
205 |
0 |
s = seq.getCharAt(i); |
206 |
0 |
if (!renderGaps && jalview.util.Comparison.isGap(s)) |
207 |
|
{ |
208 |
0 |
continue; |
209 |
|
} |
210 |
|
|
211 |
0 |
SequenceGroup currentSequenceGroup = resColourFinder |
212 |
|
.getCurrentSequenceGroup(allGroups, i); |
213 |
0 |
if (currentSequenceGroup != null) |
214 |
|
{ |
215 |
0 |
if (!currentSequenceGroup.getDisplayText()) |
216 |
|
{ |
217 |
0 |
continue; |
218 |
|
} |
219 |
|
|
220 |
0 |
if (currentSequenceGroup.getColourText()) |
221 |
|
{ |
222 |
0 |
resBoxColour = resColourFinder.getBoxColour( |
223 |
|
currentSequenceGroup.getGroupColourScheme(), seq, i); |
224 |
0 |
graphics.setColor(resBoxColour.darker()); |
225 |
|
} |
226 |
0 |
if (currentSequenceGroup.getShowNonconserved()) |
227 |
|
{ |
228 |
0 |
s = getDisplayChar(srep, i, s, '.', currentSequenceGroup); |
229 |
|
} |
230 |
|
} |
231 |
|
else |
232 |
|
{ |
233 |
0 |
if (!av.getShowText()) |
234 |
|
{ |
235 |
0 |
continue; |
236 |
|
} |
237 |
|
|
238 |
0 |
if (av.getColourText()) |
239 |
|
{ |
240 |
0 |
resBoxColour = resColourFinder |
241 |
|
.getBoxColour(av.getResidueShading(), seq, i); |
242 |
0 |
if (av.getShowBoxes()) |
243 |
|
{ |
244 |
0 |
graphics.setColor(resBoxColour.darker()); |
245 |
|
} |
246 |
|
else |
247 |
|
{ |
248 |
0 |
graphics.setColor(resBoxColour); |
249 |
|
} |
250 |
|
} |
251 |
0 |
if (av.getShowUnconserved()) |
252 |
|
{ |
253 |
0 |
s = getDisplayChar(srep, i, s, '.', null); |
254 |
|
|
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
0 |
if (av.isUpperCasebold()) |
259 |
|
{ |
260 |
0 |
fm = graphics.getFontMetrics(); |
261 |
0 |
if ('A' <= s && s <= 'Z') |
262 |
|
{ |
263 |
0 |
if (!bold) |
264 |
|
{ |
265 |
|
|
266 |
0 |
graphics.setFont(boldFont); |
267 |
|
} |
268 |
0 |
bold = true; |
269 |
|
} |
270 |
0 |
else if (bold) |
271 |
|
{ |
272 |
0 |
graphics.setFont(av.font); |
273 |
0 |
bold = false; |
274 |
|
} |
275 |
|
|
276 |
|
} |
277 |
|
|
278 |
0 |
charOffset = (avCharWidth - fm.charWidth(s)) / 2; |
279 |
0 |
graphics.drawString(String.valueOf(s), |
280 |
|
charOffset + avCharWidth * (i - start), y1); |
281 |
|
} |
282 |
|
|
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
@param |
292 |
|
@param |
293 |
|
@param |
294 |
|
@return |
295 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 14 |
Complexity Density: 3.5 |
|
296 |
0 |
private char getDisplayChar(final boolean usesrep, int position,... |
297 |
|
char sequenceChar, char conservedChar, SequenceGroup currentGroup) |
298 |
|
{ |
299 |
|
|
300 |
|
|
301 |
0 |
char conschar = (usesrep) ? (currentGroup == null |
302 |
|
|| position < currentGroup.getStartRes() |
303 |
|
|| position > currentGroup.getEndRes() |
304 |
|
? av.getAlignment().getSeqrep().getCharAt(position) |
305 |
0 |
: (currentGroup.getSeqrep() != null |
306 |
|
? currentGroup.getSeqrep().getCharAt(position) |
307 |
|
: av.getAlignment().getSeqrep() |
308 |
|
.getCharAt(position))) |
309 |
0 |
: (currentGroup != null && currentGroup.getConsensus() != null |
310 |
|
&& position >= currentGroup.getStartRes() |
311 |
|
&& position <= currentGroup.getEndRes() |
312 |
|
&& currentGroup |
313 |
|
.getConsensus().annotations.length > position) |
314 |
|
? currentGroup |
315 |
|
.getConsensus().annotations[position].displayCharacter |
316 |
|
.charAt(0) |
317 |
|
: av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter |
318 |
|
.charAt(0); |
319 |
0 |
if (!jalview.util.Comparison.isGap(conschar) |
320 |
|
&& (sequenceChar == conschar |
321 |
|
|| sequenceChar + CHAR_TO_UPPER == conschar)) |
322 |
|
{ |
323 |
0 |
sequenceChar = conservedChar; |
324 |
|
} |
325 |
0 |
return sequenceChar; |
326 |
|
} |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
328 |
0 |
public void drawHighlightedText(SequenceI seq, int start, int end,... |
329 |
|
int x1, int y1) |
330 |
|
{ |
331 |
0 |
int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); |
332 |
0 |
int pady = avCharHeight / 5; |
333 |
0 |
int charOffset = 0; |
334 |
0 |
graphics.setColor(Color.black); |
335 |
0 |
graphics.fillRect(x1, y1, avCharWidth * (end - start + 1), |
336 |
|
avCharHeight); |
337 |
0 |
graphics.setColor(Color.white); |
338 |
|
|
339 |
0 |
char s = '~'; |
340 |
|
|
341 |
0 |
if (av.validCharWidth) |
342 |
|
{ |
343 |
0 |
for (int i = start; i <= end; i++) |
344 |
|
{ |
345 |
0 |
if (i < seq.getLength()) |
346 |
|
{ |
347 |
0 |
s = seq.getCharAt(i); |
348 |
|
} |
349 |
|
|
350 |
0 |
charOffset = (avCharWidth - fm.charWidth(s)) / 2; |
351 |
0 |
graphics.drawString(String.valueOf(s), |
352 |
|
charOffset + x1 + avCharWidth * (i - start), |
353 |
|
y1 + avCharHeight - pady); |
354 |
|
} |
355 |
|
} |
356 |
|
} |
357 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
358 |
0 |
public void drawCursor(SequenceI seq, int res, int x1, int y1)... |
359 |
|
{ |
360 |
0 |
int pady = av.getCharHeight() / 5; |
361 |
0 |
int charOffset = 0; |
362 |
0 |
graphics.setColor(Color.black); |
363 |
0 |
graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight()); |
364 |
0 |
graphics.setColor(Color.white); |
365 |
|
|
366 |
0 |
graphics.setColor(Color.white); |
367 |
|
|
368 |
0 |
char s = seq.getCharAt(res); |
369 |
0 |
if (av.validCharWidth) |
370 |
|
{ |
371 |
|
|
372 |
0 |
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2; |
373 |
0 |
graphics.drawString(String.valueOf(s), charOffset + x1, |
374 |
|
(y1 + av.getCharHeight()) - pady); |
375 |
|
} |
376 |
|
} |
377 |
|
|
378 |
|
} |