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;
40 import java.awt.BasicStroke;
41 import java.awt.Color;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.Image;
47 import java.awt.font.LineMetrics;
48 import java.awt.geom.AffineTransform;
49 import java.awt.image.ImageObserver;
50 import java.util.BitSet;
51 import java.util.Hashtable;
53 public class AnnotationRenderer
55 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
57 private static final int CHAR_A = 'A'; // 65
59 private static final int CHAR_Z = 'Z'; // 90
62 * flag indicating if timing and redraw parameter info should be output
64 private final boolean debugRedraw;
66 private int charWidth, endRes, charHeight;
68 private boolean validCharWidth, hasHiddenColumns;
70 private FontMetrics fm;
72 private final boolean MAC = Platform.isAMac();
74 boolean av_renderHistogram = true, av_renderProfile = true,
75 av_normaliseProfile = false;
77 boolean av_renderInformationHistogram = true, av_renderHMMProfile = true,
78 av_normaliseHMMProfile = false, av_infoHeight = false;
80 ResidueShaderI profcolour = null;
82 private ColumnSelection columnSelection;
84 private HiddenColumns hiddenColumns;
86 private ProfilesI hconsensus;
88 private Hashtable[] complementConsensus;
90 private Hashtable[] hStrucConsensus;
92 private boolean av_ignoreGapsConsensus;
94 private boolean av_ignoreBelowBackground;
97 * attributes set from AwtRenderPanelI
100 * old image used when data is currently being calculated and cannot be
103 private Image fadedImage;
106 * panel being rendered into
108 private ImageObserver annotationPanel;
111 * width of image to render in panel
113 private int imgWidth;
116 * offset to beginning of visible area
121 * offset to end of visible area
123 private int visHeight;
126 * indicate if the renderer should only render the visible portion of the
127 * annotation given the current view settings
129 private boolean useClip = true;
132 * master flag indicating if renderer should ever try to clip. not enabled for
135 private boolean canClip = false;
137 public AnnotationRenderer()
143 * Create a new annotation Renderer
146 * flag indicating if timing and redraw parameter info should be
149 public AnnotationRenderer(boolean debugRedraw)
151 this.debugRedraw = debugRedraw;
155 * Remove any references and resources when this object is no longer required
157 public void dispose()
160 complementConsensus = null;
161 hStrucConsensus = null;
163 annotationPanel = null;
166 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
167 int x, int y, int iconOffset, int startRes, int column,
168 boolean validRes, boolean validEnd)
170 g.setColor(STEM_COLOUR);
171 int sCol = (lastSSX / charWidth) + startRes;
173 int x2 = (x * charWidth);
175 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
176 : row_annotations[column - 1].secondaryStructure;
178 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
179 || dc != row_annotations[sCol - 1].secondaryStructure;
180 boolean diffdownstream = !validRes || !validEnd
181 || row_annotations[column] == null
182 || dc != row_annotations[column].secondaryStructure;
184 if (column > 0 && Rna.isClosingParenthesis(dc))
187 // if (validRes && column>1 && row_annotations[column-2]!=null &&
188 // dc.equals(row_annotations[column-2].displayCharacter))
191 * if new annotation with a closing base pair half of the stem,
192 * display a backward arrow
194 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
196 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
207 // display a forward arrow
211 * if annotation ending with an opeing base pair half of the stem,
212 * display a forward arrow
214 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
216 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
226 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
229 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
230 Annotation[] row_annotations, int lastSSX, int x, int y,
231 int iconOffset, int startRes, int column, boolean validRes,
234 // System.out.println(nonCanColor);
236 g.setColor(nonCanColor);
237 int sCol = (lastSSX / charWidth) + startRes;
239 int x2 = (x * charWidth);
241 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
242 : row_annotations[column - 1].displayCharacter;
244 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
245 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
246 boolean diffdownstream = !validRes || !validEnd
247 || row_annotations[column] == null
248 || !dc.equals(row_annotations[column].displayCharacter);
249 // System.out.println("Column "+column+" diff up: "+diffupstream+"
250 // down:"+diffdownstream);
251 // If a closing base pair half of the stem, display a backward arrow
252 if (column > 0 && Rna.isClosingParenthesis(dc))
256 // if (validRes && column>1 && row_annotations[column-2]!=null &&
257 // dc.equals(row_annotations[column-2].displayCharacter))
259 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
261 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
273 // display a forward arrow
276 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
278 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
288 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
291 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
293 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
296 fm = annotPanel.getFontMetrics();
297 annotationPanel = annotPanel;
298 fadedImage = annotPanel.getFadedImage();
299 imgWidth = annotPanel.getFadedImageWidth();
300 // visible area for rendering
301 int[] bounds = annotPanel.getVisibleVRange();
305 visHeight = bounds[1];
320 updateFromAlignViewport(av);
323 public void updateFromAlignViewport(AlignViewportI av)
325 charWidth = av.getCharWidth();
326 endRes = av.getRanges().getEndRes();
327 charHeight = av.getCharHeight();
328 hasHiddenColumns = av.hasHiddenColumns();
329 validCharWidth = av.isValidCharWidth();
330 av_renderHistogram = av.isShowConsensusHistogram();
331 av_renderProfile = av.isShowSequenceLogo();
332 av_normaliseProfile = av.isNormaliseSequenceLogo();
333 av_renderInformationHistogram = av.isShowInformationHistogram();
334 av_renderHMMProfile = av.isShowHMMSequenceLogo();
335 av_normaliseHMMProfile = av.isNormaliseHMMSequenceLogo();
336 profcolour = av.getResidueShading();
337 if (profcolour == null || profcolour.getColourScheme() == null)
340 * Use default colour for sequence logo if
341 * the alignment has no colourscheme set
342 * (would like to use user preference but n/a for applet)
344 ColourSchemeI col = av.getAlignment().isNucleotide()
345 ? new NucleotideColourScheme()
346 : new ZappoColourScheme();
347 profcolour = new ResidueShader(col);
349 columnSelection = av.getColumnSelection();
350 hiddenColumns = av.getAlignment().getHiddenColumns();
351 hconsensus = av.getSequenceConsensusHash();
352 complementConsensus = av.getComplementConsensusHash();
353 hStrucConsensus = av.getRnaStructureConsensusHash();
354 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
355 av_ignoreBelowBackground = av.isIgnoreBelowBackground();
356 av_infoHeight = av.isInfoLetterHeight();
362 * Returns profile data; the first element is the profile type, the second is
363 * the number of distinct values, the third the total count, and the remainder
364 * depend on the profile type.
370 int[] getProfileFor(AlignmentAnnotation aa, int column)
372 // TODO : consider refactoring the global alignment calculation
373 // properties/rendering attributes as a global 'alignment group' which holds
374 // all vis settings for the alignment as a whole rather than a subset
376 if ("HMM".equals(aa.getCalcId()))
378 HiddenMarkovModel hmm = aa.sequenceRef.getHMM();
379 return AAFrequency.extractHMMProfile(hmm, column,
380 av_ignoreBelowBackground, av_infoHeight); // TODO check if this follows standard
383 if (aa.autoCalculated
384 && (aa.label.startsWith("Consensus") || aa.label
385 .startsWith("cDNA Consensus")))
387 boolean forComplement = aa.label.startsWith("cDNA Consensus");
388 if (aa.groupRef != null && aa.groupRef.consensusData != null
389 && aa.groupRef.isShowSequenceLogo())
391 // TODO? group consensus for cDNA complement
392 return AAFrequency.extractProfile(
393 aa.groupRef.consensusData.get(column),
394 aa.groupRef.getIgnoreGapsConsensus());
396 // TODO extend annotation row to enable dynamic and static profile data to
398 if (aa.groupRef == null && aa.sequenceRef == null)
402 return AAFrequency.extractCdnaProfile(complementConsensus[column],
403 av_ignoreGapsConsensus);
407 return AAFrequency.extractProfile(hconsensus.get(column),
408 av_ignoreGapsConsensus);
414 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
416 // TODO implement group structure consensus
418 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
419 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
420 * group selections return StructureFrequency.extractProfile(
421 * aa.groupRef.consensusData[column], aa.groupRef
422 * .getIgnoreGapsConsensus()); }
424 // TODO extend annotation row to enable dynamic and static profile data
427 if (aa.groupRef == null && aa.sequenceRef == null
428 && hStrucConsensus != null
429 && hStrucConsensus.length > column)
431 return StructureFrequency.extractProfile(hStrucConsensus[column],
432 av_ignoreGapsConsensus);
442 * Render the annotation rows associated with an alignment.
447 * data and view settings to render
449 * destination for graphics
451 * row where a mouse event occured (or -1)
453 * first column that will be drawn
455 * last column that will be drawn
456 * @return true if the fadedImage was used for any alignment annotation rows
457 * currently being calculated
459 public boolean drawComponent(AwtRenderPanelI annotPanel,
460 AlignViewportI av, Graphics g, int activeRow, int startRes,
463 long stime = System.currentTimeMillis();
464 boolean usedFaded = false;
466 // AnnotationPanel needs to implement: ImageObserver, access to
468 updateFromAwtRenderPanel(annotPanel, av);
469 fm = g.getFontMetrics();
470 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
481 boolean validRes = false;
482 boolean validEnd = false;
483 boolean labelAllCols = false;
484 boolean centreColLabels;
485 boolean centreColLabelsDef = av.isCentreColumnLabels();
486 boolean scaleColLabel = false;
487 final AlignmentAnnotation consensusAnnot = av
488 .getAlignmentConsensusAnnotation();
489 final AlignmentAnnotation structConsensusAnnot = av
490 .getAlignmentStrucConsensusAnnotation();
491 final AlignmentAnnotation complementConsensusAnnot = av
492 .getComplementConsensusAnnotation();
493 boolean renderHistogram = true, renderProfile = true,
494 normaliseProfile = false, isRNA = rna;
496 BitSet graphGroupDrawn = new BitSet();
497 int charOffset = 0; // offset for a label
498 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
500 Font ofont = g.getFont();
503 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
504 boolean clipst = false, clipend = false;
505 for (int i = 0; i < aa.length; i++)
507 AlignmentAnnotation row = aa[i];
510 // check if this is a consensus annotation row and set the display
511 // settings appropriately
512 // TODO: generalise this to have render styles for consensus/profile
514 if (row.groupRef != null && row == row.groupRef.getConsensus())
516 renderHistogram = row.groupRef.isShowConsensusHistogram();
517 renderProfile = row.groupRef.isShowSequenceLogo();
518 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
520 else if (row == consensusAnnot || row == structConsensusAnnot
521 || row == complementConsensusAnnot)
523 renderHistogram = av_renderHistogram;
524 renderProfile = av_renderProfile;
525 normaliseProfile = av_normaliseProfile;
527 else if ("HMM".equals(row.getCalcId()))
529 renderHistogram = av_renderInformationHistogram;
530 renderProfile = av_renderHMMProfile;
531 normaliseProfile = av_normaliseHMMProfile;
535 renderHistogram = true;
536 // don't need to set render/normaliseProfile since they are not
537 // currently used in any other annotation track renderer
540 Annotation[] row_annotations = row.annotations;
545 centreColLabels = row.centreColLabels || centreColLabelsDef;
546 labelAllCols = row.showAllColLabels;
547 scaleColLabel = row.scaleColLabel;
551 if (!useClip || ((y - charHeight) < visHeight
552 && (y + row.height + charHeight * 2) >= sOffset))
553 {// if_in_visible_region
564 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
569 // this is so that we draw the characters below the graph
574 iconOffset = charHeight - fm.getDescent();
578 else if (row.hasText)
580 iconOffset = charHeight - fm.getDescent();
588 if (row.autoCalculated && av.isCalculationInProgress(row))
592 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
593 y - row.height, imgWidth, y, annotationPanel);
594 g.setColor(Color.black);
595 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
601 * else if (annotationPanel.av.updatingConservation &&
602 * aa[i].label.equals("Conservation")) {
604 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
605 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
606 * annotationPanel.imgWidth, y, annotationPanel);
608 * g.setColor(Color.black); //
609 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
611 * continue; } else if (annotationPanel.av.updatingConservation &&
612 * aa[i].label.equals("Quality")) {
614 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
615 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
616 * annotationPanel.imgWidth, y, annotationPanel);
617 * g.setColor(Color.black); // /
618 * g.drawString("Calculating Quality....",20, y-row.height/2);
622 // first pass sets up state for drawing continuation from left-hand
625 x = (startRes == 0) ? 0 : -1;
626 while (x < endRes - startRes)
628 if (hasHiddenColumns)
630 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
631 if (column > row_annotations.length - 1)
638 column = startRes + x;
641 if ((row_annotations == null)
642 || (row_annotations.length <= column)
643 || (row_annotations[column] == null))
651 final String displayChar = validRes
652 ? row_annotations[column].displayCharacter
658 g.setColor(Color.red);
660 if (columnSelection != null)
662 if (columnSelection.contains(column))
664 g.fillRect(x * charWidth, y, charWidth, charHeight);
668 if (row.getInvalidStrucPos() > x)
670 g.setColor(Color.orange);
671 g.fillRect(x * charWidth, y, charWidth, charHeight);
673 else if (row.getInvalidStrucPos() == x)
675 g.setColor(Color.orange.darker());
676 g.fillRect(x * charWidth, y, charWidth, charHeight);
678 if (validCharWidth && validRes && displayChar != null
679 && (displayChar.length() > 0))
682 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
683 displayChar.length());
684 if (/* centreColLabels || */scaleColLabel)
686 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
687 // displayChar.length());
689 // if (scaleColLabel)
691 // justify the label and scale to fit in column
692 if (fmWidth > charWidth)
694 // scale only if the current font isn't already small enough
695 fmScaling = charWidth;
696 fmScaling /= fmWidth;
697 g.setFont(ofont.deriveFont(AffineTransform
698 .getScaleInstance(fmScaling, 1.0)));
699 // and update the label's width to reflect the scaling.
704 // TODO is it ok to use width of / show all characters here?
707 // fmWidth = fm.charWidth(displayChar.charAt(0));
709 charOffset = (int) ((charWidth - fmWidth) / 2f);
711 if (row_annotations[column].colour == null)
713 g.setColor(Color.black);
717 g.setColor(row_annotations[column].colour);
720 if (column == 0 || row.graph > 0)
722 g.drawString(displayChar, (x * charWidth) + charOffset,
725 else if (row_annotations[column - 1] == null || (labelAllCols
726 || !displayChar.equals(
727 row_annotations[column - 1].displayCharacter)
728 || (displayChar.length() < 2
729 && row_annotations[column].secondaryStructure == ' ')))
731 g.drawString(displayChar, x * charWidth + charOffset,
739 char ss = validRes ? row_annotations[column].secondaryStructure
744 // distinguish between forward/backward base-pairing
745 if (displayChar.indexOf(')') > -1)
754 if ((displayChar.indexOf(']') > -1))
762 // distinguish between forward/backward base-pairing
763 if (displayChar.indexOf('}') > -1)
771 // distinguish between forward/backward base-pairing
772 if (displayChar.indexOf('<') > -1)
778 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
780 // distinguish between forward/backward base-pairing
781 int ssLowerCase = ss + UPPER_TO_LOWER;
782 // TODO would .equals() be safer here? or charAt(0)?
783 if (displayChar.indexOf(ssLowerCase) > -1)
785 ss = (char) ssLowerCase;
789 if (!validRes || (ss != lastSS))
795 int nb_annot = x - temp;
796 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
797 // annot :"+nb_annot);
800 case '(': // Stem case for RNA secondary structure
801 case ')': // and opposite direction
802 drawStemAnnot(g, row_annotations, lastSSX, x, y,
803 iconOffset, startRes, column, validRes, validEnd);
810 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
811 iconOffset, startRes, column, validRes,
815 // no break if isRNA - falls through to drawNotCanonicalAnnot!
819 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
820 iconOffset, startRes, column, validRes,
824 // no break if isRNA - fall through to drawNotCanonicalAnnot!
883 Color nonCanColor = getNotCanonicalColor(lastSS);
884 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
885 lastSSX, x, y, iconOffset, startRes, column,
890 g.setColor(Color.gray);
891 g.fillRect(lastSSX, y + 6 + iconOffset,
892 (x * charWidth) - lastSSX, 2);
907 lastSSX = (x * charWidth);
914 if (column >= row_annotations.length)
916 column = row_annotations.length - 1;
923 if ((row_annotations == null) || (row_annotations.length <= column)
924 || (row_annotations[column] == null))
942 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
943 startRes, column, validRes, validEnd);
946 // no break if isRNA - fall through to drawNotCanonicalAnnot!
951 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
952 startRes, column, validRes, validEnd);
955 // no break if isRNA - fall through to drawNotCanonicalAnnot!
958 case ')': // Stem case for RNA secondary structure
960 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
961 startRes, column, validRes, validEnd);
1018 // System.out.println(lastSS);
1019 Color nonCanColor = getNotCanonicalColor(lastSS);
1020 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1021 x, y, iconOffset, startRes, column, validRes, validEnd);
1024 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1025 startRes, column, validRes, validEnd);
1030 if (row.graph > 0 && row.graphHeight > 0)
1032 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1034 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1036 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1037 // computed efficiently for all visible labels
1038 float groupmax = -999999, groupmin = 9999999;
1039 for (int gg = 0; gg < aa.length; gg++)
1041 if (aa[gg].graphGroup != row.graphGroup)
1048 aa[gg].visible = false;
1050 if (aa[gg].graphMax > groupmax)
1052 groupmax = aa[gg].graphMax;
1054 if (aa[gg].graphMin < groupmin)
1056 groupmin = aa[gg].graphMin;
1060 for (int gg = 0; gg < aa.length; gg++)
1062 if (aa[gg].graphGroup == row.graphGroup)
1064 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1065 endRes, y, groupmin, groupmax, row.graphHeight);
1069 graphGroupDrawn.set(row.graphGroup);
1073 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1074 row.graphMin, row.graphMax, row.graphHeight);
1077 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1079 drawBarGraph(g, row, row_annotations, startRes, endRes,
1080 row.graphMin, row.graphMax, y, renderHistogram,
1081 renderProfile, normaliseProfile);
1087 if (clipst && !clipend)
1091 } // end if_in_visible_region
1092 if (row.graph > 0 && row.hasText)
1109 "Start clip at : " + yfrom + " (index " + f_i + ")");
1114 "End clip at : " + yto + " (index " + f_to + ")");
1118 System.err.println("Annotation Rendering time:"
1119 + (System.currentTimeMillis() - stime));
1126 public static final Color GLYPHLINE_COLOR = Color.gray;
1128 public static final Color SHEET_COLOUR = Color.green;
1130 public static final Color HELIX_COLOUR = Color.red;
1132 public static final Color STEM_COLOUR = Color.blue;
1134 private Color sdNOTCANONICAL_COLOUR;
1136 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1137 int y, int iconOffset, int startRes, int column, boolean validRes,
1140 g.setColor(GLYPHLINE_COLOR);
1141 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1144 void drawSheetAnnot(Graphics g, Annotation[] row,
1146 int lastSSX, int x, int y, int iconOffset, int startRes,
1147 int column, boolean validRes, boolean validEnd)
1149 g.setColor(SHEET_COLOUR);
1151 if (!validEnd || !validRes || row == null || row[column] == null
1152 || row[column].secondaryStructure != 'E')
1154 g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1158 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1160 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1165 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1171 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1172 int y, int iconOffset, int startRes, int column, boolean validRes,
1175 g.setColor(HELIX_COLOUR);
1177 int sCol = (lastSSX / charWidth) + startRes;
1179 int x2 = (x * charWidth);
1183 int ofs = charWidth / 2;
1184 // Off by 1 offset when drawing rects and ovals
1185 // to offscreen image on the MAC
1186 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1187 if (sCol == 0 || row[sCol - 1] == null
1188 || row[sCol - 1].secondaryStructure != 'H')
1193 // g.setColor(Color.orange);
1194 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1197 if (!validRes || row[column] == null
1198 || row[column].secondaryStructure != 'H')
1204 // g.setColor(Color.magenta);
1205 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1206 x2 - x1 - ofs + 1, 8, 0, 0);
1213 if (sCol == 0 || row[sCol - 1] == null
1214 || row[sCol - 1].secondaryStructure != 'H')
1216 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1217 x1 += charWidth / 2;
1220 if (!validRes || row[column] == null
1221 || row[column].secondaryStructure != 'H')
1223 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1225 x2 -= charWidth / 2;
1228 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1231 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1232 Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1233 float max, int graphHeight)
1235 if (sRes > aa_annotations.length)
1242 // Adjustment for fastpaint to left
1248 eRes = Math.min(eRes, aa_annotations.length);
1256 float range = max - min;
1261 y2 = y - (int) ((0 - min / range) * graphHeight);
1264 g.setColor(Color.gray);
1265 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1267 eRes = Math.min(eRes, aa_annotations.length);
1270 int aaMax = aa_annotations.length - 1;
1272 while (x < eRes - sRes)
1275 if (hasHiddenColumns)
1277 column = hiddenColumns.adjustForHiddenColumns(column);
1285 if (aa_annotations[column] == null
1286 || aa_annotations[column - 1] == null)
1292 if (aa_annotations[column].colour == null)
1294 g.setColor(Color.black);
1298 g.setColor(aa_annotations[column].colour);
1301 y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1303 y2 = y - (int) (((aa_annotations[column].value - min) / range)
1306 g.drawLine(x * charWidth - charWidth / 2, y1,
1307 x * charWidth + charWidth / 2, y2);
1311 if (_aa.threshold != null)
1313 g.setColor(_aa.threshold.colour);
1314 Graphics2D g2 = (Graphics2D) g;
1315 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1316 BasicStroke.JOIN_ROUND, 3f, new float[]
1319 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1320 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1321 g2.setStroke(new BasicStroke());
1325 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1326 Annotation[] aa_annotations, int sRes, int eRes, float min,
1327 float max, int y, boolean renderHistogram, boolean renderProfile,
1328 boolean normaliseProfile)
1330 if (sRes > aa_annotations.length)
1334 Font ofont = g.getFont();
1335 eRes = Math.min(eRes, aa_annotations.length);
1337 int x = 0, y1 = y, y2 = y;
1339 float range = max - min;
1343 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1346 g.setColor(Color.gray);
1348 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1351 int aaMax = aa_annotations.length - 1;
1352 while (x < eRes - sRes)
1355 if (hasHiddenColumns)
1357 column = hiddenColumns.adjustForHiddenColumns(column);
1365 if (aa_annotations[column] == null)
1370 if (aa_annotations[column].colour == null)
1372 g.setColor(Color.black);
1376 g.setColor(aa_annotations[column].colour);
1379 y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1382 if (renderHistogram)
1386 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1390 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1393 // draw profile if available
1398 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1400 int profl[] = getProfileFor(_aa, column);
1402 // just try to draw the logo if profl is not null
1403 if (profl != null && profl[2] != 0)
1405 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1406 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1407 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1408 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1415 * Render a single base for a sequence profile, a base pair for
1416 * structure profile, and a triplet for a cdna profile
1418 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1420 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1421 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1422 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1426 * Traverse the character(s)/percentage data in the array
1429 int valuesProcessed = 0;
1430 // profl[1] is the number of values in the profile
1431 while (valuesProcessed < profl[1])
1433 if (isStructureProfile)
1435 // todo can we encode a structure pair as an int, like codons?
1436 dc[0] = (char) profl[c++];
1437 dc[1] = (char) profl[c++];
1439 else if (isCdnaProfile)
1441 dc = CodingUtils.decodeCodon(profl[c++]);
1445 dc[0] = (char) profl[c++];
1449 wdth /= fm.charsWidth(dc, 0, dc.length);
1452 // next profl[] position is profile % for the character(s)
1453 scl = htn * scale * profl[c++];
1454 lm = ofont.getLineMetrics(dc, 0, 1,
1455 g.getFontMetrics().getFontRenderContext());
1456 Font font = ofont.deriveFont(AffineTransform
1457 .getScaleInstance(wdth, scl / lm.getAscent()));
1459 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1461 // Debug - render boxes around characters
1462 // g.setColor(Color.red);
1463 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1465 // g.setColor(profcolour.findColour(dc[0]).darker());
1468 * Set character colour as per alignment colour scheme; use the
1469 * codon translation if a cDNA profile
1471 Color colour = null;
1474 final String codonTranslation = ResidueProperties
1475 .codonTranslate(new String(dc));
1476 colour = profcolour.findColour(codonTranslation.charAt(0),
1481 colour = profcolour.findColour(dc[0], column, null);
1483 g.setColor(colour == Color.white ? Color.lightGray : colour);
1485 hght = (ht + (scl - lm.getDescent()
1486 - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1488 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1496 if (_aa.threshold != null)
1498 g.setColor(_aa.threshold.colour);
1499 Graphics2D g2 = (Graphics2D) g;
1500 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1501 BasicStroke.JOIN_ROUND, 3f, new float[]
1505 - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1506 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1507 g2.setStroke(new BasicStroke());
1511 // used by overview window
1512 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1513 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1515 eRes = Math.min(eRes, aa_annotations.length);
1516 g.setColor(Color.white);
1517 g.fillRect(0, 0, width, y);
1518 g.setColor(new Color(0, 0, 180));
1522 for (int j = sRes; j < eRes; j++)
1524 if (aa_annotations[j] != null)
1526 if (aa_annotations[j].colour == null)
1528 g.setColor(Color.black);
1532 g.setColor(aa_annotations[j].colour);
1535 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1541 g.fillRect(x, y - height, charWidth, height);
1547 Color getNotCanonicalColor(char lastss)
1553 return new Color(255, 125, 5);
1557 return new Color(245, 115, 10);
1561 return new Color(235, 135, 15);
1565 return new Color(225, 105, 20);
1569 return new Color(215, 145, 30);
1573 return new Color(205, 95, 35);
1577 return new Color(195, 155, 45);
1581 return new Color(185, 85, 55);
1585 return new Color(175, 165, 65);
1589 return new Color(170, 75, 75);
1593 return new Color(160, 175, 85);
1597 return new Color(150, 65, 95);
1601 return new Color(140, 185, 105);
1605 return new Color(130, 55, 110);
1609 return new Color(120, 195, 120);
1613 return new Color(110, 45, 130);
1617 return new Color(100, 205, 140);
1621 return new Color(90, 35, 150);
1625 return new Color(85, 215, 160);
1629 return new Color(75, 25, 170);
1633 return new Color(65, 225, 180);
1637 return new Color(55, 15, 185);
1641 return new Color(45, 235, 195);
1645 return new Color(35, 5, 205);
1649 return new Color(25, 245, 215);
1653 return new Color(15, 0, 225);
1657 return new Color(10, 255, 235);
1661 return new Color(5, 150, 245);
1665 return new Color(0, 80, 255);
1668 System.out.println("This is not a interaction : " + lastss);