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.schemes.ColourSchemeI;
34 import jalview.schemes.NucleotideColourScheme;
35 import jalview.schemes.ResidueProperties;
36 import jalview.schemes.ZappoColourScheme;
37 import jalview.util.Platform;
39 import java.awt.BasicStroke;
40 import java.awt.Color;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.Graphics2D;
45 import java.awt.Image;
46 import java.awt.font.LineMetrics;
47 import java.awt.geom.AffineTransform;
48 import java.awt.image.ImageObserver;
49 import java.util.BitSet;
50 import java.util.Hashtable;
52 public class AnnotationRenderer
54 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
56 private static final int CHAR_A = 'A'; // 65
58 private static final int CHAR_Z = 'Z'; // 90
61 * flag indicating if timing and redraw parameter info should be output
63 private final boolean debugRedraw;
65 private int charWidth, endRes, charHeight;
67 private boolean validCharWidth, hasHiddenColumns;
69 private FontMetrics fm;
71 private final boolean MAC = Platform.isAMac();
73 boolean av_renderHistogram = true, av_renderProfile = true,
74 av_normaliseProfile = false;
76 ResidueShaderI profcolour = null;
78 private ColumnSelection columnSelection;
80 private HiddenColumns hiddenColumns;
82 private ProfilesI hconsensus;
84 private Hashtable[] complementConsensus;
86 private Hashtable[] hStrucConsensus;
88 private boolean av_ignoreGapsConsensus;
91 * attributes set from AwtRenderPanelI
94 * old image used when data is currently being calculated and cannot be
97 private Image fadedImage;
100 * panel being rendered into
102 private ImageObserver annotationPanel;
105 * width of image to render in panel
107 private int imgWidth;
110 * offset to beginning of visible area
115 * offset to end of visible area
117 private int visHeight;
120 * indicate if the renderer should only render the visible portion of the
121 * annotation given the current view settings
123 private boolean useClip = true;
126 * master flag indicating if renderer should ever try to clip. not enabled for
129 private boolean canClip = false;
131 public AnnotationRenderer()
137 * Create a new annotation Renderer
140 * flag indicating if timing and redraw parameter info should be
143 public AnnotationRenderer(boolean debugRedraw)
145 this.debugRedraw = debugRedraw;
149 * Remove any references and resources when this object is no longer required
151 public void dispose()
154 complementConsensus = null;
155 hStrucConsensus = null;
157 annotationPanel = null;
160 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
161 int x, int y, int iconOffset, int startRes, int column,
162 boolean validRes, boolean validEnd)
164 g.setColor(STEM_COLOUR);
165 int sCol = (lastSSX / charWidth) + startRes;
167 int x2 = (x * charWidth);
169 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
170 : row_annotations[column - 1].secondaryStructure;
172 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
173 || dc != row_annotations[sCol - 1].secondaryStructure;
174 boolean diffdownstream = !validRes || !validEnd
175 || row_annotations[column] == null
176 || dc != row_annotations[column].secondaryStructure;
178 if (column > 0 && Rna.isClosingParenthesis(dc))
181 // if (validRes && column>1 && row_annotations[column-2]!=null &&
182 // dc.equals(row_annotations[column-2].displayCharacter))
185 * if new annotation with a closing base pair half of the stem,
186 * display a backward arrow
188 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
190 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
201 // display a forward arrow
205 * if annotation ending with an opeing base pair half of the stem,
206 * display a forward arrow
208 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
210 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
220 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
223 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
224 Annotation[] row_annotations, int lastSSX, int x, int y,
225 int iconOffset, int startRes, int column, boolean validRes,
228 // System.out.println(nonCanColor);
230 g.setColor(nonCanColor);
231 int sCol = (lastSSX / charWidth) + startRes;
233 int x2 = (x * charWidth);
235 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
236 : row_annotations[column - 1].displayCharacter;
238 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
239 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
240 boolean diffdownstream = !validRes || !validEnd
241 || row_annotations[column] == null
242 || !dc.equals(row_annotations[column].displayCharacter);
243 // System.out.println("Column "+column+" diff up: "+diffupstream+"
244 // down:"+diffdownstream);
245 // If a closing base pair half of the stem, display a backward arrow
246 if (column > 0 && Rna.isClosingParenthesis(dc))
250 // if (validRes && column>1 && row_annotations[column-2]!=null &&
251 // dc.equals(row_annotations[column-2].displayCharacter))
253 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
255 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
267 // display a forward arrow
270 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
272 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
282 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
285 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
287 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
290 fm = annotPanel.getFontMetrics();
291 annotationPanel = annotPanel;
292 fadedImage = annotPanel.getFadedImage();
293 imgWidth = annotPanel.getFadedImageWidth();
294 // visible area for rendering
295 int[] bounds = annotPanel.getVisibleVRange();
299 visHeight = bounds[1];
314 updateFromAlignViewport(av);
317 public void updateFromAlignViewport(AlignViewportI av)
319 charWidth = av.getCharWidth();
320 endRes = av.getRanges().getEndRes();
321 charHeight = av.getCharHeight();
322 hasHiddenColumns = av.hasHiddenColumns();
323 validCharWidth = av.isValidCharWidth();
324 av_renderHistogram = av.isShowConsensusHistogram();
325 av_renderProfile = av.isShowSequenceLogo();
326 av_normaliseProfile = av.isNormaliseSequenceLogo();
327 profcolour = av.getResidueShading();
328 if (profcolour == null || profcolour.getColourScheme() == null)
331 * Use default colour for sequence logo if
332 * the alignment has no colourscheme set
333 * (would like to use user preference but n/a for applet)
335 ColourSchemeI col = av.getAlignment().isNucleotide()
336 ? new NucleotideColourScheme()
337 : new ZappoColourScheme();
338 profcolour = new ResidueShader(col);
340 columnSelection = av.getColumnSelection();
341 hiddenColumns = av.getAlignment().getHiddenColumns();
342 hconsensus = av.getSequenceConsensusHash();
343 complementConsensus = av.getComplementConsensusHash();
344 hStrucConsensus = av.getRnaStructureConsensusHash();
345 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
349 * Returns profile data; the first element is the profile type, the second is
350 * the number of distinct values, the third the total count, and the remainder
351 * depend on the profile type.
357 int[] getProfileFor(AlignmentAnnotation aa, int column)
359 // TODO : consider refactoring the global alignment calculation
360 // properties/rendering attributes as a global 'alignment group' which holds
361 // all vis settings for the alignment as a whole rather than a subset
363 if (aa.autoCalculated && (aa.label.startsWith("Consensus")
364 || aa.label.startsWith("cDNA Consensus")))
366 boolean forComplement = aa.label.startsWith("cDNA Consensus");
367 if (aa.groupRef != null && aa.groupRef.consensusData != null
368 && aa.groupRef.isShowSequenceLogo())
370 // TODO? group consensus for cDNA complement
371 return AAFrequency.extractProfile(
372 aa.groupRef.consensusData.get(column),
373 aa.groupRef.getIgnoreGapsConsensus());
375 // TODO extend annotation row to enable dynamic and static profile data to
377 if (aa.groupRef == null && aa.sequenceRef == null)
381 return AAFrequency.extractCdnaProfile(complementConsensus[column],
382 av_ignoreGapsConsensus);
386 return AAFrequency.extractProfile(hconsensus.get(column),
387 av_ignoreGapsConsensus);
393 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
395 // TODO implement group structure consensus
397 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
398 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
399 * group selections return StructureFrequency.extractProfile(
400 * aa.groupRef.consensusData[column], aa.groupRef
401 * .getIgnoreGapsConsensus()); }
403 // TODO extend annotation row to enable dynamic and static profile data
406 if (aa.groupRef == null && aa.sequenceRef == null
407 && hStrucConsensus != null
408 && hStrucConsensus.length > column)
410 return StructureFrequency.extractProfile(hStrucConsensus[column],
411 av_ignoreGapsConsensus);
421 * Render the annotation rows associated with an alignment.
426 * data and view settings to render
428 * destination for graphics
430 * row where a mouse event occured (or -1)
432 * first column that will be drawn
434 * last column that will be drawn
435 * @return true if the fadedImage was used for any alignment annotation rows
436 * currently being calculated
438 public boolean drawComponent(AwtRenderPanelI annotPanel,
439 AlignViewportI av, Graphics g, int activeRow, int startRes,
442 long stime = System.currentTimeMillis();
443 boolean usedFaded = false;
445 // AnnotationPanel needs to implement: ImageObserver, access to
447 updateFromAwtRenderPanel(annotPanel, av);
448 fm = g.getFontMetrics();
449 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
460 boolean validRes = false;
461 boolean validEnd = false;
462 boolean labelAllCols = false;
463 boolean centreColLabels;
464 boolean centreColLabelsDef = av.isCentreColumnLabels();
465 boolean scaleColLabel = false;
466 final AlignmentAnnotation consensusAnnot = av
467 .getAlignmentConsensusAnnotation();
468 final AlignmentAnnotation structConsensusAnnot = av
469 .getAlignmentStrucConsensusAnnotation();
470 final AlignmentAnnotation complementConsensusAnnot = av
471 .getComplementConsensusAnnotation();
472 boolean renderHistogram = true, renderProfile = true,
473 normaliseProfile = false, isRNA = rna;
475 BitSet graphGroupDrawn = new BitSet();
476 int charOffset = 0; // offset for a label
477 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
479 Font ofont = g.getFont();
482 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
483 boolean clipst = false, clipend = false;
484 for (int i = 0; i < aa.length; i++)
486 AlignmentAnnotation row = aa[i];
489 // check if this is a consensus annotation row and set the display
490 // settings appropriately
491 // TODO: generalise this to have render styles for consensus/profile
493 if (row.groupRef != null && row == row.groupRef.getConsensus())
495 renderHistogram = row.groupRef.isShowConsensusHistogram();
496 renderProfile = row.groupRef.isShowSequenceLogo();
497 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
499 else if (row == consensusAnnot || row == structConsensusAnnot
500 || row == complementConsensusAnnot)
502 renderHistogram = av_renderHistogram;
503 renderProfile = av_renderProfile;
504 normaliseProfile = av_normaliseProfile;
508 renderHistogram = true;
509 // don't need to set render/normaliseProfile since they are not
510 // currently used in any other annotation track renderer
513 Annotation[] row_annotations = row.annotations;
518 centreColLabels = row.centreColLabels || centreColLabelsDef;
519 labelAllCols = row.showAllColLabels;
520 scaleColLabel = row.scaleColLabel;
524 if (!useClip || ((y - charHeight) < visHeight
525 && (y + row.height + charHeight * 2) >= sOffset))
526 {// if_in_visible_region
537 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
542 // this is so that we draw the characters below the graph
547 iconOffset = charHeight - fm.getDescent();
551 else if (row.hasText)
553 iconOffset = charHeight - fm.getDescent();
561 if (row.autoCalculated && av.isCalculationInProgress(row))
565 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
566 y - row.height, imgWidth, y, annotationPanel);
567 g.setColor(Color.black);
568 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
574 * else if (annotationPanel.av.updatingConservation &&
575 * aa[i].label.equals("Conservation")) {
577 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
578 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
579 * annotationPanel.imgWidth, y, annotationPanel);
581 * g.setColor(Color.black); //
582 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
584 * continue; } else if (annotationPanel.av.updatingConservation &&
585 * aa[i].label.equals("Quality")) {
587 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
588 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
589 * annotationPanel.imgWidth, y, annotationPanel);
590 * g.setColor(Color.black); // /
591 * g.drawString("Calculating Quality....",20, y-row.height/2);
595 // first pass sets up state for drawing continuation from left-hand
598 x = (startRes == 0) ? 0 : -1;
599 while (x < endRes - startRes)
601 if (hasHiddenColumns)
603 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
604 if (column > row_annotations.length - 1)
611 column = startRes + x;
614 if ((row_annotations == null)
615 || (row_annotations.length <= column)
616 || (row_annotations[column] == null))
624 final String displayChar = validRes
625 ? row_annotations[column].displayCharacter
631 g.setColor(Color.red);
633 if (columnSelection != null)
635 if (columnSelection.contains(column))
637 g.fillRect(x * charWidth, y, charWidth, charHeight);
641 if (row.getInvalidStrucPos() > x)
643 g.setColor(Color.orange);
644 g.fillRect(x * charWidth, y, charWidth, charHeight);
646 else if (row.getInvalidStrucPos() == x)
648 g.setColor(Color.orange.darker());
649 g.fillRect(x * charWidth, y, charWidth, charHeight);
651 if (validCharWidth && validRes && displayChar != null
652 && (displayChar.length() > 0))
655 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
656 displayChar.length());
657 if (/* centreColLabels || */scaleColLabel)
659 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
660 // displayChar.length());
662 // if (scaleColLabel)
664 // justify the label and scale to fit in column
665 if (fmWidth > charWidth)
667 // scale only if the current font isn't already small enough
668 fmScaling = charWidth;
669 fmScaling /= fmWidth;
670 g.setFont(ofont.deriveFont(AffineTransform
671 .getScaleInstance(fmScaling, 1.0)));
672 // and update the label's width to reflect the scaling.
677 // TODO is it ok to use width of / show all characters here?
680 // fmWidth = fm.charWidth(displayChar.charAt(0));
682 charOffset = (int) ((charWidth - fmWidth) / 2f);
684 if (row_annotations[column].colour == null)
686 g.setColor(Color.black);
690 g.setColor(row_annotations[column].colour);
693 if (column == 0 || row.graph > 0)
695 g.drawString(displayChar, (x * charWidth) + charOffset,
698 else if (row_annotations[column - 1] == null || (labelAllCols
699 || !displayChar.equals(
700 row_annotations[column - 1].displayCharacter)
701 || (displayChar.length() < 2
702 && row_annotations[column].secondaryStructure == ' ')))
704 g.drawString(displayChar, x * charWidth + charOffset,
712 char ss = validRes ? row_annotations[column].secondaryStructure
717 // distinguish between forward/backward base-pairing
718 if (displayChar.indexOf(')') > -1)
727 if ((displayChar.indexOf(']') > -1))
735 // distinguish between forward/backward base-pairing
736 if (displayChar.indexOf('}') > -1)
744 // distinguish between forward/backward base-pairing
745 if (displayChar.indexOf('<') > -1)
751 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
753 // distinguish between forward/backward base-pairing
754 int ssLowerCase = ss + UPPER_TO_LOWER;
755 // TODO would .equals() be safer here? or charAt(0)?
756 if (displayChar.indexOf(ssLowerCase) > -1)
758 ss = (char) ssLowerCase;
762 if (!validRes || (ss != lastSS))
768 int nb_annot = x - temp;
769 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
770 // annot :"+nb_annot);
773 case '(': // Stem case for RNA secondary structure
774 case ')': // and opposite direction
775 drawStemAnnot(g, row_annotations, lastSSX, x, y,
776 iconOffset, startRes, column, validRes, validEnd);
783 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
784 iconOffset, startRes, column, validRes,
788 // no break if isRNA - falls through to drawNotCanonicalAnnot!
792 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
793 iconOffset, startRes, column, validRes,
797 // no break if isRNA - fall through to drawNotCanonicalAnnot!
856 Color nonCanColor = getNotCanonicalColor(lastSS);
857 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
858 lastSSX, x, y, iconOffset, startRes, column,
863 g.setColor(Color.gray);
864 g.fillRect(lastSSX, y + 6 + iconOffset,
865 (x * charWidth) - lastSSX, 2);
880 lastSSX = (x * charWidth);
887 if (column >= row_annotations.length)
889 column = row_annotations.length - 1;
896 if ((row_annotations == null) || (row_annotations.length <= column)
897 || (row_annotations[column] == null))
915 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
916 startRes, column, validRes, validEnd);
919 // no break if isRNA - fall through to drawNotCanonicalAnnot!
924 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
925 startRes, column, validRes, validEnd);
928 // no break if isRNA - fall through to drawNotCanonicalAnnot!
931 case ')': // Stem case for RNA secondary structure
933 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
934 startRes, column, validRes, validEnd);
991 // System.out.println(lastSS);
992 Color nonCanColor = getNotCanonicalColor(lastSS);
993 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
994 x, y, iconOffset, startRes, column, validRes, validEnd);
997 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
998 startRes, column, validRes, validEnd);
1003 if (row.graph > 0 && row.graphHeight > 0)
1005 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1007 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1009 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1010 // computed efficiently for all visible labels
1011 float groupmax = -999999, groupmin = 9999999;
1012 for (int gg = 0; gg < aa.length; gg++)
1014 if (aa[gg].graphGroup != row.graphGroup)
1021 aa[gg].visible = false;
1023 if (aa[gg].graphMax > groupmax)
1025 groupmax = aa[gg].graphMax;
1027 if (aa[gg].graphMin < groupmin)
1029 groupmin = aa[gg].graphMin;
1033 for (int gg = 0; gg < aa.length; gg++)
1035 if (aa[gg].graphGroup == row.graphGroup)
1037 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1038 endRes, y, groupmin, groupmax, row.graphHeight);
1042 graphGroupDrawn.set(row.graphGroup);
1046 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1047 row.graphMin, row.graphMax, row.graphHeight);
1050 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1052 drawBarGraph(g, row, row_annotations, startRes, endRes,
1053 row.graphMin, row.graphMax, y, renderHistogram,
1054 renderProfile, normaliseProfile);
1060 if (clipst && !clipend)
1064 } // end if_in_visible_region
1065 if (row.graph > 0 && row.hasText)
1082 "Start clip at : " + yfrom + " (index " + f_i + ")");
1087 "End clip at : " + yto + " (index " + f_to + ")");
1091 System.err.println("Annotation Rendering time:"
1092 + (System.currentTimeMillis() - stime));
1099 public static final Color GLYPHLINE_COLOR = Color.gray;
1101 public static final Color SHEET_COLOUR = Color.green;
1103 public static final Color HELIX_COLOUR = Color.red;
1105 public static final Color STEM_COLOUR = Color.blue;
1107 private Color sdNOTCANONICAL_COLOUR;
1109 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1110 int y, int iconOffset, int startRes, int column, boolean validRes,
1113 g.setColor(GLYPHLINE_COLOR);
1114 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1117 void drawSheetAnnot(Graphics g, Annotation[] row,
1119 int lastSSX, int x, int y, int iconOffset, int startRes,
1120 int column, boolean validRes, boolean validEnd)
1122 g.setColor(SHEET_COLOUR);
1124 if (!validEnd || !validRes || row == null || row[column] == null
1125 || row[column].secondaryStructure != 'E')
1127 g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1131 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1133 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1138 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1144 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1145 int y, int iconOffset, int startRes, int column, boolean validRes,
1148 g.setColor(HELIX_COLOUR);
1150 int sCol = (lastSSX / charWidth) + startRes;
1152 int x2 = (x * charWidth);
1156 int ofs = charWidth / 2;
1157 // Off by 1 offset when drawing rects and ovals
1158 // to offscreen image on the MAC
1159 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1160 if (sCol == 0 || row[sCol - 1] == null
1161 || row[sCol - 1].secondaryStructure != 'H')
1166 // g.setColor(Color.orange);
1167 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1170 if (!validRes || row[column] == null
1171 || row[column].secondaryStructure != 'H')
1177 // g.setColor(Color.magenta);
1178 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1179 x2 - x1 - ofs + 1, 8, 0, 0);
1186 if (sCol == 0 || row[sCol - 1] == null
1187 || row[sCol - 1].secondaryStructure != 'H')
1189 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1190 x1 += charWidth / 2;
1193 if (!validRes || row[column] == null
1194 || row[column].secondaryStructure != 'H')
1196 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1198 x2 -= charWidth / 2;
1201 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1204 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1205 Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1206 float max, int graphHeight)
1208 if (sRes > aa_annotations.length)
1215 // Adjustment for fastpaint to left
1221 eRes = Math.min(eRes, aa_annotations.length);
1229 float range = max - min;
1234 y2 = y - (int) ((0 - min / range) * graphHeight);
1237 g.setColor(Color.gray);
1238 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1240 eRes = Math.min(eRes, aa_annotations.length);
1243 int aaMax = aa_annotations.length - 1;
1245 while (x < eRes - sRes)
1248 if (hasHiddenColumns)
1250 column = hiddenColumns.adjustForHiddenColumns(column);
1258 if (aa_annotations[column] == null
1259 || aa_annotations[column - 1] == null)
1265 if (aa_annotations[column].colour == null)
1267 g.setColor(Color.black);
1271 g.setColor(aa_annotations[column].colour);
1274 y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1276 y2 = y - (int) (((aa_annotations[column].value - min) / range)
1279 g.drawLine(x * charWidth - charWidth / 2, y1,
1280 x * charWidth + charWidth / 2, y2);
1284 if (_aa.threshold != null)
1286 g.setColor(_aa.threshold.colour);
1287 Graphics2D g2 = (Graphics2D) g;
1288 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1289 BasicStroke.JOIN_ROUND, 3f, new float[]
1292 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1293 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1294 g2.setStroke(new BasicStroke());
1298 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1299 Annotation[] aa_annotations, int sRes, int eRes, float min,
1300 float max, int y, boolean renderHistogram, boolean renderProfile,
1301 boolean normaliseProfile)
1303 if (sRes > aa_annotations.length)
1307 Font ofont = g.getFont();
1308 eRes = Math.min(eRes, aa_annotations.length);
1310 int x = 0, y1 = y, y2 = y;
1312 float range = max - min;
1316 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1319 g.setColor(Color.gray);
1321 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1324 int aaMax = aa_annotations.length - 1;
1325 while (x < eRes - sRes)
1328 if (hasHiddenColumns)
1330 column = hiddenColumns.adjustForHiddenColumns(column);
1338 if (aa_annotations[column] == null)
1343 if (aa_annotations[column].colour == null)
1345 g.setColor(Color.black);
1349 g.setColor(aa_annotations[column].colour);
1352 y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1355 if (renderHistogram)
1359 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1363 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1366 // draw profile if available
1371 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1373 int profl[] = getProfileFor(_aa, column);
1375 // just try to draw the logo if profl is not null
1376 if (profl != null && profl[2] != 0)
1378 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1379 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1380 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1381 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1388 * Render a single base for a sequence profile, a base pair for
1389 * structure profile, and a triplet for a cdna profile
1391 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1393 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1394 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1395 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1399 * Traverse the character(s)/percentage data in the array
1402 int valuesProcessed = 0;
1403 // profl[1] is the number of values in the profile
1404 while (valuesProcessed < profl[1])
1406 if (isStructureProfile)
1408 // todo can we encode a structure pair as an int, like codons?
1409 dc[0] = (char) profl[c++];
1410 dc[1] = (char) profl[c++];
1412 else if (isCdnaProfile)
1414 dc = CodingUtils.decodeCodon(profl[c++]);
1418 dc[0] = (char) profl[c++];
1422 wdth /= fm.charsWidth(dc, 0, dc.length);
1425 // next profl[] position is profile % for the character(s)
1426 scl = htn * scale * profl[c++];
1427 lm = ofont.getLineMetrics(dc, 0, 1,
1428 g.getFontMetrics().getFontRenderContext());
1429 Font font = ofont.deriveFont(AffineTransform
1430 .getScaleInstance(wdth, scl / lm.getAscent()));
1432 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1434 // Debug - render boxes around characters
1435 // g.setColor(Color.red);
1436 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1438 // g.setColor(profcolour.findColour(dc[0]).darker());
1441 * Set character colour as per alignment colour scheme; use the
1442 * codon translation if a cDNA profile
1444 Color colour = null;
1447 final String codonTranslation = ResidueProperties
1448 .codonTranslate(new String(dc));
1449 colour = profcolour.findColour(codonTranslation.charAt(0),
1454 colour = profcolour.findColour(dc[0], column, null);
1456 g.setColor(colour == Color.white ? Color.lightGray : colour);
1458 hght = (ht + (scl - lm.getDescent()
1459 - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1461 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1469 if (_aa.threshold != null)
1471 g.setColor(_aa.threshold.colour);
1472 Graphics2D g2 = (Graphics2D) g;
1473 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1474 BasicStroke.JOIN_ROUND, 3f, new float[]
1478 - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1479 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1480 g2.setStroke(new BasicStroke());
1484 // used by overview window
1485 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1486 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1488 eRes = Math.min(eRes, aa_annotations.length);
1489 g.setColor(Color.white);
1490 g.fillRect(0, 0, width, y);
1491 g.setColor(new Color(0, 0, 180));
1495 for (int j = sRes; j < eRes; j++)
1497 if (aa_annotations[j] != null)
1499 if (aa_annotations[j].colour == null)
1501 g.setColor(Color.black);
1505 g.setColor(aa_annotations[j].colour);
1508 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1514 g.fillRect(x, y - height, charWidth, height);
1520 Color getNotCanonicalColor(char lastss)
1526 return new Color(255, 125, 5);
1530 return new Color(245, 115, 10);
1534 return new Color(235, 135, 15);
1538 return new Color(225, 105, 20);
1542 return new Color(215, 145, 30);
1546 return new Color(205, 95, 35);
1550 return new Color(195, 155, 45);
1554 return new Color(185, 85, 55);
1558 return new Color(175, 165, 65);
1562 return new Color(170, 75, 75);
1566 return new Color(160, 175, 85);
1570 return new Color(150, 65, 95);
1574 return new Color(140, 185, 105);
1578 return new Color(130, 55, 110);
1582 return new Color(120, 195, 120);
1586 return new Color(110, 45, 130);
1590 return new Color(100, 205, 140);
1594 return new Color(90, 35, 150);
1598 return new Color(85, 215, 160);
1602 return new Color(75, 25, 170);
1606 return new Color(65, 225, 180);
1610 return new Color(55, 15, 185);
1614 return new Color(45, 235, 195);
1618 return new Color(35, 5, 205);
1622 return new Color(25, 245, 215);
1626 return new Color(15, 0, 225);
1630 return new Color(10, 255, 235);
1634 return new Color(5, 150, 245);
1638 return new Color(0, 80, 255);
1641 System.out.println("This is not a interaction : " + lastss);