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.schemes.ColourSchemeI;
32 import jalview.schemes.ResidueProperties;
33 import jalview.util.Platform;
35 import java.awt.BasicStroke;
36 import java.awt.Color;
38 import java.awt.FontMetrics;
39 import java.awt.Graphics;
40 import java.awt.Graphics2D;
41 import java.awt.Image;
42 import java.awt.font.LineMetrics;
43 import java.awt.geom.AffineTransform;
44 import java.awt.image.ImageObserver;
45 import java.util.BitSet;
46 import java.util.Hashtable;
48 public class AnnotationRenderer
50 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
52 private static final int CHAR_A = 'A'; // 65
54 private static final int CHAR_Z = 'Z'; // 90
57 * flag indicating if timing and redraw parameter info should be output
59 private final boolean debugRedraw;
61 private int charWidth, endRes, charHeight;
63 private boolean validCharWidth, hasHiddenColumns;
65 private FontMetrics fm;
67 private final boolean MAC = Platform.isAMac();
69 boolean av_renderHistogram = true, av_renderProfile = true,
70 av_normaliseProfile = false;
72 ColourSchemeI profcolour = null;
74 private ColumnSelection columnSelection;
76 private Hashtable[] hconsensus;
78 private Hashtable[] complementConsensus;
80 private Hashtable[] hStrucConsensus;
82 private boolean av_ignoreGapsConsensus;
85 * attributes set from AwtRenderPanelI
88 * old image used when data is currently being calculated and cannot be
91 private Image fadedImage;
94 * panel being rendered into
96 private ImageObserver annotationPanel;
99 * width of image to render in panel
101 private int imgWidth;
104 * offset to beginning of visible area
109 * offset to end of visible area
111 private int visHeight;
114 * indicate if the renderer should only render the visible portion of the
115 * annotation given the current view settings
117 private boolean useClip = true;
120 * master flag indicating if renderer should ever try to clip. not enabled for
123 private boolean canClip = false;
125 public AnnotationRenderer()
131 * Create a new annotation Renderer
134 * flag indicating if timing and redraw parameter info should be
137 public AnnotationRenderer(boolean debugRedraw)
139 this.debugRedraw = debugRedraw;
143 * Remove any references and resources when this object is no longer required
145 public void dispose()
148 complementConsensus = null;
149 hStrucConsensus = null;
151 annotationPanel = null;
154 void drawStemAnnot(Graphics g, Annotation[] row_annotations,
155 int lastSSX, int x, int y, int iconOffset, int startRes,
156 int column, boolean validRes, boolean validEnd)
158 g.setColor(STEM_COLOUR);
159 int sCol = (lastSSX / charWidth) + startRes;
161 int x2 = (x * charWidth);
163 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
164 : row_annotations[column - 1].secondaryStructure;
166 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
167 || dc != row_annotations[sCol - 1].secondaryStructure;
168 boolean diffdownstream = !validRes || !validEnd
169 || row_annotations[column] == null
170 || dc != row_annotations[column].secondaryStructure;
172 if (column > 0 && Rna.isClosingParenthesis(dc))
175 // if (validRes && column>1 && row_annotations[column-2]!=null &&
176 // dc.equals(row_annotations[column-2].displayCharacter))
179 * if new annotation with a closing base pair half of the stem,
180 * display a backward arrow
182 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
183 new int[] { y + iconOffset, y + 14 + iconOffset,
184 y + 8 + iconOffset }, 3);
194 // display a forward arrow
198 * if annotation ending with an opeing base pair half of the stem,
199 * display a forward arrow
201 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
202 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
211 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
214 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
215 Annotation[] row_annotations, int lastSSX, int x, int y,
216 int iconOffset, int startRes, int column, boolean validRes,
219 // System.out.println(nonCanColor);
221 g.setColor(nonCanColor);
222 int sCol = (lastSSX / charWidth) + startRes;
224 int x2 = (x * charWidth);
226 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
227 : row_annotations[column - 1].displayCharacter;
229 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
230 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
231 boolean diffdownstream = !validRes || !validEnd
232 || row_annotations[column] == null
233 || !dc.equals(row_annotations[column].displayCharacter);
234 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
235 // If a closing base pair half of the stem, display a backward arrow
236 if (column > 0 && Rna.isClosingParenthesis(dc))
240 // if (validRes && column>1 && row_annotations[column-2]!=null &&
241 // dc.equals(row_annotations[column-2].displayCharacter))
243 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
244 new int[] { y + iconOffset, y + 14 + iconOffset,
245 y + 8 + iconOffset }, 3);
256 // display a forward arrow
259 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
260 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
269 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
272 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
274 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
277 fm = annotPanel.getFontMetrics();
278 annotationPanel = annotPanel;
279 fadedImage = annotPanel.getFadedImage();
280 imgWidth = annotPanel.getFadedImageWidth();
281 // visible area for rendering
282 int[] bounds = annotPanel.getVisibleVRange();
286 visHeight = bounds[1];
301 updateFromAlignViewport(av);
304 public void updateFromAlignViewport(AlignViewportI av)
306 charWidth = av.getCharWidth();
307 endRes = av.getEndRes();
308 charHeight = av.getCharHeight();
309 hasHiddenColumns = av.hasHiddenColumns();
310 validCharWidth = av.isValidCharWidth();
311 av_renderHistogram = av.isShowConsensusHistogram();
312 av_renderProfile = av.isShowSequenceLogo();
313 av_normaliseProfile = av.isNormaliseSequenceLogo();
314 profcolour = av.getGlobalColourScheme();
315 if (profcolour == null)
317 // Set the default colour for sequence logo if the alignnent has no
319 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
320 : new jalview.schemes.ZappoColourScheme();
322 columnSelection = av.getColumnSelection();
323 hconsensus = av.getSequenceConsensusHash();
324 complementConsensus = av.getComplementConsensusHash();
325 hStrucConsensus = av.getRnaStructureConsensusHash();
326 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
330 * Returns profile data; the first element is the profile type, the second is
331 * the number of distinct values, the third the total count, and the remainder
332 * depend on the profile type.
338 int[] getProfileFor(AlignmentAnnotation aa, int column)
340 // TODO : consider refactoring the global alignment calculation
341 // properties/rendering attributes as a global 'alignment group' which holds
342 // all vis settings for the alignment as a whole rather than a subset
344 if (aa.autoCalculated
345 && (aa.label.startsWith("Consensus") || aa.label
346 .startsWith("cDNA Consensus")))
348 boolean forComplement = aa.label.startsWith("cDNA Consensus");
349 if (aa.groupRef != null && aa.groupRef.consensusData != null
350 && aa.groupRef.isShowSequenceLogo())
352 // TODO? group consensus for cDNA complement
353 return AAFrequency.extractProfile(
354 aa.groupRef.consensusData[column],
355 aa.groupRef.getIgnoreGapsConsensus());
357 // TODO extend annotation row to enable dynamic and static profile data to
359 if (aa.groupRef == null && aa.sequenceRef == null)
363 return AAFrequency.extractCdnaProfile(
364 complementConsensus[column], av_ignoreGapsConsensus);
368 return AAFrequency.extractProfile(hconsensus[column],
369 av_ignoreGapsConsensus);
375 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
377 // TODO implement group structure consensus
379 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
380 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
381 * group selections return StructureFrequency.extractProfile(
382 * aa.groupRef.consensusData[column], aa.groupRef
383 * .getIgnoreGapsConsensus()); }
385 // TODO extend annotation row to enable dynamic and static profile data
388 if (aa.groupRef == null && aa.sequenceRef == null
389 && hStrucConsensus != null
390 && hStrucConsensus.length > column)
392 return StructureFrequency.extractProfile(hStrucConsensus[column],
393 av_ignoreGapsConsensus);
403 * Render the annotation rows associated with an alignment.
408 * data and view settings to render
410 * destination for graphics
412 * row where a mouse event occured (or -1)
414 * first column that will be drawn
416 * last column that will be drawn
417 * @return true if the fadedImage was used for any alignment annotation rows
418 * currently being calculated
420 public boolean drawComponent(AwtRenderPanelI annotPanel,
421 AlignViewportI av, Graphics g, int activeRow, int startRes,
424 long stime = System.currentTimeMillis();
425 boolean usedFaded = false;
427 // AnnotationPanel needs to implement: ImageObserver, access to
429 updateFromAwtRenderPanel(annotPanel, av);
430 fm = g.getFontMetrics();
431 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
442 boolean validRes = false;
443 boolean validEnd = false;
444 boolean labelAllCols = false;
445 boolean centreColLabels;
446 boolean centreColLabelsDef = av.isCentreColumnLabels();
447 boolean scaleColLabel = false;
448 final AlignmentAnnotation consensusAnnot = av
449 .getAlignmentConsensusAnnotation();
450 final AlignmentAnnotation structConsensusAnnot = av
451 .getAlignmentStrucConsensusAnnotation();
452 final AlignmentAnnotation complementConsensusAnnot = av
453 .getComplementConsensusAnnotation();
454 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
456 BitSet graphGroupDrawn = new BitSet();
457 int charOffset = 0; // offset for a label
458 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
460 Font ofont = g.getFont();
463 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
464 boolean clipst = false, clipend = false;
465 for (int i = 0; i < aa.length; i++)
467 AlignmentAnnotation row = aa[i];
470 // check if this is a consensus annotation row and set the display
471 // settings appropriately
472 // TODO: generalise this to have render styles for consensus/profile
474 if (row.groupRef != null && row == row.groupRef.getConsensus())
476 renderHistogram = row.groupRef.isShowConsensusHistogram();
477 renderProfile = row.groupRef.isShowSequenceLogo();
478 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
480 else if (row == consensusAnnot || row == structConsensusAnnot
481 || row == complementConsensusAnnot)
483 renderHistogram = av_renderHistogram;
484 renderProfile = av_renderProfile;
485 normaliseProfile = av_normaliseProfile;
489 renderHistogram = true;
490 // don't need to set render/normaliseProfile since they are not
491 // currently used in any other annotation track renderer
494 Annotation[] row_annotations = row.annotations;
499 centreColLabels = row.centreColLabels || centreColLabelsDef;
500 labelAllCols = row.showAllColLabels;
501 scaleColLabel = row.scaleColLabel;
506 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
507 {// if_in_visible_region
518 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
523 // this is so that we draw the characters below the graph
528 iconOffset = charHeight - fm.getDescent();
532 else if (row.hasText)
534 iconOffset = charHeight - fm.getDescent();
542 if (row.autoCalculated && av.isCalculationInProgress(row))
546 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
547 - row.height, imgWidth, y, annotationPanel);
548 g.setColor(Color.black);
549 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
555 * else if (annotationPanel.av.updatingConservation &&
556 * aa[i].label.equals("Conservation")) {
558 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
559 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
560 * annotationPanel.imgWidth, y, annotationPanel);
562 * g.setColor(Color.black); //
563 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
565 * continue; } else if (annotationPanel.av.updatingConservation &&
566 * aa[i].label.equals("Quality")) {
568 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
569 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
570 * annotationPanel.imgWidth, y, annotationPanel);
571 * g.setColor(Color.black); // /
572 * g.drawString("Calculating Quality....",20, y-row.height/2);
576 // first pass sets up state for drawing continuation from left-hand
579 x = (startRes == 0) ? 0 : -1;
580 while (x < endRes - startRes)
582 if (hasHiddenColumns)
584 column = columnSelection.adjustForHiddenColumns(startRes + x);
585 if (column > row_annotations.length - 1)
592 column = startRes + x;
595 if ((row_annotations == null)
596 || (row_annotations.length <= column)
597 || (row_annotations[column] == null))
605 final String displayChar = validRes ? row_annotations[column].displayCharacter
611 g.setColor(Color.red);
613 if (columnSelection != null)
615 if (columnSelection.contains(column))
617 g.fillRect(x * charWidth, y, charWidth, charHeight);
621 if (row.getInvalidStrucPos() > x)
623 g.setColor(Color.orange);
624 g.fillRect(x * charWidth, y, charWidth, charHeight);
626 else if (row.getInvalidStrucPos() == x)
628 g.setColor(Color.orange.darker());
629 g.fillRect(x * charWidth, y, charWidth, charHeight);
631 if (validCharWidth && validRes && displayChar != null
632 && (displayChar.length() > 0))
635 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
636 displayChar.length());
637 if (/* centreColLabels || */scaleColLabel)
639 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
640 // displayChar.length());
642 // if (scaleColLabel)
644 // justify the label and scale to fit in column
645 if (fmWidth > charWidth)
647 // scale only if the current font isn't already small enough
648 fmScaling = charWidth;
649 fmScaling /= fmWidth;
650 g.setFont(ofont.deriveFont(AffineTransform
651 .getScaleInstance(fmScaling, 1.0)));
652 // and update the label's width to reflect the scaling.
657 // TODO is it ok to use width of / show all characters here?
660 // fmWidth = fm.charWidth(displayChar.charAt(0));
662 charOffset = (int) ((charWidth - fmWidth) / 2f);
664 if (row_annotations[column].colour == null)
666 g.setColor(Color.black);
670 g.setColor(row_annotations[column].colour);
673 if (column == 0 || row.graph > 0)
675 g.drawString(displayChar, (x * charWidth) + charOffset, y
678 else if (row_annotations[column - 1] == null
681 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
682 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
684 g.drawString(displayChar, x * charWidth + charOffset, y
692 char ss = validRes ? row_annotations[column].secondaryStructure
697 // distinguish between forward/backward base-pairing
698 if (displayChar.indexOf(')') > -1)
707 if ((displayChar.indexOf(']') > -1))
715 // distinguish between forward/backward base-pairing
716 if (displayChar.indexOf('}') > -1)
724 // distinguish between forward/backward base-pairing
725 if (displayChar.indexOf('<') > -1)
731 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
733 // distinguish between forward/backward base-pairing
734 int ssLowerCase = ss + UPPER_TO_LOWER;
735 // TODO would .equals() be safer here? or charAt(0)?
736 if (displayChar.indexOf(ssLowerCase) > -1)
738 ss = (char) ssLowerCase;
742 if (!validRes || (ss != lastSS))
748 int nb_annot = x - temp;
749 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
752 case '(': // Stem case for RNA secondary structure
753 case ')': // and opposite direction
754 drawStemAnnot(g, row_annotations, lastSSX, x, y,
755 iconOffset, startRes, column, validRes, validEnd);
762 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
763 iconOffset, startRes, column, validRes,
767 // no break if isRNA - falls through to drawNotCanonicalAnnot!
771 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
772 iconOffset, startRes, column, validRes,
776 // no break if isRNA - fall through to drawNotCanonicalAnnot!
835 Color nonCanColor = getNotCanonicalColor(lastSS);
836 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
837 lastSSX, x, y, iconOffset, startRes, column,
842 g.setColor(Color.gray);
843 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
859 lastSSX = (x * charWidth);
866 if (column >= row_annotations.length)
868 column = row_annotations.length - 1;
875 if ((row_annotations == null) || (row_annotations.length <= column)
876 || (row_annotations[column] == null))
894 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
895 startRes, column, validRes, validEnd);
898 // no break if isRNA - fall through to drawNotCanonicalAnnot!
903 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
904 startRes, column, validRes, validEnd);
907 // no break if isRNA - fall through to drawNotCanonicalAnnot!
910 case ')': // Stem case for RNA secondary structure
912 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
913 startRes, column, validRes, validEnd);
970 // System.out.println(lastSS);
971 Color nonCanColor = getNotCanonicalColor(lastSS);
972 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
973 x, y, iconOffset, startRes, column, validRes, validEnd);
976 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
977 startRes, column, validRes, validEnd);
982 if (row.graph > 0 && row.graphHeight > 0)
984 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
986 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
988 // TODO: JAL-1291 revise rendering model so the graphGroup map is
989 // computed efficiently for all visible labels
990 float groupmax = -999999, groupmin = 9999999;
991 for (int gg = 0; gg < aa.length; gg++)
993 if (aa[gg].graphGroup != row.graphGroup)
1000 aa[gg].visible = false;
1002 if (aa[gg].graphMax > groupmax)
1004 groupmax = aa[gg].graphMax;
1006 if (aa[gg].graphMin < groupmin)
1008 groupmin = aa[gg].graphMin;
1012 for (int gg = 0; gg < aa.length; gg++)
1014 if (aa[gg].graphGroup == row.graphGroup)
1016 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1017 endRes, y, groupmin, groupmax, row.graphHeight);
1021 graphGroupDrawn.set(row.graphGroup);
1025 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1026 row.graphMin, row.graphMax, row.graphHeight);
1029 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1031 drawBarGraph(g, row, row_annotations, startRes, endRes,
1032 row.graphMin, row.graphMax, y, renderHistogram,
1033 renderProfile, normaliseProfile);
1039 if (clipst && !clipend)
1043 }// end if_in_visible_region
1044 if (row.graph > 0 && row.hasText)
1060 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1065 System.err.println("End clip at : " + yto + " (index " + f_to
1070 System.err.println("Annotation Rendering time:"
1071 + (System.currentTimeMillis() - stime));
1078 public static final Color GLYPHLINE_COLOR = Color.gray;
1080 public static final Color SHEET_COLOUR = Color.green;
1082 public static final Color HELIX_COLOUR = Color.red;
1084 public static final Color STEM_COLOUR = Color.blue;
1086 private Color sdNOTCANONICAL_COLOUR;
1088 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1089 int x, int y, int iconOffset, int startRes, int column,
1090 boolean validRes, boolean validEnd)
1092 g.setColor(GLYPHLINE_COLOR);
1093 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1096 void drawSheetAnnot(Graphics g, Annotation[] row,
1098 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1099 boolean validRes, boolean validEnd)
1101 g.setColor(SHEET_COLOUR);
1103 if (!validEnd || !validRes || row == null || row[column] == null
1104 || row[column].secondaryStructure != 'E')
1106 g.fillRect(lastSSX, y + 4 + iconOffset,
1107 (x * charWidth) - lastSSX - 4, 7);
1108 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1109 (x * charWidth) }, new int[] { y + iconOffset,
1110 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1114 g.fillRect(lastSSX, y + 4 + iconOffset,
1115 (x + 1) * charWidth - lastSSX, 7);
1120 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1121 int x, int y, int iconOffset, int startRes, int column,
1122 boolean validRes, boolean validEnd)
1124 g.setColor(HELIX_COLOUR);
1126 int sCol = (lastSSX / charWidth) + startRes;
1128 int x2 = (x * charWidth);
1132 int ofs = charWidth / 2;
1133 // Off by 1 offset when drawing rects and ovals
1134 // to offscreen image on the MAC
1135 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1136 if (sCol == 0 || row[sCol - 1] == null
1137 || row[sCol - 1].secondaryStructure != 'H')
1142 // g.setColor(Color.orange);
1143 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1146 if (!validRes || row[column] == null
1147 || row[column].secondaryStructure != 'H')
1153 // g.setColor(Color.magenta);
1154 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1162 if (sCol == 0 || row[sCol - 1] == null
1163 || row[sCol - 1].secondaryStructure != 'H')
1165 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1166 x1 += charWidth / 2;
1169 if (!validRes || row[column] == null
1170 || row[column].secondaryStructure != 'H')
1172 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1174 x2 -= charWidth / 2;
1177 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1180 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1181 Annotation[] aa_annotations, int sRes, int eRes, int y,
1182 float min, float max, int graphHeight)
1184 if (sRes > aa_annotations.length)
1191 // Adjustment for fastpaint to left
1197 eRes = Math.min(eRes, aa_annotations.length);
1205 float range = max - min;
1210 y2 = y - (int) ((0 - min / range) * graphHeight);
1213 g.setColor(Color.gray);
1214 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1216 eRes = Math.min(eRes, aa_annotations.length);
1219 int aaMax = aa_annotations.length - 1;
1221 while (x < eRes - sRes)
1224 if (hasHiddenColumns)
1226 column = columnSelection.adjustForHiddenColumns(column);
1234 if (aa_annotations[column] == null
1235 || aa_annotations[column - 1] == null)
1241 if (aa_annotations[column].colour == null)
1243 g.setColor(Color.black);
1247 g.setColor(aa_annotations[column].colour);
1251 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1253 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1255 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1256 + charWidth / 2, y2);
1260 if (_aa.threshold != null)
1262 g.setColor(_aa.threshold.colour);
1263 Graphics2D g2 = (Graphics2D) g;
1264 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1265 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1267 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1268 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1269 g2.setStroke(new BasicStroke());
1273 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1274 Annotation[] aa_annotations, int sRes, int eRes, float min,
1275 float max, int y, boolean renderHistogram, boolean renderProfile,
1276 boolean normaliseProfile)
1278 if (sRes > aa_annotations.length)
1282 Font ofont = g.getFont();
1283 eRes = Math.min(eRes, aa_annotations.length);
1285 int x = 0, y1 = y, y2 = y;
1287 float range = max - min;
1291 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1294 g.setColor(Color.gray);
1296 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1299 int aaMax = aa_annotations.length - 1;
1300 while (x < eRes - sRes)
1303 if (hasHiddenColumns)
1305 column = columnSelection.adjustForHiddenColumns(column);
1313 if (aa_annotations[column] == null)
1318 if (aa_annotations[column].colour == null)
1320 g.setColor(Color.black);
1324 g.setColor(aa_annotations[column].colour);
1328 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1330 if (renderHistogram)
1334 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1338 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1341 // draw profile if available
1346 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1348 int profl[] = getProfileFor(_aa, column);
1350 // just try to draw the logo if profl is not null
1351 if (profl != null && profl[2] != 0)
1353 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1354 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1355 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1356 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1363 * Render a single base for a sequence profile, a base pair for
1364 * structure profile, and a triplet for a cdna profile
1366 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1368 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1369 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1370 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1374 * Traverse the character(s)/percentage data in the array
1377 int valuesProcessed = 0;
1378 // profl[1] is the number of values in the profile
1379 while (valuesProcessed < profl[1])
1381 if (isStructureProfile)
1383 // todo can we encode a structure pair as an int, like codons?
1384 dc[0] = (char) profl[c++];
1385 dc[1] = (char) profl[c++];
1387 else if (isCdnaProfile)
1389 dc = CodingUtils.decodeCodon(profl[c++]);
1393 dc[0] = (char) profl[c++];
1397 wdth /= fm.charsWidth(dc, 0, dc.length);
1400 // next profl[] position is profile % for the character(s)
1401 scl = htn * scale * profl[c++];
1402 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1403 .getFontRenderContext());
1404 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1405 wdth, scl / lm.getAscent()));
1407 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1409 // Debug - render boxes around characters
1410 // g.setColor(Color.red);
1411 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1413 // g.setColor(profcolour.findColour(dc[0]).darker());
1416 * Set character colour as per alignment colour scheme; use the
1417 * codon translation if a cDNA profile
1419 Color colour = null;
1422 final String codonTranslation = ResidueProperties
1423 .codonTranslate(new String(dc));
1424 colour = profcolour.findColour(codonTranslation.charAt(0),
1429 colour = profcolour.findColour(dc[0], column, null);
1431 g.setColor(colour == Color.white ? Color.lightGray : colour);
1433 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1434 .getBaselineIndex()]));
1436 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1444 if (_aa.threshold != null)
1446 g.setColor(_aa.threshold.colour);
1447 Graphics2D g2 = (Graphics2D) g;
1448 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1449 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1451 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1453 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1454 g2.setStroke(new BasicStroke());
1458 // used by overview window
1459 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1460 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1462 eRes = Math.min(eRes, aa_annotations.length);
1463 g.setColor(Color.white);
1464 g.fillRect(0, 0, width, y);
1465 g.setColor(new Color(0, 0, 180));
1469 for (int j = sRes; j < eRes; j++)
1471 if (aa_annotations[j] != null)
1473 if (aa_annotations[j].colour == null)
1475 g.setColor(Color.black);
1479 g.setColor(aa_annotations[j].colour);
1482 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1488 g.fillRect(x, y - height, charWidth, height);
1494 Color getNotCanonicalColor(char lastss)
1500 return new Color(255, 125, 5);
1504 return new Color(245, 115, 10);
1508 return new Color(235, 135, 15);
1512 return new Color(225, 105, 20);
1516 return new Color(215, 145, 30);
1520 return new Color(205, 95, 35);
1524 return new Color(195, 155, 45);
1528 return new Color(185, 85, 55);
1532 return new Color(175, 165, 65);
1536 return new Color(170, 75, 75);
1540 return new Color(160, 175, 85);
1544 return new Color(150, 65, 95);
1548 return new Color(140, 185, 105);
1552 return new Color(130, 55, 110);
1556 return new Color(120, 195, 120);
1560 return new Color(110, 45, 130);
1564 return new Color(100, 205, 140);
1568 return new Color(90, 35, 150);
1572 return new Color(85, 215, 160);
1576 return new Color(75, 25, 170);
1580 return new Color(65, 225, 180);
1584 return new Color(55, 15, 185);
1588 return new Color(45, 235, 195);
1592 return new Color(35, 5, 205);
1596 return new Color(25, 245, 215);
1600 return new Color(15, 0, 225);
1604 return new Color(10, 255, 235);
1608 return new Color(5, 150, 245);
1612 return new Color(0, 80, 255);
1615 System.out.println("This is not a interaction : " + lastss);