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