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 boolean av_renderHistogram = true, av_renderProfile = true,
76 av_normaliseProfile = false;
78 boolean av_renderInformationHistogram = true, av_renderHMMProfile = true,
79 av_normaliseHMMProfile = false, av_infoHeight = false;
81 ResidueShaderI profcolour = null;
83 private ColumnSelection columnSelection;
85 private HiddenColumns hiddenColumns;
87 private ProfilesI hconsensus;
89 private Hashtable[] complementConsensus;
91 private Hashtable[] hStrucConsensus;
93 private boolean av_ignoreGapsConsensus;
95 private boolean av_ignoreBelowBackground;
98 * attributes set from AwtRenderPanelI
101 * old image used when data is currently being calculated and cannot be
104 private Image fadedImage;
107 * panel being rendered into
109 private ImageObserver annotationPanel;
112 * width of image to render in panel
114 private int imgWidth;
117 * offset to beginning of visible area
122 * offset to end of visible area
124 private int visHeight;
127 * indicate if the renderer should only render the visible portion of the
128 * annotation given the current view settings
130 private boolean useClip = true;
133 * master flag indicating if renderer should ever try to clip. not enabled for
136 private boolean canClip = false;
138 public AnnotationRenderer()
144 * Create a new annotation Renderer
147 * flag indicating if timing and redraw parameter info should be
150 public AnnotationRenderer(boolean debugRedraw)
152 this.debugRedraw = debugRedraw;
156 * Remove any references and resources when this object is no longer required
158 public void dispose()
161 complementConsensus = null;
162 hStrucConsensus = null;
164 annotationPanel = null;
167 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
168 int x, int y, int iconOffset, int startRes, int column,
169 boolean validRes, boolean validEnd)
171 g.setColor(STEM_COLOUR);
172 int sCol = (lastSSX / charWidth)
173 + hiddenColumns.adjustForHiddenColumns(startRes);
175 int x2 = (x * charWidth);
177 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
178 : row_annotations[column - 1].secondaryStructure;
180 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
181 || dc != row_annotations[sCol - 1].secondaryStructure;
182 boolean diffdownstream = !validRes || !validEnd
183 || row_annotations[column] == null
184 || dc != row_annotations[column].secondaryStructure;
186 if (column > 0 && Rna.isClosingParenthesis(dc))
189 // if (validRes && column>1 && row_annotations[column-2]!=null &&
190 // dc.equals(row_annotations[column-2].displayCharacter))
193 * if new annotation with a closing base pair half of the stem,
194 * display a backward arrow
196 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
198 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
209 // display a forward arrow
213 * if annotation ending with an opeing base pair half of the stem,
214 * display a forward arrow
216 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
218 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
228 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
231 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
232 Annotation[] row_annotations, int lastSSX, int x, int y,
233 int iconOffset, int startRes, int column, boolean validRes,
236 // System.out.println(nonCanColor);
238 g.setColor(nonCanColor);
239 int sCol = (lastSSX / charWidth)
240 + hiddenColumns.adjustForHiddenColumns(startRes);
242 int x2 = (x * charWidth);
244 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
245 : row_annotations[column - 1].displayCharacter;
247 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
248 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
249 boolean diffdownstream = !validRes || !validEnd
250 || row_annotations[column] == null
251 || !dc.equals(row_annotations[column].displayCharacter);
252 // System.out.println("Column "+column+" diff up: "+diffupstream+"
253 // down:"+diffdownstream);
254 // If a closing base pair half of the stem, display a backward arrow
255 if (column > 0 && Rna.isClosingParenthesis(dc))
259 // if (validRes && column>1 && row_annotations[column-2]!=null &&
260 // dc.equals(row_annotations[column-2].displayCharacter))
262 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
264 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
276 // display a forward arrow
279 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
281 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
291 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
294 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
296 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
299 fm = annotPanel.getFontMetrics();
300 annotationPanel = annotPanel;
301 fadedImage = annotPanel.getFadedImage();
302 imgWidth = annotPanel.getFadedImageWidth();
303 // visible area for rendering
304 int[] bounds = annotPanel.getVisibleVRange();
308 visHeight = bounds[1];
323 updateFromAlignViewport(av);
326 public void updateFromAlignViewport(AlignViewportI av)
328 charWidth = av.getCharWidth();
329 endRes = av.getRanges().getEndRes();
330 charHeight = av.getCharHeight();
331 hasHiddenColumns = av.hasHiddenColumns();
332 validCharWidth = av.isValidCharWidth();
333 av_renderHistogram = av.isShowConsensusHistogram();
334 av_renderProfile = av.isShowSequenceLogo();
335 av_normaliseProfile = av.isNormaliseSequenceLogo();
336 av_renderInformationHistogram = av.isShowInformationHistogram();
337 av_renderHMMProfile = av.isShowHMMSequenceLogo();
338 av_normaliseHMMProfile = av.isNormaliseHMMSequenceLogo();
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.getSequenceConsensusHash();
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.consensusData != null
392 && aa.groupRef.isShowSequenceLogo())
394 // TODO? group consensus for cDNA complement
395 return AAFrequency.extractProfile(
396 aa.groupRef.consensusData.get(column),
397 aa.groupRef.getIgnoreGapsConsensus());
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 renderHistogram = av_renderInformationHistogram;
533 renderProfile = av_renderHMMProfile;
534 normaliseProfile = av_normaliseHMMProfile;
538 renderHistogram = true;
539 // don't need to set render/normaliseProfile since they are not
540 // currently used in any other annotation track renderer
543 Annotation[] row_annotations = row.annotations;
548 centreColLabels = row.centreColLabels || centreColLabelsDef;
549 labelAllCols = row.showAllColLabels;
550 scaleColLabel = row.scaleColLabel;
554 if (!useClip || ((y - charHeight) < visHeight
555 && (y + row.height + charHeight * 2) >= sOffset))
556 {// if_in_visible_region
567 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
572 // this is so that we draw the characters below the graph
577 iconOffset = charHeight - fm.getDescent();
581 else if (row.hasText)
583 iconOffset = charHeight - fm.getDescent();
591 if (row.autoCalculated && av.isCalculationInProgress(row))
595 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
596 y - row.height, imgWidth, y, annotationPanel);
597 g.setColor(Color.black);
598 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
604 * else if (annotationPanel.av.updatingConservation &&
605 * aa[i].label.equals("Conservation")) {
607 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
608 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
609 * annotationPanel.imgWidth, y, annotationPanel);
611 * g.setColor(Color.black); //
612 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
614 * continue; } else if (annotationPanel.av.updatingConservation &&
615 * aa[i].label.equals("Quality")) {
617 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
618 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
619 * annotationPanel.imgWidth, y, annotationPanel);
620 * g.setColor(Color.black); // /
621 * g.drawString("Calculating Quality....",20, y-row.height/2);
625 // first pass sets up state for drawing continuation from left-hand
628 x = (startRes == 0) ? 0 : -1;
629 while (x < endRes - startRes)
631 if (hasHiddenColumns)
633 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
634 if (column > row_annotations.length - 1)
641 column = startRes + x;
644 if ((row_annotations == null)
645 || (row_annotations.length <= column)
646 || (row_annotations[column] == null))
654 final String displayChar = validRes
655 ? row_annotations[column].displayCharacter
661 g.setColor(Color.red);
663 if (columnSelection != null)
665 if (columnSelection.contains(column))
667 g.fillRect(x * charWidth, y, charWidth, charHeight);
671 if (row.getInvalidStrucPos() > x)
673 g.setColor(Color.orange);
674 g.fillRect(x * charWidth, y, charWidth, charHeight);
676 else if (row.getInvalidStrucPos() == x)
678 g.setColor(Color.orange.darker());
679 g.fillRect(x * charWidth, y, charWidth, charHeight);
681 if (validCharWidth && validRes && displayChar != null
682 && (displayChar.length() > 0))
685 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
686 displayChar.length());
687 if (/* centreColLabels || */scaleColLabel)
689 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
690 // displayChar.length());
692 // if (scaleColLabel)
694 // justify the label and scale to fit in column
695 if (fmWidth > charWidth)
697 // scale only if the current font isn't already small enough
698 fmScaling = charWidth;
699 fmScaling /= fmWidth;
700 g.setFont(ofont.deriveFont(AffineTransform
701 .getScaleInstance(fmScaling, 1.0)));
702 // and update the label's width to reflect the scaling.
707 // TODO is it ok to use width of / show all characters here?
710 // fmWidth = fm.charWidth(displayChar.charAt(0));
712 charOffset = (int) ((charWidth - fmWidth) / 2f);
714 if (row_annotations[column].colour == null)
716 g.setColor(Color.black);
720 g.setColor(row_annotations[column].colour);
723 if (column == 0 || row.graph > 0)
725 g.drawString(displayChar, (x * charWidth) + charOffset,
728 else if (row_annotations[column - 1] == null || (labelAllCols
729 || !displayChar.equals(
730 row_annotations[column - 1].displayCharacter)
731 || (displayChar.length() < 2
732 && row_annotations[column].secondaryStructure == ' ')))
734 g.drawString(displayChar, x * charWidth + charOffset,
742 char ss = validRes ? row_annotations[column].secondaryStructure
747 // distinguish between forward/backward base-pairing
748 if (displayChar.indexOf(')') > -1)
757 if ((displayChar.indexOf(']') > -1))
765 // distinguish between forward/backward base-pairing
766 if (displayChar.indexOf('}') > -1)
774 // distinguish between forward/backward base-pairing
775 if (displayChar.indexOf('<') > -1)
781 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
783 // distinguish between forward/backward base-pairing
784 int ssLowerCase = ss + UPPER_TO_LOWER;
785 // TODO would .equals() be safer here? or charAt(0)?
786 if (displayChar.indexOf(ssLowerCase) > -1)
788 ss = (char) ssLowerCase;
792 if (!validRes || (ss != lastSS))
798 int nb_annot = x - temp;
799 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
800 // annot :"+nb_annot);
803 case '(': // Stem case for RNA secondary structure
804 case ')': // and opposite direction
805 drawStemAnnot(g, row_annotations, lastSSX, x, y,
806 iconOffset, startRes, column, validRes, validEnd);
813 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
814 iconOffset, startRes, column, validRes,
818 // no break if isRNA - falls through to drawNotCanonicalAnnot!
822 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
823 iconOffset, startRes, column, validRes,
827 // no break if isRNA - fall through to drawNotCanonicalAnnot!
886 Color nonCanColor = getNotCanonicalColor(lastSS);
887 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
888 lastSSX, x, y, iconOffset, startRes, column,
893 g.setColor(Color.gray);
894 g.fillRect(lastSSX, y + 6 + iconOffset,
895 (x * charWidth) - lastSSX, 2);
910 lastSSX = (x * charWidth);
917 if (column >= row_annotations.length)
919 column = row_annotations.length - 1;
926 if ((row_annotations == null) || (row_annotations.length <= column)
927 || (row_annotations[column] == null))
945 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
946 startRes, column, validRes, validEnd);
949 // no break if isRNA - fall through to drawNotCanonicalAnnot!
954 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
955 startRes, column, validRes, validEnd);
958 // no break if isRNA - fall through to drawNotCanonicalAnnot!
961 case ')': // Stem case for RNA secondary structure
963 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
964 startRes, column, validRes, validEnd);
1021 // System.out.println(lastSS);
1022 Color nonCanColor = getNotCanonicalColor(lastSS);
1023 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1024 x, y, iconOffset, startRes, column, validRes, validEnd);
1027 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1028 startRes, column, validRes, validEnd);
1033 if (row.graph > 0 && row.graphHeight > 0)
1035 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1037 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1039 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1040 // computed efficiently for all visible labels
1041 float groupmax = -999999, groupmin = 9999999;
1042 for (int gg = 0; gg < aa.length; gg++)
1044 if (aa[gg].graphGroup != row.graphGroup)
1051 aa[gg].visible = false;
1053 if (aa[gg].graphMax > groupmax)
1055 groupmax = aa[gg].graphMax;
1057 if (aa[gg].graphMin < groupmin)
1059 groupmin = aa[gg].graphMin;
1063 for (int gg = 0; gg < aa.length; gg++)
1065 if (aa[gg].graphGroup == row.graphGroup)
1067 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1068 endRes, y, groupmin, groupmax, row.graphHeight);
1072 graphGroupDrawn.set(row.graphGroup);
1076 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1077 row.graphMin, row.graphMax, row.graphHeight);
1080 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1082 drawBarGraph(g, row, row_annotations, startRes, endRes,
1083 row.graphMin, row.graphMax, y, renderHistogram,
1084 renderProfile, normaliseProfile);
1090 if (clipst && !clipend)
1094 } // end if_in_visible_region
1095 if (row.graph > 0 && row.hasText)
1112 "Start clip at : " + yfrom + " (index " + f_i + ")");
1117 "End clip at : " + yto + " (index " + f_to + ")");
1121 System.err.println("Annotation Rendering time:"
1122 + (System.currentTimeMillis() - stime));
1129 public static final Color GLYPHLINE_COLOR = Color.gray;
1131 public static final Color SHEET_COLOUR = Color.green;
1133 public static final Color HELIX_COLOUR = Color.red;
1135 public static final Color STEM_COLOUR = Color.blue;
1137 private Color sdNOTCANONICAL_COLOUR;
1139 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1140 int y, int iconOffset, int startRes, int column, boolean validRes,
1143 g.setColor(GLYPHLINE_COLOR);
1144 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1147 void drawSheetAnnot(Graphics g, Annotation[] row,
1149 int lastSSX, int x, int y, int iconOffset, int startRes,
1150 int column, boolean validRes, boolean validEnd)
1152 g.setColor(SHEET_COLOUR);
1154 if (!validEnd || !validRes || row == null || row[column] == null
1155 || row[column].secondaryStructure != 'E')
1157 g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1161 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1163 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1168 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1174 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1175 int y, int iconOffset, int startRes, int column, boolean validRes,
1178 g.setColor(HELIX_COLOUR);
1180 int sCol = (lastSSX / charWidth)
1181 + hiddenColumns.adjustForHiddenColumns(startRes);
1183 int x2 = (x * charWidth);
1187 int ofs = charWidth / 2;
1188 // Off by 1 offset when drawing rects and ovals
1189 // to offscreen image on the MAC
1190 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1191 if (sCol == 0 || row[sCol - 1] == null
1192 || row[sCol - 1].secondaryStructure != 'H')
1197 // g.setColor(Color.orange);
1198 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1201 if (!validRes || row[column] == null
1202 || row[column].secondaryStructure != 'H')
1208 // g.setColor(Color.magenta);
1209 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1210 x2 - x1 - ofs + 1, 8, 0, 0);
1217 if (sCol == 0 || row[sCol - 1] == null
1218 || row[sCol - 1].secondaryStructure != 'H')
1220 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1221 x1 += charWidth / 2;
1224 if (!validRes || row[column] == null
1225 || row[column].secondaryStructure != 'H')
1227 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1229 x2 -= charWidth / 2;
1232 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1235 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1236 Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1237 float max, int graphHeight)
1239 if (sRes > aa_annotations.length)
1246 // Adjustment for fastpaint to left
1252 eRes = Math.min(eRes, aa_annotations.length);
1260 float range = max - min;
1265 y2 = y - (int) ((0 - min / range) * graphHeight);
1268 g.setColor(Color.gray);
1269 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1271 eRes = Math.min(eRes, aa_annotations.length);
1274 int aaMax = aa_annotations.length - 1;
1276 while (x < eRes - sRes)
1279 if (hasHiddenColumns)
1281 column = hiddenColumns.adjustForHiddenColumns(column);
1289 if (aa_annotations[column] == null
1290 || aa_annotations[column - 1] == null)
1296 if (aa_annotations[column].colour == null)
1298 g.setColor(Color.black);
1302 g.setColor(aa_annotations[column].colour);
1305 y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1307 y2 = y - (int) (((aa_annotations[column].value - min) / range)
1310 g.drawLine(x * charWidth - charWidth / 2, y1,
1311 x * charWidth + charWidth / 2, y2);
1315 if (_aa.threshold != null)
1317 g.setColor(_aa.threshold.colour);
1318 Graphics2D g2 = (Graphics2D) g;
1319 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1320 BasicStroke.JOIN_ROUND, 3f, new float[]
1323 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1324 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1325 g2.setStroke(new BasicStroke());
1329 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1330 Annotation[] aa_annotations, int sRes, int eRes, float min,
1331 float max, int y, boolean renderHistogram, boolean renderProfile,
1332 boolean normaliseProfile)
1334 if (sRes > aa_annotations.length)
1338 Font ofont = g.getFont();
1339 eRes = Math.min(eRes, aa_annotations.length);
1341 int x = 0, y1 = y, y2 = y;
1343 float range = max - min;
1347 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1350 g.setColor(Color.gray);
1352 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1355 int aaMax = aa_annotations.length - 1;
1356 while (x < eRes - sRes)
1359 if (hasHiddenColumns)
1361 column = hiddenColumns.adjustForHiddenColumns(column);
1369 if (aa_annotations[column] == null)
1374 if (aa_annotations[column].colour == null)
1376 g.setColor(Color.black);
1380 g.setColor(aa_annotations[column].colour);
1383 y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1386 if (renderHistogram)
1390 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1394 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1397 // draw profile if available
1402 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1404 int profl[] = getProfileFor(_aa, column);
1406 // just try to draw the logo if profl is not null
1407 if (profl != null && profl[2] != 0)
1409 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1410 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1411 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1412 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1419 * Render a single base for a sequence profile, a base pair for
1420 * structure profile, and a triplet for a cdna profile
1422 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1424 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1425 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1426 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1430 * Traverse the character(s)/percentage data in the array
1433 int valuesProcessed = 0;
1434 // profl[1] is the number of values in the profile
1435 while (valuesProcessed < profl[1])
1437 if (isStructureProfile)
1439 // todo can we encode a structure pair as an int, like codons?
1440 dc[0] = (char) profl[c++];
1441 dc[1] = (char) profl[c++];
1443 else if (isCdnaProfile)
1445 dc = CodingUtils.decodeCodon(profl[c++]);
1449 dc[0] = (char) profl[c++];
1453 wdth /= fm.charsWidth(dc, 0, dc.length);
1456 // next profl[] position is profile % for the character(s)
1457 scl = htn * scale * profl[c++];
1458 lm = ofont.getLineMetrics(dc, 0, 1,
1459 g.getFontMetrics().getFontRenderContext());
1460 Font font = ofont.deriveFont(AffineTransform
1461 .getScaleInstance(wdth, scl / lm.getAscent()));
1463 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1465 // Debug - render boxes around characters
1466 // g.setColor(Color.red);
1467 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1469 // g.setColor(profcolour.findColour(dc[0]).darker());
1472 * Set character colour as per alignment colour scheme; use the
1473 * codon translation if a cDNA profile
1475 Color colour = null;
1478 final String codonTranslation = ResidueProperties
1479 .codonTranslate(new String(dc));
1480 colour = profcolour.findColour(codonTranslation.charAt(0),
1485 colour = profcolour.findColour(dc[0], column, null);
1487 g.setColor(colour == Color.white ? Color.lightGray : colour);
1489 hght = (ht + (scl - lm.getDescent()
1490 - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1492 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1500 if (_aa.threshold != null)
1502 g.setColor(_aa.threshold.colour);
1503 Graphics2D g2 = (Graphics2D) g;
1504 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1505 BasicStroke.JOIN_ROUND, 3f, new float[]
1509 - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1510 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1511 g2.setStroke(new BasicStroke());
1515 // used by overview window
1516 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1517 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1519 eRes = Math.min(eRes, aa_annotations.length);
1520 g.setColor(Color.white);
1521 g.fillRect(0, 0, width, y);
1522 g.setColor(new Color(0, 0, 180));
1526 for (int j = sRes; j < eRes; j++)
1528 if (aa_annotations[j] != null)
1530 if (aa_annotations[j].colour == null)
1532 g.setColor(Color.black);
1536 g.setColor(aa_annotations[j].colour);
1539 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1545 g.fillRect(x, y - height, charWidth, height);
1551 Color getNotCanonicalColor(char lastss)
1557 return new Color(255, 125, 5);
1561 return new Color(245, 115, 10);
1565 return new Color(235, 135, 15);
1569 return new Color(225, 105, 20);
1573 return new Color(215, 145, 30);
1577 return new Color(205, 95, 35);
1581 return new Color(195, 155, 45);
1585 return new Color(185, 85, 55);
1589 return new Color(175, 165, 65);
1593 return new Color(170, 75, 75);
1597 return new Color(160, 175, 85);
1601 return new Color(150, 65, 95);
1605 return new Color(140, 185, 105);
1609 return new Color(130, 55, 110);
1613 return new Color(120, 195, 120);
1617 return new Color(110, 45, 130);
1621 return new Color(100, 205, 140);
1625 return new Color(90, 35, 150);
1629 return new Color(85, 215, 160);
1633 return new Color(75, 25, 170);
1637 return new Color(65, 225, 180);
1641 return new Color(55, 15, 185);
1645 return new Color(45, 235, 195);
1649 return new Color(35, 5, 205);
1653 return new Color(25, 245, 215);
1657 return new Color(15, 0, 225);
1661 return new Color(10, 255, 235);
1665 return new Color(5, 150, 245);
1669 return new Color(0, 80, 255);
1672 System.out.println("This is not a interaction : " + lastss);