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