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.StructureFrequency;
26 import jalview.api.AlignViewportI;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.schemes.ColourSchemeI;
31 import jalview.schemes.ResidueProperties;
33 import java.awt.BasicStroke;
34 import java.awt.Color;
36 import java.awt.FontMetrics;
37 import java.awt.Graphics;
38 import java.awt.Graphics2D;
39 import java.awt.Image;
40 import java.awt.font.LineMetrics;
41 import java.awt.geom.AffineTransform;
42 import java.awt.image.ImageObserver;
43 import java.util.BitSet;
44 import java.util.Hashtable;
46 import com.stevesoft.pat.Regex;
48 public class AnnotationRenderer
50 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
52 private static final int CHAR_A = 'A'; // 65
54 private static final int CHAR_Z = 'Z'; // 90
57 * flag indicating if timing and redraw parameter info should be output
59 private final boolean debugRedraw;
61 public AnnotationRenderer()
67 * Create a new annotation Renderer
70 * flag indicating if timing and redraw parameter info should be
73 public AnnotationRenderer(boolean debugRedraw)
75 this.debugRedraw = debugRedraw;
78 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
79 int lastSSX, int x, int y, int iconOffset, int startRes,
80 int column, boolean validRes, boolean validEnd)
82 g.setColor(STEM_COLOUR);
83 int sCol = (lastSSX / charWidth) + startRes;
85 int x2 = (x * charWidth);
86 Regex closeparen = new Regex("(\\))");
88 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
89 : row_annotations[column - 1].secondaryStructure;
91 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
92 || dc != row_annotations[sCol - 1].secondaryStructure;
93 boolean diffdownstream = !validRes || !validEnd
94 || row_annotations[column] == null
95 || dc != row_annotations[column].secondaryStructure;
96 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
97 // If a closing base pair half of the stem, display a backward arrow
98 if (column > 0 && ResidueProperties.isCloseParenRNA(dc))
102 // if (validRes && column>1 && row_annotations[column-2]!=null &&
103 // dc.equals(row_annotations[column-2].displayCharacter))
105 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
106 new int[] { y + iconOffset, y + 14 + iconOffset,
107 y + 8 + iconOffset }, 3);
118 // display a forward arrow
121 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
122 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
131 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
134 private int charWidth, endRes, charHeight;
136 private boolean validCharWidth, hasHiddenColumns;
138 private FontMetrics fm;
140 private final boolean MAC = jalview.util.Platform.isAMac();
142 boolean av_renderHistogram = true, av_renderProfile = true,
143 av_normaliseProfile = false;
145 ColourSchemeI profcolour = null;
147 private ColumnSelection columnSelection;
149 private Hashtable[] hconsensus;
151 private Hashtable[] complementConsensus;
153 private Hashtable[] hStrucConsensus;
155 private boolean av_ignoreGapsConsensus;
158 * attributes set from AwtRenderPanelI
161 * old image used when data is currently being calculated and cannot be
164 private Image fadedImage;
167 * panel being rendered into
169 private ImageObserver annotationPanel;
172 * width of image to render in panel
174 private int imgWidth;
177 * offset to beginning of visible area
182 * offset to end of visible area
184 private int visHeight;
187 * indicate if the renderer should only render the visible portion of the
188 * annotation given the current view settings
190 private boolean useClip = true;
193 * master flag indicating if renderer should ever try to clip. not enabled for
196 private boolean canClip = false;
198 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
199 Annotation[] row_annotations, int lastSSX, int x, int y,
200 int iconOffset, int startRes, int column, boolean validRes,
203 // System.out.println(nonCanColor);
205 g.setColor(nonCanColor);
206 int sCol = (lastSSX / charWidth) + startRes;
208 int x2 = (x * charWidth);
209 Regex closeparen = new Regex("}|]|<|[a-z]");
211 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
212 : row_annotations[column - 1].displayCharacter;
214 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
215 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
216 boolean diffdownstream = !validRes || !validEnd
217 || row_annotations[column] == null
218 || !dc.equals(row_annotations[column].displayCharacter);
219 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
220 // If a closing base pair half of the stem, display a backward arrow
221 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
226 // if (validRes && column>1 && row_annotations[column-2]!=null &&
227 // dc.equals(row_annotations[column-2].displayCharacter))
229 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
230 new int[] { y + iconOffset, y + 14 + iconOffset,
231 y + 8 + iconOffset }, 3);
242 // display a forward arrow
245 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
246 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
255 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
258 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
260 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
263 fm = annotPanel.getFontMetrics();
264 annotationPanel = annotPanel;
265 fadedImage = annotPanel.getFadedImage();
266 imgWidth = annotPanel.getFadedImageWidth();
267 // visible area for rendering
268 int[] bounds = annotPanel.getVisibleVRange();
272 visHeight = bounds[1];
287 updateFromAlignViewport(av);
290 public void updateFromAlignViewport(AlignViewportI av)
292 charWidth = av.getCharWidth();
293 endRes = av.getEndRes();
294 charHeight = av.getCharHeight();
295 hasHiddenColumns = av.hasHiddenColumns();
296 validCharWidth = av.isValidCharWidth();
297 av_renderHistogram = av.isShowConsensusHistogram();
298 av_renderProfile = av.isShowSequenceLogo();
299 av_normaliseProfile = av.isNormaliseSequenceLogo();
300 profcolour = av.getGlobalColourScheme();
301 if (profcolour == null)
303 // Set the default colour for sequence logo if the alignnent has no
305 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
306 : new jalview.schemes.ZappoColourScheme();
308 columnSelection = av.getColumnSelection();
309 hconsensus = av.getSequenceConsensusHash();
310 complementConsensus = av.getComplementConsensusHash();
311 hStrucConsensus = av.getRnaStructureConsensusHash();
312 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
316 * Returns profile data; the first element is the profile type, the second is
317 * the number of distinct values, the third the total count, and the remainder
318 * depend on the profile type.
324 public int[] getProfileFor(AlignmentAnnotation aa, int column)
326 // TODO : consider refactoring the global alignment calculation
327 // properties/rendering attributes as a global 'alignment group' which holds
328 // all vis settings for the alignment as a whole rather than a subset
330 if (aa.autoCalculated
331 && (aa.label.startsWith("Consensus") || aa.label
332 .startsWith("cDNA Consensus")))
334 boolean forComplement = aa.label.startsWith("cDNA Consensus");
335 if (aa.groupRef != null && aa.groupRef.consensusData != null
336 && aa.groupRef.isShowSequenceLogo())
338 // TODO? group consensus for cDNA complement
339 return AAFrequency.extractProfile(
340 aa.groupRef.consensusData[column],
341 aa.groupRef.getIgnoreGapsConsensus());
343 // TODO extend annotation row to enable dynamic and static profile data to
345 if (aa.groupRef == null && aa.sequenceRef == null)
349 return AAFrequency.extractCdnaProfile(
350 complementConsensus[column], av_ignoreGapsConsensus);
354 return AAFrequency.extractProfile(hconsensus[column],
355 av_ignoreGapsConsensus);
361 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
363 // TODO implement group structure consensus
365 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
366 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
367 * group selections return StructureFrequency.extractProfile(
368 * aa.groupRef.consensusData[column], aa.groupRef
369 * .getIgnoreGapsConsensus()); }
371 // TODO extend annotation row to enable dynamic and static profile data
374 if (aa.groupRef == null && aa.sequenceRef == null
375 && hStrucConsensus != null
376 && hStrucConsensus.length > column)
378 return StructureFrequency.extractProfile(hStrucConsensus[column],
379 av_ignoreGapsConsensus);
389 * Render the annotation rows associated with an alignment.
394 * data and view settings to render
396 * destination for graphics
398 * row where a mouse event occured (or -1)
400 * first column that will be drawn
402 * last column that will be drawn
403 * @return true if the fadedImage was used for any alignment annotation rows
404 * currently being calculated
406 public boolean drawComponent(AwtRenderPanelI annotPanel,
407 AlignViewportI av, Graphics g, int activeRow, int startRes,
410 long stime = System.currentTimeMillis();
411 boolean usedFaded = false;
413 // AnnotationPanel needs to implement: ImageObserver, access to
415 updateFromAwtRenderPanel(annotPanel, av);
416 fm = g.getFontMetrics();
417 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
428 boolean validRes = false;
429 boolean validEnd = false;
430 boolean labelAllCols = false;
431 boolean centreColLabels;
432 boolean centreColLabelsDef = av.isCentreColumnLabels();
433 boolean scaleColLabel = false;
434 final AlignmentAnnotation consensusAnnot = av
435 .getAlignmentConsensusAnnotation();
436 final AlignmentAnnotation structConsensusAnnot = av
437 .getAlignmentStrucConsensusAnnotation();
438 final AlignmentAnnotation complementConsensusAnnot = av
439 .getComplementConsensusAnnotation();
440 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
442 BitSet graphGroupDrawn = new BitSet();
443 int charOffset = 0; // offset for a label
444 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
446 Font ofont = g.getFont();
449 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
450 boolean clipst = false, clipend = false;
451 for (int i = 0; i < aa.length; i++)
453 AlignmentAnnotation row = aa[i];
456 // check if this is a consensus annotation row and set the display
457 // settings appropriately
458 // TODO: generalise this to have render styles for consensus/profile
460 if (row.groupRef != null && row == row.groupRef.getConsensus())
462 renderHistogram = row.groupRef.isShowConsensusHistogram();
463 renderProfile = row.groupRef.isShowSequenceLogo();
464 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
466 else if (row == consensusAnnot || row == structConsensusAnnot
467 || row == complementConsensusAnnot)
469 renderHistogram = av_renderHistogram;
470 renderProfile = av_renderProfile;
471 normaliseProfile = av_normaliseProfile;
475 renderHistogram = true;
476 // don't need to set render/normaliseProfile since they are not
477 // currently used in any other annotation track renderer
480 Annotation[] row_annotations = row.annotations;
485 centreColLabels = row.centreColLabels || centreColLabelsDef;
486 labelAllCols = row.showAllColLabels;
487 scaleColLabel = row.scaleColLabel;
492 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
493 {// if_in_visible_region
504 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
509 // this is so that we draw the characters below the graph
514 iconOffset = charHeight - fm.getDescent();
518 else if (row.hasText)
520 iconOffset = charHeight - fm.getDescent();
528 if (row.autoCalculated && av.isCalculationInProgress(row))
532 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
533 - row.height, imgWidth, y, annotationPanel);
534 g.setColor(Color.black);
535 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
541 * else if (annotationPanel.av.updatingConservation &&
542 * aa[i].label.equals("Conservation")) {
544 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
545 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
546 * annotationPanel.imgWidth, y, annotationPanel);
548 * g.setColor(Color.black); //
549 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
551 * continue; } else if (annotationPanel.av.updatingConservation &&
552 * aa[i].label.equals("Quality")) {
554 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
555 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
556 * annotationPanel.imgWidth, y, annotationPanel);
557 * g.setColor(Color.black); // /
558 * g.drawString("Calculating Quality....",20, y-row.height/2);
562 // first pass sets up state for drawing continuation from left-hand
565 x = (startRes == 0) ? 0 : -1;
566 while (x < endRes - startRes)
568 if (hasHiddenColumns)
570 column = columnSelection.adjustForHiddenColumns(startRes + x);
571 if (column > row_annotations.length - 1)
578 column = startRes + x;
581 if ((row_annotations == null)
582 || (row_annotations.length <= column)
583 || (row_annotations[column] == null))
591 final String displayChar = validRes ? row_annotations[column].displayCharacter
597 g.setColor(Color.red);
599 if (columnSelection != null)
601 for (int v : columnSelection.getSelected())
605 g.fillRect(x * charWidth, y, charWidth, charHeight);
610 if (row.getInvalidStrucPos() > x)
612 g.setColor(Color.orange);
613 g.fillRect(x * charWidth, y, charWidth, charHeight);
615 else if (row.getInvalidStrucPos() == x)
617 g.setColor(Color.orange.darker());
618 g.fillRect(x * charWidth, y, charWidth, charHeight);
620 if (validCharWidth && validRes && displayChar != null
621 && (displayChar.length() > 0))
624 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
625 displayChar.length());
626 if (/* centreColLabels || */scaleColLabel)
628 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
629 // displayChar.length());
631 // if (scaleColLabel)
633 // justify the label and scale to fit in column
634 if (fmWidth > charWidth)
636 // scale only if the current font isn't already small enough
637 fmScaling = charWidth;
638 fmScaling /= fmWidth;
639 g.setFont(ofont.deriveFont(AffineTransform
640 .getScaleInstance(fmScaling, 1.0)));
641 // and update the label's width to reflect the scaling.
646 // TODO is it ok to use width of / show all characters here?
649 // fmWidth = fm.charWidth(displayChar.charAt(0));
651 charOffset = (int) ((charWidth - fmWidth) / 2f);
653 if (row_annotations[column].colour == null)
655 g.setColor(Color.black);
659 g.setColor(row_annotations[column].colour);
662 if (column == 0 || row.graph > 0)
664 g.drawString(displayChar, (x * charWidth) + charOffset, y
667 else if (row_annotations[column - 1] == null
670 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
671 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
673 g.drawString(displayChar, x * charWidth + charOffset, y
681 char ss = validRes ? row_annotations[column].secondaryStructure
686 // distinguish between forward/backward base-pairing
687 if (displayChar.indexOf(')') > -1)
696 if ((displayChar.indexOf(']') > -1))
704 // distinguish between forward/backward base-pairing
705 if (displayChar.indexOf('}') > -1)
713 // distinguish between forward/backward base-pairing
714 if (displayChar.indexOf('<') > -1)
720 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
722 // distinguish between forward/backward base-pairing
723 int ssLowerCase = ss + UPPER_TO_LOWER;
724 // TODO would .equals() be safer here? or charAt(0)?
725 if (displayChar.indexOf(ssLowerCase) > -1)
727 ss = (char) ssLowerCase;
731 if (!validRes || (ss != lastSS))
737 int nb_annot = x - temp;
738 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
741 case '(': // Stem case for RNA secondary structure
742 case ')': // and opposite direction
743 drawStemAnnot(g, row_annotations, lastSSX, x, y,
744 iconOffset, startRes, column, validRes, validEnd);
751 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
752 iconOffset, startRes, column, validRes,
760 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
761 iconOffset, startRes, column, validRes,
823 Color nonCanColor = getNotCanonicalColor(lastSS);
824 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
825 lastSSX, x, y, iconOffset, startRes, column,
830 g.setColor(Color.gray);
831 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
847 lastSSX = (x * charWidth);
854 if (column >= row_annotations.length)
856 column = row_annotations.length - 1;
863 if ((row_annotations == null) || (row_annotations.length <= column)
864 || (row_annotations[column] == null))
883 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
884 startRes, column, validRes, validEnd);
891 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
892 startRes, column, validRes, validEnd);
897 case ')': // Stem case for RNA secondary structure
899 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
900 startRes, column, validRes, validEnd);
957 // System.out.println(lastSS);
958 Color nonCanColor = getNotCanonicalColor(lastSS);
959 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
960 x, y, iconOffset, startRes, column, validRes, validEnd);
963 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
964 startRes, column, validRes, validEnd);
969 if (row.graph > 0 && row.graphHeight > 0)
971 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
973 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
975 // TODO: JAL-1291 revise rendering model so the graphGroup map is
976 // computed efficiently for all visible labels
977 float groupmax = -999999, groupmin = 9999999;
978 for (int gg = 0; gg < aa.length; gg++)
980 if (aa[gg].graphGroup != row.graphGroup)
987 aa[gg].visible = false;
989 if (aa[gg].graphMax > groupmax)
991 groupmax = aa[gg].graphMax;
993 if (aa[gg].graphMin < groupmin)
995 groupmin = aa[gg].graphMin;
999 for (int gg = 0; gg < aa.length; gg++)
1001 if (aa[gg].graphGroup == row.graphGroup)
1003 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1004 endRes, y, groupmin, groupmax, row.graphHeight);
1008 graphGroupDrawn.set(row.graphGroup);
1012 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1013 row.graphMin, row.graphMax, row.graphHeight);
1016 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1018 drawBarGraph(g, row, row_annotations, startRes, endRes,
1019 row.graphMin, row.graphMax, y, renderHistogram,
1020 renderProfile, normaliseProfile);
1026 if (clipst && !clipend)
1030 }// end if_in_visible_region
1031 if (row.graph > 0 && row.hasText)
1047 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1052 System.err.println("End clip at : " + yto + " (index " + f_to
1057 System.err.println("Annotation Rendering time:"
1058 + (System.currentTimeMillis() - stime));
1065 public static final Color GLYPHLINE_COLOR = Color.gray;
1067 public static final Color SHEET_COLOUR = Color.green;
1069 public static final Color HELIX_COLOUR = Color.red;
1071 public static final Color STEM_COLOUR = Color.blue;
1073 private Color sdNOTCANONICAL_COLOUR;
1075 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1076 int x, int y, int iconOffset, int startRes, int column,
1077 boolean validRes, boolean validEnd)
1079 g.setColor(GLYPHLINE_COLOR);
1080 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1083 public void drawSheetAnnot(Graphics g, Annotation[] row,
1085 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1086 boolean validRes, boolean validEnd)
1088 g.setColor(SHEET_COLOUR);
1090 if (!validEnd || !validRes || row == null || row[column] == null
1091 || row[column].secondaryStructure != 'E')
1093 g.fillRect(lastSSX, y + 4 + iconOffset,
1094 (x * charWidth) - lastSSX - 4, 7);
1095 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1096 (x * charWidth) }, new int[] { y + iconOffset,
1097 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1101 g.fillRect(lastSSX, y + 4 + iconOffset,
1102 (x + 1) * charWidth - lastSSX, 7);
1107 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1108 int x, int y, int iconOffset, int startRes, int column,
1109 boolean validRes, boolean validEnd)
1111 g.setColor(HELIX_COLOUR);
1113 int sCol = (lastSSX / charWidth) + startRes;
1115 int x2 = (x * charWidth);
1119 int ofs = charWidth / 2;
1120 // Off by 1 offset when drawing rects and ovals
1121 // to offscreen image on the MAC
1122 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1123 if (sCol == 0 || row[sCol - 1] == null
1124 || row[sCol - 1].secondaryStructure != 'H')
1129 // g.setColor(Color.orange);
1130 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1133 if (!validRes || row[column] == null
1134 || row[column].secondaryStructure != 'H')
1140 // g.setColor(Color.magenta);
1141 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1149 if (sCol == 0 || row[sCol - 1] == null
1150 || row[sCol - 1].secondaryStructure != 'H')
1152 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1153 x1 += charWidth / 2;
1156 if (!validRes || row[column] == null
1157 || row[column].secondaryStructure != 'H')
1159 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1161 x2 -= charWidth / 2;
1164 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1167 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1168 Annotation[] aa_annotations, int sRes, int eRes, int y,
1169 float min, float max, int graphHeight)
1171 if (sRes > aa_annotations.length)
1178 // Adjustment for fastpaint to left
1184 eRes = Math.min(eRes, aa_annotations.length);
1192 float range = max - min;
1197 y2 = y - (int) ((0 - min / range) * graphHeight);
1200 g.setColor(Color.gray);
1201 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1203 eRes = Math.min(eRes, aa_annotations.length);
1206 int aaMax = aa_annotations.length - 1;
1208 while (x < eRes - sRes)
1211 if (hasHiddenColumns)
1213 column = columnSelection.adjustForHiddenColumns(column);
1221 if (aa_annotations[column] == null
1222 || aa_annotations[column - 1] == null)
1228 if (aa_annotations[column].colour == null)
1230 g.setColor(Color.black);
1234 g.setColor(aa_annotations[column].colour);
1238 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1240 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1242 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1243 + charWidth / 2, y2);
1247 if (_aa.threshold != null)
1249 g.setColor(_aa.threshold.colour);
1250 Graphics2D g2 = (Graphics2D) g;
1251 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1252 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1254 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1255 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1256 g2.setStroke(new BasicStroke());
1260 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1261 Annotation[] aa_annotations, int sRes, int eRes, float min,
1262 float max, int y, boolean renderHistogram, boolean renderProfile,
1263 boolean normaliseProfile)
1265 if (sRes > aa_annotations.length)
1269 Font ofont = g.getFont();
1270 eRes = Math.min(eRes, aa_annotations.length);
1272 int x = 0, y1 = y, y2 = y;
1274 float range = max - min;
1278 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1281 g.setColor(Color.gray);
1283 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1286 int aaMax = aa_annotations.length - 1;
1287 while (x < eRes - sRes)
1290 if (hasHiddenColumns)
1292 column = columnSelection.adjustForHiddenColumns(column);
1300 if (aa_annotations[column] == null)
1305 if (aa_annotations[column].colour == null)
1307 g.setColor(Color.black);
1311 g.setColor(aa_annotations[column].colour);
1315 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1317 if (renderHistogram)
1321 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1325 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1328 // draw profile if available
1333 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1335 int profl[] = getProfileFor(_aa, column);
1337 // just try to draw the logo if profl is not null
1338 if (profl != null && profl[2] != 0)
1340 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1341 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1342 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1343 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1350 * Render a single base for a sequence profile, a base pair for
1351 * structure profile, and a triplet for a cdna profile
1353 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1355 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1356 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1357 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1361 * Traverse the character(s)/percentage data in the array
1364 int valuesProcessed = 0;
1365 // profl[1] is the number of values in the profile
1366 while (valuesProcessed < profl[1])
1368 if (isStructureProfile)
1370 // todo can we encode a structure pair as an int, like codons?
1371 dc[0] = (char) profl[c++];
1372 dc[1] = (char) profl[c++];
1374 else if (isCdnaProfile)
1376 dc = CodingUtils.decodeCodon(profl[c++]);
1380 dc[0] = (char) profl[c++];
1384 wdth /= fm.charsWidth(dc, 0, dc.length);
1387 // next profl[] position is profile % for the character(s)
1388 scl = htn * scale * profl[c++];
1389 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1390 .getFontRenderContext());
1391 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1392 wdth, scl / lm.getAscent())));
1393 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1395 // Debug - render boxes around characters
1396 // g.setColor(Color.red);
1397 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1399 // g.setColor(profcolour.findColour(dc[0]).darker());
1402 * Set character colour as per alignment colour scheme; use the
1403 * codon translation if a cDNA profile
1405 Color colour = null;
1408 final String codonTranslation = ResidueProperties
1409 .codonTranslate(new String(dc));
1410 colour = profcolour.findColour(codonTranslation.charAt(0),
1415 colour = profcolour.findColour(dc[0], column, null);
1417 g.setColor(colour == Color.white ? Color.lightGray : colour);
1419 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1420 .getBaselineIndex()]));
1422 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1430 if (_aa.threshold != null)
1432 g.setColor(_aa.threshold.colour);
1433 Graphics2D g2 = (Graphics2D) g;
1434 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1435 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1437 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1439 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1440 g2.setStroke(new BasicStroke());
1444 // used by overview window
1445 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1446 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1448 eRes = Math.min(eRes, aa_annotations.length);
1449 g.setColor(Color.white);
1450 g.fillRect(0, 0, width, y);
1451 g.setColor(new Color(0, 0, 180));
1455 for (int j = sRes; j < eRes; j++)
1457 if (aa_annotations[j] != null)
1459 if (aa_annotations[j].colour == null)
1461 g.setColor(Color.black);
1465 g.setColor(aa_annotations[j].colour);
1468 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1474 g.fillRect(x, y - height, charWidth, height);
1480 Color getNotCanonicalColor(char lastss)
1486 return new Color(255, 125, 5);
1490 return new Color(245, 115, 10);
1494 return new Color(235, 135, 15);
1498 return new Color(225, 105, 20);
1502 return new Color(215, 145, 30);
1506 return new Color(205, 95, 35);
1510 return new Color(195, 155, 45);
1514 return new Color(185, 85, 55);
1518 return new Color(175, 165, 65);
1522 return new Color(170, 75, 75);
1526 return new Color(160, 175, 85);
1530 return new Color(150, 65, 95);
1534 return new Color(140, 185, 105);
1538 return new Color(130, 55, 110);
1542 return new Color(120, 195, 120);
1546 return new Color(110, 45, 130);
1550 return new Color(100, 205, 140);
1554 return new Color(90, 35, 150);
1558 return new Color(85, 215, 160);
1562 return new Color(75, 25, 170);
1566 return new Color(65, 225, 180);
1570 return new Color(55, 15, 185);
1574 return new Color(45, 235, 195);
1578 return new Color(35, 5, 205);
1582 return new Color(25, 245, 215);
1586 return new Color(15, 0, 225);
1590 return new Color(10, 255, 235);
1594 return new Color(5, 150, 245);
1598 return new Color(0, 80, 255);
1601 System.out.println("This is not a interaction : " + lastss);