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