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