9aec02cccd135ba46860fdc95a8264ef76cd67a8
[jalview.git] / src / jalview / renderer / AnnotationRenderer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.renderer;
22
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.CodingUtils;
25 import jalview.analysis.Rna;
26 import jalview.analysis.StructureFrequency;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.HiddenMarkovModel;
33 import jalview.datamodel.ProfilesI;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.NucleotideColourScheme;
36 import jalview.schemes.ResidueProperties;
37 import jalview.schemes.ZappoColourScheme;
38 import jalview.util.Platform;
39
40 import java.awt.BasicStroke;
41 import java.awt.Color;
42 import java.awt.Font;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.Image;
47 import java.awt.font.LineMetrics;
48 import java.awt.geom.AffineTransform;
49 import java.awt.image.ImageObserver;
50 import java.util.BitSet;
51 import java.util.Hashtable;
52
53 public class AnnotationRenderer
54 {
55   private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
56
57   private static final int CHAR_A = 'A'; // 65
58
59   private static final int CHAR_Z = 'Z'; // 90
60
61   /**
62    * flag indicating if timing and redraw parameter info should be output
63    */
64   private final boolean debugRedraw;
65
66   private int charWidth, endRes, charHeight;
67
68   private boolean validCharWidth, hasHiddenColumns;
69
70   private FontMetrics fm;
71
72   private final boolean MAC = Platform.isAMac();
73
74   boolean av_renderHistogram = true, av_renderProfile = true,
75           av_normaliseProfile = false;
76
77   boolean av_renderInformationHistogram = true, av_renderHMMProfile = true,
78           av_normaliseHMMProfile = false;
79
80   ResidueShaderI profcolour = null;
81
82   private ColumnSelection columnSelection;
83   
84   private HiddenColumns hiddenColumns;
85
86   private ProfilesI hconsensus;
87
88   private Hashtable[] complementConsensus;
89
90   private Hashtable[] hStrucConsensus;
91
92   private boolean av_ignoreGapsConsensus;
93
94   private boolean av_ignoreBelowBackground;
95
96   /**
97    * attributes set from AwtRenderPanelI
98    */
99   /**
100    * old image used when data is currently being calculated and cannot be
101    * rendered
102    */
103   private Image fadedImage;
104
105   /**
106    * panel being rendered into
107    */
108   private ImageObserver annotationPanel;
109
110   /**
111    * width of image to render in panel
112    */
113   private int imgWidth;
114
115   /**
116    * offset to beginning of visible area
117    */
118   private int sOffset;
119
120   /**
121    * offset to end of visible area
122    */
123   private int visHeight;
124
125   /**
126    * indicate if the renderer should only render the visible portion of the
127    * annotation given the current view settings
128    */
129   private boolean useClip = true;
130
131   /**
132    * master flag indicating if renderer should ever try to clip. not enabled for
133    * jalview 2.8.1
134    */
135   private boolean canClip = false;
136
137   public AnnotationRenderer()
138   {
139     this(false);
140   }
141
142   /**
143    * Create a new annotation Renderer
144    * 
145    * @param debugRedraw
146    *          flag indicating if timing and redraw parameter info should be
147    *          output
148    */
149   public AnnotationRenderer(boolean debugRedraw)
150   {
151     this.debugRedraw = debugRedraw;
152   }
153
154   /**
155    * Remove any references and resources when this object is no longer required
156    */
157   public void dispose()
158   {
159     hconsensus = null;
160     complementConsensus = null;
161     hStrucConsensus = null;
162     fadedImage = null;
163     annotationPanel = null;
164   }
165
166   void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
167           int x, int y, int iconOffset, int startRes, int column,
168           boolean validRes, boolean validEnd)
169   {
170     g.setColor(STEM_COLOUR);
171     int sCol = (lastSSX / charWidth) + startRes;
172     int x1 = lastSSX;
173     int x2 = (x * charWidth);
174
175     char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
176             : row_annotations[column - 1].secondaryStructure;
177
178     boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
179             || dc != row_annotations[sCol - 1].secondaryStructure;
180     boolean diffdownstream = !validRes || !validEnd
181             || row_annotations[column] == null
182             || dc != row_annotations[column].secondaryStructure;
183
184     if (column > 0 && Rna.isClosingParenthesis(dc))
185     {
186       if (diffupstream)
187       // if (validRes && column>1 && row_annotations[column-2]!=null &&
188       // dc.equals(row_annotations[column-2].displayCharacter))
189       {
190         /*
191          * if new annotation with a closing base pair half of the stem, 
192          * display a backward arrow
193          */
194         g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
195                 new int[] { y + iconOffset, y + 14 + iconOffset,
196                     y + 8 + iconOffset }, 3);
197         x1 += 5;
198       }
199       if (diffdownstream)
200       {
201         x2 -= 1;
202       }
203     }
204     else
205     {
206       // display a forward arrow
207       if (diffdownstream)
208       {
209         /*
210          * if annotation ending with an opeing base pair half of the stem, 
211          * display a forward arrow
212          */
213         g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
214             y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
215         x2 -= 5;
216       }
217       if (diffupstream)
218       {
219         x1 += 1;
220       }
221     }
222     // draw arrow body
223     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
224   }
225
226   void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
227           Annotation[] row_annotations, int lastSSX, int x, int y,
228           int iconOffset, int startRes, int column, boolean validRes,
229           boolean validEnd)
230   {
231     // System.out.println(nonCanColor);
232
233     g.setColor(nonCanColor);
234     int sCol = (lastSSX / charWidth) + startRes;
235     int x1 = lastSSX;
236     int x2 = (x * charWidth);
237
238     String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
239             : row_annotations[column - 1].displayCharacter;
240
241     boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
242             || !dc.equals(row_annotations[sCol - 1].displayCharacter);
243     boolean diffdownstream = !validRes || !validEnd
244             || row_annotations[column] == null
245             || !dc.equals(row_annotations[column].displayCharacter);
246     // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
247     // If a closing base pair half of the stem, display a backward arrow
248     if (column > 0 && Rna.isClosingParenthesis(dc))
249     {
250
251       if (diffupstream)
252       // if (validRes && column>1 && row_annotations[column-2]!=null &&
253       // dc.equals(row_annotations[column-2].displayCharacter))
254       {
255         g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
256                 new int[] { y + iconOffset, y + 14 + iconOffset,
257                     y + 8 + iconOffset }, 3);
258         x1 += 5;
259       }
260       if (diffdownstream)
261       {
262         x2 -= 1;
263       }
264     }
265     else
266     {
267
268       // display a forward arrow
269       if (diffdownstream)
270       {
271         g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
272             y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
273         x2 -= 5;
274       }
275       if (diffupstream)
276       {
277         x1 += 1;
278       }
279     }
280     // draw arrow body
281     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
282   }
283
284   // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
285   // av)
286   public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
287           AlignViewportI av)
288   {
289     fm = annotPanel.getFontMetrics();
290     annotationPanel = annotPanel;
291     fadedImage = annotPanel.getFadedImage();
292     imgWidth = annotPanel.getFadedImageWidth();
293     // visible area for rendering
294     int[] bounds = annotPanel.getVisibleVRange();
295     if (bounds != null)
296     {
297       sOffset = bounds[0];
298       visHeight = bounds[1];
299       if (visHeight == 0)
300       {
301         useClip = false;
302       }
303       else
304       {
305         useClip = canClip;
306       }
307     }
308     else
309     {
310       useClip = false;
311     }
312
313     updateFromAlignViewport(av);
314   }
315
316   public void updateFromAlignViewport(AlignViewportI av)
317   {
318     charWidth = av.getCharWidth();
319     endRes = av.getRanges().getEndRes();
320     charHeight = av.getCharHeight();
321     hasHiddenColumns = av.hasHiddenColumns();
322     validCharWidth = av.isValidCharWidth();
323     av_renderHistogram = av.isShowConsensusHistogram();
324     av_renderProfile = av.isShowSequenceLogo();
325     av_normaliseProfile = av.isNormaliseSequenceLogo();
326     av_renderInformationHistogram = av.isShowInformationHistogram();
327     av_renderHMMProfile = av.isShowHMMSequenceLogo();
328     av_normaliseHMMProfile = av.isNormaliseHMMSequenceLogo();
329     profcolour = av.getResidueShading();
330     if (profcolour == null || profcolour.getColourScheme() == null)
331     {
332       /*
333        * Use default colour for sequence logo if 
334        * the alignment has no colourscheme set
335        * (would like to use user preference but n/a for applet)
336        */
337       ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
338               : new ZappoColourScheme();
339       profcolour = new ResidueShader(col);
340     }
341     columnSelection = av.getColumnSelection();
342     hiddenColumns = av.getAlignment().getHiddenColumns();
343     hconsensus = av.getSequenceConsensusHash();
344     complementConsensus = av.getComplementConsensusHash();
345     hStrucConsensus = av.getRnaStructureConsensusHash();
346     av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
347     av_ignoreBelowBackground = av.isIgnoreBelowBackground();
348   }
349
350
351
352   /**
353    * Returns profile data; the first element is the profile type, the second is
354    * the number of distinct values, the third the total count, and the remainder
355    * depend on the profile type.
356    * 
357    * @param aa
358    * @param column
359    * @return
360    */
361   int[] getProfileFor(AlignmentAnnotation aa, int column)
362   {
363     // TODO : consider refactoring the global alignment calculation
364     // properties/rendering attributes as a global 'alignment group' which holds
365     // all vis settings for the alignment as a whole rather than a subset
366     //
367     if (aa.label.startsWith("Information"))
368     {
369       HiddenMarkovModel hmm = aa.sequenceRef.getHMM();
370       return AAFrequency.extractHMMProfile(hmm, column,
371               av_ignoreBelowBackground); // TODO check if this follows standard
372                                          // pipeline
373     }
374     if (aa.autoCalculated
375             && (aa.label.startsWith("Consensus") || aa.label
376                     .startsWith("cDNA Consensus")))
377     {
378       boolean forComplement = aa.label.startsWith("cDNA Consensus");
379       if (aa.groupRef != null && aa.groupRef.consensusData != null
380               && aa.groupRef.isShowSequenceLogo())
381       {
382         // TODO? group consensus for cDNA complement
383         return AAFrequency.extractProfile(
384                 aa.groupRef.consensusData.get(column),
385                 aa.groupRef.getIgnoreGapsConsensus());
386       }
387       // TODO extend annotation row to enable dynamic and static profile data to
388       // be stored
389       if (aa.groupRef == null && aa.sequenceRef == null)
390       {
391         if (forComplement)
392         {
393           return AAFrequency.extractCdnaProfile(
394                   complementConsensus[column], av_ignoreGapsConsensus);
395         }
396         else
397         {
398           return AAFrequency.extractProfile(
399 hconsensus.get(column),
400                   av_ignoreGapsConsensus);
401         }
402       }
403     }
404     else
405     {
406       if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
407       {
408         // TODO implement group structure consensus
409         /*
410          * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
411          * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
412          * group selections return StructureFrequency.extractProfile(
413          * aa.groupRef.consensusData[column], aa.groupRef
414          * .getIgnoreGapsConsensus()); }
415          */
416         // TODO extend annotation row to enable dynamic and static profile data
417         // to
418         // be stored
419         if (aa.groupRef == null && aa.sequenceRef == null
420                 && hStrucConsensus != null
421                 && hStrucConsensus.length > column)
422         {
423           return StructureFrequency.extractProfile(hStrucConsensus[column],
424                   av_ignoreGapsConsensus);
425         }
426       }
427     }
428     return null;
429   }
430
431   boolean rna = false;
432
433   /**
434    * Render the annotation rows associated with an alignment.
435    * 
436    * @param annotPanel
437    *          container frame
438    * @param av
439    *          data and view settings to render
440    * @param g
441    *          destination for graphics
442    * @param activeRow
443    *          row where a mouse event occured (or -1)
444    * @param startRes
445    *          first column that will be drawn
446    * @param endRes
447    *          last column that will be drawn
448    * @return true if the fadedImage was used for any alignment annotation rows
449    *         currently being calculated
450    */
451   public boolean drawComponent(AwtRenderPanelI annotPanel,
452           AlignViewportI av, Graphics g, int activeRow, int startRes,
453           int endRes)
454   {
455     long stime = System.currentTimeMillis();
456     boolean usedFaded = false;
457     // NOTES:
458     // AnnotationPanel needs to implement: ImageObserver, access to
459     // AlignViewport
460     updateFromAwtRenderPanel(annotPanel, av);
461     fm = g.getFontMetrics();
462     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
463     int temp = 0;
464     if (aa == null)
465     {
466       return false;
467     }
468     int x = 0, y = 0;
469     int column = 0;
470     char lastSS;
471     int lastSSX;
472     int iconOffset = 0;
473     boolean validRes = false;
474     boolean validEnd = false;
475     boolean labelAllCols = false;
476     boolean centreColLabels;
477     boolean centreColLabelsDef = av.isCentreColumnLabels();
478     boolean scaleColLabel = false;
479     final AlignmentAnnotation consensusAnnot = av
480             .getAlignmentConsensusAnnotation();
481     final AlignmentAnnotation informationAnnot = av
482             .getAlignmentInformationAnnotation();
483     final AlignmentAnnotation structConsensusAnnot = av
484             .getAlignmentStrucConsensusAnnotation();
485     final AlignmentAnnotation complementConsensusAnnot = av
486             .getComplementConsensusAnnotation();
487     boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
488
489     BitSet graphGroupDrawn = new BitSet();
490     int charOffset = 0; // offset for a label
491     float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
492     // column.
493     Font ofont = g.getFont();
494     // \u03B2 \u03B1
495     // debug ints
496     int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
497     boolean clipst = false, clipend = false;
498     for (int i = 0; i < aa.length; i++)
499     {
500       AlignmentAnnotation row = aa[i];
501       isRNA = row.isRNA();
502       {
503         // check if this is a consensus annotation row and set the display
504         // settings appropriately
505         // TODO: generalise this to have render styles for consensus/profile
506         // data
507         if (row.groupRef != null && row == row.groupRef.getConsensus())
508         {
509           renderHistogram = row.groupRef.isShowConsensusHistogram();
510           renderProfile = row.groupRef.isShowSequenceLogo();
511           normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
512         }
513         else if (row == consensusAnnot || row == structConsensusAnnot
514                 || row == complementConsensusAnnot)
515         {
516           renderHistogram = av_renderHistogram;
517           renderProfile = av_renderProfile;
518           normaliseProfile = av_normaliseProfile;
519         }
520         else if (row == informationAnnot)
521         {
522           renderHistogram = av_renderInformationHistogram;
523           renderProfile = av_renderHMMProfile;
524           normaliseProfile = av_normaliseHMMProfile;
525         }
526         else
527         {
528           renderHistogram = true;
529           // don't need to set render/normaliseProfile since they are not
530           // currently used in any other annotation track renderer
531         }
532       }
533       Annotation[] row_annotations = row.annotations;
534       if (!row.visible)
535       {
536         continue;
537       }
538       centreColLabels = row.centreColLabels || centreColLabelsDef;
539       labelAllCols = row.showAllColLabels;
540       scaleColLabel = row.scaleColLabel;
541       lastSS = ' ';
542       lastSSX = 0;
543
544       if (!useClip
545               || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
546       {// if_in_visible_region
547         if (!clipst)
548         {
549           clipst = true;
550           yfrom = y;
551           f_i = i;
552         }
553         yto = y;
554         f_to = i;
555         if (row.graph > 0)
556         {
557           if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
558           {
559             continue;
560           }
561
562           // this is so that we draw the characters below the graph
563           y += row.height;
564
565           if (row.hasText)
566           {
567             iconOffset = charHeight - fm.getDescent();
568             y -= charHeight;
569           }
570         }
571         else if (row.hasText)
572         {
573           iconOffset = charHeight - fm.getDescent();
574
575         }
576         else
577         {
578           iconOffset = 0;
579         }
580
581         if (row.autoCalculated && av.isCalculationInProgress(row))
582         {
583           y += charHeight;
584           usedFaded = true;
585           g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
586                   - row.height, imgWidth, y, annotationPanel);
587           g.setColor(Color.black);
588           // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
589
590           continue;
591         }
592
593         /*
594          * else if (annotationPanel.av.updatingConservation &&
595          * aa[i].label.equals("Conservation")) {
596          * 
597          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
598          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
599          * annotationPanel.imgWidth, y, annotationPanel);
600          * 
601          * g.setColor(Color.black); //
602          * g.drawString("Calculating Conservation.....",20, y-row.height/2);
603          * 
604          * continue; } else if (annotationPanel.av.updatingConservation &&
605          * aa[i].label.equals("Quality")) {
606          * 
607          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
608          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
609          * annotationPanel.imgWidth, y, annotationPanel);
610          * g.setColor(Color.black); // /
611          * g.drawString("Calculating Quality....",20, y-row.height/2);
612          * 
613          * continue; }
614          */
615         // first pass sets up state for drawing continuation from left-hand
616         // column
617         // of startRes
618         x = (startRes == 0) ? 0 : -1;
619         while (x < endRes - startRes)
620         {
621           if (hasHiddenColumns)
622           {
623             column = hiddenColumns.adjustForHiddenColumns(startRes + x);
624             if (column > row_annotations.length - 1)
625             {
626               break;
627             }
628           }
629           else
630           {
631             column = startRes + x;
632           }
633
634           if ((row_annotations == null)
635                   || (row_annotations.length <= column)
636                   || (row_annotations[column] == null))
637           {
638             validRes = false;
639           }
640           else
641           {
642             validRes = true;
643           }
644           final String displayChar = validRes ? row_annotations[column].displayCharacter
645                   : null;
646           if (x > -1)
647           {
648             if (activeRow == i)
649             {
650               g.setColor(Color.red);
651
652               if (columnSelection != null)
653               {
654                 if (columnSelection.contains(column))
655                 {
656                   g.fillRect(x * charWidth, y, charWidth, charHeight);
657                 }
658               }
659             }
660             if (row.getInvalidStrucPos() > x)
661             {
662               g.setColor(Color.orange);
663               g.fillRect(x * charWidth, y, charWidth, charHeight);
664             }
665             else if (row.getInvalidStrucPos() == x)
666             {
667               g.setColor(Color.orange.darker());
668               g.fillRect(x * charWidth, y, charWidth, charHeight);
669             }
670             if (validCharWidth && validRes && displayChar != null
671                     && (displayChar.length() > 0))
672             {
673
674               fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
675                       displayChar.length());
676               if (/* centreColLabels || */scaleColLabel)
677               {
678                 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
679                 // displayChar.length());
680                 //
681                 // if (scaleColLabel)
682                 // {
683                 // justify the label and scale to fit in column
684                 if (fmWidth > charWidth)
685                 {
686                   // scale only if the current font isn't already small enough
687                   fmScaling = charWidth;
688                   fmScaling /= fmWidth;
689                   g.setFont(ofont.deriveFont(AffineTransform
690                           .getScaleInstance(fmScaling, 1.0)));
691                   // and update the label's width to reflect the scaling.
692                   fmWidth = charWidth;
693                 }
694                 // }
695               }
696               // TODO is it ok to use width of / show all characters here?
697               // else
698               // {
699               // fmWidth = fm.charWidth(displayChar.charAt(0));
700               // }
701               charOffset = (int) ((charWidth - fmWidth) / 2f);
702
703               if (row_annotations[column].colour == null)
704               {
705                 g.setColor(Color.black);
706               }
707               else
708               {
709                 g.setColor(row_annotations[column].colour);
710               }
711
712               if (column == 0 || row.graph > 0)
713               {
714                 g.drawString(displayChar, (x * charWidth) + charOffset, y
715                         + iconOffset);
716               }
717               else if (row_annotations[column - 1] == null
718                       || (labelAllCols
719                               || !displayChar
720                                       .equals(row_annotations[column - 1].displayCharacter) || (displayChar
721                               .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
722               {
723                 g.drawString(displayChar, x * charWidth + charOffset, y
724                         + iconOffset);
725               }
726               g.setFont(ofont);
727             }
728           }
729           if (row.hasIcons)
730           {
731             char ss = validRes ? row_annotations[column].secondaryStructure
732                     : '-';
733
734             if (ss == '(')
735             {
736               // distinguish between forward/backward base-pairing
737               if (displayChar.indexOf(')') > -1)
738               {
739
740                 ss = ')';
741
742               }
743             }
744             if (ss == '[')
745             {
746               if ((displayChar.indexOf(']') > -1))
747               {
748                 ss = ']';
749
750               }
751             }
752             if (ss == '{')
753             {
754               // distinguish between forward/backward base-pairing
755               if (displayChar.indexOf('}') > -1)
756               {
757                 ss = '}';
758
759               }
760             }
761             if (ss == '<')
762             {
763               // distinguish between forward/backward base-pairing
764               if (displayChar.indexOf('<') > -1)
765               {
766                 ss = '>';
767
768               }
769             }
770             if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
771             {
772               // distinguish between forward/backward base-pairing
773               int ssLowerCase = ss + UPPER_TO_LOWER;
774               // TODO would .equals() be safer here? or charAt(0)?
775               if (displayChar.indexOf(ssLowerCase) > -1)
776               {
777                 ss = (char) ssLowerCase;
778               }
779             }
780
781             if (!validRes || (ss != lastSS))
782             {
783
784               if (x > -1)
785               {
786
787                 int nb_annot = x - temp;
788                 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
789                 switch (lastSS)
790                 {
791                 case '(': // Stem case for RNA secondary structure
792                 case ')': // and opposite direction
793                   drawStemAnnot(g, row_annotations, lastSSX, x, y,
794                           iconOffset, startRes, column, validRes, validEnd);
795                   temp = x;
796                   break;
797
798                 case 'H':
799                   if (!isRNA)
800                   {
801                     drawHelixAnnot(g, row_annotations, lastSSX, x, y,
802                             iconOffset, startRes, column, validRes,
803                             validEnd);
804                     break;
805                   }
806                   // no break if isRNA - falls through to drawNotCanonicalAnnot!
807                 case 'E':
808                   if (!isRNA)
809                   {
810                     drawSheetAnnot(g, row_annotations, lastSSX, x, y,
811                             iconOffset, startRes, column, validRes,
812                             validEnd);
813                     break;
814                   }
815                   // no break if isRNA - fall through to drawNotCanonicalAnnot!
816
817                 case '{':
818                 case '}':
819                 case '[':
820                 case ']':
821                 case '>':
822                 case '<':
823                 case 'A':
824                 case 'a':
825                 case 'B':
826                 case 'b':
827                 case 'C':
828                 case 'c':
829                 case 'D':
830                 case 'd':
831                 case 'e':
832                 case 'F':
833                 case 'f':
834                 case 'G':
835                 case 'g':
836                 case 'h':
837                 case 'I':
838                 case 'i':
839                 case 'J':
840                 case 'j':
841                 case 'K':
842                 case 'k':
843                 case 'L':
844                 case 'l':
845                 case 'M':
846                 case 'm':
847                 case 'N':
848                 case 'n':
849                 case 'O':
850                 case 'o':
851                 case 'P':
852                 case 'p':
853                 case 'Q':
854                 case 'q':
855                 case 'R':
856                 case 'r':
857                 case 'S':
858                 case 's':
859                 case 'T':
860                 case 't':
861                 case 'U':
862                 case 'u':
863                 case 'V':
864                 case 'v':
865                 case 'W':
866                 case 'w':
867                 case 'X':
868                 case 'x':
869                 case 'Y':
870                 case 'y':
871                 case 'Z':
872                 case 'z':
873
874                   Color nonCanColor = getNotCanonicalColor(lastSS);
875                   drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
876                           lastSSX, x, y, iconOffset, startRes, column,
877                           validRes, validEnd);
878                   temp = x;
879                   break;
880                 default:
881                   g.setColor(Color.gray);
882                   g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
883                           - lastSSX, 2);
884                   temp = x;
885                   break;
886                 }
887               }
888               if (validRes)
889               {
890                 lastSS = ss;
891               }
892               else
893               {
894                 lastSS = ' ';
895               }
896               if (x > -1)
897               {
898                 lastSSX = (x * charWidth);
899               }
900             }
901           }
902           column++;
903           x++;
904         }
905         if (column >= row_annotations.length)
906         {
907           column = row_annotations.length - 1;
908           validEnd = false;
909         }
910         else
911         {
912           validEnd = true;
913         }
914         if ((row_annotations == null) || (row_annotations.length <= column)
915                 || (row_annotations[column] == null))
916         {
917           validRes = false;
918         }
919         else
920         {
921           validRes = true;
922         }
923         // x ++;
924
925         if (row.hasIcons)
926         {
927           switch (lastSS)
928           {
929
930           case 'H':
931             if (!isRNA)
932             {
933               drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
934                       startRes, column, validRes, validEnd);
935               break;
936             }
937             // no break if isRNA - fall through to drawNotCanonicalAnnot!
938
939           case 'E':
940             if (!isRNA)
941             {
942               drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
943                       startRes, column, validRes, validEnd);
944               break;
945             }
946             // no break if isRNA - fall through to drawNotCanonicalAnnot!
947
948           case '(':
949           case ')': // Stem case for RNA secondary structure
950
951             drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
952                     startRes, column, validRes, validEnd);
953
954             break;
955           case '{':
956           case '}':
957           case '[':
958           case ']':
959           case '>':
960           case '<':
961           case 'A':
962           case 'a':
963           case 'B':
964           case 'b':
965           case 'C':
966           case 'c':
967           case 'D':
968           case 'd':
969           case 'e':
970           case 'F':
971           case 'f':
972           case 'G':
973           case 'g':
974           case 'h':
975           case 'I':
976           case 'i':
977           case 'J':
978           case 'j':
979           case 'K':
980           case 'k':
981           case 'L':
982           case 'l':
983           case 'M':
984           case 'm':
985           case 'N':
986           case 'n':
987           case 'O':
988           case 'o':
989           case 'P':
990           case 'p':
991           case 'Q':
992           case 'q':
993           case 'R':
994           case 'r':
995           case 'T':
996           case 't':
997           case 'U':
998           case 'u':
999           case 'V':
1000           case 'v':
1001           case 'W':
1002           case 'w':
1003           case 'X':
1004           case 'x':
1005           case 'Y':
1006           case 'y':
1007           case 'Z':
1008           case 'z':
1009             // System.out.println(lastSS);
1010             Color nonCanColor = getNotCanonicalColor(lastSS);
1011             drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1012                     x, y, iconOffset, startRes, column, validRes, validEnd);
1013             break;
1014           default:
1015             drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1016                     startRes, column, validRes, validEnd);
1017             break;
1018           }
1019         }
1020
1021         if (row.graph > 0 && row.graphHeight > 0)
1022         {
1023           if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1024           {
1025             if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1026             {
1027               // TODO: JAL-1291 revise rendering model so the graphGroup map is
1028               // computed efficiently for all visible labels
1029               float groupmax = -999999, groupmin = 9999999;
1030               for (int gg = 0; gg < aa.length; gg++)
1031               {
1032                 if (aa[gg].graphGroup != row.graphGroup)
1033                 {
1034                   continue;
1035                 }
1036
1037                 if (aa[gg] != row)
1038                 {
1039                   aa[gg].visible = false;
1040                 }
1041                 if (aa[gg].graphMax > groupmax)
1042                 {
1043                   groupmax = aa[gg].graphMax;
1044                 }
1045                 if (aa[gg].graphMin < groupmin)
1046                 {
1047                   groupmin = aa[gg].graphMin;
1048                 }
1049               }
1050
1051               for (int gg = 0; gg < aa.length; gg++)
1052               {
1053                 if (aa[gg].graphGroup == row.graphGroup)
1054                 {
1055                   drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1056                           endRes, y, groupmin, groupmax, row.graphHeight);
1057                 }
1058               }
1059
1060               graphGroupDrawn.set(row.graphGroup);
1061             }
1062             else
1063             {
1064               drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1065                       row.graphMin, row.graphMax, row.graphHeight);
1066             }
1067           }
1068           else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1069           {
1070             drawBarGraph(g, row, row_annotations, startRes, endRes,
1071                     row.graphMin, row.graphMax, y, renderHistogram,
1072                     renderProfile, normaliseProfile);
1073           }
1074         }
1075       }
1076       else
1077       {
1078         if (clipst && !clipend)
1079         {
1080           clipend = true;
1081         }
1082       }// end if_in_visible_region
1083       if (row.graph > 0 && row.hasText)
1084       {
1085         y += charHeight;
1086       }
1087
1088       if (row.graph == 0)
1089       {
1090         y += aa[i].height;
1091       }
1092     }
1093     if (debugRedraw)
1094     {
1095       if (canClip)
1096       {
1097         if (clipst)
1098         {
1099           System.err.println("Start clip at : " + yfrom + " (index " + f_i
1100                   + ")");
1101         }
1102         if (clipend)
1103         {
1104           System.err.println("End clip at : " + yto + " (index " + f_to
1105                   + ")");
1106         }
1107       }
1108       ;
1109       System.err.println("Annotation Rendering time:"
1110               + (System.currentTimeMillis() - stime));
1111     }
1112     ;
1113
1114     return !usedFaded;
1115   }
1116
1117   public static final Color GLYPHLINE_COLOR = Color.gray;
1118
1119   public static final Color SHEET_COLOUR = Color.green;
1120
1121   public static final Color HELIX_COLOUR = Color.red;
1122
1123   public static final Color STEM_COLOUR = Color.blue;
1124
1125   private Color sdNOTCANONICAL_COLOUR;
1126
1127   void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1128           int y, int iconOffset, int startRes, int column,
1129           boolean validRes, boolean validEnd)
1130   {
1131     g.setColor(GLYPHLINE_COLOR);
1132     g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1133   }
1134
1135   void drawSheetAnnot(Graphics g, Annotation[] row,
1136
1137   int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1138           boolean validRes, boolean validEnd)
1139   {
1140     g.setColor(SHEET_COLOUR);
1141
1142     if (!validEnd || !validRes || row == null || row[column] == null
1143             || row[column].secondaryStructure != 'E')
1144     {
1145       g.fillRect(lastSSX, y + 4 + iconOffset,
1146               (x * charWidth) - lastSSX - 4, 7);
1147       g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1148           (x * charWidth) }, new int[] { y + iconOffset,
1149           y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1150     }
1151     else
1152     {
1153       g.fillRect(lastSSX, y + 4 + iconOffset,
1154               (x + 1) * charWidth - lastSSX, 7);
1155     }
1156
1157   }
1158
1159   void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1160           int y, int iconOffset, int startRes, int column,
1161           boolean validRes, boolean validEnd)
1162   {
1163     g.setColor(HELIX_COLOUR);
1164
1165     int sCol = (lastSSX / charWidth) + startRes;
1166     int x1 = lastSSX;
1167     int x2 = (x * charWidth);
1168
1169     if (MAC)
1170     {
1171       int ofs = charWidth / 2;
1172       // Off by 1 offset when drawing rects and ovals
1173       // to offscreen image on the MAC
1174       g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1175       if (sCol == 0 || row[sCol - 1] == null
1176               || row[sCol - 1].secondaryStructure != 'H')
1177       {
1178       }
1179       else
1180       {
1181         // g.setColor(Color.orange);
1182         g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1183                 0, 0);
1184       }
1185       if (!validRes || row[column] == null
1186               || row[column].secondaryStructure != 'H')
1187       {
1188
1189       }
1190       else
1191       {
1192         // g.setColor(Color.magenta);
1193         g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1194                 + 1, 8, 0, 0);
1195
1196       }
1197
1198       return;
1199     }
1200
1201     if (sCol == 0 || row[sCol - 1] == null
1202             || row[sCol - 1].secondaryStructure != 'H')
1203     {
1204       g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1205       x1 += charWidth / 2;
1206     }
1207
1208     if (!validRes || row[column] == null
1209             || row[column].secondaryStructure != 'H')
1210     {
1211       g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1212               8, 270, 180);
1213       x2 -= charWidth / 2;
1214     }
1215
1216     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1217   }
1218
1219   void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1220           Annotation[] aa_annotations, int sRes, int eRes, int y,
1221           float min, float max, int graphHeight)
1222   {
1223     if (sRes > aa_annotations.length)
1224     {
1225       return;
1226     }
1227
1228     int x = 0;
1229
1230     // Adjustment for fastpaint to left
1231     if (eRes < endRes)
1232     {
1233       eRes++;
1234     }
1235
1236     eRes = Math.min(eRes, aa_annotations.length);
1237
1238     if (sRes == 0)
1239     {
1240       x++;
1241     }
1242
1243     int y1 = y, y2 = y;
1244     float range = max - min;
1245
1246     // //Draw origin
1247     if (min < 0)
1248     {
1249       y2 = y - (int) ((0 - min / range) * graphHeight);
1250     }
1251
1252     g.setColor(Color.gray);
1253     g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1254
1255     eRes = Math.min(eRes, aa_annotations.length);
1256
1257     int column;
1258     int aaMax = aa_annotations.length - 1;
1259
1260     while (x < eRes - sRes)
1261     {
1262       column = sRes + x;
1263       if (hasHiddenColumns)
1264       {
1265         column = hiddenColumns.adjustForHiddenColumns(column);
1266       }
1267
1268       if (column > aaMax)
1269       {
1270         break;
1271       }
1272
1273       if (aa_annotations[column] == null
1274               || aa_annotations[column - 1] == null)
1275       {
1276         x++;
1277         continue;
1278       }
1279
1280       if (aa_annotations[column].colour == null)
1281       {
1282         g.setColor(Color.black);
1283       }
1284       else
1285       {
1286         g.setColor(aa_annotations[column].colour);
1287       }
1288
1289       y1 = y
1290               - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1291       y2 = y
1292               - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1293
1294       g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1295               + charWidth / 2, y2);
1296       x++;
1297     }
1298
1299     if (_aa.threshold != null)
1300     {
1301       g.setColor(_aa.threshold.colour);
1302       Graphics2D g2 = (Graphics2D) g;
1303       g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1304               BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1305
1306       y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1307       g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1308       g2.setStroke(new BasicStroke());
1309     }
1310   }
1311
1312   void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1313           Annotation[] aa_annotations, int sRes, int eRes, float min,
1314           float max, int y, boolean renderHistogram, boolean renderProfile,
1315           boolean normaliseProfile)
1316   {
1317     if (sRes > aa_annotations.length)
1318     {
1319       return;
1320     }
1321     Font ofont = g.getFont();
1322     eRes = Math.min(eRes, aa_annotations.length);
1323
1324     int x = 0, y1 = y, y2 = y;
1325
1326     float range = max - min;
1327
1328     if (min < 0)
1329     {
1330       y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1331     }
1332
1333     g.setColor(Color.gray);
1334
1335     g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1336
1337     int column;
1338     int aaMax = aa_annotations.length - 1;
1339     while (x < eRes - sRes)
1340     {
1341       column = sRes + x;
1342       if (hasHiddenColumns)
1343       {
1344         column = hiddenColumns.adjustForHiddenColumns(column);
1345       }
1346
1347       if (column > aaMax)
1348       {
1349         break;
1350       }
1351
1352       if (aa_annotations[column] == null)
1353       {
1354         x++;
1355         continue;
1356       }
1357       if (aa_annotations[column].colour == null)
1358       {
1359         g.setColor(Color.black);
1360       }
1361       else
1362       {
1363         g.setColor(aa_annotations[column].colour);
1364       }
1365
1366       y1 = y
1367               - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1368
1369       if (renderHistogram)
1370       {
1371         if (y1 - y2 > 0)
1372         {
1373           g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1374         }
1375         else
1376         {
1377           g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1378         }
1379       }
1380       // draw profile if available
1381       if (renderProfile)
1382       {
1383
1384         /*
1385          * {profile type, #values, total count, char1, pct1, char2, pct2...}
1386          */
1387         int profl[] = getProfileFor(_aa, column);
1388
1389         // just try to draw the logo if profl is not null
1390         if (profl != null && profl[2] != 0)
1391         {
1392           boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1393           boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1394           float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1395           double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1396           double hght;
1397           float wdth;
1398           double ht2 = 0;
1399           char[] dc;
1400
1401           /**
1402            * Render a single base for a sequence profile, a base pair for
1403            * structure profile, and a triplet for a cdna profile
1404            */
1405           dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1406
1407           LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1408           double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1409           float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1410           double scl = 0.0;
1411
1412           /*
1413            * Traverse the character(s)/percentage data in the array
1414            */
1415           int c = 3;
1416           int valuesProcessed = 0;
1417           // profl[1] is the number of values in the profile
1418           while (valuesProcessed < profl[1])
1419           {
1420             if (isStructureProfile)
1421             {
1422               // todo can we encode a structure pair as an int, like codons?
1423               dc[0] = (char) profl[c++];
1424               dc[1] = (char) profl[c++];
1425             }
1426             else if (isCdnaProfile)
1427             {
1428               dc = CodingUtils.decodeCodon(profl[c++]);
1429             }
1430             else
1431             {
1432               dc[0] = (char) profl[c++];
1433             }
1434
1435             wdth = charWidth;
1436             wdth /= fm.charsWidth(dc, 0, dc.length);
1437
1438             ht += scl;
1439             // next profl[] position is profile % for the character(s)
1440             scl = htn * scale * profl[c++];
1441             lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1442                     .getFontRenderContext());
1443             Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1444                     wdth, scl / lm.getAscent()));
1445             g.setFont(font);
1446             lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1447
1448             // Debug - render boxes around characters
1449             // g.setColor(Color.red);
1450             // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1451             // (int)(scl));
1452             // g.setColor(profcolour.findColour(dc[0]).darker());
1453
1454             /*
1455              * Set character colour as per alignment colour scheme; use the
1456              * codon translation if a cDNA profile
1457              */
1458             Color colour = null;
1459             if (isCdnaProfile)
1460             {
1461               final String codonTranslation = ResidueProperties
1462                       .codonTranslate(new String(dc));
1463               colour = profcolour.findColour(codonTranslation.charAt(0),
1464                       column, null);
1465             }
1466             else
1467             {
1468               colour = profcolour.findColour(dc[0], column, null);
1469             }
1470             g.setColor(colour == Color.white ? Color.lightGray : colour);
1471
1472             hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1473                     .getBaselineIndex()]));
1474
1475             g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1476             valuesProcessed++;
1477           }
1478           g.setFont(ofont);
1479         }
1480       }
1481       x++;
1482     }
1483     if (_aa.threshold != null)
1484     {
1485       g.setColor(_aa.threshold.colour);
1486       Graphics2D g2 = (Graphics2D) g;
1487       g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1488               BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1489
1490       y2 = (int) (y - ((_aa.threshold.value - min) / range)
1491               * _aa.graphHeight);
1492       g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1493       g2.setStroke(new BasicStroke());
1494     }
1495   }
1496
1497   // used by overview window
1498   public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1499           Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1500   {
1501     eRes = Math.min(eRes, aa_annotations.length);
1502     g.setColor(Color.white);
1503     g.fillRect(0, 0, width, y);
1504     g.setColor(new Color(0, 0, 180));
1505
1506     int x = 0, height;
1507
1508     for (int j = sRes; j < eRes; j++)
1509     {
1510       if (aa_annotations[j] != null)
1511       {
1512         if (aa_annotations[j].colour == null)
1513         {
1514           g.setColor(Color.black);
1515         }
1516         else
1517         {
1518           g.setColor(aa_annotations[j].colour);
1519         }
1520
1521         height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1522         if (height > y)
1523         {
1524           height = y;
1525         }
1526
1527         g.fillRect(x, y - height, charWidth, height);
1528       }
1529       x += charWidth;
1530     }
1531   }
1532
1533   Color getNotCanonicalColor(char lastss)
1534   {
1535     switch (lastss)
1536     {
1537     case '{':
1538     case '}':
1539       return new Color(255, 125, 5);
1540
1541     case '[':
1542     case ']':
1543       return new Color(245, 115, 10);
1544
1545     case '>':
1546     case '<':
1547       return new Color(235, 135, 15);
1548
1549     case 'A':
1550     case 'a':
1551       return new Color(225, 105, 20);
1552
1553     case 'B':
1554     case 'b':
1555       return new Color(215, 145, 30);
1556
1557     case 'C':
1558     case 'c':
1559       return new Color(205, 95, 35);
1560
1561     case 'D':
1562     case 'd':
1563       return new Color(195, 155, 45);
1564
1565     case 'E':
1566     case 'e':
1567       return new Color(185, 85, 55);
1568
1569     case 'F':
1570     case 'f':
1571       return new Color(175, 165, 65);
1572
1573     case 'G':
1574     case 'g':
1575       return new Color(170, 75, 75);
1576
1577     case 'H':
1578     case 'h':
1579       return new Color(160, 175, 85);
1580
1581     case 'I':
1582     case 'i':
1583       return new Color(150, 65, 95);
1584
1585     case 'J':
1586     case 'j':
1587       return new Color(140, 185, 105);
1588
1589     case 'K':
1590     case 'k':
1591       return new Color(130, 55, 110);
1592
1593     case 'L':
1594     case 'l':
1595       return new Color(120, 195, 120);
1596
1597     case 'M':
1598     case 'm':
1599       return new Color(110, 45, 130);
1600
1601     case 'N':
1602     case 'n':
1603       return new Color(100, 205, 140);
1604
1605     case 'O':
1606     case 'o':
1607       return new Color(90, 35, 150);
1608
1609     case 'P':
1610     case 'p':
1611       return new Color(85, 215, 160);
1612
1613     case 'Q':
1614     case 'q':
1615       return new Color(75, 25, 170);
1616
1617     case 'R':
1618     case 'r':
1619       return new Color(65, 225, 180);
1620
1621     case 'S':
1622     case 's':
1623       return new Color(55, 15, 185);
1624
1625     case 'T':
1626     case 't':
1627       return new Color(45, 235, 195);
1628
1629     case 'U':
1630     case 'u':
1631       return new Color(35, 5, 205);
1632
1633     case 'V':
1634     case 'v':
1635       return new Color(25, 245, 215);
1636
1637     case 'W':
1638     case 'w':
1639       return new Color(15, 0, 225);
1640
1641     case 'X':
1642     case 'x':
1643       return new Color(10, 255, 235);
1644
1645     case 'Y':
1646     case 'y':
1647       return new Color(5, 150, 245);
1648
1649     case 'Z':
1650     case 'z':
1651       return new Color(0, 80, 255);
1652
1653     default:
1654       System.out.println("This is not a interaction : " + lastss);
1655       return null;
1656
1657     }
1658   }
1659 }