2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.renderer;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.CodingUtils;
25 import jalview.analysis.Rna;
26 import jalview.analysis.StructureFrequency;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.ProfilesI;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.NucleotideColourScheme;
35 import jalview.schemes.ResidueProperties;
36 import jalview.schemes.ZappoColourScheme;
37 import jalview.util.Platform;
39 import java.awt.BasicStroke;
40 import java.awt.Color;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.Graphics2D;
45 import java.awt.Image;
46 import java.awt.font.LineMetrics;
47 import java.awt.geom.AffineTransform;
48 import java.awt.image.ImageObserver;
49 import java.util.BitSet;
50 import java.util.Hashtable;
52 public class AnnotationRenderer
54 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
56 private static final int CHAR_A = 'A'; // 65
58 private static final int CHAR_Z = 'Z'; // 90
61 * flag indicating if timing and redraw parameter info should be output
63 private final boolean debugRedraw;
65 private int charWidth, endRes, charHeight;
67 private boolean validCharWidth, hasHiddenColumns;
69 private FontMetrics fm;
71 private final boolean MAC = Platform.isAMac();
73 boolean av_renderHistogram = true, av_renderProfile = true,
74 av_normaliseProfile = false;
76 ResidueShaderI profcolour = null;
78 private ColumnSelection columnSelection;
80 private HiddenColumns hiddenColumns;
82 private ProfilesI hconsensus;
84 private Hashtable[] complementConsensus;
86 private Hashtable[] hStrucConsensus;
88 private boolean av_ignoreGapsConsensus;
91 * attributes set from AwtRenderPanelI
94 * old image used when data is currently being calculated and cannot be
97 private Image fadedImage;
100 * panel being rendered into
102 private ImageObserver annotationPanel;
105 * width of image to render in panel
107 private int imgWidth;
110 * offset to beginning of visible area
115 * offset to end of visible area
117 private int visHeight;
120 * indicate if the renderer should only render the visible portion of the
121 * annotation given the current view settings
123 private boolean useClip = true;
126 * master flag indicating if renderer should ever try to clip. not enabled for
129 private boolean canClip = false;
131 public AnnotationRenderer()
137 * Create a new annotation Renderer
140 * flag indicating if timing and redraw parameter info should be
143 public AnnotationRenderer(boolean debugRedraw)
145 this.debugRedraw = debugRedraw;
149 * Remove any references and resources when this object is no longer required
151 public void dispose()
154 complementConsensus = null;
155 hStrucConsensus = null;
157 annotationPanel = 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 updateFromAlignViewport(av);
310 public void updateFromAlignViewport(AlignViewportI av)
312 charWidth = av.getCharWidth();
313 endRes = av.getRanges().getEndRes();
314 charHeight = av.getCharHeight();
315 hasHiddenColumns = av.hasHiddenColumns();
316 validCharWidth = av.isValidCharWidth();
317 av_renderHistogram = av.isShowConsensusHistogram();
318 av_renderProfile = av.isShowSequenceLogo();
319 av_normaliseProfile = av.isNormaliseSequenceLogo();
320 profcolour = av.getResidueShading();
321 if (profcolour == null || profcolour.getColourScheme() == null)
324 * Use default colour for sequence logo if
325 * the alignment has no colourscheme set
326 * (would like to use user preference but n/a for applet)
328 ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
329 : new ZappoColourScheme();
330 profcolour = new ResidueShader(col);
332 columnSelection = av.getColumnSelection();
333 hiddenColumns = av.getAlignment().getHiddenColumns();
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(
380 hconsensus.get(column),
381 av_ignoreGapsConsensus);
387 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
389 // TODO implement group structure consensus
391 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
392 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
393 * group selections return StructureFrequency.extractProfile(
394 * aa.groupRef.consensusData[column], aa.groupRef
395 * .getIgnoreGapsConsensus()); }
397 // TODO extend annotation row to enable dynamic and static profile data
400 if (aa.groupRef == null && aa.sequenceRef == null
401 && hStrucConsensus != null
402 && hStrucConsensus.length > column)
404 return StructureFrequency.extractProfile(hStrucConsensus[column],
405 av_ignoreGapsConsensus);
415 * Render the annotation rows associated with an alignment.
420 * data and view settings to render
422 * destination for graphics
424 * row where a mouse event occured (or -1)
426 * first column that will be drawn
428 * last column that will be drawn
429 * @return true if the fadedImage was used for any alignment annotation rows
430 * currently being calculated
432 public boolean drawComponent(AwtRenderPanelI annotPanel,
433 AlignViewportI av, Graphics g, int activeRow, int startRes,
436 long stime = System.currentTimeMillis();
437 boolean usedFaded = false;
439 // AnnotationPanel needs to implement: ImageObserver, access to
441 updateFromAwtRenderPanel(annotPanel, av);
442 fm = g.getFontMetrics();
443 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
454 boolean validRes = false;
455 boolean validEnd = false;
456 boolean labelAllCols = false;
457 boolean centreColLabels;
458 boolean centreColLabelsDef = av.isCentreColumnLabels();
459 boolean scaleColLabel = false;
460 final AlignmentAnnotation consensusAnnot = av
461 .getAlignmentConsensusAnnotation();
462 final AlignmentAnnotation structConsensusAnnot = av
463 .getAlignmentStrucConsensusAnnotation();
464 final AlignmentAnnotation complementConsensusAnnot = av
465 .getComplementConsensusAnnotation();
466 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
468 BitSet graphGroupDrawn = new BitSet();
469 int charOffset = 0; // offset for a label
470 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
472 Font ofont = g.getFont();
475 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
476 boolean clipst = false, clipend = false;
477 for (int i = 0; i < aa.length; i++)
479 AlignmentAnnotation row = aa[i];
482 // check if this is a consensus annotation row and set the display
483 // settings appropriately
484 // TODO: generalise this to have render styles for consensus/profile
486 if (row.groupRef != null && row == row.groupRef.getConsensus())
488 renderHistogram = row.groupRef.isShowConsensusHistogram();
489 renderProfile = row.groupRef.isShowSequenceLogo();
490 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
492 else if (row == consensusAnnot || row == structConsensusAnnot
493 || row == complementConsensusAnnot)
495 renderHistogram = av_renderHistogram;
496 renderProfile = av_renderProfile;
497 normaliseProfile = av_normaliseProfile;
501 renderHistogram = true;
502 // don't need to set render/normaliseProfile since they are not
503 // currently used in any other annotation track renderer
506 Annotation[] row_annotations = row.annotations;
511 centreColLabels = row.centreColLabels || centreColLabelsDef;
512 labelAllCols = row.showAllColLabels;
513 scaleColLabel = row.scaleColLabel;
518 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
519 {// if_in_visible_region
530 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
535 // this is so that we draw the characters below the graph
540 iconOffset = charHeight - fm.getDescent();
544 else if (row.hasText)
546 iconOffset = charHeight - fm.getDescent();
554 if (row.autoCalculated && av.isCalculationInProgress(row))
558 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
559 - row.height, imgWidth, y, annotationPanel);
560 g.setColor(Color.black);
561 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
567 * else if (annotationPanel.av.updatingConservation &&
568 * aa[i].label.equals("Conservation")) {
570 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
571 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
572 * annotationPanel.imgWidth, y, annotationPanel);
574 * g.setColor(Color.black); //
575 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
577 * continue; } else if (annotationPanel.av.updatingConservation &&
578 * aa[i].label.equals("Quality")) {
580 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
581 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
582 * annotationPanel.imgWidth, y, annotationPanel);
583 * g.setColor(Color.black); // /
584 * g.drawString("Calculating Quality....",20, y-row.height/2);
588 // first pass sets up state for drawing continuation from left-hand
591 x = (startRes == 0) ? 0 : -1;
592 while (x < endRes - startRes)
594 if (hasHiddenColumns)
596 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
597 if (column > row_annotations.length - 1)
604 column = startRes + x;
607 if ((row_annotations == null)
608 || (row_annotations.length <= column)
609 || (row_annotations[column] == null))
617 final String displayChar = validRes ? row_annotations[column].displayCharacter
623 g.setColor(Color.red);
625 if (columnSelection != null)
627 if (columnSelection.contains(column))
629 g.fillRect(x * charWidth, y, charWidth, charHeight);
633 if (row.getInvalidStrucPos() > x)
635 g.setColor(Color.orange);
636 g.fillRect(x * charWidth, y, charWidth, charHeight);
638 else if (row.getInvalidStrucPos() == x)
640 g.setColor(Color.orange.darker());
641 g.fillRect(x * charWidth, y, charWidth, charHeight);
643 if (validCharWidth && validRes && displayChar != null
644 && (displayChar.length() > 0))
647 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
648 displayChar.length());
649 if (/* centreColLabels || */scaleColLabel)
651 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
652 // displayChar.length());
654 // if (scaleColLabel)
656 // justify the label and scale to fit in column
657 if (fmWidth > charWidth)
659 // scale only if the current font isn't already small enough
660 fmScaling = charWidth;
661 fmScaling /= fmWidth;
662 g.setFont(ofont.deriveFont(AffineTransform
663 .getScaleInstance(fmScaling, 1.0)));
664 // and update the label's width to reflect the scaling.
669 // TODO is it ok to use width of / show all characters here?
672 // fmWidth = fm.charWidth(displayChar.charAt(0));
674 charOffset = (int) ((charWidth - fmWidth) / 2f);
676 if (row_annotations[column].colour == null)
678 g.setColor(Color.black);
682 g.setColor(row_annotations[column].colour);
685 if (column == 0 || row.graph > 0)
687 g.drawString(displayChar, (x * charWidth) + charOffset, y
690 else if (row_annotations[column - 1] == null
693 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
694 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
696 g.drawString(displayChar, x * charWidth + charOffset, y
704 char ss = validRes ? row_annotations[column].secondaryStructure
709 // distinguish between forward/backward base-pairing
710 if (displayChar.indexOf(')') > -1)
719 if ((displayChar.indexOf(']') > -1))
727 // distinguish between forward/backward base-pairing
728 if (displayChar.indexOf('}') > -1)
736 // distinguish between forward/backward base-pairing
737 if (displayChar.indexOf('<') > -1)
743 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
745 // distinguish between forward/backward base-pairing
746 int ssLowerCase = ss + UPPER_TO_LOWER;
747 // TODO would .equals() be safer here? or charAt(0)?
748 if (displayChar.indexOf(ssLowerCase) > -1)
750 ss = (char) ssLowerCase;
754 if (!validRes || (ss != lastSS))
760 int nb_annot = x - temp;
761 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
764 case '(': // Stem case for RNA secondary structure
765 case ')': // and opposite direction
766 drawStemAnnot(g, row_annotations, lastSSX, x, y,
767 iconOffset, startRes, column, validRes, validEnd);
774 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
775 iconOffset, startRes, column, validRes,
779 // no break if isRNA - falls through to drawNotCanonicalAnnot!
783 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
784 iconOffset, startRes, column, validRes,
788 // no break if isRNA - fall through to drawNotCanonicalAnnot!
847 Color nonCanColor = getNotCanonicalColor(lastSS);
848 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
849 lastSSX, x, y, iconOffset, startRes, column,
854 g.setColor(Color.gray);
855 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
871 lastSSX = (x * charWidth);
878 if (column >= row_annotations.length)
880 column = row_annotations.length - 1;
887 if ((row_annotations == null) || (row_annotations.length <= column)
888 || (row_annotations[column] == null))
906 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
907 startRes, column, validRes, validEnd);
910 // no break if isRNA - fall through to drawNotCanonicalAnnot!
915 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
916 startRes, column, validRes, validEnd);
919 // no break if isRNA - fall through to drawNotCanonicalAnnot!
922 case ')': // Stem case for RNA secondary structure
924 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
925 startRes, column, validRes, validEnd);
982 // System.out.println(lastSS);
983 Color nonCanColor = getNotCanonicalColor(lastSS);
984 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
985 x, y, iconOffset, startRes, column, validRes, validEnd);
988 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
989 startRes, column, validRes, validEnd);
994 if (row.graph > 0 && row.graphHeight > 0)
996 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
998 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1000 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1001 // computed efficiently for all visible labels
1002 float groupmax = -999999, groupmin = 9999999;
1003 for (int gg = 0; gg < aa.length; gg++)
1005 if (aa[gg].graphGroup != row.graphGroup)
1012 aa[gg].visible = false;
1014 if (aa[gg].graphMax > groupmax)
1016 groupmax = aa[gg].graphMax;
1018 if (aa[gg].graphMin < groupmin)
1020 groupmin = aa[gg].graphMin;
1024 for (int gg = 0; gg < aa.length; gg++)
1026 if (aa[gg].graphGroup == row.graphGroup)
1028 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1029 endRes, y, groupmin, groupmax, row.graphHeight);
1033 graphGroupDrawn.set(row.graphGroup);
1037 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1038 row.graphMin, row.graphMax, row.graphHeight);
1041 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1043 drawBarGraph(g, row, row_annotations, startRes, endRes,
1044 row.graphMin, row.graphMax, y, renderHistogram,
1045 renderProfile, normaliseProfile);
1051 if (clipst && !clipend)
1055 }// end if_in_visible_region
1056 if (row.graph > 0 && row.hasText)
1072 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1077 System.err.println("End clip at : " + yto + " (index " + f_to
1082 System.err.println("Annotation Rendering time:"
1083 + (System.currentTimeMillis() - stime));
1090 public static final Color GLYPHLINE_COLOR = Color.gray;
1092 public static final Color SHEET_COLOUR = Color.green;
1094 public static final Color HELIX_COLOUR = Color.red;
1096 public static final Color STEM_COLOUR = Color.blue;
1098 private Color sdNOTCANONICAL_COLOUR;
1100 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1101 int y, int iconOffset, int startRes, int column,
1102 boolean validRes, boolean validEnd)
1104 g.setColor(GLYPHLINE_COLOR);
1105 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1108 void drawSheetAnnot(Graphics g, Annotation[] row,
1110 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1111 boolean validRes, boolean validEnd)
1113 g.setColor(SHEET_COLOUR);
1115 if (!validEnd || !validRes || row == null || row[column] == null
1116 || row[column].secondaryStructure != 'E')
1118 g.fillRect(lastSSX, y + 4 + iconOffset,
1119 (x * charWidth) - lastSSX - 4, 7);
1120 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1121 (x * charWidth) }, new int[] { y + iconOffset,
1122 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1126 g.fillRect(lastSSX, y + 4 + iconOffset,
1127 (x + 1) * charWidth - lastSSX, 7);
1132 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1133 int y, int iconOffset, int startRes, int column,
1134 boolean validRes, boolean validEnd)
1136 g.setColor(HELIX_COLOUR);
1138 int sCol = (lastSSX / charWidth) + startRes;
1140 int x2 = (x * charWidth);
1144 int ofs = charWidth / 2;
1145 // Off by 1 offset when drawing rects and ovals
1146 // to offscreen image on the MAC
1147 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1148 if (sCol == 0 || row[sCol - 1] == null
1149 || row[sCol - 1].secondaryStructure != 'H')
1154 // g.setColor(Color.orange);
1155 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1158 if (!validRes || row[column] == null
1159 || row[column].secondaryStructure != 'H')
1165 // g.setColor(Color.magenta);
1166 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1174 if (sCol == 0 || row[sCol - 1] == null
1175 || row[sCol - 1].secondaryStructure != 'H')
1177 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1178 x1 += charWidth / 2;
1181 if (!validRes || row[column] == null
1182 || row[column].secondaryStructure != 'H')
1184 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1186 x2 -= charWidth / 2;
1189 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1192 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1193 Annotation[] aa_annotations, int sRes, int eRes, int y,
1194 float min, float max, int graphHeight)
1196 if (sRes > aa_annotations.length)
1203 // Adjustment for fastpaint to left
1209 eRes = Math.min(eRes, aa_annotations.length);
1217 float range = max - min;
1222 y2 = y - (int) ((0 - min / range) * graphHeight);
1225 g.setColor(Color.gray);
1226 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1228 eRes = Math.min(eRes, aa_annotations.length);
1231 int aaMax = aa_annotations.length - 1;
1233 while (x < eRes - sRes)
1236 if (hasHiddenColumns)
1238 column = hiddenColumns.adjustForHiddenColumns(column);
1246 if (aa_annotations[column] == null
1247 || aa_annotations[column - 1] == null)
1253 if (aa_annotations[column].colour == null)
1255 g.setColor(Color.black);
1259 g.setColor(aa_annotations[column].colour);
1263 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1265 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1267 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1268 + charWidth / 2, y2);
1272 if (_aa.threshold != null)
1274 g.setColor(_aa.threshold.colour);
1275 Graphics2D g2 = (Graphics2D) g;
1276 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1277 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1279 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1280 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1281 g2.setStroke(new BasicStroke());
1285 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1286 Annotation[] aa_annotations, int sRes, int eRes, float min,
1287 float max, int y, boolean renderHistogram, boolean renderProfile,
1288 boolean normaliseProfile)
1290 if (sRes > aa_annotations.length)
1294 Font ofont = g.getFont();
1295 eRes = Math.min(eRes, aa_annotations.length);
1297 int x = 0, y1 = y, y2 = y;
1299 float range = max - min;
1303 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1306 g.setColor(Color.gray);
1308 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1311 int aaMax = aa_annotations.length - 1;
1312 while (x < eRes - sRes)
1315 if (hasHiddenColumns)
1317 column = hiddenColumns.adjustForHiddenColumns(column);
1325 if (aa_annotations[column] == null)
1330 if (aa_annotations[column].colour == null)
1332 g.setColor(Color.black);
1336 g.setColor(aa_annotations[column].colour);
1340 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1342 if (renderHistogram)
1346 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1350 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1353 // draw profile if available
1358 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1360 int profl[] = getProfileFor(_aa, column);
1362 // just try to draw the logo if profl is not null
1363 if (profl != null && profl[2] != 0)
1365 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1366 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1367 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1368 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1375 * Render a single base for a sequence profile, a base pair for
1376 * structure profile, and a triplet for a cdna profile
1378 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1380 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1381 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1382 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1386 * Traverse the character(s)/percentage data in the array
1389 int valuesProcessed = 0;
1390 // profl[1] is the number of values in the profile
1391 while (valuesProcessed < profl[1])
1393 if (isStructureProfile)
1395 // todo can we encode a structure pair as an int, like codons?
1396 dc[0] = (char) profl[c++];
1397 dc[1] = (char) profl[c++];
1399 else if (isCdnaProfile)
1401 dc = CodingUtils.decodeCodon(profl[c++]);
1405 dc[0] = (char) profl[c++];
1409 wdth /= fm.charsWidth(dc, 0, dc.length);
1412 // next profl[] position is profile % for the character(s)
1413 scl = htn * scale * profl[c++];
1414 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1415 .getFontRenderContext());
1416 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1417 wdth, scl / lm.getAscent()));
1419 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1421 // Debug - render boxes around characters
1422 // g.setColor(Color.red);
1423 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1425 // g.setColor(profcolour.findColour(dc[0]).darker());
1428 * Set character colour as per alignment colour scheme; use the
1429 * codon translation if a cDNA profile
1431 Color colour = null;
1434 final String codonTranslation = ResidueProperties
1435 .codonTranslate(new String(dc));
1436 colour = profcolour.findColour(codonTranslation.charAt(0),
1441 colour = profcolour.findColour(dc[0], column, null);
1443 g.setColor(colour == Color.white ? Color.lightGray : colour);
1445 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1446 .getBaselineIndex()]));
1448 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1456 if (_aa.threshold != null)
1458 g.setColor(_aa.threshold.colour);
1459 Graphics2D g2 = (Graphics2D) g;
1460 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1461 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1463 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1465 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1466 g2.setStroke(new BasicStroke());
1470 // used by overview window
1471 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1472 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1474 eRes = Math.min(eRes, aa_annotations.length);
1475 g.setColor(Color.white);
1476 g.fillRect(0, 0, width, y);
1477 g.setColor(new Color(0, 0, 180));
1481 for (int j = sRes; j < eRes; j++)
1483 if (aa_annotations[j] != null)
1485 if (aa_annotations[j].colour == null)
1487 g.setColor(Color.black);
1491 g.setColor(aa_annotations[j].colour);
1494 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1500 g.fillRect(x, y - height, charWidth, height);
1506 Color getNotCanonicalColor(char lastss)
1512 return new Color(255, 125, 5);
1516 return new Color(245, 115, 10);
1520 return new Color(235, 135, 15);
1524 return new Color(225, 105, 20);
1528 return new Color(215, 145, 30);
1532 return new Color(205, 95, 35);
1536 return new Color(195, 155, 45);
1540 return new Color(185, 85, 55);
1544 return new Color(175, 165, 65);
1548 return new Color(170, 75, 75);
1552 return new Color(160, 175, 85);
1556 return new Color(150, 65, 95);
1560 return new Color(140, 185, 105);
1564 return new Color(130, 55, 110);
1568 return new Color(120, 195, 120);
1572 return new Color(110, 45, 130);
1576 return new Color(100, 205, 140);
1580 return new Color(90, 35, 150);
1584 return new Color(85, 215, 160);
1588 return new Color(75, 25, 170);
1592 return new Color(65, 225, 180);
1596 return new Color(55, 15, 185);
1600 return new Color(45, 235, 195);
1604 return new Color(35, 5, 205);
1608 return new Color(25, 245, 215);
1612 return new Color(15, 0, 225);
1616 return new Color(10, 255, 235);
1620 return new Color(5, 150, 245);
1624 return new Color(0, 80, 255);
1627 System.out.println("This is not a interaction : " + lastss);