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.HiddenMarkovModel;
33 import jalview.datamodel.ProfilesI;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.NucleotideColourScheme;
36 import jalview.schemes.ResidueProperties;
37 import jalview.schemes.ZappoColourScheme;
38 import jalview.util.Platform;
39 import jalview.workers.InformationThread;
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 // todo remove these flags, read from group/viewport where needed
76 boolean av_renderHistogram = true;
78 boolean av_renderProfile = true;
80 boolean av_normaliseProfile = false;
82 boolean av_infoHeight = false;
84 ResidueShaderI profcolour = null;
86 private ColumnSelection columnSelection;
88 private HiddenColumns hiddenColumns;
90 private ProfilesI hconsensus;
92 private Hashtable[] complementConsensus;
94 private Hashtable[] hStrucConsensus;
96 private boolean av_ignoreGapsConsensus;
98 private boolean av_ignoreBelowBackground;
101 * attributes set from AwtRenderPanelI
104 * old image used when data is currently being calculated and cannot be
107 private Image fadedImage;
110 * panel being rendered into
112 private ImageObserver annotationPanel;
115 * width of image to render in panel
117 private int imgWidth;
120 * offset to beginning of visible area
125 * offset to end of visible area
127 private int visHeight;
130 * indicate if the renderer should only render the visible portion of the
131 * annotation given the current view settings
133 private boolean useClip = true;
136 * master flag indicating if renderer should ever try to clip. not enabled for
139 private boolean canClip = false;
141 public AnnotationRenderer()
147 * Create a new annotation Renderer
150 * flag indicating if timing and redraw parameter info should be
153 public AnnotationRenderer(boolean debugRedraw)
155 this.debugRedraw = debugRedraw;
159 * Remove any references and resources when this object is no longer required
161 public void dispose()
164 complementConsensus = null;
165 hStrucConsensus = null;
167 annotationPanel = null;
170 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
171 int x, int y, int iconOffset, int startRes, int column,
172 boolean validRes, boolean validEnd)
174 g.setColor(STEM_COLOUR);
175 int sCol = (lastSSX / charWidth)
176 + hiddenColumns.visibleToAbsoluteColumn(startRes);
178 int x2 = (x * charWidth);
180 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
181 : row_annotations[column - 1].secondaryStructure;
183 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
184 || dc != row_annotations[sCol - 1].secondaryStructure;
185 boolean diffdownstream = !validRes || !validEnd
186 || row_annotations[column] == null
187 || dc != row_annotations[column].secondaryStructure;
189 if (column > 0 && Rna.isClosingParenthesis(dc))
192 // if (validRes && column>1 && row_annotations[column-2]!=null &&
193 // dc.equals(row_annotations[column-2].displayCharacter))
196 * if new annotation with a closing base pair half of the stem,
197 * display a backward arrow
199 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
201 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
212 // display a forward arrow
216 * if annotation ending with an opeing base pair half of the stem,
217 * display a forward arrow
219 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
221 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
231 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
234 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
235 Annotation[] row_annotations, int lastSSX, int x, int y,
236 int iconOffset, int startRes, int column, boolean validRes,
239 // System.out.println(nonCanColor);
241 g.setColor(nonCanColor);
242 int sCol = (lastSSX / charWidth)
243 + hiddenColumns.visibleToAbsoluteColumn(startRes);
245 int x2 = (x * charWidth);
247 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
248 : row_annotations[column - 1].displayCharacter;
250 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
251 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
252 boolean diffdownstream = !validRes || !validEnd
253 || row_annotations[column] == null
254 || !dc.equals(row_annotations[column].displayCharacter);
255 // System.out.println("Column "+column+" diff up: "+diffupstream+"
256 // down:"+diffdownstream);
257 // If a closing base pair half of the stem, display a backward arrow
258 if (column > 0 && Rna.isClosingParenthesis(dc))
262 // if (validRes && column>1 && row_annotations[column-2]!=null &&
263 // dc.equals(row_annotations[column-2].displayCharacter))
265 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
267 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
279 // display a forward arrow
282 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
284 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
294 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
297 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
299 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
302 fm = annotPanel.getFontMetrics();
303 annotationPanel = annotPanel;
304 fadedImage = annotPanel.getFadedImage();
305 imgWidth = annotPanel.getFadedImageWidth();
306 // visible area for rendering
307 int[] bounds = annotPanel.getVisibleVRange();
311 visHeight = bounds[1];
326 updateFromAlignViewport(av);
329 public void updateFromAlignViewport(AlignViewportI av)
331 charWidth = av.getCharWidth();
332 endRes = av.getRanges().getEndRes();
333 charHeight = av.getCharHeight();
334 hasHiddenColumns = av.hasHiddenColumns();
335 validCharWidth = av.isValidCharWidth();
336 av_renderHistogram = av.isShowConsensusHistogram();
337 av_renderProfile = av.isShowSequenceLogo();
338 av_normaliseProfile = av.isNormaliseSequenceLogo();
339 profcolour = av.getResidueShading();
340 if (profcolour == null || profcolour.getColourScheme() == null)
343 * Use default colour for sequence logo if
344 * the alignment has no colourscheme set
345 * (would like to use user preference but n/a for applet)
347 ColourSchemeI col = av.getAlignment().isNucleotide()
348 ? new NucleotideColourScheme()
349 : new ZappoColourScheme();
350 profcolour = new ResidueShader(col);
352 columnSelection = av.getColumnSelection();
353 hiddenColumns = av.getAlignment().getHiddenColumns();
354 hconsensus = av.getConsensusProfiles();
355 complementConsensus = av.getComplementConsensusHash();
356 hStrucConsensus = av.getRnaStructureConsensusHash();
357 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
358 av_ignoreBelowBackground = av.isIgnoreBelowBackground();
359 av_infoHeight = av.isInfoLetterHeight();
365 * Returns profile data; the first element is the profile type, the second is
366 * the number of distinct values, the third the total count, and the remainder
367 * depend on the profile type.
373 int[] getProfileFor(AlignmentAnnotation aa, int column)
375 // TODO : consider refactoring the global alignment calculation
376 // properties/rendering attributes as a global 'alignment group' which holds
377 // all vis settings for the alignment as a whole rather than a subset
379 if (InformationThread.HMM_CALC_ID.equals(aa.getCalcId()))
381 HiddenMarkovModel hmm = aa.sequenceRef.getHMM();
382 return AAFrequency.extractHMMProfile(hmm, column,
383 av_ignoreBelowBackground, av_infoHeight); // TODO check if this follows standard
386 if (aa.autoCalculated
387 && (aa.label.startsWith("Consensus") || aa.label
388 .startsWith("cDNA Consensus")))
390 boolean forComplement = aa.label.startsWith("cDNA Consensus");
391 if (aa.groupRef != null && aa.groupRef.getConsensusData() != null
392 && aa.groupRef.isShowSequenceLogo())
394 // TODO? group consensus for cDNA complement
395 return AAFrequency.extractProfile(
396 aa.groupRef.getConsensusData().get(column),
397 aa.groupRef.isIgnoreGapsConsensus());
399 // TODO extend annotation row to enable dynamic and static profile data to
401 if (aa.groupRef == null && aa.sequenceRef == null)
405 return AAFrequency.extractCdnaProfile(complementConsensus[column],
406 av_ignoreGapsConsensus);
410 return AAFrequency.extractProfile(hconsensus.get(column),
411 av_ignoreGapsConsensus);
417 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
419 // TODO implement group structure consensus
421 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
422 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
423 * group selections return StructureFrequency.extractProfile(
424 * aa.groupRef.consensusData[column], aa.groupRef
425 * .getIgnoreGapsConsensus()); }
427 // TODO extend annotation row to enable dynamic and static profile data
430 if (aa.groupRef == null && aa.sequenceRef == null
431 && hStrucConsensus != null
432 && hStrucConsensus.length > column)
434 return StructureFrequency.extractProfile(hStrucConsensus[column],
435 av_ignoreGapsConsensus);
445 * Render the annotation rows associated with an alignment.
450 * data and view settings to render
452 * destination for graphics
454 * row where a mouse event occured (or -1)
456 * first column that will be drawn
458 * last column that will be drawn
459 * @return true if the fadedImage was used for any alignment annotation rows
460 * currently being calculated
462 public boolean drawComponent(AwtRenderPanelI annotPanel,
463 AlignViewportI av, Graphics g, int activeRow, int startRes,
466 long stime = System.currentTimeMillis();
467 boolean usedFaded = false;
469 // AnnotationPanel needs to implement: ImageObserver, access to
471 updateFromAwtRenderPanel(annotPanel, av);
472 fm = g.getFontMetrics();
473 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
484 boolean validRes = false;
485 boolean validEnd = false;
486 boolean labelAllCols = false;
487 boolean centreColLabels;
488 boolean centreColLabelsDef = av.isCentreColumnLabels();
489 boolean scaleColLabel = false;
490 final AlignmentAnnotation consensusAnnot = av
491 .getAlignmentConsensusAnnotation();
492 final AlignmentAnnotation structConsensusAnnot = av
493 .getAlignmentStrucConsensusAnnotation();
494 final AlignmentAnnotation complementConsensusAnnot = av
495 .getComplementConsensusAnnotation();
496 boolean renderHistogram = true, renderProfile = true,
497 normaliseProfile = false, isRNA = rna;
499 BitSet graphGroupDrawn = new BitSet();
500 int charOffset = 0; // offset for a label
501 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
503 Font ofont = g.getFont();
506 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
507 boolean clipst = false, clipend = false;
508 for (int i = 0; i < aa.length; i++)
510 AlignmentAnnotation row = aa[i];
513 // check if this is a consensus annotation row and set the display
514 // settings appropriately
515 // TODO: generalise this to have render styles for consensus/profile
517 if (row.groupRef != null && row == row.groupRef.getConsensus())
519 renderHistogram = row.groupRef.isShowConsensusHistogram();
520 renderProfile = row.groupRef.isShowSequenceLogo();
521 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
523 else if (row == consensusAnnot || row == structConsensusAnnot
524 || row == complementConsensusAnnot)
526 renderHistogram = av_renderHistogram;
527 renderProfile = av_renderProfile;
528 normaliseProfile = av_normaliseProfile;
530 else if (InformationThread.HMM_CALC_ID.equals(row.getCalcId()))
532 if (row.groupRef != null)
534 renderHistogram = row.groupRef.isShowInformationHistogram();
535 renderProfile = row.groupRef.isShowHMMSequenceLogo();
536 normaliseProfile = row.groupRef.isNormaliseHMMSequenceLogo();
540 renderHistogram = av.isShowInformationHistogram();
541 renderProfile = av.isShowHMMSequenceLogo();
542 normaliseProfile = av.isNormaliseHMMSequenceLogo();
547 renderHistogram = true;
548 // don't need to set render/normaliseProfile since they are not
549 // currently used in any other annotation track renderer
552 Annotation[] row_annotations = row.annotations;
557 centreColLabels = row.centreColLabels || centreColLabelsDef;
558 labelAllCols = row.showAllColLabels;
559 scaleColLabel = row.scaleColLabel;
563 if (!useClip || ((y - charHeight) < visHeight
564 && (y + row.height + charHeight * 2) >= sOffset))
565 {// if_in_visible_region
576 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
581 // this is so that we draw the characters below the graph
586 iconOffset = charHeight - fm.getDescent();
590 else if (row.hasText)
592 iconOffset = charHeight - fm.getDescent();
600 if (row.autoCalculated && av.isCalculationInProgress(row))
604 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
605 y - row.height, imgWidth, y, annotationPanel);
606 g.setColor(Color.black);
607 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
613 * else if (annotationPanel.av.updatingConservation &&
614 * aa[i].label.equals("Conservation")) {
616 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
617 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
618 * annotationPanel.imgWidth, y, annotationPanel);
620 * g.setColor(Color.black); //
621 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
623 * continue; } else if (annotationPanel.av.updatingConservation &&
624 * aa[i].label.equals("Quality")) {
626 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
627 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
628 * annotationPanel.imgWidth, y, annotationPanel);
629 * g.setColor(Color.black); // /
630 * g.drawString("Calculating Quality....",20, y-row.height/2);
634 // first pass sets up state for drawing continuation from left-hand
637 x = (startRes == 0) ? 0 : -1;
638 while (x < endRes - startRes)
640 if (hasHiddenColumns)
642 column = hiddenColumns.visibleToAbsoluteColumn(startRes + x);
643 if (column > row_annotations.length - 1)
650 column = startRes + x;
653 if ((row_annotations == null)
654 || (row_annotations.length <= column)
655 || (row_annotations[column] == null))
663 final String displayChar = validRes
664 ? row_annotations[column].displayCharacter
670 g.setColor(Color.red);
672 if (columnSelection != null)
674 if (columnSelection.contains(column))
676 g.fillRect(x * charWidth, y, charWidth, charHeight);
680 if (row.getInvalidStrucPos() > x)
682 g.setColor(Color.orange);
683 g.fillRect(x * charWidth, y, charWidth, charHeight);
685 else if (row.getInvalidStrucPos() == x)
687 g.setColor(Color.orange.darker());
688 g.fillRect(x * charWidth, y, charWidth, charHeight);
690 if (validCharWidth && validRes && displayChar != null
691 && (displayChar.length() > 0))
694 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
695 displayChar.length());
696 if (/* centreColLabels || */scaleColLabel)
698 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
699 // displayChar.length());
701 // if (scaleColLabel)
703 // justify the label and scale to fit in column
704 if (fmWidth > charWidth)
706 // scale only if the current font isn't already small enough
707 fmScaling = charWidth;
708 fmScaling /= fmWidth;
709 g.setFont(ofont.deriveFont(AffineTransform
710 .getScaleInstance(fmScaling, 1.0)));
711 // and update the label's width to reflect the scaling.
716 // TODO is it ok to use width of / show all characters here?
719 // fmWidth = fm.charWidth(displayChar.charAt(0));
721 charOffset = (int) ((charWidth - fmWidth) / 2f);
723 if (row_annotations[column].colour == null)
725 g.setColor(Color.black);
729 g.setColor(row_annotations[column].colour);
732 if (column == 0 || row.graph > 0)
734 g.drawString(displayChar, (x * charWidth) + charOffset,
737 else if (row_annotations[column - 1] == null || (labelAllCols
738 || !displayChar.equals(
739 row_annotations[column - 1].displayCharacter)
740 || (displayChar.length() < 2
741 && row_annotations[column].secondaryStructure == ' ')))
743 g.drawString(displayChar, x * charWidth + charOffset,
751 char ss = validRes ? row_annotations[column].secondaryStructure
756 // distinguish between forward/backward base-pairing
757 if (displayChar.indexOf(')') > -1)
766 if ((displayChar.indexOf(']') > -1))
774 // distinguish between forward/backward base-pairing
775 if (displayChar.indexOf('}') > -1)
783 // distinguish between forward/backward base-pairing
784 if (displayChar.indexOf('<') > -1)
790 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
792 // distinguish between forward/backward base-pairing
793 int ssLowerCase = ss + UPPER_TO_LOWER;
794 // TODO would .equals() be safer here? or charAt(0)?
795 if (displayChar.indexOf(ssLowerCase) > -1)
797 ss = (char) ssLowerCase;
801 if (!validRes || (ss != lastSS))
807 int nb_annot = x - temp;
808 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
809 // annot :"+nb_annot);
812 case '(': // Stem case for RNA secondary structure
813 case ')': // and opposite direction
814 drawStemAnnot(g, row_annotations, lastSSX, x, y,
815 iconOffset, startRes, column, validRes, validEnd);
822 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
823 iconOffset, startRes, column, validRes,
827 // no break if isRNA - falls through to drawNotCanonicalAnnot!
831 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
832 iconOffset, startRes, column, validRes,
836 // no break if isRNA - fall through to drawNotCanonicalAnnot!
895 Color nonCanColor = getNotCanonicalColor(lastSS);
896 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
897 lastSSX, x, y, iconOffset, startRes, column,
902 g.setColor(Color.gray);
903 g.fillRect(lastSSX, y + 6 + iconOffset,
904 (x * charWidth) - lastSSX, 2);
919 lastSSX = (x * charWidth);
926 if (column >= row_annotations.length)
928 column = row_annotations.length - 1;
935 if ((row_annotations == null) || (row_annotations.length <= column)
936 || (row_annotations[column] == null))
954 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
955 startRes, column, validRes, validEnd);
958 // no break if isRNA - fall through to drawNotCanonicalAnnot!
963 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
964 startRes, column, validRes, validEnd);
967 // no break if isRNA - fall through to drawNotCanonicalAnnot!
970 case ')': // Stem case for RNA secondary structure
972 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
973 startRes, column, validRes, validEnd);
1030 // System.out.println(lastSS);
1031 Color nonCanColor = getNotCanonicalColor(lastSS);
1032 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1033 x, y, iconOffset, startRes, column, validRes, validEnd);
1036 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1037 startRes, column, validRes, validEnd);
1042 if (row.graph > 0 && row.graphHeight > 0)
1044 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1046 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1048 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1049 // computed efficiently for all visible labels
1050 float groupmax = -999999, groupmin = 9999999;
1051 for (int gg = 0; gg < aa.length; gg++)
1053 if (aa[gg].graphGroup != row.graphGroup)
1060 aa[gg].visible = false;
1062 if (aa[gg].graphMax > groupmax)
1064 groupmax = aa[gg].graphMax;
1066 if (aa[gg].graphMin < groupmin)
1068 groupmin = aa[gg].graphMin;
1072 for (int gg = 0; gg < aa.length; gg++)
1074 if (aa[gg].graphGroup == row.graphGroup)
1076 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1077 endRes, y, groupmin, groupmax, row.graphHeight);
1081 graphGroupDrawn.set(row.graphGroup);
1085 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1086 row.graphMin, row.graphMax, row.graphHeight);
1089 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1091 drawBarGraph(g, row, row_annotations, startRes, endRes,
1092 row.graphMin, row.graphMax, y, renderHistogram,
1093 renderProfile, normaliseProfile);
1099 if (clipst && !clipend)
1103 } // end if_in_visible_region
1104 if (row.graph > 0 && row.hasText)
1121 "Start clip at : " + yfrom + " (index " + f_i + ")");
1126 "End clip at : " + yto + " (index " + f_to + ")");
1130 System.err.println("Annotation Rendering time:"
1131 + (System.currentTimeMillis() - stime));
1138 public static final Color GLYPHLINE_COLOR = Color.gray;
1140 public static final Color SHEET_COLOUR = Color.green;
1142 public static final Color HELIX_COLOUR = Color.red;
1144 public static final Color STEM_COLOUR = Color.blue;
1146 private Color sdNOTCANONICAL_COLOUR;
1148 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1149 int y, int iconOffset, int startRes, int column, boolean validRes,
1152 g.setColor(GLYPHLINE_COLOR);
1153 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1156 void drawSheetAnnot(Graphics g, Annotation[] row,
1158 int lastSSX, int x, int y, int iconOffset, int startRes,
1159 int column, boolean validRes, boolean validEnd)
1161 g.setColor(SHEET_COLOUR);
1163 if (!validEnd || !validRes || row == null || row[column] == null
1164 || row[column].secondaryStructure != 'E')
1166 g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1170 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1172 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1177 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1183 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1184 int y, int iconOffset, int startRes, int column, boolean validRes,
1187 g.setColor(HELIX_COLOUR);
1189 int sCol = (lastSSX / charWidth)
1190 + hiddenColumns.visibleToAbsoluteColumn(startRes);
1192 int x2 = (x * charWidth);
1196 int ofs = charWidth / 2;
1197 // Off by 1 offset when drawing rects and ovals
1198 // to offscreen image on the MAC
1199 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1200 if (sCol == 0 || row[sCol - 1] == null
1201 || row[sCol - 1].secondaryStructure != 'H')
1206 // g.setColor(Color.orange);
1207 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1210 if (!validRes || row[column] == null
1211 || row[column].secondaryStructure != 'H')
1217 // g.setColor(Color.magenta);
1218 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1219 x2 - x1 - ofs + 1, 8, 0, 0);
1226 if (sCol == 0 || row[sCol - 1] == null
1227 || row[sCol - 1].secondaryStructure != 'H')
1229 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1230 x1 += charWidth / 2;
1233 if (!validRes || row[column] == null
1234 || row[column].secondaryStructure != 'H')
1236 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1238 x2 -= charWidth / 2;
1241 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1244 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1245 Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1246 float max, int graphHeight)
1248 if (sRes > aa_annotations.length)
1255 // Adjustment for fastpaint to left
1261 eRes = Math.min(eRes, aa_annotations.length);
1269 float range = max - min;
1274 y2 = y - (int) ((0 - min / range) * graphHeight);
1277 g.setColor(Color.gray);
1278 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1280 eRes = Math.min(eRes, aa_annotations.length);
1283 int aaMax = aa_annotations.length - 1;
1285 while (x < eRes - sRes)
1288 if (hasHiddenColumns)
1290 column = hiddenColumns.visibleToAbsoluteColumn(column);
1298 if (aa_annotations[column] == null
1299 || aa_annotations[column - 1] == null)
1305 if (aa_annotations[column].colour == null)
1307 g.setColor(Color.black);
1311 g.setColor(aa_annotations[column].colour);
1314 y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1316 y2 = y - (int) (((aa_annotations[column].value - min) / range)
1319 g.drawLine(x * charWidth - charWidth / 2, y1,
1320 x * charWidth + charWidth / 2, y2);
1324 if (_aa.threshold != null)
1326 g.setColor(_aa.threshold.colour);
1327 Graphics2D g2 = (Graphics2D) g;
1328 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1329 BasicStroke.JOIN_ROUND, 3f, new float[]
1332 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1333 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1334 g2.setStroke(new BasicStroke());
1338 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1339 Annotation[] aa_annotations, int sRes, int eRes, float min,
1340 float max, int y, boolean renderHistogram, boolean renderProfile,
1341 boolean normaliseProfile)
1343 if (sRes > aa_annotations.length)
1347 Font ofont = g.getFont();
1348 eRes = Math.min(eRes, aa_annotations.length);
1350 int x = 0, y1 = y, y2 = y;
1352 float range = max - min;
1356 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1359 g.setColor(Color.gray);
1361 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1364 int aaMax = aa_annotations.length - 1;
1365 while (x < eRes - sRes)
1368 if (hasHiddenColumns)
1370 column = hiddenColumns.visibleToAbsoluteColumn(column);
1378 if (aa_annotations[column] == null)
1383 if (aa_annotations[column].colour == null)
1385 g.setColor(Color.black);
1389 g.setColor(aa_annotations[column].colour);
1392 y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1395 if (renderHistogram)
1399 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1403 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1406 // draw profile if available
1411 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1413 int profl[] = getProfileFor(_aa, column);
1415 // just try to draw the logo if profl is not null
1416 if (profl != null && profl[2] != 0)
1418 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1419 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1420 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1421 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1428 * Render a single base for a sequence profile, a base pair for
1429 * structure profile, and a triplet for a cdna profile
1431 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1433 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1434 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1435 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1439 * Traverse the character(s)/percentage data in the array
1442 int valuesProcessed = 0;
1443 // profl[1] is the number of values in the profile
1444 while (valuesProcessed < profl[1])
1446 if (isStructureProfile)
1448 // todo can we encode a structure pair as an int, like codons?
1449 dc[0] = (char) profl[c++];
1450 dc[1] = (char) profl[c++];
1452 else if (isCdnaProfile)
1454 dc = CodingUtils.decodeCodon(profl[c++]);
1458 dc[0] = (char) profl[c++];
1462 wdth /= fm.charsWidth(dc, 0, dc.length);
1465 // next profl[] position is profile % for the character(s)
1466 scl = htn * scale * profl[c++];
1467 lm = ofont.getLineMetrics(dc, 0, 1,
1468 g.getFontMetrics().getFontRenderContext());
1469 Font font = ofont.deriveFont(AffineTransform
1470 .getScaleInstance(wdth, scl / lm.getAscent()));
1472 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1474 // Debug - render boxes around characters
1475 // g.setColor(Color.red);
1476 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1478 // g.setColor(profcolour.findColour(dc[0]).darker());
1481 * Set character colour as per alignment colour scheme; use the
1482 * codon translation if a cDNA profile
1484 Color colour = null;
1487 final String codonTranslation = ResidueProperties
1488 .codonTranslate(new String(dc));
1489 colour = profcolour.findColour(codonTranslation.charAt(0),
1494 colour = profcolour.findColour(dc[0], column, null);
1496 g.setColor(colour == Color.white ? Color.lightGray : colour);
1498 hght = (ht + (scl - lm.getDescent()
1499 - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1501 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1509 if (_aa.threshold != null)
1511 g.setColor(_aa.threshold.colour);
1512 Graphics2D g2 = (Graphics2D) g;
1513 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1514 BasicStroke.JOIN_ROUND, 3f, new float[]
1518 - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1519 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1520 g2.setStroke(new BasicStroke());
1524 // used by overview window
1525 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1526 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1528 eRes = Math.min(eRes, aa_annotations.length);
1529 g.setColor(Color.white);
1530 g.fillRect(0, 0, width, y);
1531 g.setColor(new Color(0, 0, 180));
1535 for (int j = sRes; j < eRes; j++)
1537 if (aa_annotations[j] != null)
1539 if (aa_annotations[j].colour == null)
1541 g.setColor(Color.black);
1545 g.setColor(aa_annotations[j].colour);
1548 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1554 g.fillRect(x, y - height, charWidth, height);
1560 Color getNotCanonicalColor(char lastss)
1566 return new Color(255, 125, 5);
1570 return new Color(245, 115, 10);
1574 return new Color(235, 135, 15);
1578 return new Color(225, 105, 20);
1582 return new Color(215, 145, 30);
1586 return new Color(205, 95, 35);
1590 return new Color(195, 155, 45);
1594 return new Color(185, 85, 55);
1598 return new Color(175, 165, 65);
1602 return new Color(170, 75, 75);
1606 return new Color(160, 175, 85);
1610 return new Color(150, 65, 95);
1614 return new Color(140, 185, 105);
1618 return new Color(130, 55, 110);
1622 return new Color(120, 195, 120);
1626 return new Color(110, 45, 130);
1630 return new Color(100, 205, 140);
1634 return new Color(90, 35, 150);
1638 return new Color(85, 215, 160);
1642 return new Color(75, 25, 170);
1646 return new Color(65, 225, 180);
1650 return new Color(55, 15, 185);
1654 return new Color(45, 235, 195);
1658 return new Color(35, 5, 205);
1662 return new Color(25, 245, 215);
1666 return new Color(15, 0, 225);
1670 return new Color(10, 255, 235);
1674 return new Color(5, 150, 245);
1678 return new Color(0, 80, 255);
1681 System.out.println("This is not a interaction : " + lastss);