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