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