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.renderer.api.AnnotationRendererFactoryI;
33 import jalview.renderer.api.AnnotationRowRendererI;
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 ResidueShaderI profcolour = null;
79 private ColumnSelection columnSelection;
81 private ProfilesI hconsensus;
83 private Hashtable[] complementConsensus;
85 private Hashtable[] hStrucConsensus;
87 private boolean av_ignoreGapsConsensus;
90 * attributes set from AwtRenderPanelI
93 * old image used when data is currently being calculated and cannot be
96 private Image fadedImage;
99 * panel being rendered into
101 private ImageObserver annotationPanel;
104 * width of image to render in panel
106 private int imgWidth;
109 * offset to beginning of visible area
114 * offset to end of visible area
116 private int visHeight;
119 * indicate if the renderer should only render the visible portion of the
120 * annotation given the current view settings
122 private boolean useClip = true;
125 * master flag indicating if renderer should ever try to clip. not enabled for
128 private boolean canClip = false;
130 public AnnotationRenderer()
136 * Create a new annotation Renderer
139 * flag indicating if timing and redraw parameter info should be
142 public AnnotationRenderer(boolean debugRedraw)
144 this.debugRedraw = debugRedraw;
148 * Remove any references and resources when this object is no longer required
150 public void dispose()
153 complementConsensus = null;
154 hStrucConsensus = null;
156 annotationPanel = null;
157 rendererFactoryI = null;
160 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
161 int x, int y, int iconOffset, int startRes, int column,
162 boolean validRes, boolean validEnd)
164 g.setColor(STEM_COLOUR);
165 int sCol = (lastSSX / charWidth) + startRes;
167 int x2 = (x * charWidth);
169 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
170 : row_annotations[column - 1].secondaryStructure;
172 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
173 || dc != row_annotations[sCol - 1].secondaryStructure;
174 boolean diffdownstream = !validRes || !validEnd
175 || row_annotations[column] == null
176 || dc != row_annotations[column].secondaryStructure;
178 if (column > 0 && Rna.isClosingParenthesis(dc))
181 // if (validRes && column>1 && row_annotations[column-2]!=null &&
182 // dc.equals(row_annotations[column-2].displayCharacter))
185 * if new annotation with a closing base pair half of the stem,
186 * display a backward arrow
188 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
189 new int[] { y + iconOffset, y + 14 + iconOffset,
190 y + 8 + iconOffset }, 3);
200 // display a forward arrow
204 * if annotation ending with an opeing base pair half of the stem,
205 * display a forward arrow
207 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
208 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
217 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
220 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
221 Annotation[] row_annotations, int lastSSX, int x, int y,
222 int iconOffset, int startRes, int column, boolean validRes,
225 // System.out.println(nonCanColor);
227 g.setColor(nonCanColor);
228 int sCol = (lastSSX / charWidth) + startRes;
230 int x2 = (x * charWidth);
232 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
233 : row_annotations[column - 1].displayCharacter;
235 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
236 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
237 boolean diffdownstream = !validRes || !validEnd
238 || row_annotations[column] == null
239 || !dc.equals(row_annotations[column].displayCharacter);
240 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
241 // If a closing base pair half of the stem, display a backward arrow
242 if (column > 0 && Rna.isClosingParenthesis(dc))
246 // if (validRes && column>1 && row_annotations[column-2]!=null &&
247 // dc.equals(row_annotations[column-2].displayCharacter))
249 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
250 new int[] { y + iconOffset, y + 14 + iconOffset,
251 y + 8 + iconOffset }, 3);
262 // display a forward arrow
265 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
266 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
275 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
278 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
280 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
283 fm = annotPanel.getFontMetrics();
284 annotationPanel = annotPanel;
285 fadedImage = annotPanel.getFadedImage();
286 imgWidth = annotPanel.getFadedImageWidth();
287 // visible area for rendering
288 int[] bounds = annotPanel.getVisibleVRange();
292 visHeight = bounds[1];
307 rendererFactoryI = AnnotationRendererFactory.getRendererFactory();
308 updateFromAlignViewport(av);
311 public void updateFromAlignViewport(AlignViewportI av)
313 charWidth = av.getCharWidth();
314 endRes = av.getEndRes();
315 charHeight = av.getCharHeight();
316 hasHiddenColumns = av.hasHiddenColumns();
317 validCharWidth = av.isValidCharWidth();
318 av_renderHistogram = av.isShowConsensusHistogram();
319 av_renderProfile = av.isShowSequenceLogo();
320 av_normaliseProfile = av.isNormaliseSequenceLogo();
321 profcolour = av.getResidueShading();
322 if (profcolour == null || profcolour.getColourScheme() == null)
325 * Use default colour for sequence logo if
326 * the alignment has no colourscheme set
327 * (would like to use user preference but n/a for applet)
329 ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
330 : new ZappoColourScheme();
331 profcolour = new ResidueShader(col);
333 columnSelection = av.getColumnSelection();
334 hconsensus = av.getSequenceConsensusHash();
335 complementConsensus = av.getComplementConsensusHash();
336 hStrucConsensus = av.getRnaStructureConsensusHash();
337 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
341 * Returns profile data; the first element is the profile type, the second is
342 * the number of distinct values, the third the total count, and the remainder
343 * depend on the profile type.
349 int[] getProfileFor(AlignmentAnnotation aa, int column)
351 // TODO : consider refactoring the global alignment calculation
352 // properties/rendering attributes as a global 'alignment group' which holds
353 // all vis settings for the alignment as a whole rather than a subset
355 if (aa.autoCalculated
356 && (aa.label.startsWith("Consensus") || aa.label
357 .startsWith("cDNA Consensus")))
359 boolean forComplement = aa.label.startsWith("cDNA Consensus");
360 if (aa.groupRef != null && aa.groupRef.consensusData != null
361 && aa.groupRef.isShowSequenceLogo())
363 // TODO? group consensus for cDNA complement
364 return AAFrequency.extractProfile(
365 aa.groupRef.consensusData.get(column),
366 aa.groupRef.getIgnoreGapsConsensus());
368 // TODO extend annotation row to enable dynamic and static profile data to
370 if (aa.groupRef == null && aa.sequenceRef == null)
374 return AAFrequency.extractCdnaProfile(
375 complementConsensus[column], av_ignoreGapsConsensus);
379 return AAFrequency.extractProfile(hconsensus.get(column),
380 av_ignoreGapsConsensus);
386 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
388 // TODO implement group structure consensus
390 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
391 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
392 * group selections return StructureFrequency.extractProfile(
393 * aa.groupRef.consensusData[column], aa.groupRef
394 * .getIgnoreGapsConsensus()); }
396 // TODO extend annotation row to enable dynamic and static profile data
399 if (aa.groupRef == null && aa.sequenceRef == null
400 && hStrucConsensus != null
401 && hStrucConsensus.length > column)
403 return StructureFrequency.extractProfile(hStrucConsensus[column],
404 av_ignoreGapsConsensus);
413 private AnnotationRendererFactoryI rendererFactoryI;
416 * Render the annotation rows associated with an alignment.
421 * data and view settings to render
423 * destination for graphics
425 * row where a mouse event occured (or -1)
427 * first column that will be drawn
429 * last column that will be drawn
430 * @return true if the fadedImage was used for any alignment annotation rows
431 * currently being calculated
433 public boolean drawComponent(AwtRenderPanelI annotPanel,
434 AlignViewportI av, Graphics g, int activeRow, int startRes,
437 long stime = System.currentTimeMillis();
438 boolean usedFaded = false;
440 // AnnotationPanel needs to implement: ImageObserver, access to
442 updateFromAwtRenderPanel(annotPanel, av);
443 fm = g.getFontMetrics();
444 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
455 boolean validRes = false;
456 boolean validEnd = false;
457 boolean labelAllCols = false;
458 boolean centreColLabels;
459 boolean centreColLabelsDef = av.isCentreColumnLabels();
460 boolean scaleColLabel = false;
461 final AlignmentAnnotation consensusAnnot = av
462 .getAlignmentConsensusAnnotation();
463 final AlignmentAnnotation structConsensusAnnot = av
464 .getAlignmentStrucConsensusAnnotation();
465 final AlignmentAnnotation complementConsensusAnnot = av
466 .getComplementConsensusAnnotation();
467 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
469 BitSet graphGroupDrawn = new BitSet();
470 int charOffset = 0; // offset for a label
471 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
473 Font ofont = g.getFont();
476 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
477 boolean clipst = false, clipend = false;
478 for (int i = 0; i < aa.length; i++)
480 AlignmentAnnotation row = aa[i];
483 // check if this is a consensus annotation row and set the display
484 // settings appropriately
485 // TODO: generalise this to have render styles for consensus/profile
487 if (row.groupRef != null && row == row.groupRef.getConsensus())
489 renderHistogram = row.groupRef.isShowConsensusHistogram();
490 renderProfile = row.groupRef.isShowSequenceLogo();
491 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
493 else if (row == consensusAnnot || row == structConsensusAnnot
494 || row == complementConsensusAnnot)
496 renderHistogram = av_renderHistogram;
497 renderProfile = av_renderProfile;
498 normaliseProfile = av_normaliseProfile;
502 renderHistogram = true;
503 // don't need to set render/normaliseProfile since they are not
504 // currently used in any other annotation track renderer
507 Annotation[] row_annotations = row.annotations;
512 centreColLabels = row.centreColLabels || centreColLabelsDef;
513 labelAllCols = row.showAllColLabels;
514 scaleColLabel = row.scaleColLabel;
519 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
520 {// if_in_visible_region
531 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
536 // this is so that we draw the characters below the graph
541 iconOffset = charHeight - fm.getDescent();
545 else if (row.hasText)
547 iconOffset = charHeight - fm.getDescent();
555 if (row.autoCalculated && av.isCalculationInProgress(row))
559 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
560 - row.height, imgWidth, y, annotationPanel);
561 g.setColor(Color.black);
562 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
568 * else if (annotationPanel.av.updatingConservation &&
569 * aa[i].label.equals("Conservation")) {
571 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
572 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
573 * annotationPanel.imgWidth, y, annotationPanel);
575 * g.setColor(Color.black); //
576 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
578 * continue; } else if (annotationPanel.av.updatingConservation &&
579 * aa[i].label.equals("Quality")) {
581 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
582 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
583 * annotationPanel.imgWidth, y, annotationPanel);
584 * g.setColor(Color.black); // /
585 * g.drawString("Calculating Quality....",20, y-row.height/2);
589 // first pass sets up state for drawing continuation from left-hand
592 x = (startRes == 0) ? 0 : -1;
593 while (x < endRes - startRes)
595 if (hasHiddenColumns)
597 column = columnSelection.adjustForHiddenColumns(startRes + x);
598 if (column > row_annotations.length - 1)
605 column = startRes + x;
608 if ((row_annotations == null)
609 || (row_annotations.length <= column)
610 || (row_annotations[column] == null))
618 final String displayChar = validRes ? row_annotations[column].displayCharacter
624 g.setColor(Color.red);
626 if (columnSelection != null)
628 if (columnSelection.contains(column))
630 g.fillRect(x * charWidth, y, charWidth, charHeight);
634 if (row.getInvalidStrucPos() > x)
636 g.setColor(Color.orange);
637 g.fillRect(x * charWidth, y, charWidth, charHeight);
639 else if (row.getInvalidStrucPos() == x)
641 g.setColor(Color.orange.darker());
642 g.fillRect(x * charWidth, y, charWidth, charHeight);
644 if (validCharWidth && validRes && displayChar != null
645 && (displayChar.length() > 0))
648 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
649 displayChar.length());
650 if (/* centreColLabels || */scaleColLabel)
652 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
653 // displayChar.length());
655 // if (scaleColLabel)
657 // justify the label and scale to fit in column
658 if (fmWidth > charWidth)
660 // scale only if the current font isn't already small enough
661 fmScaling = charWidth;
662 fmScaling /= fmWidth;
663 g.setFont(ofont.deriveFont(AffineTransform
664 .getScaleInstance(fmScaling, 1.0)));
665 // and update the label's width to reflect the scaling.
670 // TODO is it ok to use width of / show all characters here?
673 // fmWidth = fm.charWidth(displayChar.charAt(0));
675 charOffset = (int) ((charWidth - fmWidth) / 2f);
677 if (row_annotations[column].colour == null)
679 g.setColor(Color.black);
683 g.setColor(row_annotations[column].colour);
686 if (column == 0 || row.graph > 0)
688 g.drawString(displayChar, (x * charWidth) + charOffset, y
691 else if (row_annotations[column - 1] == null
694 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
695 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
697 g.drawString(displayChar, x * charWidth + charOffset, y
705 char ss = validRes ? row_annotations[column].secondaryStructure
710 // distinguish between forward/backward base-pairing
711 if (displayChar.indexOf(')') > -1)
720 if ((displayChar.indexOf(']') > -1))
728 // distinguish between forward/backward base-pairing
729 if (displayChar.indexOf('}') > -1)
737 // distinguish between forward/backward base-pairing
738 if (displayChar.indexOf('<') > -1)
744 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
746 // distinguish between forward/backward base-pairing
747 int ssLowerCase = ss + UPPER_TO_LOWER;
748 // TODO would .equals() be safer here? or charAt(0)?
749 if (displayChar.indexOf(ssLowerCase) > -1)
751 ss = (char) ssLowerCase;
755 if (!validRes || (ss != lastSS))
761 int nb_annot = x - temp;
762 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
765 case '(': // Stem case for RNA secondary structure
766 case ')': // and opposite direction
767 drawStemAnnot(g, row_annotations, lastSSX, x, y,
768 iconOffset, startRes, column, validRes, validEnd);
775 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
776 iconOffset, startRes, column, validRes,
780 // no break if isRNA - falls through to drawNotCanonicalAnnot!
784 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
785 iconOffset, startRes, column, validRes,
789 // no break if isRNA - fall through to drawNotCanonicalAnnot!
848 Color nonCanColor = getNotCanonicalColor(lastSS);
849 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
850 lastSSX, x, y, iconOffset, startRes, column,
855 g.setColor(Color.gray);
856 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
872 lastSSX = (x * charWidth);
879 if (column >= row_annotations.length)
881 column = row_annotations.length - 1;
888 if ((row_annotations == null) || (row_annotations.length <= column)
889 || (row_annotations[column] == null))
907 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
908 startRes, column, validRes, validEnd);
911 // no break if isRNA - fall through to drawNotCanonicalAnnot!
916 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
917 startRes, column, validRes, validEnd);
920 // no break if isRNA - fall through to drawNotCanonicalAnnot!
923 case ')': // Stem case for RNA secondary structure
925 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
926 startRes, column, validRes, validEnd);
983 // System.out.println(lastSS);
984 Color nonCanColor = getNotCanonicalColor(lastSS);
985 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
986 x, y, iconOffset, startRes, column, validRes, validEnd);
989 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
990 startRes, column, validRes, validEnd);
995 if (row.graph > 0 && row.graphHeight > 0)
997 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
999 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1001 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1002 // computed efficiently for all visible labels
1003 float groupmax = -999999, groupmin = 9999999;
1004 for (int gg = 0; gg < aa.length; gg++)
1006 if (aa[gg].graphGroup != row.graphGroup)
1013 aa[gg].visible = false;
1015 if (aa[gg].graphMax > groupmax)
1017 groupmax = aa[gg].graphMax;
1019 if (aa[gg].graphMin < groupmin)
1021 groupmin = aa[gg].graphMin;
1025 for (int gg = 0; gg < aa.length; gg++)
1027 if (aa[gg].graphGroup == row.graphGroup)
1029 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1030 endRes, y, groupmin, groupmax, row.graphHeight);
1034 graphGroupDrawn.set(row.graphGroup);
1038 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1039 row.graphMin, row.graphMax, row.graphHeight);
1042 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1044 drawBarGraph(g, row, row_annotations, startRes, endRes,
1045 row.graphMin, row.graphMax, y, renderHistogram,
1046 renderProfile, normaliseProfile);
1050 AnnotationRowRendererI renderer = rendererFactoryI
1051 .getRendererFor(row);
1052 if (renderer != null)
1054 renderer.renderRow(g, charWidth, charHeight,
1055 hasHiddenColumns, av, columnSelection, row,
1056 row_annotations, startRes, endRes, row.graphMin,
1061 if (renderer == null)
1063 System.err.println("No renderer found for "
1068 System.err.println("rendered with "
1069 + renderer.getClass().toString());
1078 if (clipst && !clipend)
1082 }// end if_in_visible_region
1083 if (row.graph > 0 && row.hasText)
1099 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1104 System.err.println("End clip at : " + yto + " (index " + f_to
1109 System.err.println("Annotation Rendering time:"
1110 + (System.currentTimeMillis() - stime));
1117 public static final Color GLYPHLINE_COLOR = Color.gray;
1119 public static final Color SHEET_COLOUR = Color.green;
1121 public static final Color HELIX_COLOUR = Color.red;
1123 public static final Color STEM_COLOUR = Color.blue;
1125 private Color sdNOTCANONICAL_COLOUR;
1127 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1128 int y, int iconOffset, int startRes, int column,
1129 boolean validRes, boolean validEnd)
1131 g.setColor(GLYPHLINE_COLOR);
1132 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1135 void drawSheetAnnot(Graphics g, Annotation[] row,
1137 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1138 boolean validRes, boolean validEnd)
1140 g.setColor(SHEET_COLOUR);
1142 if (!validEnd || !validRes || row == null || row[column] == null
1143 || row[column].secondaryStructure != 'E')
1145 g.fillRect(lastSSX, y + 4 + iconOffset,
1146 (x * charWidth) - lastSSX - 4, 7);
1147 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1148 (x * charWidth) }, new int[] { y + iconOffset,
1149 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1153 g.fillRect(lastSSX, y + 4 + iconOffset,
1154 (x + 1) * charWidth - lastSSX, 7);
1159 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1160 int y, int iconOffset, int startRes, int column,
1161 boolean validRes, boolean validEnd)
1163 g.setColor(HELIX_COLOUR);
1165 int sCol = (lastSSX / charWidth) + startRes;
1167 int x2 = (x * charWidth);
1171 int ofs = charWidth / 2;
1172 // Off by 1 offset when drawing rects and ovals
1173 // to offscreen image on the MAC
1174 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1175 if (sCol == 0 || row[sCol - 1] == null
1176 || row[sCol - 1].secondaryStructure != 'H')
1181 // g.setColor(Color.orange);
1182 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1185 if (!validRes || row[column] == null
1186 || row[column].secondaryStructure != 'H')
1192 // g.setColor(Color.magenta);
1193 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1201 if (sCol == 0 || row[sCol - 1] == null
1202 || row[sCol - 1].secondaryStructure != 'H')
1204 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1205 x1 += charWidth / 2;
1208 if (!validRes || row[column] == null
1209 || row[column].secondaryStructure != 'H')
1211 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1213 x2 -= charWidth / 2;
1216 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1219 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1220 Annotation[] aa_annotations, int sRes, int eRes, int y,
1221 float min, float max, int graphHeight)
1223 if (sRes > aa_annotations.length)
1230 // Adjustment for fastpaint to left
1236 eRes = Math.min(eRes, aa_annotations.length);
1244 float range = max - min;
1249 y2 = y - (int) ((0 - min / range) * graphHeight);
1252 g.setColor(Color.gray);
1253 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1255 eRes = Math.min(eRes, aa_annotations.length);
1258 int aaMax = aa_annotations.length - 1;
1260 while (x < eRes - sRes)
1263 if (hasHiddenColumns)
1265 column = columnSelection.adjustForHiddenColumns(column);
1273 if (aa_annotations[column] == null
1274 || aa_annotations[column - 1] == null)
1280 if (aa_annotations[column].colour == null)
1282 g.setColor(Color.black);
1286 g.setColor(aa_annotations[column].colour);
1290 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1292 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1294 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1295 + charWidth / 2, y2);
1299 if (_aa.threshold != null)
1301 g.setColor(_aa.threshold.colour);
1302 Graphics2D g2 = (Graphics2D) g;
1303 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1304 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1306 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1307 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1308 g2.setStroke(new BasicStroke());
1312 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1313 Annotation[] aa_annotations, int sRes, int eRes, float min,
1314 float max, int y, boolean renderHistogram, boolean renderProfile,
1315 boolean normaliseProfile)
1317 if (sRes > aa_annotations.length)
1321 Font ofont = g.getFont();
1322 eRes = Math.min(eRes, aa_annotations.length);
1324 int x = 0, y1 = y, y2 = y;
1326 float range = max - min;
1330 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1333 g.setColor(Color.gray);
1335 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1338 int aaMax = aa_annotations.length - 1;
1339 while (x < eRes - sRes)
1342 if (hasHiddenColumns)
1344 column = columnSelection.adjustForHiddenColumns(column);
1352 if (aa_annotations[column] == null)
1357 if (aa_annotations[column].colour == null)
1359 g.setColor(Color.black);
1363 g.setColor(aa_annotations[column].colour);
1367 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1369 if (renderHistogram)
1373 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1377 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1380 // draw profile if available
1385 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1387 int profl[] = getProfileFor(_aa, column);
1389 // just try to draw the logo if profl is not null
1390 if (profl != null && profl[2] != 0)
1392 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1393 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1394 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1395 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1402 * Render a single base for a sequence profile, a base pair for
1403 * structure profile, and a triplet for a cdna profile
1405 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1407 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1408 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1409 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1413 * Traverse the character(s)/percentage data in the array
1416 int valuesProcessed = 0;
1417 // profl[1] is the number of values in the profile
1418 while (valuesProcessed < profl[1])
1420 if (isStructureProfile)
1422 // todo can we encode a structure pair as an int, like codons?
1423 dc[0] = (char) profl[c++];
1424 dc[1] = (char) profl[c++];
1426 else if (isCdnaProfile)
1428 dc = CodingUtils.decodeCodon(profl[c++]);
1432 dc[0] = (char) profl[c++];
1436 wdth /= fm.charsWidth(dc, 0, dc.length);
1439 // next profl[] position is profile % for the character(s)
1440 scl = htn * scale * profl[c++];
1441 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1442 .getFontRenderContext());
1443 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1444 wdth, scl / lm.getAscent()));
1446 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1448 // Debug - render boxes around characters
1449 // g.setColor(Color.red);
1450 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1452 // g.setColor(profcolour.findColour(dc[0]).darker());
1455 * Set character colour as per alignment colour scheme; use the
1456 * codon translation if a cDNA profile
1458 Color colour = null;
1461 final String codonTranslation = ResidueProperties
1462 .codonTranslate(new String(dc));
1463 colour = profcolour.findColour(codonTranslation.charAt(0),
1468 colour = profcolour.findColour(dc[0], column, null);
1470 g.setColor(colour == Color.white ? Color.lightGray : colour);
1472 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1473 .getBaselineIndex()]));
1475 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1483 if (_aa.threshold != null)
1485 g.setColor(_aa.threshold.colour);
1486 Graphics2D g2 = (Graphics2D) g;
1487 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1488 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1490 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1492 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1493 g2.setStroke(new BasicStroke());
1497 // used by overview window
1498 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1499 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1501 eRes = Math.min(eRes, aa_annotations.length);
1502 g.setColor(Color.white);
1503 g.fillRect(0, 0, width, y);
1504 g.setColor(new Color(0, 0, 180));
1508 for (int j = sRes; j < eRes; j++)
1510 if (aa_annotations[j] != null)
1512 if (aa_annotations[j].colour == null)
1514 g.setColor(Color.black);
1518 g.setColor(aa_annotations[j].colour);
1521 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1527 g.fillRect(x, y - height, charWidth, height);
1533 Color getNotCanonicalColor(char lastss)
1539 return new Color(255, 125, 5);
1543 return new Color(245, 115, 10);
1547 return new Color(235, 135, 15);
1551 return new Color(225, 105, 20);
1555 return new Color(215, 145, 30);
1559 return new Color(205, 95, 35);
1563 return new Color(195, 155, 45);
1567 return new Color(185, 85, 55);
1571 return new Color(175, 165, 65);
1575 return new Color(170, 75, 75);
1579 return new Color(160, 175, 85);
1583 return new Color(150, 65, 95);
1587 return new Color(140, 185, 105);
1591 return new Color(130, 55, 110);
1595 return new Color(120, 195, 120);
1599 return new Color(110, 45, 130);
1603 return new Color(100, 205, 140);
1607 return new Color(90, 35, 150);
1611 return new Color(85, 215, 160);
1615 return new Color(75, 25, 170);
1619 return new Color(65, 225, 180);
1623 return new Color(55, 15, 185);
1627 return new Color(45, 235, 195);
1631 return new Color(35, 5, 205);
1635 return new Color(25, 245, 215);
1639 return new Color(15, 0, 225);
1643 return new Color(10, 255, 235);
1647 return new Color(5, 150, 245);
1651 return new Color(0, 80, 255);
1654 System.out.println("This is not a interaction : " + lastss);