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.ProfilesI;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ResidueProperties;
34 import jalview.util.Platform;
36 import java.awt.BasicStroke;
37 import java.awt.Color;
39 import java.awt.FontMetrics;
40 import java.awt.Graphics;
41 import java.awt.Graphics2D;
42 import java.awt.Image;
43 import java.awt.font.LineMetrics;
44 import java.awt.geom.AffineTransform;
45 import java.awt.image.ImageObserver;
46 import java.util.BitSet;
47 import java.util.Hashtable;
49 public class AnnotationRenderer
51 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
53 private static final int CHAR_A = 'A'; // 65
55 private static final int CHAR_Z = 'Z'; // 90
58 * flag indicating if timing and redraw parameter info should be output
60 private final boolean debugRedraw;
62 private int charWidth, endRes, charHeight;
64 private boolean validCharWidth, hasHiddenColumns;
66 private FontMetrics fm;
68 private final boolean MAC = Platform.isAMac();
70 boolean av_renderHistogram = true, av_renderProfile = true,
71 av_normaliseProfile = false;
73 ColourSchemeI profcolour = null;
75 private ColumnSelection columnSelection;
77 private ProfilesI hconsensus;
79 private Hashtable[] complementConsensus;
81 private Hashtable[] hStrucConsensus;
83 private boolean av_ignoreGapsConsensus;
86 * attributes set from AwtRenderPanelI
89 * old image used when data is currently being calculated and cannot be
92 private Image fadedImage;
95 * panel being rendered into
97 private ImageObserver annotationPanel;
100 * width of image to render in panel
102 private int imgWidth;
105 * offset to beginning of visible area
110 * offset to end of visible area
112 private int visHeight;
115 * indicate if the renderer should only render the visible portion of the
116 * annotation given the current view settings
118 private boolean useClip = true;
121 * master flag indicating if renderer should ever try to clip. not enabled for
124 private boolean canClip = false;
126 public AnnotationRenderer()
132 * Create a new annotation Renderer
135 * flag indicating if timing and redraw parameter info should be
138 public AnnotationRenderer(boolean debugRedraw)
140 this.debugRedraw = debugRedraw;
144 * Remove any references and resources when this object is no longer required
146 public void dispose()
149 complementConsensus = null;
150 hStrucConsensus = null;
152 annotationPanel = null;
155 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
156 int x, int y, int iconOffset, int startRes, int column,
157 boolean validRes, boolean validEnd)
159 g.setColor(STEM_COLOUR);
160 int sCol = (lastSSX / charWidth) + startRes;
162 int x2 = (x * charWidth);
164 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
165 : row_annotations[column - 1].secondaryStructure;
167 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
168 || dc != row_annotations[sCol - 1].secondaryStructure;
169 boolean diffdownstream = !validRes || !validEnd
170 || row_annotations[column] == null
171 || dc != row_annotations[column].secondaryStructure;
173 if (column > 0 && Rna.isClosingParenthesis(dc))
176 // if (validRes && column>1 && row_annotations[column-2]!=null &&
177 // dc.equals(row_annotations[column-2].displayCharacter))
180 * if new annotation with a closing base pair half of the stem,
181 * display a backward arrow
183 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
184 new int[] { y + iconOffset, y + 14 + iconOffset,
185 y + 8 + iconOffset }, 3);
195 // display a forward arrow
199 * if annotation ending with an opeing base pair half of the stem,
200 * display a forward arrow
202 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
203 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
212 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
215 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
216 Annotation[] row_annotations, int lastSSX, int x, int y,
217 int iconOffset, int startRes, int column, boolean validRes,
220 // System.out.println(nonCanColor);
222 g.setColor(nonCanColor);
223 int sCol = (lastSSX / charWidth) + startRes;
225 int x2 = (x * charWidth);
227 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
228 : row_annotations[column - 1].displayCharacter;
230 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
231 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
232 boolean diffdownstream = !validRes || !validEnd
233 || row_annotations[column] == null
234 || !dc.equals(row_annotations[column].displayCharacter);
235 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
236 // If a closing base pair half of the stem, display a backward arrow
237 if (column > 0 && Rna.isClosingParenthesis(dc))
241 // if (validRes && column>1 && row_annotations[column-2]!=null &&
242 // dc.equals(row_annotations[column-2].displayCharacter))
244 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
245 new int[] { y + iconOffset, y + 14 + iconOffset,
246 y + 8 + iconOffset }, 3);
257 // display a forward arrow
260 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
261 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
270 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
273 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
275 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
278 fm = annotPanel.getFontMetrics();
279 annotationPanel = annotPanel;
280 fadedImage = annotPanel.getFadedImage();
281 imgWidth = annotPanel.getFadedImageWidth();
282 // visible area for rendering
283 int[] bounds = annotPanel.getVisibleVRange();
287 visHeight = bounds[1];
302 updateFromAlignViewport(av);
305 public void updateFromAlignViewport(AlignViewportI av)
307 charWidth = av.getCharWidth();
308 endRes = av.getEndRes();
309 charHeight = av.getCharHeight();
310 hasHiddenColumns = av.hasHiddenColumns();
311 validCharWidth = av.isValidCharWidth();
312 av_renderHistogram = av.isShowConsensusHistogram();
313 av_renderProfile = av.isShowSequenceLogo();
314 av_normaliseProfile = av.isNormaliseSequenceLogo();
315 profcolour = av.getGlobalColourScheme();
316 if (profcolour == null)
318 // Set the default colour for sequence logo if the alignnent has no
320 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
321 : new jalview.schemes.ZappoColourScheme();
323 columnSelection = av.getColumnSelection();
324 hconsensus = av.getSequenceConsensusHash();
325 complementConsensus = av.getComplementConsensusHash();
326 hStrucConsensus = av.getRnaStructureConsensusHash();
327 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
331 * Returns profile data; the first element is the profile type, the second is
332 * the number of distinct values, the third the total count, and the remainder
333 * depend on the profile type.
339 int[] getProfileFor(AlignmentAnnotation aa, int column)
341 // TODO : consider refactoring the global alignment calculation
342 // properties/rendering attributes as a global 'alignment group' which holds
343 // all vis settings for the alignment as a whole rather than a subset
345 if (aa.autoCalculated
346 && (aa.label.startsWith("Consensus") || aa.label
347 .startsWith("cDNA Consensus")))
349 boolean forComplement = aa.label.startsWith("cDNA Consensus");
350 if (aa.groupRef != null && aa.groupRef.consensusData != null
351 && aa.groupRef.isShowSequenceLogo())
353 // TODO? group consensus for cDNA complement
354 return AAFrequency.extractProfile(
355 aa.groupRef.consensusData.get(column),
356 aa.groupRef.getIgnoreGapsConsensus());
358 // TODO extend annotation row to enable dynamic and static profile data to
360 if (aa.groupRef == null && aa.sequenceRef == null)
364 return AAFrequency.extractCdnaProfile(
365 complementConsensus[column], av_ignoreGapsConsensus);
369 return AAFrequency.extractProfile(hconsensus.get(column),
370 av_ignoreGapsConsensus);
376 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
378 // TODO implement group structure consensus
380 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
381 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
382 * group selections return StructureFrequency.extractProfile(
383 * aa.groupRef.consensusData[column], aa.groupRef
384 * .getIgnoreGapsConsensus()); }
386 // TODO extend annotation row to enable dynamic and static profile data
389 if (aa.groupRef == null && aa.sequenceRef == null
390 && hStrucConsensus != null
391 && hStrucConsensus.length > column)
393 return StructureFrequency.extractProfile(hStrucConsensus[column],
394 av_ignoreGapsConsensus);
404 * Render the annotation rows associated with an alignment.
409 * data and view settings to render
411 * destination for graphics
413 * row where a mouse event occured (or -1)
415 * first column that will be drawn
417 * last column that will be drawn
418 * @return true if the fadedImage was used for any alignment annotation rows
419 * currently being calculated
421 public boolean drawComponent(AwtRenderPanelI annotPanel,
422 AlignViewportI av, Graphics g, int activeRow, int startRes,
425 long stime = System.currentTimeMillis();
426 boolean usedFaded = false;
428 // AnnotationPanel needs to implement: ImageObserver, access to
430 updateFromAwtRenderPanel(annotPanel, av);
431 fm = g.getFontMetrics();
432 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
443 boolean validRes = false;
444 boolean validEnd = false;
445 boolean labelAllCols = false;
446 boolean centreColLabels;
447 boolean centreColLabelsDef = av.isCentreColumnLabels();
448 boolean scaleColLabel = false;
449 final AlignmentAnnotation consensusAnnot = av
450 .getAlignmentConsensusAnnotation();
451 final AlignmentAnnotation structConsensusAnnot = av
452 .getAlignmentStrucConsensusAnnotation();
453 final AlignmentAnnotation complementConsensusAnnot = av
454 .getComplementConsensusAnnotation();
455 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
457 BitSet graphGroupDrawn = new BitSet();
458 int charOffset = 0; // offset for a label
459 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
461 Font ofont = g.getFont();
464 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
465 boolean clipst = false, clipend = false;
466 for (int i = 0; i < aa.length; i++)
468 AlignmentAnnotation row = aa[i];
471 // check if this is a consensus annotation row and set the display
472 // settings appropriately
473 // TODO: generalise this to have render styles for consensus/profile
475 if (row.groupRef != null && row == row.groupRef.getConsensus())
477 renderHistogram = row.groupRef.isShowConsensusHistogram();
478 renderProfile = row.groupRef.isShowSequenceLogo();
479 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
481 else if (row == consensusAnnot || row == structConsensusAnnot
482 || row == complementConsensusAnnot)
484 renderHistogram = av_renderHistogram;
485 renderProfile = av_renderProfile;
486 normaliseProfile = av_normaliseProfile;
490 renderHistogram = true;
491 // don't need to set render/normaliseProfile since they are not
492 // currently used in any other annotation track renderer
495 Annotation[] row_annotations = row.annotations;
500 centreColLabels = row.centreColLabels || centreColLabelsDef;
501 labelAllCols = row.showAllColLabels;
502 scaleColLabel = row.scaleColLabel;
507 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
508 {// if_in_visible_region
519 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
524 // this is so that we draw the characters below the graph
529 iconOffset = charHeight - fm.getDescent();
533 else if (row.hasText)
535 iconOffset = charHeight - fm.getDescent();
543 if (row.autoCalculated && av.isCalculationInProgress(row))
547 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
548 - row.height, imgWidth, y, annotationPanel);
549 g.setColor(Color.black);
550 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
556 * else if (annotationPanel.av.updatingConservation &&
557 * aa[i].label.equals("Conservation")) {
559 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
560 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
561 * annotationPanel.imgWidth, y, annotationPanel);
563 * g.setColor(Color.black); //
564 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
566 * continue; } else if (annotationPanel.av.updatingConservation &&
567 * aa[i].label.equals("Quality")) {
569 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
570 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
571 * annotationPanel.imgWidth, y, annotationPanel);
572 * g.setColor(Color.black); // /
573 * g.drawString("Calculating Quality....",20, y-row.height/2);
577 // first pass sets up state for drawing continuation from left-hand
580 x = (startRes == 0) ? 0 : -1;
581 while (x < endRes - startRes)
583 if (hasHiddenColumns)
585 column = columnSelection.adjustForHiddenColumns(startRes + x);
586 if (column > row_annotations.length - 1)
593 column = startRes + x;
596 if ((row_annotations == null)
597 || (row_annotations.length <= column)
598 || (row_annotations[column] == null))
606 final String displayChar = validRes ? row_annotations[column].displayCharacter
612 g.setColor(Color.red);
614 if (columnSelection != null)
616 if (columnSelection.contains(column))
618 g.fillRect(x * charWidth, y, charWidth, charHeight);
622 if (row.getInvalidStrucPos() > x)
624 g.setColor(Color.orange);
625 g.fillRect(x * charWidth, y, charWidth, charHeight);
627 else if (row.getInvalidStrucPos() == x)
629 g.setColor(Color.orange.darker());
630 g.fillRect(x * charWidth, y, charWidth, charHeight);
632 if (validCharWidth && validRes && displayChar != null
633 && (displayChar.length() > 0))
636 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
637 displayChar.length());
638 if (/* centreColLabels || */scaleColLabel)
640 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
641 // displayChar.length());
643 // if (scaleColLabel)
645 // justify the label and scale to fit in column
646 if (fmWidth > charWidth)
648 // scale only if the current font isn't already small enough
649 fmScaling = charWidth;
650 fmScaling /= fmWidth;
651 g.setFont(ofont.deriveFont(AffineTransform
652 .getScaleInstance(fmScaling, 1.0)));
653 // and update the label's width to reflect the scaling.
658 // TODO is it ok to use width of / show all characters here?
661 // fmWidth = fm.charWidth(displayChar.charAt(0));
663 charOffset = (int) ((charWidth - fmWidth) / 2f);
665 if (row_annotations[column].colour == null)
667 g.setColor(Color.black);
671 g.setColor(row_annotations[column].colour);
674 if (column == 0 || row.graph > 0)
676 g.drawString(displayChar, (x * charWidth) + charOffset, y
679 else if (row_annotations[column - 1] == null
682 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
683 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
685 g.drawString(displayChar, x * charWidth + charOffset, y
693 char ss = validRes ? row_annotations[column].secondaryStructure
698 // distinguish between forward/backward base-pairing
699 if (displayChar.indexOf(')') > -1)
708 if ((displayChar.indexOf(']') > -1))
716 // distinguish between forward/backward base-pairing
717 if (displayChar.indexOf('}') > -1)
725 // distinguish between forward/backward base-pairing
726 if (displayChar.indexOf('<') > -1)
732 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
734 // distinguish between forward/backward base-pairing
735 int ssLowerCase = ss + UPPER_TO_LOWER;
736 // TODO would .equals() be safer here? or charAt(0)?
737 if (displayChar.indexOf(ssLowerCase) > -1)
739 ss = (char) ssLowerCase;
743 if (!validRes || (ss != lastSS))
749 int nb_annot = x - temp;
750 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
753 case '(': // Stem case for RNA secondary structure
754 case ')': // and opposite direction
755 drawStemAnnot(g, row_annotations, lastSSX, x, y,
756 iconOffset, startRes, column, validRes, validEnd);
763 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
764 iconOffset, startRes, column, validRes,
768 // no break if isRNA - falls through to drawNotCanonicalAnnot!
772 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
773 iconOffset, startRes, column, validRes,
777 // no break if isRNA - fall through to drawNotCanonicalAnnot!
836 Color nonCanColor = getNotCanonicalColor(lastSS);
837 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
838 lastSSX, x, y, iconOffset, startRes, column,
843 g.setColor(Color.gray);
844 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
860 lastSSX = (x * charWidth);
867 if (column >= row_annotations.length)
869 column = row_annotations.length - 1;
876 if ((row_annotations == null) || (row_annotations.length <= column)
877 || (row_annotations[column] == null))
895 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
896 startRes, column, validRes, validEnd);
899 // no break if isRNA - fall through to drawNotCanonicalAnnot!
904 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
905 startRes, column, validRes, validEnd);
908 // no break if isRNA - fall through to drawNotCanonicalAnnot!
911 case ')': // Stem case for RNA secondary structure
913 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
914 startRes, column, validRes, validEnd);
971 // System.out.println(lastSS);
972 Color nonCanColor = getNotCanonicalColor(lastSS);
973 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
974 x, y, iconOffset, startRes, column, validRes, validEnd);
977 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
978 startRes, column, validRes, validEnd);
983 if (row.graph > 0 && row.graphHeight > 0)
985 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
987 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
989 // TODO: JAL-1291 revise rendering model so the graphGroup map is
990 // computed efficiently for all visible labels
991 float groupmax = -999999, groupmin = 9999999;
992 for (int gg = 0; gg < aa.length; gg++)
994 if (aa[gg].graphGroup != row.graphGroup)
1001 aa[gg].visible = false;
1003 if (aa[gg].graphMax > groupmax)
1005 groupmax = aa[gg].graphMax;
1007 if (aa[gg].graphMin < groupmin)
1009 groupmin = aa[gg].graphMin;
1013 for (int gg = 0; gg < aa.length; gg++)
1015 if (aa[gg].graphGroup == row.graphGroup)
1017 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1018 endRes, y, groupmin, groupmax, row.graphHeight);
1022 graphGroupDrawn.set(row.graphGroup);
1026 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1027 row.graphMin, row.graphMax, row.graphHeight);
1030 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1032 if (row.autoCalculated && row.label != null
1033 && row.label.startsWith("Consen"))
1035 drawProfileDensity(g, row, row_annotations, startRes, endRes,
1036 row.graphMin, row.graphMax, y);
1040 drawBarGraph(g, row, row_annotations, startRes, endRes,
1041 row.graphMin, row.graphMax, y, renderHistogram,
1042 renderProfile, normaliseProfile);
1049 if (clipst && !clipend)
1053 }// end if_in_visible_region
1054 if (row.graph > 0 && row.hasText)
1070 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1075 System.err.println("End clip at : " + yto + " (index " + f_to
1080 System.err.println("Annotation Rendering time:"
1081 + (System.currentTimeMillis() - stime));
1088 public static final Color GLYPHLINE_COLOR = Color.gray;
1090 public static final Color SHEET_COLOUR = Color.green;
1092 public static final Color HELIX_COLOUR = Color.red;
1094 public static final Color STEM_COLOUR = Color.blue;
1096 private Color sdNOTCANONICAL_COLOUR;
1098 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1099 int y, int iconOffset, int startRes, int column,
1100 boolean validRes, boolean validEnd)
1102 g.setColor(GLYPHLINE_COLOR);
1103 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1106 void drawSheetAnnot(Graphics g, Annotation[] row,
1108 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1109 boolean validRes, boolean validEnd)
1111 g.setColor(SHEET_COLOUR);
1113 if (!validEnd || !validRes || row == null || row[column] == null
1114 || row[column].secondaryStructure != 'E')
1116 g.fillRect(lastSSX, y + 4 + iconOffset,
1117 (x * charWidth) - lastSSX - 4, 7);
1118 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1119 (x * charWidth) }, new int[] { y + iconOffset,
1120 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1124 g.fillRect(lastSSX, y + 4 + iconOffset,
1125 (x + 1) * charWidth - lastSSX, 7);
1130 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1131 int y, int iconOffset, int startRes, int column,
1132 boolean validRes, boolean validEnd)
1134 g.setColor(HELIX_COLOUR);
1136 int sCol = (lastSSX / charWidth) + startRes;
1138 int x2 = (x * charWidth);
1142 int ofs = charWidth / 2;
1143 // Off by 1 offset when drawing rects and ovals
1144 // to offscreen image on the MAC
1145 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1146 if (sCol == 0 || row[sCol - 1] == null
1147 || row[sCol - 1].secondaryStructure != 'H')
1152 // g.setColor(Color.orange);
1153 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1156 if (!validRes || row[column] == null
1157 || row[column].secondaryStructure != 'H')
1163 // g.setColor(Color.magenta);
1164 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1172 if (sCol == 0 || row[sCol - 1] == null
1173 || row[sCol - 1].secondaryStructure != 'H')
1175 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1176 x1 += charWidth / 2;
1179 if (!validRes || row[column] == null
1180 || row[column].secondaryStructure != 'H')
1182 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1184 x2 -= charWidth / 2;
1187 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1190 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1191 Annotation[] aa_annotations, int sRes, int eRes, int y,
1192 float min, float max, int graphHeight)
1194 if (sRes > aa_annotations.length)
1201 // Adjustment for fastpaint to left
1207 eRes = Math.min(eRes, aa_annotations.length);
1215 float range = max - min;
1220 y2 = y - (int) ((0 - min / range) * graphHeight);
1223 g.setColor(Color.gray);
1224 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1226 eRes = Math.min(eRes, aa_annotations.length);
1229 int aaMax = aa_annotations.length - 1;
1231 while (x < eRes - sRes)
1234 if (hasHiddenColumns)
1236 column = columnSelection.adjustForHiddenColumns(column);
1244 if (aa_annotations[column] == null
1245 || aa_annotations[column - 1] == null)
1251 if (aa_annotations[column].colour == null)
1253 g.setColor(Color.black);
1257 g.setColor(aa_annotations[column].colour);
1261 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1263 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1265 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1266 + charWidth / 2, y2);
1270 if (_aa.threshold != null)
1272 g.setColor(_aa.threshold.colour);
1273 Graphics2D g2 = (Graphics2D) g;
1274 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1275 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1277 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1278 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1279 g2.setStroke(new BasicStroke());
1283 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1284 Annotation[] aa_annotations, int sRes, int eRes, float min,
1285 float max, int y, boolean renderHistogram, boolean renderProfile,
1286 boolean normaliseProfile)
1288 if (sRes > aa_annotations.length)
1292 Font ofont = g.getFont();
1293 eRes = Math.min(eRes, aa_annotations.length);
1295 int x = 0, y1 = y, y2 = y;
1297 float range = max - min;
1301 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1304 g.setColor(Color.gray);
1306 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1309 int aaMax = aa_annotations.length - 1;
1310 while (x < eRes - sRes)
1313 if (hasHiddenColumns)
1315 column = columnSelection.adjustForHiddenColumns(column);
1323 if (aa_annotations[column] == null)
1328 if (aa_annotations[column].colour == null)
1330 g.setColor(Color.black);
1334 g.setColor(aa_annotations[column].colour);
1338 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1340 if (renderHistogram)
1344 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1348 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1351 // draw profile if available
1356 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1358 int profl[] = getProfileFor(_aa, column);
1360 // just try to draw the logo if profl is not null
1361 if (profl != null && profl[2] != 0)
1363 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1364 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1365 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1366 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1373 * Render a single base for a sequence profile, a base pair for
1374 * structure profile, and a triplet for a cdna profile
1376 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1378 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1379 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1380 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1384 * Traverse the character(s)/percentage data in the array
1387 int valuesProcessed = 0;
1388 // profl[1] is the number of values in the profile
1389 while (valuesProcessed < profl[1])
1391 if (isStructureProfile)
1393 // todo can we encode a structure pair as an int, like codons?
1394 dc[0] = (char) profl[c++];
1395 dc[1] = (char) profl[c++];
1397 else if (isCdnaProfile)
1399 dc = CodingUtils.decodeCodon(profl[c++]);
1403 dc[0] = (char) profl[c++];
1407 wdth /= fm.charsWidth(dc, 0, dc.length);
1410 // next profl[] position is profile % for the character(s)
1411 scl = htn * scale * profl[c++];
1412 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1413 .getFontRenderContext());
1414 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1415 wdth, scl / lm.getAscent()));
1417 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1419 // Debug - render boxes around characters
1420 // g.setColor(Color.red);
1421 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1423 // g.setColor(profcolour.findColour(dc[0]).darker());
1426 * Set character colour as per alignment colour scheme; use the
1427 * codon translation if a cDNA profile
1429 Color colour = null;
1432 final String codonTranslation = ResidueProperties
1433 .codonTranslate(new String(dc));
1434 colour = profcolour.findColour(codonTranslation.charAt(0),
1439 colour = profcolour.findColour(dc[0], column, null);
1441 g.setColor(colour == Color.white ? Color.lightGray : colour);
1443 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1444 .getBaselineIndex()]));
1446 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1454 if (_aa.threshold != null)
1456 g.setColor(_aa.threshold.colour);
1457 Graphics2D g2 = (Graphics2D) g;
1458 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1459 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1461 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1463 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1464 g2.setStroke(new BasicStroke());
1468 // used by overview window
1469 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1470 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1472 eRes = Math.min(eRes, aa_annotations.length);
1473 g.setColor(Color.white);
1474 g.fillRect(0, 0, width, y);
1475 g.setColor(new Color(0, 0, 180));
1479 for (int j = sRes; j < eRes; j++)
1481 if (aa_annotations[j] != null)
1483 if (aa_annotations[j].colour == null)
1485 g.setColor(Color.black);
1489 g.setColor(aa_annotations[j].colour);
1492 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1498 g.fillRect(x, y - height, charWidth, height);
1504 Color getNotCanonicalColor(char lastss)
1510 return new Color(255, 125, 5);
1514 return new Color(245, 115, 10);
1518 return new Color(235, 135, 15);
1522 return new Color(225, 105, 20);
1526 return new Color(215, 145, 30);
1530 return new Color(205, 95, 35);
1534 return new Color(195, 155, 45);
1538 return new Color(185, 85, 55);
1542 return new Color(175, 165, 65);
1546 return new Color(170, 75, 75);
1550 return new Color(160, 175, 85);
1554 return new Color(150, 65, 95);
1558 return new Color(140, 185, 105);
1562 return new Color(130, 55, 110);
1566 return new Color(120, 195, 120);
1570 return new Color(110, 45, 130);
1574 return new Color(100, 205, 140);
1578 return new Color(90, 35, 150);
1582 return new Color(85, 215, 160);
1586 return new Color(75, 25, 170);
1590 return new Color(65, 225, 180);
1594 return new Color(55, 15, 185);
1598 return new Color(45, 235, 195);
1602 return new Color(35, 5, 205);
1606 return new Color(25, 245, 215);
1610 return new Color(15, 0, 225);
1614 return new Color(10, 255, 235);
1618 return new Color(5, 150, 245);
1622 return new Color(0, 80, 255);
1625 System.out.println("This is not a interaction : " + lastss);
1631 void drawProfileDensity(Graphics g, AlignmentAnnotation _aa,
1632 Annotation[] aa_annotations, int sRes, int eRes, float min,
1635 if (sRes > aa_annotations.length)
1639 Font ofont = g.getFont();
1640 eRes = Math.min(eRes, aa_annotations.length);
1646 g.setColor(Color.pink);
1648 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1651 int aaMax = aa_annotations.length - 1;
1652 while (x < eRes - sRes)
1655 if (hasHiddenColumns)
1657 column = columnSelection.adjustForHiddenColumns(column);
1665 if (aa_annotations[column] == null)
1670 if (aa_annotations[column].colour == null)
1672 g.setColor(Color.black);
1676 g.setColor(aa_annotations[column].colour);
1681 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1683 int profl[] = getProfileFor(_aa, column);
1685 // just try to draw the logo if profl is not null
1686 if (profl != null && profl[2] != 0)
1688 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1689 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1690 float ht = y2; // - _aa.graphHeight;
1694 * Render a single base for a sequence profile, a base pair for
1695 * structure profile, and a triplet for a cdna profile
1697 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1699 double scale = _aa.graphHeight / (profl[1]);
1702 * Traverse the character(s)/percentage data in the array
1705 int valuesProcessed = 0;
1706 // profl[1] is the number of values in the profile
1708 while (valuesProcessed < profl[1])
1710 if (isStructureProfile)
1712 // todo can we encode a structure pair as an int, like codons?
1713 dc[0] = (char) profl[c++];
1714 dc[1] = (char) profl[c++];
1716 else if (isCdnaProfile)
1718 dc = CodingUtils.decodeCodon(profl[c++]);
1722 dc[0] = (char) profl[c++];
1726 // next profl[] position is profile % for the character(s)
1728 g.setColor(jalview.util.ColorUtils.getGraduatedColour(profl[c++],
1729 0f, Color.gray, 100, Color.blue));
1730 // g.setColor(profcolour.findColour(dc[0]).darker());
1732 g.fillRect(x * charWidth, (int) ht, charWidth, (int) scale);
1741 // if (_aa.threshold != null)
1743 // g.setColor(_aa.threshold.colour);
1744 // Graphics2D g2 = (Graphics2D) g;
1745 // g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1746 // BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1748 // y2 = (int) (y - ((_aa.threshold.value - min) / range)
1749 // * _aa.graphHeight);
1750 // g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1751 // g2.setStroke(new BasicStroke());