2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.renderer;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.CodingUtils;
25 import jalview.analysis.Rna;
26 import jalview.analysis.StructureFrequency;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.ProfilesI;
33 import jalview.renderer.api.AnnotationRendererFactoryI;
34 import jalview.renderer.api.AnnotationRowRendererI;
35 import jalview.schemes.ColourSchemeI;
36 import jalview.schemes.NucleotideColourScheme;
37 import jalview.schemes.ResidueProperties;
38 import jalview.schemes.ZappoColourScheme;
39 import jalview.util.Platform;
41 import java.awt.BasicStroke;
42 import java.awt.Color;
44 import java.awt.FontMetrics;
45 import java.awt.Graphics;
46 import java.awt.Graphics2D;
47 import java.awt.Image;
48 import java.awt.font.LineMetrics;
49 import java.awt.geom.AffineTransform;
50 import java.awt.image.ImageObserver;
51 import java.util.BitSet;
52 import java.util.Hashtable;
54 public class AnnotationRenderer
56 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
58 private static final int CHAR_A = 'A'; // 65
60 private static final int CHAR_Z = 'Z'; // 90
63 * flag indicating if timing and redraw parameter info should be output
65 private final boolean debugRedraw;
67 private int charWidth, endRes, charHeight;
69 private boolean validCharWidth, hasHiddenColumns;
71 private FontMetrics fm;
73 private final boolean MAC = Platform.isAMac();
75 boolean av_renderHistogram = true, av_renderProfile = true,
76 av_normaliseProfile = false;
78 ResidueShaderI profcolour = null;
80 private ColumnSelection columnSelection;
82 private HiddenColumns hiddenColumns;
84 private ProfilesI hconsensus;
86 private Hashtable[] complementConsensus;
88 private Hashtable[] hStrucConsensus;
90 private boolean av_ignoreGapsConsensus;
93 * attributes set from AwtRenderPanelI
96 * old image used when data is currently being calculated and cannot be
99 private Image fadedImage;
102 * panel being rendered into
104 private ImageObserver annotationPanel;
107 * width of image to render in panel
109 private int imgWidth;
112 * offset to beginning of visible area
117 * offset to end of visible area
119 private int visHeight;
122 * indicate if the renderer should only render the visible portion of the
123 * annotation given the current view settings
125 private boolean useClip = true;
128 * master flag indicating if renderer should ever try to clip. not enabled for
131 private boolean canClip = false;
133 public AnnotationRenderer()
139 * Create a new annotation Renderer
142 * flag indicating if timing and redraw parameter info should be
145 public AnnotationRenderer(boolean debugRedraw)
147 this.debugRedraw = debugRedraw;
151 * Remove any references and resources when this object is no longer required
153 public void dispose()
156 complementConsensus = null;
157 hStrucConsensus = null;
159 annotationPanel = null;
160 rendererFactoryI = null;
163 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
164 int x, int y, int iconOffset, int startRes, int column,
165 boolean validRes, boolean validEnd)
167 g.setColor(STEM_COLOUR);
168 int sCol = (lastSSX / charWidth)
169 + hiddenColumns.visibleToAbsoluteColumn(startRes);
171 int x2 = (x * charWidth);
173 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
174 : row_annotations[column - 1].secondaryStructure;
176 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
177 || dc != row_annotations[sCol - 1].secondaryStructure;
178 boolean diffdownstream = !validRes || !validEnd
179 || row_annotations[column] == null
180 || dc != row_annotations[column].secondaryStructure;
182 if (column > 0 && Rna.isClosingParenthesis(dc))
185 // if (validRes && column>1 && row_annotations[column-2]!=null &&
186 // dc.equals(row_annotations[column-2].displayCharacter))
189 * if new annotation with a closing base pair half of the stem,
190 * display a backward arrow
192 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
194 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
205 // display a forward arrow
209 * if annotation ending with an opeing base pair half of the stem,
210 * display a forward arrow
212 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
214 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
224 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
227 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
228 Annotation[] row_annotations, int lastSSX, int x, int y,
229 int iconOffset, int startRes, int column, boolean validRes,
232 // System.out.println(nonCanColor);
234 g.setColor(nonCanColor);
235 int sCol = (lastSSX / charWidth)
236 + hiddenColumns.visibleToAbsoluteColumn(startRes);
238 int x2 = (x * charWidth);
240 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
241 : row_annotations[column - 1].displayCharacter;
243 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
244 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
245 boolean diffdownstream = !validRes || !validEnd
246 || row_annotations[column] == null
247 || !dc.equals(row_annotations[column].displayCharacter);
248 // System.out.println("Column "+column+" diff up: "+diffupstream+"
249 // down:"+diffdownstream);
250 // If a closing base pair half of the stem, display a backward arrow
251 if (column > 0 && Rna.isClosingParenthesis(dc))
255 // if (validRes && column>1 && row_annotations[column-2]!=null &&
256 // dc.equals(row_annotations[column-2].displayCharacter))
258 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
260 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
272 // display a forward arrow
275 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
277 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
287 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
290 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
292 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
295 fm = annotPanel.getFontMetrics();
296 annotationPanel = annotPanel;
297 fadedImage = annotPanel.getFadedImage();
298 imgWidth = annotPanel.getFadedImageWidth();
299 // visible area for rendering
300 int[] bounds = annotPanel.getVisibleVRange();
304 visHeight = bounds[1];
319 rendererFactoryI = AnnotationRendererFactory.getRendererFactory();
320 updateFromAlignViewport(av);
323 public void updateFromAlignViewport(AlignViewportI av)
325 charWidth = av.getCharWidth();
326 endRes = av.getRanges().getEndRes();
327 charHeight = av.getCharHeight();
328 hasHiddenColumns = av.hasHiddenColumns();
329 validCharWidth = av.isValidCharWidth();
330 av_renderHistogram = av.isShowConsensusHistogram();
331 av_renderProfile = av.isShowSequenceLogo();
332 av_normaliseProfile = av.isNormaliseSequenceLogo();
333 profcolour = av.getResidueShading();
334 if (profcolour == null || profcolour.getColourScheme() == null)
337 * Use default colour for sequence logo if
338 * the alignment has no colourscheme set
339 * (would like to use user preference but n/a for applet)
341 ColourSchemeI col = av.getAlignment().isNucleotide()
342 ? new NucleotideColourScheme()
343 : new ZappoColourScheme();
344 profcolour = new ResidueShader(col);
346 columnSelection = av.getColumnSelection();
347 hiddenColumns = av.getAlignment().getHiddenColumns();
348 hconsensus = av.getSequenceConsensusHash();
349 complementConsensus = av.getComplementConsensusHash();
350 hStrucConsensus = av.getRnaStructureConsensusHash();
351 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
355 * Returns profile data; the first element is the profile type, the second is
356 * the number of distinct values, the third the total count, and the remainder
357 * depend on the profile type.
363 int[] getProfileFor(AlignmentAnnotation aa, int column)
365 // TODO : consider refactoring the global alignment calculation
366 // properties/rendering attributes as a global 'alignment group' which holds
367 // all vis settings for the alignment as a whole rather than a subset
369 if (aa.autoCalculated && (aa.label.startsWith("Consensus")
370 || aa.label.startsWith("cDNA Consensus")))
372 boolean forComplement = aa.label.startsWith("cDNA Consensus");
373 if (aa.groupRef != null && aa.groupRef.consensusData != null
374 && aa.groupRef.isShowSequenceLogo())
376 // TODO? group consensus for cDNA complement
377 return AAFrequency.extractProfile(
378 aa.groupRef.consensusData.get(column),
379 aa.groupRef.getIgnoreGapsConsensus());
381 // TODO extend annotation row to enable dynamic and static profile data to
383 if (aa.groupRef == null && aa.sequenceRef == null)
387 return AAFrequency.extractCdnaProfile(complementConsensus[column],
388 av_ignoreGapsConsensus);
392 return AAFrequency.extractProfile(hconsensus.get(column),
393 av_ignoreGapsConsensus);
399 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
401 // TODO implement group structure consensus
403 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
404 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
405 * group selections return StructureFrequency.extractProfile(
406 * aa.groupRef.consensusData[column], aa.groupRef
407 * .getIgnoreGapsConsensus()); }
409 // TODO extend annotation row to enable dynamic and static profile data
412 if (aa.groupRef == null && aa.sequenceRef == null
413 && hStrucConsensus != null
414 && hStrucConsensus.length > column)
416 return StructureFrequency.extractProfile(hStrucConsensus[column],
417 av_ignoreGapsConsensus);
426 private AnnotationRendererFactoryI rendererFactoryI;
429 * Render the annotation rows associated with an alignment.
434 * data and view settings to render
436 * destination for graphics
438 * row where a mouse event occured (or -1)
440 * first column that will be drawn
442 * last column that will be drawn
443 * @return true if the fadedImage was used for any alignment annotation rows
444 * currently being calculated
446 public boolean drawComponent(AwtRenderPanelI annotPanel,
447 AlignViewportI av, Graphics g, int activeRow, int startRes,
450 long stime = System.currentTimeMillis();
451 boolean usedFaded = false;
453 // AnnotationPanel needs to implement: ImageObserver, access to
455 updateFromAwtRenderPanel(annotPanel, av);
456 fm = g.getFontMetrics();
457 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
468 boolean validRes = false;
469 boolean validEnd = false;
470 boolean labelAllCols = false;
471 boolean centreColLabels;
472 boolean centreColLabelsDef = av.isCentreColumnLabels();
473 boolean scaleColLabel = false;
474 final AlignmentAnnotation consensusAnnot = av
475 .getAlignmentConsensusAnnotation();
476 final AlignmentAnnotation structConsensusAnnot = av
477 .getAlignmentStrucConsensusAnnotation();
478 final AlignmentAnnotation complementConsensusAnnot = av
479 .getComplementConsensusAnnotation();
480 boolean renderHistogram = true, renderProfile = true,
481 normaliseProfile = false, isRNA = rna;
483 BitSet graphGroupDrawn = new BitSet();
484 int charOffset = 0; // offset for a label
485 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
487 Font ofont = g.getFont();
490 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
491 boolean clipst = false, clipend = false;
492 for (int i = 0; i < aa.length; i++)
494 AlignmentAnnotation row = aa[i];
497 // check if this is a consensus annotation row and set the display
498 // settings appropriately
499 // TODO: generalise this to have render styles for consensus/profile
501 if (row.groupRef != null && row == row.groupRef.getConsensus())
503 renderHistogram = row.groupRef.isShowConsensusHistogram();
504 renderProfile = row.groupRef.isShowSequenceLogo();
505 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
507 else if (row == consensusAnnot || row == structConsensusAnnot
508 || row == complementConsensusAnnot)
510 renderHistogram = av_renderHistogram;
511 renderProfile = av_renderProfile;
512 normaliseProfile = av_normaliseProfile;
516 renderHistogram = true;
517 // don't need to set render/normaliseProfile since they are not
518 // currently used in any other annotation track renderer
521 Annotation[] row_annotations = row.annotations;
526 centreColLabels = row.centreColLabels || centreColLabelsDef;
527 labelAllCols = row.showAllColLabels;
528 scaleColLabel = row.scaleColLabel;
532 if (!useClip || ((y - charHeight) < visHeight
533 && (y + row.height + charHeight * 2) >= sOffset))
534 {// if_in_visible_region
545 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
550 // this is so that we draw the characters below the graph
555 iconOffset = charHeight - fm.getDescent();
559 else if (row.hasText)
561 iconOffset = charHeight - fm.getDescent();
569 if (row.autoCalculated && av.isCalculationInProgress(row))
573 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
574 y - row.height, imgWidth, y, annotationPanel);
575 g.setColor(Color.black);
576 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
582 * else if (annotationPanel.av.updatingConservation &&
583 * aa[i].label.equals("Conservation")) {
585 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
586 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
587 * annotationPanel.imgWidth, y, annotationPanel);
589 * g.setColor(Color.black); //
590 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
592 * continue; } else if (annotationPanel.av.updatingConservation &&
593 * aa[i].label.equals("Quality")) {
595 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
596 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
597 * annotationPanel.imgWidth, y, annotationPanel);
598 * g.setColor(Color.black); // /
599 * g.drawString("Calculating Quality....",20, y-row.height/2);
603 // first pass sets up state for drawing continuation from left-hand
606 x = (startRes == 0) ? 0 : -1;
607 while (x < endRes - startRes)
609 if (hasHiddenColumns)
611 column = hiddenColumns.visibleToAbsoluteColumn(startRes + x);
612 if (column > row_annotations.length - 1)
619 column = startRes + x;
622 if ((row_annotations == null)
623 || (row_annotations.length <= column)
624 || (row_annotations[column] == null))
632 final String displayChar = validRes
633 ? row_annotations[column].displayCharacter
639 g.setColor(Color.red);
641 if (columnSelection != null)
643 if (columnSelection.contains(column))
645 g.fillRect(x * charWidth, y, charWidth, charHeight);
649 if (row.getInvalidStrucPos() > x)
651 g.setColor(Color.orange);
652 g.fillRect(x * charWidth, y, charWidth, charHeight);
654 else if (row.getInvalidStrucPos() == x)
656 g.setColor(Color.orange.darker());
657 g.fillRect(x * charWidth, y, charWidth, charHeight);
659 if (validCharWidth && validRes && displayChar != null
660 && (displayChar.length() > 0))
663 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
664 displayChar.length());
665 if (/* centreColLabels || */scaleColLabel)
667 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
668 // displayChar.length());
670 // if (scaleColLabel)
672 // justify the label and scale to fit in column
673 if (fmWidth > charWidth)
675 // scale only if the current font isn't already small enough
676 fmScaling = charWidth;
677 fmScaling /= fmWidth;
678 g.setFont(ofont.deriveFont(AffineTransform
679 .getScaleInstance(fmScaling, 1.0)));
680 // and update the label's width to reflect the scaling.
685 // TODO is it ok to use width of / show all characters here?
688 // fmWidth = fm.charWidth(displayChar.charAt(0));
690 charOffset = (int) ((charWidth - fmWidth) / 2f);
692 if (row_annotations[column].colour == null)
694 g.setColor(Color.black);
698 g.setColor(row_annotations[column].colour);
701 if (column == 0 || row.graph > 0)
703 g.drawString(displayChar, (x * charWidth) + charOffset,
706 else if (row_annotations[column - 1] == null || (labelAllCols
707 || !displayChar.equals(
708 row_annotations[column - 1].displayCharacter)
709 || (displayChar.length() < 2
710 && row_annotations[column].secondaryStructure == ' ')))
712 g.drawString(displayChar, x * charWidth + charOffset,
720 char ss = validRes ? row_annotations[column].secondaryStructure
725 // distinguish between forward/backward base-pairing
726 if (displayChar.indexOf(')') > -1)
735 if ((displayChar.indexOf(']') > -1))
743 // distinguish between forward/backward base-pairing
744 if (displayChar.indexOf('}') > -1)
752 // distinguish between forward/backward base-pairing
753 if (displayChar.indexOf('<') > -1)
759 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
761 // distinguish between forward/backward base-pairing
762 int ssLowerCase = ss + UPPER_TO_LOWER;
763 // TODO would .equals() be safer here? or charAt(0)?
764 if (displayChar.indexOf(ssLowerCase) > -1)
766 ss = (char) ssLowerCase;
770 if (!validRes || (ss != lastSS))
776 int nb_annot = x - temp;
777 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
778 // annot :"+nb_annot);
781 case '(': // Stem case for RNA secondary structure
782 case ')': // and opposite direction
783 drawStemAnnot(g, row_annotations, lastSSX, x, y,
784 iconOffset, startRes, column, validRes, validEnd);
791 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
792 iconOffset, startRes, column, validRes,
796 // no break if isRNA - falls through to drawNotCanonicalAnnot!
800 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
801 iconOffset, startRes, column, validRes,
805 // no break if isRNA - fall through to drawNotCanonicalAnnot!
864 Color nonCanColor = getNotCanonicalColor(lastSS);
865 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
866 lastSSX, x, y, iconOffset, startRes, column,
871 g.setColor(Color.gray);
872 g.fillRect(lastSSX, y + 6 + iconOffset,
873 (x * charWidth) - lastSSX, 2);
888 lastSSX = (x * charWidth);
895 if (column >= row_annotations.length)
897 column = row_annotations.length - 1;
904 if ((row_annotations == null) || (row_annotations.length <= column)
905 || (row_annotations[column] == null))
923 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
924 startRes, column, validRes, validEnd);
927 // no break if isRNA - fall through to drawNotCanonicalAnnot!
932 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
933 startRes, column, validRes, validEnd);
936 // no break if isRNA - fall through to drawNotCanonicalAnnot!
939 case ')': // Stem case for RNA secondary structure
941 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
942 startRes, column, validRes, validEnd);
999 // System.out.println(lastSS);
1000 Color nonCanColor = getNotCanonicalColor(lastSS);
1001 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1002 x, y, iconOffset, startRes, column, validRes, validEnd);
1005 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1006 startRes, column, validRes, validEnd);
1011 if (row.graph > 0 && row.graphHeight > 0)
1013 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1015 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1017 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1018 // computed efficiently for all visible labels
1019 float groupmax = -999999, groupmin = 9999999;
1020 for (int gg = 0; gg < aa.length; gg++)
1022 if (aa[gg].graphGroup != row.graphGroup)
1029 aa[gg].visible = false;
1031 if (aa[gg].graphMax > groupmax)
1033 groupmax = aa[gg].graphMax;
1035 if (aa[gg].graphMin < groupmin)
1037 groupmin = aa[gg].graphMin;
1041 for (int gg = 0; gg < aa.length; gg++)
1043 if (aa[gg].graphGroup == row.graphGroup)
1045 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1046 endRes, y, groupmin, groupmax, row.graphHeight);
1050 graphGroupDrawn.set(row.graphGroup);
1054 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1055 row.graphMin, row.graphMax, row.graphHeight);
1058 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1060 drawBarGraph(g, row, row_annotations, startRes, endRes,
1061 row.graphMin, row.graphMax, y, renderHistogram,
1062 renderProfile, normaliseProfile);
1066 AnnotationRowRendererI renderer = rendererFactoryI
1067 .getRendererFor(row);
1068 if (renderer != null)
1070 renderer.renderRow(g, charWidth, charHeight,
1071 hasHiddenColumns, av, hiddenColumns, columnSelection,
1072 row, row_annotations, startRes, endRes, row.graphMin,
1077 if (renderer == null)
1079 System.err.println("No renderer found for "
1084 System.err.println("rendered with "
1085 + renderer.getClass().toString());
1094 if (clipst && !clipend)
1098 } // end if_in_visible_region
1099 if (row.graph > 0 && row.hasText)
1116 "Start clip at : " + yfrom + " (index " + f_i + ")");
1121 "End clip at : " + yto + " (index " + f_to + ")");
1125 System.err.println("Annotation Rendering time:"
1126 + (System.currentTimeMillis() - stime));
1133 public static final Color GLYPHLINE_COLOR = Color.gray;
1135 public static final Color SHEET_COLOUR = Color.green;
1137 public static final Color HELIX_COLOUR = Color.red;
1139 public static final Color STEM_COLOUR = Color.blue;
1141 private Color sdNOTCANONICAL_COLOUR;
1143 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1144 int y, int iconOffset, int startRes, int column, boolean validRes,
1147 g.setColor(GLYPHLINE_COLOR);
1148 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1151 void drawSheetAnnot(Graphics g, Annotation[] row,
1153 int lastSSX, int x, int y, int iconOffset, int startRes,
1154 int column, boolean validRes, boolean validEnd)
1156 g.setColor(SHEET_COLOUR);
1158 if (!validEnd || !validRes || row == null || row[column] == null
1159 || row[column].secondaryStructure != 'E')
1161 g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1165 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1167 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1172 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1178 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1179 int y, int iconOffset, int startRes, int column, boolean validRes,
1182 g.setColor(HELIX_COLOUR);
1184 int sCol = (lastSSX / charWidth)
1185 + hiddenColumns.visibleToAbsoluteColumn(startRes);
1187 int x2 = (x * charWidth);
1191 int ofs = charWidth / 2;
1192 // Off by 1 offset when drawing rects and ovals
1193 // to offscreen image on the MAC
1194 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1195 if (sCol == 0 || row[sCol - 1] == null
1196 || row[sCol - 1].secondaryStructure != 'H')
1201 // g.setColor(Color.orange);
1202 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1205 if (!validRes || row[column] == null
1206 || row[column].secondaryStructure != 'H')
1212 // g.setColor(Color.magenta);
1213 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1214 x2 - x1 - ofs + 1, 8, 0, 0);
1221 if (sCol == 0 || row[sCol - 1] == null
1222 || row[sCol - 1].secondaryStructure != 'H')
1224 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1225 x1 += charWidth / 2;
1228 if (!validRes || row[column] == null
1229 || row[column].secondaryStructure != 'H')
1231 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1233 x2 -= charWidth / 2;
1236 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1239 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1240 Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1241 float max, int graphHeight)
1243 if (sRes > aa_annotations.length)
1250 // Adjustment for fastpaint to left
1256 eRes = Math.min(eRes, aa_annotations.length);
1264 float range = max - min;
1269 y2 = y - (int) ((0 - min / range) * graphHeight);
1272 g.setColor(Color.gray);
1273 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1275 eRes = Math.min(eRes, aa_annotations.length);
1278 int aaMax = aa_annotations.length - 1;
1280 while (x < eRes - sRes)
1283 if (hasHiddenColumns)
1285 column = hiddenColumns.visibleToAbsoluteColumn(column);
1293 if (aa_annotations[column] == null
1294 || aa_annotations[column - 1] == null)
1300 if (aa_annotations[column].colour == null)
1302 g.setColor(Color.black);
1306 g.setColor(aa_annotations[column].colour);
1309 y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1311 y2 = y - (int) (((aa_annotations[column].value - min) / range)
1314 g.drawLine(x * charWidth - charWidth / 2, y1,
1315 x * charWidth + charWidth / 2, y2);
1319 if (_aa.threshold != null)
1321 g.setColor(_aa.threshold.colour);
1322 Graphics2D g2 = (Graphics2D) g;
1323 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1324 BasicStroke.JOIN_ROUND, 3f, new float[]
1327 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1328 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1329 g2.setStroke(new BasicStroke());
1333 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1334 Annotation[] aa_annotations, int sRes, int eRes, float min,
1335 float max, int y, boolean renderHistogram, boolean renderProfile,
1336 boolean normaliseProfile)
1338 if (sRes > aa_annotations.length)
1342 Font ofont = g.getFont();
1343 eRes = Math.min(eRes, aa_annotations.length);
1345 int x = 0, y1 = y, y2 = y;
1347 float range = max - min;
1351 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1354 g.setColor(Color.gray);
1356 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1359 int aaMax = aa_annotations.length - 1;
1360 while (x < eRes - sRes)
1363 if (hasHiddenColumns)
1365 column = hiddenColumns.visibleToAbsoluteColumn(column);
1373 if (aa_annotations[column] == null)
1378 if (aa_annotations[column].colour == null)
1380 g.setColor(Color.black);
1384 g.setColor(aa_annotations[column].colour);
1387 y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1390 if (renderHistogram)
1394 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1398 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1401 // draw profile if available
1406 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1408 int profl[] = getProfileFor(_aa, column);
1410 // just try to draw the logo if profl is not null
1411 if (profl != null && profl[2] != 0)
1413 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1414 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1415 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1416 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1423 * Render a single base for a sequence profile, a base pair for
1424 * structure profile, and a triplet for a cdna profile
1426 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1428 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1429 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1430 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1434 * Traverse the character(s)/percentage data in the array
1437 int valuesProcessed = 0;
1438 // profl[1] is the number of values in the profile
1439 while (valuesProcessed < profl[1])
1441 if (isStructureProfile)
1443 // todo can we encode a structure pair as an int, like codons?
1444 dc[0] = (char) profl[c++];
1445 dc[1] = (char) profl[c++];
1447 else if (isCdnaProfile)
1449 dc = CodingUtils.decodeCodon(profl[c++]);
1453 dc[0] = (char) profl[c++];
1457 wdth /= fm.charsWidth(dc, 0, dc.length);
1460 // next profl[] position is profile % for the character(s)
1461 scl = htn * scale * profl[c++];
1462 lm = ofont.getLineMetrics(dc, 0, 1,
1463 g.getFontMetrics().getFontRenderContext());
1464 Font font = ofont.deriveFont(AffineTransform
1465 .getScaleInstance(wdth, scl / lm.getAscent()));
1467 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1469 // Debug - render boxes around characters
1470 // g.setColor(Color.red);
1471 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1473 // g.setColor(profcolour.findColour(dc[0]).darker());
1476 * Set character colour as per alignment colour scheme; use the
1477 * codon translation if a cDNA profile
1479 Color colour = null;
1482 final String codonTranslation = ResidueProperties
1483 .codonTranslate(new String(dc));
1484 colour = profcolour.findColour(codonTranslation.charAt(0),
1489 colour = profcolour.findColour(dc[0], column, null);
1491 g.setColor(colour == Color.white ? Color.lightGray : colour);
1493 hght = (ht + (scl - lm.getDescent()
1494 - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1496 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1504 if (_aa.threshold != null)
1506 g.setColor(_aa.threshold.colour);
1507 Graphics2D g2 = (Graphics2D) g;
1508 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1509 BasicStroke.JOIN_ROUND, 3f, new float[]
1513 - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1514 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1515 g2.setStroke(new BasicStroke());
1519 // used by overview window
1520 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1521 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1523 eRes = Math.min(eRes, aa_annotations.length);
1524 g.setColor(Color.white);
1525 g.fillRect(0, 0, width, y);
1526 g.setColor(new Color(0, 0, 180));
1530 for (int j = sRes; j < eRes; j++)
1532 if (aa_annotations[j] != null)
1534 if (aa_annotations[j].colour == null)
1536 g.setColor(Color.black);
1540 g.setColor(aa_annotations[j].colour);
1543 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1549 g.fillRect(x, y - height, charWidth, height);
1555 Color getNotCanonicalColor(char lastss)
1561 return new Color(255, 125, 5);
1565 return new Color(245, 115, 10);
1569 return new Color(235, 135, 15);
1573 return new Color(225, 105, 20);
1577 return new Color(215, 145, 30);
1581 return new Color(205, 95, 35);
1585 return new Color(195, 155, 45);
1589 return new Color(185, 85, 55);
1593 return new Color(175, 165, 65);
1597 return new Color(170, 75, 75);
1601 return new Color(160, 175, 85);
1605 return new Color(150, 65, 95);
1609 return new Color(140, 185, 105);
1613 return new Color(130, 55, 110);
1617 return new Color(120, 195, 120);
1621 return new Color(110, 45, 130);
1625 return new Color(100, 205, 140);
1629 return new Color(90, 35, 150);
1633 return new Color(85, 215, 160);
1637 return new Color(75, 25, 170);
1641 return new Color(65, 225, 180);
1645 return new Color(55, 15, 185);
1649 return new Color(45, 235, 195);
1653 return new Color(35, 5, 205);
1657 return new Color(25, 245, 215);
1661 return new Color(15, 0, 225);
1665 return new Color(10, 255, 235);
1669 return new Color(5, 150, 245);
1673 return new Color(0, 80, 255);
1676 System.out.println("This is not a interaction : " + lastss);