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