JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / renderer / AnnotationRenderer.js
1 Clazz.declarePackage ("jalview.renderer");\r
2 Clazz.load (["jalview.util.Platform", "java.awt.Color"], "jalview.renderer.AnnotationRenderer", ["jalview.analysis.AAFrequency", "$.CodingUtils", "$.StructureFrequency", "jalview.jsdev.RegExp", "jalview.schemes.NucleotideColourScheme", "$.ResidueProperties", "$.ZappoColourScheme", "java.awt.BasicStroke", "java.awt.geom.AffineTransform", "java.util.BitSet"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.debugRedraw = false;\r
5 this.charWidth = 0;\r
6 this.endRes = 0;\r
7 this.charHeight = 0;\r
8 this.validCharWidth = false;\r
9 this.hasHiddenColumns = false;\r
10 this.fm = null;\r
11 this.MAC = false;\r
12 this.av_renderHistogram = true;\r
13 this.av_renderProfile = true;\r
14 this.av_normaliseProfile = false;\r
15 this.profcolour = null;\r
16 this.columnSelection = null;\r
17 this.hconsensus = null;\r
18 this.complementConsensus = null;\r
19 this.hStrucConsensus = null;\r
20 this.av_ignoreGapsConsensus = false;\r
21 this.fadedImage = null;\r
22 this.annotationPanel = null;\r
23 this.imgWidth = 0;\r
24 this.sOffset = 0;\r
25 this.visHeight = 0;\r
26 this.useClip = true;\r
27 this.canClip = false;\r
28 this.rna = false;\r
29 this.sdNOTCANONICAL_COLOUR = null;\r
30 Clazz.instantialize (this, arguments);\r
31 }, jalview.renderer, "AnnotationRenderer");\r
32 Clazz.prepareFields (c$, function () {\r
33 this.MAC = jalview.util.Platform.isAMac ();\r
34 });\r
35 Clazz.makeConstructor (c$, \r
36 function () {\r
37 this.construct (false);\r
38 });\r
39 Clazz.makeConstructor (c$, \r
40 function (debugRedraw) {\r
41 this.debugRedraw = debugRedraw;\r
42 }, "~B");\r
43 Clazz.defineMethod (c$, "drawStemAnnot", \r
44 function (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd) {\r
45 g.setColor (jalview.renderer.AnnotationRenderer.STEM_COLOUR);\r
46 var sCol = (Clazz.doubleToInt (lastSSX / this.charWidth)) + startRes;\r
47 var x1 = lastSSX;\r
48 var x2 = (x * this.charWidth);\r
49 var closeparen = jalview.jsdev.RegExp.newRegex (["(\\))"]);\r
50 var dc = (column == 0 || row_annotations[column - 1] == null) ? ' ' : row_annotations[column - 1].secondaryStructure;\r
51 var diffupstream = sCol == 0 || row_annotations[sCol - 1] == null || dc != row_annotations[sCol - 1].secondaryStructure;\r
52 var diffdownstream = !validRes || !validEnd || row_annotations[column] == null || dc != row_annotations[column].secondaryStructure;\r
53 if (column > 0 && jalview.schemes.ResidueProperties.isCloseParenRNA (dc)) {\r
54 if (diffupstream) {\r
55 g.fillPolygon ( Clazz.newIntArray (-1, [lastSSX + 5, lastSSX + 5, lastSSX]),  Clazz.newIntArray (-1, [y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset]), 3);\r
56 x1 += 5;\r
57 }if (diffdownstream) {\r
58 x2 -= 1;\r
59 }} else {\r
60 if (diffdownstream) {\r
61 g.fillPolygon ( Clazz.newIntArray (-1, [x2 - 5, x2 - 5, x2]),  Clazz.newIntArray (-1, [y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset]), 3);\r
62 x2 -= 5;\r
63 }if (diffupstream) {\r
64 x1 += 1;\r
65 }}g.fillRect (x1, y + 4 + iconOffset, x2 - x1, 7);\r
66 }, "java.awt.Graphics,~A,~N,~N,~N,~N,~N,~N,~B,~B");\r
67 Clazz.defineMethod (c$, "drawNotCanonicalAnnot", \r
68 function (g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd) {\r
69 g.setColor (nonCanColor);\r
70 var sCol = (Clazz.doubleToInt (lastSSX / this.charWidth)) + startRes;\r
71 var x1 = lastSSX;\r
72 var x2 = (x * this.charWidth);\r
73 var closeparen = jalview.jsdev.RegExp.newRegex (["}|]|<|[a-z]"]);\r
74 var dc = (column == 0 || row_annotations[column - 1] == null) ? "" : row_annotations[column - 1].displayCharacter;\r
75 var diffupstream = sCol == 0 || row_annotations[sCol - 1] == null || !dc.equals (row_annotations[sCol - 1].displayCharacter);\r
76 var diffdownstream = !validRes || !validEnd || row_annotations[column] == null || !dc.equals (row_annotations[column].displayCharacter);\r
77 if (column > 0 && closeparen.search (dc)) {\r
78 if (diffupstream) {\r
79 g.fillPolygon ( Clazz.newIntArray (-1, [lastSSX + 5, lastSSX + 5, lastSSX]),  Clazz.newIntArray (-1, [y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset]), 3);\r
80 x1 += 5;\r
81 }if (diffdownstream) {\r
82 x2 -= 1;\r
83 }} else {\r
84 if (diffdownstream) {\r
85 g.fillPolygon ( Clazz.newIntArray (-1, [x2 - 5, x2 - 5, x2]),  Clazz.newIntArray (-1, [y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset]), 3);\r
86 x2 -= 5;\r
87 }if (diffupstream) {\r
88 x1 += 1;\r
89 }}g.fillRect (x1, y + 4 + iconOffset, x2 - x1, 7);\r
90 }, "java.awt.Graphics,java.awt.Color,~A,~N,~N,~N,~N,~N,~N,~B,~B");\r
91 Clazz.defineMethod (c$, "updateFromAwtRenderPanel", \r
92 function (annotPanel, av) {\r
93 this.fm = annotPanel.getFontMetrics ();\r
94 this.annotationPanel = annotPanel;\r
95 this.fadedImage = annotPanel.getFadedImage ();\r
96 this.imgWidth = annotPanel.getFadedImageWidth ();\r
97 var bounds = annotPanel.getVisibleVRange ();\r
98 if (bounds != null) {\r
99 this.sOffset = bounds[0];\r
100 this.visHeight = bounds[1];\r
101 if (this.visHeight == 0) {\r
102 this.useClip = false;\r
103 } else {\r
104 this.useClip = this.canClip;\r
105 }} else {\r
106 this.useClip = false;\r
107 }this.updateFromAlignViewport (av);\r
108 }, "jalview.renderer.AwtRenderPanelI,jalview.api.AlignViewportI");\r
109 Clazz.defineMethod (c$, "updateFromAlignViewport", \r
110 function (av) {\r
111 this.charWidth = av.getCharWidth ();\r
112 this.endRes = av.getEndRes ();\r
113 this.charHeight = av.getCharHeight ();\r
114 this.hasHiddenColumns = av.hasHiddenColumns ();\r
115 this.validCharWidth = av.isValidCharWidth ();\r
116 this.av_renderHistogram = av.isShowConsensusHistogram ();\r
117 this.av_renderProfile = av.isShowSequenceLogo ();\r
118 this.av_normaliseProfile = av.isNormaliseSequenceLogo ();\r
119 this.profcolour = av.getGlobalColourScheme ();\r
120 if (this.profcolour == null) {\r
121 this.profcolour = av.getAlignment ().isNucleotide () ?  new jalview.schemes.NucleotideColourScheme () :  new jalview.schemes.ZappoColourScheme ();\r
122 }this.columnSelection = av.getColumnSelection ();\r
123 this.hconsensus = av.getSequenceConsensusHash ();\r
124 this.complementConsensus = av.getComplementConsensusHash ();\r
125 this.hStrucConsensus = av.getRnaStructureConsensusHash ();\r
126 this.av_ignoreGapsConsensus = av.isIgnoreGapsConsensus ();\r
127 }, "jalview.api.AlignViewportI");\r
128 Clazz.defineMethod (c$, "getProfileFor", \r
129 function (aa, column) {\r
130 if (aa.autoCalculated && (aa.label.startsWith ("Consensus") || aa.label.startsWith ("cDNA Consensus"))) {\r
131 var forComplement = aa.label.startsWith ("cDNA Consensus");\r
132 if (aa.groupRef != null && aa.groupRef.consensusData != null && aa.groupRef.isShowSequenceLogo ()) {\r
133 return jalview.analysis.AAFrequency.extractProfile (aa.groupRef.consensusData[column], aa.groupRef.getIgnoreGapsConsensus ());\r
134 }if (aa.groupRef == null && aa.sequenceRef == null) {\r
135 if (forComplement) {\r
136 return jalview.analysis.AAFrequency.extractCdnaProfile (this.complementConsensus[column], this.av_ignoreGapsConsensus);\r
137 } else {\r
138 return jalview.analysis.AAFrequency.extractProfile (this.hconsensus[column], this.av_ignoreGapsConsensus);\r
139 }}} else {\r
140 if (aa.autoCalculated && aa.label.startsWith ("StrucConsensus")) {\r
141 if (aa.groupRef == null && aa.sequenceRef == null && this.hStrucConsensus != null && this.hStrucConsensus.length > column) {\r
142 return jalview.analysis.StructureFrequency.extractProfile (this.hStrucConsensus[column], this.av_ignoreGapsConsensus);\r
143 }}}return null;\r
144 }, "jalview.datamodel.AlignmentAnnotation,~N");\r
145 Clazz.defineMethod (c$, "drawComponent", \r
146 function (annotPanel, av, g, activeRow, startRes, endRes) {\r
147 var stime = System.currentTimeMillis ();\r
148 var usedFaded = false;\r
149 this.updateFromAwtRenderPanel (annotPanel, av);\r
150 this.fm = g.getFontMetrics ();\r
151 var aa = av.getAlignment ().getAlignmentAnnotation ();\r
152 var temp = 0;\r
153 if (aa == null) {\r
154 return false;\r
155 }var x = 0;\r
156 var y = 0;\r
157 var column = 0;\r
158 var lastSS;\r
159 var lastSSX;\r
160 var iconOffset = 0;\r
161 var validRes = false;\r
162 var validEnd = false;\r
163 var labelAllCols = false;\r
164 var centreColLabels;\r
165 var centreColLabelsDef = av.isCentreColumnLabels ();\r
166 var scaleColLabel = false;\r
167 var consensusAnnot = av.getAlignmentConsensusAnnotation ();\r
168 var structConsensusAnnot = av.getAlignmentStrucConsensusAnnotation ();\r
169 var complementConsensusAnnot = av.getComplementConsensusAnnotation ();\r
170 var renderHistogram = true;\r
171 var renderProfile = true;\r
172 var normaliseProfile = false;\r
173 var isRNA = this.rna;\r
174 var graphGroupDrawn =  new java.util.BitSet ();\r
175 var charOffset = 0;\r
176 var fmWidth;\r
177 var fmScaling = 1;\r
178 var ofont = g.getFont ();\r
179 var yfrom = 0;\r
180 var f_i = 0;\r
181 var yto = 0;\r
182 var f_to = 0;\r
183 var clipst = false;\r
184 var clipend = false;\r
185 for (var i = 0; i < aa.length; i++) {\r
186 var row = aa[i];\r
187 isRNA = row.isRNA ();\r
188 {\r
189 if (row.groupRef != null && row === row.groupRef.getConsensus ()) {\r
190 renderHistogram = row.groupRef.isShowConsensusHistogram ();\r
191 renderProfile = row.groupRef.isShowSequenceLogo ();\r
192 normaliseProfile = row.groupRef.isNormaliseSequenceLogo ();\r
193 } else if (row === consensusAnnot || row === structConsensusAnnot || row === complementConsensusAnnot) {\r
194 renderHistogram = this.av_renderHistogram;\r
195 renderProfile = this.av_renderProfile;\r
196 normaliseProfile = this.av_normaliseProfile;\r
197 } else {\r
198 renderHistogram = true;\r
199 }}var row_annotations = row.annotations;\r
200 if (!row.visible) {\r
201 continue;\r
202 }centreColLabels = row.centreColLabels || centreColLabelsDef;\r
203 labelAllCols = row.showAllColLabels;\r
204 scaleColLabel = row.scaleColLabel;\r
205 lastSS = ' ';\r
206 lastSSX = 0;\r
207 if (!this.useClip || ((y - this.charHeight) < this.visHeight && (y + row.height + this.charHeight * 2) >= this.sOffset)) {\r
208 if (!clipst) {\r
209 clipst = true;\r
210 yfrom = y;\r
211 f_i = i;\r
212 }yto = y;\r
213 f_to = i;\r
214 if (row.graph > 0) {\r
215 if (row.graphGroup > -1 && graphGroupDrawn.get (row.graphGroup)) {\r
216 continue;\r
217 }y += row.height;\r
218 if (row.hasText) {\r
219 iconOffset = this.charHeight - this.fm.getDescent ();\r
220 y -= this.charHeight;\r
221 }} else if (row.hasText) {\r
222 iconOffset = this.charHeight - this.fm.getDescent ();\r
223 } else {\r
224 iconOffset = 0;\r
225 }if (row.autoCalculated && av.isCalculationInProgress (row)) {\r
226 y += this.charHeight;\r
227 usedFaded = true;\r
228 g.drawImage (this.fadedImage, 0, y - row.height, this.imgWidth, y, 0, y - row.height, this.imgWidth, y, this.annotationPanel);\r
229 g.setColor (java.awt.Color.black);\r
230 continue;\r
231 }x = (startRes == 0) ? 0 : -1;\r
232 while (x < endRes - startRes) {\r
233 if (this.hasHiddenColumns) {\r
234 column = this.columnSelection.adjustForHiddenColumns (startRes + x);\r
235 if (column > row_annotations.length - 1) {\r
236 break;\r
237 }} else {\r
238 column = startRes + x;\r
239 }if ((row_annotations == null) || (row_annotations.length <= column) || (row_annotations[column] == null)) {\r
240 validRes = false;\r
241 } else {\r
242 validRes = true;\r
243 }var displayChar = validRes ? row_annotations[column].displayCharacter : null;\r
244 if (x > -1) {\r
245 if (activeRow == i) {\r
246 g.setColor (java.awt.Color.red);\r
247 if (this.columnSelection != null) {\r
248 for (var n = 0; n < this.columnSelection.size (); n++) {\r
249 var v = this.columnSelection.columnAt (n);\r
250 if (v == column) {\r
251 g.fillRect (x * this.charWidth, y, this.charWidth, this.charHeight);\r
252 }}\r
253 }}if (row.getInvalidStrucPos () > x) {\r
254 g.setColor (java.awt.Color.orange);\r
255 g.fillRect (x * this.charWidth, y, this.charWidth, this.charHeight);\r
256 } else if (row.getInvalidStrucPos () == x) {\r
257 g.setColor (java.awt.Color.orange.darker ());\r
258 g.fillRect (x * this.charWidth, y, this.charWidth, this.charHeight);\r
259 }if (this.validCharWidth && validRes && displayChar != null && (displayChar.length > 0)) {\r
260 fmWidth = this.fm.charsWidth (displayChar.toCharArray (), 0, displayChar.length);\r
261 if (scaleColLabel) {\r
262 if (fmWidth > this.charWidth) {\r
263 fmScaling = this.charWidth;\r
264 fmScaling /= fmWidth;\r
265 g.setFont (ofont.deriveFont (java.awt.geom.AffineTransform.getScaleInstance (fmScaling, 1.0)));\r
266 fmWidth = this.charWidth;\r
267 }}charOffset = Clazz.floatToInt ((this.charWidth - fmWidth) / 2);\r
268 if (row_annotations[column].colour == null) {\r
269 g.setColor (java.awt.Color.black);\r
270 } else {\r
271 g.setColor (row_annotations[column].colour);\r
272 }if (column == 0 || row.graph > 0) {\r
273 g.drawString (displayChar, (x * this.charWidth) + charOffset, y + iconOffset);\r
274 } else if (row_annotations[column - 1] == null || (labelAllCols || !displayChar.equals (row_annotations[column - 1].displayCharacter) || (displayChar.length < 2 && row_annotations[column].secondaryStructure == ' '))) {\r
275 g.drawString (displayChar, x * this.charWidth + charOffset, y + iconOffset);\r
276 }g.setFont (ofont);\r
277 }}if (row.hasIcons) {\r
278 var ss = validRes ? row_annotations[column].secondaryStructure : '-';\r
279 if (ss == '(') {\r
280 if (displayChar.indexOf (')') > -1) {\r
281 ss = ')';\r
282 }}if (ss == '[') {\r
283 if ((displayChar.indexOf (']') > -1)) {\r
284 ss = ']';\r
285 }}if (ss == '{') {\r
286 if (displayChar.indexOf ('}') > -1) {\r
287 ss = '}';\r
288 }}if (ss == '<') {\r
289 if (displayChar.indexOf ('<') > -1) {\r
290 ss = '>';\r
291 }}if (ss.charCodeAt (0) >= 65) {\r
292 if (displayChar.indexOf (ss.charCodeAt (0) + 32) > -1) {\r
293 ss = String.fromCharCode (ss.charCodeAt (0) + 32);\r
294 }}if (!validRes || (ss != lastSS)) {\r
295 if (x > -1) {\r
296 var nb_annot = x - temp;\r
297 switch (lastSS) {\r
298 case '(':\r
299 case ')':\r
300 this.drawStemAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
301 temp = x;\r
302 break;\r
303 case 'H':\r
304 if (!isRNA) {\r
305 this.drawHelixAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
306 break;\r
307 }case 'E':\r
308 if (!isRNA) {\r
309 this.drawSheetAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
310 break;\r
311 }case '{':\r
312 case '}':\r
313 case '[':\r
314 case ']':\r
315 case '>':\r
316 case '<':\r
317 case 'A':\r
318 case 'a':\r
319 case 'B':\r
320 case 'b':\r
321 case 'C':\r
322 case 'c':\r
323 case 'D':\r
324 case 'd':\r
325 case 'e':\r
326 case 'F':\r
327 case 'f':\r
328 case 'G':\r
329 case 'g':\r
330 case 'h':\r
331 case 'I':\r
332 case 'i':\r
333 case 'J':\r
334 case 'j':\r
335 case 'K':\r
336 case 'k':\r
337 case 'L':\r
338 case 'l':\r
339 case 'M':\r
340 case 'm':\r
341 case 'N':\r
342 case 'n':\r
343 case 'O':\r
344 case 'o':\r
345 case 'P':\r
346 case 'p':\r
347 case 'Q':\r
348 case 'q':\r
349 case 'R':\r
350 case 'r':\r
351 case 'S':\r
352 case 's':\r
353 case 'T':\r
354 case 't':\r
355 case 'U':\r
356 case 'u':\r
357 case 'V':\r
358 case 'v':\r
359 case 'W':\r
360 case 'w':\r
361 case 'X':\r
362 case 'x':\r
363 case 'Y':\r
364 case 'y':\r
365 case 'Z':\r
366 case 'z':\r
367 var nonCanColor = this.getNotCanonicalColor (lastSS);\r
368 this.drawNotCanonicalAnnot (g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
369 temp = x;\r
370 break;\r
371 default:\r
372 g.setColor (java.awt.Color.gray);\r
373 g.fillRect (lastSSX, y + 6 + iconOffset, (x * this.charWidth) - lastSSX, 2);\r
374 temp = x;\r
375 break;\r
376 }\r
377 }if (validRes) {\r
378 lastSS = ss;\r
379 } else {\r
380 lastSS = ' ';\r
381 }if (x > -1) {\r
382 lastSSX = (x * this.charWidth);\r
383 }}}column++;\r
384 x++;\r
385 }\r
386 if (column >= row_annotations.length) {\r
387 column = row_annotations.length - 1;\r
388 validEnd = false;\r
389 } else {\r
390 validEnd = true;\r
391 }if ((row_annotations == null) || (row_annotations.length <= column) || (row_annotations[column] == null)) {\r
392 validRes = false;\r
393 } else {\r
394 validRes = true;\r
395 }if (row.hasIcons) {\r
396 switch (lastSS) {\r
397 case 'H':\r
398 if (!isRNA) {\r
399 this.drawHelixAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
400 break;\r
401 }case 'E':\r
402 if (!isRNA) {\r
403 this.drawSheetAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
404 break;\r
405 }case '(':\r
406 case ')':\r
407 this.drawStemAnnot (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
408 break;\r
409 case '{':\r
410 case '}':\r
411 case '[':\r
412 case ']':\r
413 case '>':\r
414 case '<':\r
415 case 'A':\r
416 case 'a':\r
417 case 'B':\r
418 case 'b':\r
419 case 'C':\r
420 case 'c':\r
421 case 'D':\r
422 case 'd':\r
423 case 'e':\r
424 case 'F':\r
425 case 'f':\r
426 case 'G':\r
427 case 'g':\r
428 case 'h':\r
429 case 'I':\r
430 case 'i':\r
431 case 'J':\r
432 case 'j':\r
433 case 'K':\r
434 case 'k':\r
435 case 'L':\r
436 case 'l':\r
437 case 'M':\r
438 case 'm':\r
439 case 'N':\r
440 case 'n':\r
441 case 'O':\r
442 case 'o':\r
443 case 'P':\r
444 case 'p':\r
445 case 'Q':\r
446 case 'q':\r
447 case 'R':\r
448 case 'r':\r
449 case 'T':\r
450 case 't':\r
451 case 'U':\r
452 case 'u':\r
453 case 'V':\r
454 case 'v':\r
455 case 'W':\r
456 case 'w':\r
457 case 'X':\r
458 case 'x':\r
459 case 'Y':\r
460 case 'y':\r
461 case 'Z':\r
462 case 'z':\r
463 var nonCanColor = this.getNotCanonicalColor (lastSS);\r
464 this.drawNotCanonicalAnnot (g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
465 break;\r
466 default:\r
467 this.drawGlyphLine (g, row_annotations, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd);\r
468 break;\r
469 }\r
470 }if (row.graph > 0 && row.graphHeight > 0) {\r
471 if (row.graph == 2) {\r
472 if (row.graphGroup > -1 && !graphGroupDrawn.get (row.graphGroup)) {\r
473 var groupmax = -999999;\r
474 var groupmin = 9999999;\r
475 for (var gg = 0; gg < aa.length; gg++) {\r
476 if (aa[gg].graphGroup != row.graphGroup) {\r
477 continue;\r
478 }if (aa[gg] !== row) {\r
479 aa[gg].visible = false;\r
480 }if (aa[gg].graphMax > groupmax) {\r
481 groupmax = aa[gg].graphMax;\r
482 }if (aa[gg].graphMin < groupmin) {\r
483 groupmin = aa[gg].graphMin;\r
484 }}\r
485 for (var gg = 0; gg < aa.length; gg++) {\r
486 if (aa[gg].graphGroup == row.graphGroup) {\r
487 this.drawLineGraph (g, aa[gg], aa[gg].annotations, startRes, endRes, y, groupmin, groupmax, row.graphHeight);\r
488 }}\r
489 graphGroupDrawn.set (row.graphGroup);\r
490 } else {\r
491 this.drawLineGraph (g, row, row_annotations, startRes, endRes, y, row.graphMin, row.graphMax, row.graphHeight);\r
492 }} else if (row.graph == 1) {\r
493 this.drawBarGraph (g, row, row_annotations, startRes, endRes, row.graphMin, row.graphMax, y, renderHistogram, renderProfile, normaliseProfile);\r
494 }}} else {\r
495 if (clipst && !clipend) {\r
496 clipend = true;\r
497 }}if (row.graph > 0 && row.hasText) {\r
498 y += this.charHeight;\r
499 }if (row.graph == 0) {\r
500 y += aa[i].height;\r
501 }}\r
502 if (this.debugRedraw) {\r
503 if (this.canClip) {\r
504 if (clipst) {\r
505 System.err.println ("Start clip at : " + yfrom + " (index " + f_i + ")");\r
506 }if (clipend) {\r
507 System.err.println ("End clip at : " + yto + " (index " + f_to + ")");\r
508 }};System.err.println ("Annotation Rendering time:" + (System.currentTimeMillis () - stime));\r
509 };return !usedFaded;\r
510 }, "jalview.renderer.AwtRenderPanelI,jalview.api.AlignViewportI,java.awt.Graphics,~N,~N,~N");\r
511 Clazz.defineMethod (c$, "drawGlyphLine", \r
512 function (g, row, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd) {\r
513 g.setColor (jalview.renderer.AnnotationRenderer.GLYPHLINE_COLOR);\r
514 g.fillRect (lastSSX, y + 6 + iconOffset, (x * this.charWidth) - lastSSX, 2);\r
515 }, "java.awt.Graphics,~A,~N,~N,~N,~N,~N,~N,~B,~B");\r
516 Clazz.defineMethod (c$, "drawSheetAnnot", \r
517 function (g, row, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd) {\r
518 g.setColor (jalview.renderer.AnnotationRenderer.SHEET_COLOUR);\r
519 if (!validEnd || !validRes || row == null || row[column] == null || row[column].secondaryStructure != 'E') {\r
520 g.fillRect (lastSSX, y + 4 + iconOffset, (x * this.charWidth) - lastSSX - 4, 7);\r
521 g.fillPolygon ( Clazz.newIntArray (-1, [(x * this.charWidth) - 4, (x * this.charWidth) - 4, (x * this.charWidth)]),  Clazz.newIntArray (-1, [y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset]), 3);\r
522 } else {\r
523 g.fillRect (lastSSX, y + 4 + iconOffset, (x + 1) * this.charWidth - lastSSX, 7);\r
524 }}, "java.awt.Graphics,~A,~N,~N,~N,~N,~N,~N,~B,~B");\r
525 Clazz.defineMethod (c$, "drawHelixAnnot", \r
526 function (g, row, lastSSX, x, y, iconOffset, startRes, column, validRes, validEnd) {\r
527 g.setColor (jalview.renderer.AnnotationRenderer.HELIX_COLOUR);\r
528 var sCol = (Clazz.doubleToInt (lastSSX / this.charWidth)) + startRes;\r
529 var x1 = lastSSX;\r
530 var x2 = (x * this.charWidth);\r
531 if (this.MAC) {\r
532 var ofs = Clazz.doubleToInt (this.charWidth / 2);\r
533 g.fillRoundRect (lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);\r
534 if (sCol == 0 || row[sCol - 1] == null || row[sCol - 1].secondaryStructure != 'H') {\r
535 } else {\r
536 g.fillRoundRect (lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8, 0, 0);\r
537 }if (!validRes || row[column] == null || row[column].secondaryStructure != 'H') {\r
538 } else {\r
539 g.fillRoundRect (lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8, 0, 0);\r
540 }return;\r
541 }if (sCol == 0 || row[sCol - 1] == null || row[sCol - 1].secondaryStructure != 'H') {\r
542 g.fillArc (lastSSX, y + 4 + iconOffset, this.charWidth, 8, 90, 180);\r
543 x1 += Clazz.doubleToInt (this.charWidth / 2);\r
544 }if (!validRes || row[column] == null || row[column].secondaryStructure != 'H') {\r
545 g.fillArc ((x * this.charWidth) - this.charWidth, y + 4 + iconOffset, this.charWidth, 8, 270, 180);\r
546 x2 -= Clazz.doubleToInt (this.charWidth / 2);\r
547 }g.fillRect (x1, y + 4 + iconOffset, x2 - x1, 8);\r
548 }, "java.awt.Graphics,~A,~N,~N,~N,~N,~N,~N,~B,~B");\r
549 Clazz.defineMethod (c$, "drawLineGraph", \r
550 function (g, _aa, aa_annotations, sRes, eRes, y, min, max, graphHeight) {\r
551 if (sRes > aa_annotations.length) {\r
552 return;\r
553 }var x = 0;\r
554 if (eRes < this.endRes) {\r
555 eRes++;\r
556 }eRes = Math.min (eRes, aa_annotations.length);\r
557 if (sRes == 0) {\r
558 x++;\r
559 }var y1 = y;\r
560 var y2 = y;\r
561 var range = max - min;\r
562 if (min < 0) {\r
563 y2 = y - Clazz.floatToInt ((0 - min / range) * graphHeight);\r
564 }g.setColor (java.awt.Color.gray);\r
565 g.drawLine (x - this.charWidth, y2, (eRes - sRes + 1) * this.charWidth, y2);\r
566 eRes = Math.min (eRes, aa_annotations.length);\r
567 var column;\r
568 var aaMax = aa_annotations.length - 1;\r
569 while (x < eRes - sRes) {\r
570 column = sRes + x;\r
571 if (this.hasHiddenColumns) {\r
572 column = this.columnSelection.adjustForHiddenColumns (column);\r
573 }if (column > aaMax) {\r
574 break;\r
575 }if (aa_annotations[column] == null || aa_annotations[column - 1] == null) {\r
576 x++;\r
577 continue;\r
578 }if (aa_annotations[column].colour == null) {\r
579 g.setColor (java.awt.Color.black);\r
580 } else {\r
581 g.setColor (aa_annotations[column].colour);\r
582 }y1 = y - Clazz.floatToInt (((aa_annotations[column - 1].value - min) / range) * graphHeight);\r
583 y2 = y - Clazz.floatToInt (((aa_annotations[column].value - min) / range) * graphHeight);\r
584 g.drawLine (x * this.charWidth - Clazz.doubleToInt (this.charWidth / 2), y1, x * this.charWidth + Clazz.doubleToInt (this.charWidth / 2), y2);\r
585 x++;\r
586 }\r
587 if (_aa.threshold != null) {\r
588 g.setColor (_aa.threshold.colour);\r
589 var g2 = g;\r
590 g2.setStroke ( new java.awt.BasicStroke (1, 2, 1, 3,  Clazz.newFloatArray (-1, [5, 3]), 0));\r
591 y2 = Clazz.floatToInt (y - ((_aa.threshold.value - min) / range) * graphHeight);\r
592 g.drawLine (0, y2, (eRes - sRes) * this.charWidth, y2);\r
593 g2.setStroke ( new java.awt.BasicStroke ());\r
594 }}, "java.awt.Graphics,jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~N,~N,~N,~N");\r
595 Clazz.defineMethod (c$, "drawBarGraph", \r
596 function (g, _aa, aa_annotations, sRes, eRes, min, max, y, renderHistogram, renderProfile, normaliseProfile) {\r
597 if (sRes > aa_annotations.length) {\r
598 return;\r
599 }var ofont = g.getFont ();\r
600 eRes = Math.min (eRes, aa_annotations.length);\r
601 var x = 0;\r
602 var y1 = y;\r
603 var y2 = y;\r
604 var range = max - min;\r
605 if (min < 0) {\r
606 y2 = y - Clazz.floatToInt ((0 - min / (range)) * _aa.graphHeight);\r
607 }g.setColor (java.awt.Color.gray);\r
608 g.drawLine (x, y2, (eRes - sRes) * this.charWidth, y2);\r
609 var column;\r
610 var aaMax = aa_annotations.length - 1;\r
611 while (x < eRes - sRes) {\r
612 column = sRes + x;\r
613 if (this.hasHiddenColumns) {\r
614 column = this.columnSelection.adjustForHiddenColumns (column);\r
615 }if (column > aaMax) {\r
616 break;\r
617 }if (aa_annotations[column] == null) {\r
618 x++;\r
619 continue;\r
620 }if (aa_annotations[column].colour == null) {\r
621 g.setColor (java.awt.Color.black);\r
622 } else {\r
623 g.setColor (aa_annotations[column].colour);\r
624 }y1 = y - Clazz.floatToInt (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);\r
625 if (renderHistogram) {\r
626 if (y1 - y2 > 0) {\r
627 g.fillRect (x * this.charWidth, y2, this.charWidth, y1 - y2);\r
628 } else {\r
629 g.fillRect (x * this.charWidth, y1, this.charWidth, y2 - y1);\r
630 }}if (renderProfile) {\r
631 var profl = this.getProfileFor (_aa, column);\r
632 if (profl != null && profl[2] != 0) {\r
633 var isStructureProfile = profl[0] == 1;\r
634 var isCdnaProfile = profl[0] == 2;\r
635 var ht = normaliseProfile ? y - _aa.graphHeight : y1;\r
636 var htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);\r
637 var hght;\r
638 var wdth;\r
639 var ht2 = 0;\r
640 var dc;\r
641 dc =  Clazz.newCharArray (isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1), '\0');\r
642 var lm = g.getFontMetrics (ofont).getLineMetrics ("Q", g);\r
643 var scale = 1 / (normaliseProfile ? profl[2] : 100);\r
644 var ofontHeight = 1 / lm.getAscent ();\r
645 var scl = 0.0;\r
646 var c = 3;\r
647 var valuesProcessed = 0;\r
648 while (valuesProcessed < profl[1]) {\r
649 if (isStructureProfile) {\r
650 dc[0] = String.fromCharCode (profl[c++]);\r
651 dc[1] = String.fromCharCode (profl[c++]);\r
652 } else if (isCdnaProfile) {\r
653 dc = jalview.analysis.CodingUtils.decodeCodon (profl[c++]);\r
654 } else {\r
655 dc[0] = String.fromCharCode (profl[c++]);\r
656 }wdth = this.charWidth;\r
657 wdth /= this.fm.charsWidth (dc, 0, dc.length);\r
658 ht += scl;\r
659 scl = htn * scale * profl[c++];\r
660 lm = ofont.getLineMetrics (dc, 0, 1, g.getFontMetrics ().getFontRenderContext ());\r
661 g.setFont (ofont.deriveFont (java.awt.geom.AffineTransform.getScaleInstance (wdth, scl / lm.getAscent ())));\r
662 lm = g.getFontMetrics ().getLineMetrics (dc, 0, 1, g);\r
663 var colour = null;\r
664 if (isCdnaProfile) {\r
665 var codonTranslation = jalview.schemes.ResidueProperties.codonTranslate ( String.instantialize (dc));\r
666 colour = this.profcolour.findColour (codonTranslation.charAt (0), column, null);\r
667 } else {\r
668 colour = this.profcolour.findColour (dc[0], column, null);\r
669 }g.setColor (colour === java.awt.Color.white ? java.awt.Color.lightGray : colour);\r
670 hght = (ht + (scl - lm.getDescent () - lm.getBaselineOffsets ()[lm.getBaselineIndex ()]));\r
671 g.drawChars (dc, 0, dc.length, x * this.charWidth, Clazz.doubleToInt (hght));\r
672 valuesProcessed++;\r
673 }\r
674 g.setFont (ofont);\r
675 }}x++;\r
676 }\r
677 if (_aa.threshold != null) {\r
678 g.setColor (_aa.threshold.colour);\r
679 var g2 = g;\r
680 g2.setStroke ( new java.awt.BasicStroke (1, 2, 1, 3,  Clazz.newFloatArray (-1, [5, 3]), 0));\r
681 y2 = Clazz.floatToInt (y - ((_aa.threshold.value - min) / range) * _aa.graphHeight);\r
682 g.drawLine (0, y2, (eRes - sRes) * this.charWidth, y2);\r
683 g2.setStroke ( new java.awt.BasicStroke ());\r
684 }}, "java.awt.Graphics,jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~N,~N,~N,~B,~B,~B");\r
685 Clazz.defineMethod (c$, "drawGraph", \r
686 function (g, _aa, aa_annotations, width, y, sRes, eRes) {\r
687 eRes = Math.min (eRes, aa_annotations.length);\r
688 g.setColor (java.awt.Color.white);\r
689 g.fillRect (0, 0, width, y);\r
690 g.setColor ( new java.awt.Color (0, 0, 180));\r
691 var x = 0;\r
692 var height;\r
693 for (var j = sRes; j < eRes; j++) {\r
694 if (aa_annotations[j] != null) {\r
695 if (aa_annotations[j].colour == null) {\r
696 g.setColor (java.awt.Color.black);\r
697 } else {\r
698 g.setColor (aa_annotations[j].colour);\r
699 }height = Clazz.floatToInt ((aa_annotations[j].value / _aa.graphMax) * y);\r
700 if (height > y) {\r
701 height = y;\r
702 }g.fillRect (x, y - height, this.charWidth, height);\r
703 }x += this.charWidth;\r
704 }\r
705 }, "java.awt.Graphics,jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~N,~N");\r
706 Clazz.defineMethod (c$, "getNotCanonicalColor", \r
707 function (lastss) {\r
708 switch (lastss) {\r
709 case '{':\r
710 case '}':\r
711 return  new java.awt.Color (255, 125, 5);\r
712 case '[':\r
713 case ']':\r
714 return  new java.awt.Color (245, 115, 10);\r
715 case '>':\r
716 case '<':\r
717 return  new java.awt.Color (235, 135, 15);\r
718 case 'A':\r
719 case 'a':\r
720 return  new java.awt.Color (225, 105, 20);\r
721 case 'B':\r
722 case 'b':\r
723 return  new java.awt.Color (215, 145, 30);\r
724 case 'C':\r
725 case 'c':\r
726 return  new java.awt.Color (205, 95, 35);\r
727 case 'D':\r
728 case 'd':\r
729 return  new java.awt.Color (195, 155, 45);\r
730 case 'E':\r
731 case 'e':\r
732 return  new java.awt.Color (185, 85, 55);\r
733 case 'F':\r
734 case 'f':\r
735 return  new java.awt.Color (175, 165, 65);\r
736 case 'G':\r
737 case 'g':\r
738 return  new java.awt.Color (170, 75, 75);\r
739 case 'H':\r
740 case 'h':\r
741 return  new java.awt.Color (160, 175, 85);\r
742 case 'I':\r
743 case 'i':\r
744 return  new java.awt.Color (150, 65, 95);\r
745 case 'J':\r
746 case 'j':\r
747 return  new java.awt.Color (140, 185, 105);\r
748 case 'K':\r
749 case 'k':\r
750 return  new java.awt.Color (130, 55, 110);\r
751 case 'L':\r
752 case 'l':\r
753 return  new java.awt.Color (120, 195, 120);\r
754 case 'M':\r
755 case 'm':\r
756 return  new java.awt.Color (110, 45, 130);\r
757 case 'N':\r
758 case 'n':\r
759 return  new java.awt.Color (100, 205, 140);\r
760 case 'O':\r
761 case 'o':\r
762 return  new java.awt.Color (90, 35, 150);\r
763 case 'P':\r
764 case 'p':\r
765 return  new java.awt.Color (85, 215, 160);\r
766 case 'Q':\r
767 case 'q':\r
768 return  new java.awt.Color (75, 25, 170);\r
769 case 'R':\r
770 case 'r':\r
771 return  new java.awt.Color (65, 225, 180);\r
772 case 'S':\r
773 case 's':\r
774 return  new java.awt.Color (55, 15, 185);\r
775 case 'T':\r
776 case 't':\r
777 return  new java.awt.Color (45, 235, 195);\r
778 case 'U':\r
779 case 'u':\r
780 return  new java.awt.Color (35, 5, 205);\r
781 case 'V':\r
782 case 'v':\r
783 return  new java.awt.Color (25, 245, 215);\r
784 case 'W':\r
785 case 'w':\r
786 return  new java.awt.Color (15, 0, 225);\r
787 case 'X':\r
788 case 'x':\r
789 return  new java.awt.Color (10, 255, 235);\r
790 case 'Y':\r
791 case 'y':\r
792 return  new java.awt.Color (5, 150, 245);\r
793 case 'Z':\r
794 case 'z':\r
795 return  new java.awt.Color (0, 80, 255);\r
796 default:\r
797 System.out.println ("This is not a interaction : " + lastss);\r
798 return null;\r
799 }\r
800 }, "~S");\r
801 c$.GLYPHLINE_COLOR = c$.prototype.GLYPHLINE_COLOR = java.awt.Color.gray;\r
802 c$.SHEET_COLOUR = c$.prototype.SHEET_COLOUR = java.awt.Color.green;\r
803 c$.HELIX_COLOUR = c$.prototype.HELIX_COLOUR = java.awt.Color.red;\r
804 c$.STEM_COLOUR = c$.prototype.STEM_COLOUR = java.awt.Color.blue;\r
805 });\r