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.jsdev.RegExp;
31 import jalview.jsdev.api.RegExpInterface;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.NucleotideColourScheme;
34 import jalview.schemes.ResidueProperties;
35 import jalview.schemes.ZappoColourScheme;
36 import jalview.util.Platform;
38 import java.awt.BasicStroke;
39 import java.awt.Color;
41 import java.awt.FontMetrics;
42 import java.awt.Graphics;
43 import java.awt.Graphics2D;
44 import java.awt.Image;
45 import java.awt.font.LineMetrics;
46 import java.awt.geom.AffineTransform;
47 import java.awt.image.ImageObserver;
48 import java.util.BitSet;
49 import java.util.Hashtable;
51 //import com.stevesoft.pat.Regex;
53 public class AnnotationRenderer
56 * flag indicating if timing and redraw parameter info should be output
58 private final boolean debugRedraw;
60 public AnnotationRenderer()
66 * Create a new annotation Renderer
69 * flag indicating if timing and redraw parameter info should be
72 public AnnotationRenderer(boolean debugRedraw)
74 this.debugRedraw = debugRedraw;
77 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
78 int lastSSX, int x, int y, int iconOffset, int startRes,
79 int column, boolean validRes, boolean validEnd)
81 g.setColor(STEM_COLOUR);
82 int sCol = (lastSSX / charWidth) + startRes;
84 int x2 = (x * charWidth);
85 RegExpInterface closeparen = RegExp.newRegex("(\\))");
87 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
88 : row_annotations[column - 1].secondaryStructure;
90 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
91 || dc != row_annotations[sCol - 1].secondaryStructure;
92 boolean diffdownstream = !validRes || !validEnd
93 || row_annotations[column] == null
94 || dc != row_annotations[column].secondaryStructure;
95 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
96 // If a closing base pair half of the stem, display a backward arrow
97 if (column > 0 && ResidueProperties.isCloseParenRNA(dc))
101 // if (validRes && column>1 && row_annotations[column-2]!=null &&
102 // dc.equals(row_annotations[column-2].displayCharacter))
104 g.fillPolygon(new int[]
105 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
106 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
117 // display a forward arrow
120 g.fillPolygon(new int[]
121 { 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 = 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 RegExpInterface closeparen = RegExp.newRegex("}|]|<|[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[]
230 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
231 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
242 // display a forward arrow
245 g.fillPolygon(new int[]
246 { x2 - 5, x2 - 5, x2 }, new int[]
247 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
256 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
259 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
261 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
264 fm = annotPanel.getFontMetrics();
265 annotationPanel = annotPanel;
266 fadedImage = annotPanel.getFadedImage();
267 imgWidth = annotPanel.getFadedImageWidth();
268 // visible area for rendering
269 int[] bounds = annotPanel.getVisibleVRange();
273 visHeight = bounds[1];
288 updateFromAlignViewport(av);
291 public void updateFromAlignViewport(AlignViewportI av)
293 charWidth = av.getCharWidth();
294 endRes = av.getEndRes();
295 charHeight = av.getCharHeight();
296 hasHiddenColumns = av.hasHiddenColumns();
297 validCharWidth = av.isValidCharWidth();
298 av_renderHistogram = av.isShowConsensusHistogram();
299 av_renderProfile = av.isShowSequenceLogo();
300 av_normaliseProfile = av.isNormaliseSequenceLogo();
301 profcolour = av.getGlobalColourScheme();
302 if (profcolour == null)
304 // Set the default colour for sequence logo if the alignnent has no
306 profcolour = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
307 : new ZappoColourScheme();
309 columnSelection = av.getColumnSelection();
310 hconsensus = av.getSequenceConsensusHash();
311 complementConsensus = av.getComplementConsensusHash();
312 hStrucConsensus = av.getRnaStructureConsensusHash();
313 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
317 * Returns profile data; the first element is the profile type, the second is
318 * the number of distinct values, the third the total count, and the remainder
319 * depend on the profile type.
325 public int[] getProfileFor(AlignmentAnnotation aa, int column)
327 // TODO : consider refactoring the global alignment calculation
328 // properties/rendering attributes as a global 'alignment group' which holds
329 // all vis settings for the alignment as a whole rather than a subset
331 if (aa.autoCalculated
332 && (aa.label.startsWith("Consensus") || aa.label
333 .startsWith("cDNA Consensus")))
335 boolean forComplement = aa.label.startsWith("cDNA Consensus");
336 if (aa.groupRef != null && aa.groupRef.consensusData != null
337 && aa.groupRef.isShowSequenceLogo())
339 // TODO? group consensus for cDNA complement
340 return AAFrequency.extractProfile(
341 aa.groupRef.consensusData[column],
342 aa.groupRef.getIgnoreGapsConsensus());
344 // TODO extend annotation row to enable dynamic and static profile data to
346 if (aa.groupRef == null && aa.sequenceRef == null)
350 return AAFrequency.extractCdnaProfile(
351 complementConsensus[column], av_ignoreGapsConsensus);
355 return AAFrequency.extractProfile(hconsensus[column],
356 av_ignoreGapsConsensus);
362 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
364 // TODO implement group structure consensus
366 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
367 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
368 * group selections return StructureFrequency.extractProfile(
369 * aa.groupRef.consensusData[column], aa.groupRef
370 * .getIgnoreGapsConsensus()); }
372 // TODO extend annotation row to enable dynamic and static profile data
375 if (aa.groupRef == null && aa.sequenceRef == null
376 && hStrucConsensus != null
377 && hStrucConsensus.length > column)
379 return StructureFrequency.extractProfile(hStrucConsensus[column],
380 av_ignoreGapsConsensus);
390 * Render the annotation rows associated with an alignment.
395 * data and view settings to render
397 * destination for graphics
399 * row where a mouse event occured (or -1)
401 * first column that will be drawn
403 * last column that will be drawn
404 * @return true if the fadedImage was used for any alignment annotation rows
405 * currently being calculated
407 public boolean drawComponent(AwtRenderPanelI annotPanel,
408 AlignViewportI av, Graphics g, int activeRow, int startRes,
411 long stime = System.currentTimeMillis();
412 boolean usedFaded = false;
414 // AnnotationPanel needs to implement: ImageObserver, access to
416 updateFromAwtRenderPanel(annotPanel, av);
417 fm = g.getFontMetrics();
418 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
429 boolean validRes = false;
430 boolean validEnd = false;
431 boolean labelAllCols = false;
432 boolean centreColLabels;
433 boolean centreColLabelsDef = av.isCentreColumnLabels();
434 boolean scaleColLabel = false;
435 final AlignmentAnnotation consensusAnnot = av
436 .getAlignmentConsensusAnnotation();
437 final AlignmentAnnotation structConsensusAnnot = av
438 .getAlignmentStrucConsensusAnnotation();
439 final AlignmentAnnotation complementConsensusAnnot = av
440 .getComplementConsensusAnnotation();
441 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
443 BitSet graphGroupDrawn = new BitSet();
444 int charOffset = 0; // offset for a label
445 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
447 Font ofont = g.getFont();
450 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
451 boolean clipst = false, clipend = false;
452 for (int i = 0; i < aa.length; i++)
454 AlignmentAnnotation row = aa[i];
457 // check if this is a consensus annotation row and set the display
458 // settings appropriately
459 // TODO: generalise this to have render styles for consensus/profile
461 if (row.groupRef != null && row == row.groupRef.getConsensus())
463 renderHistogram = row.groupRef.isShowConsensusHistogram();
464 renderProfile = row.groupRef.isShowSequenceLogo();
465 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
467 else if (row == consensusAnnot || row == structConsensusAnnot
468 || row == complementConsensusAnnot)
470 renderHistogram = av_renderHistogram;
471 renderProfile = av_renderProfile;
472 normaliseProfile = av_normaliseProfile;
476 renderHistogram = true;
477 // don't need to set render/normaliseProfile since they are not
478 // currently used in any other annotation track renderer
481 Annotation[] row_annotations = row.annotations;
486 centreColLabels = row.centreColLabels || centreColLabelsDef;
487 labelAllCols = row.showAllColLabels;
488 scaleColLabel = row.scaleColLabel;
493 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
494 {// if_in_visible_region
505 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
510 // this is so that we draw the characters below the graph
515 iconOffset = charHeight - fm.getDescent();
519 else if (row.hasText)
521 iconOffset = charHeight - fm.getDescent();
529 if (row.autoCalculated && av.isCalculationInProgress(row))
533 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
534 - row.height, imgWidth, y, annotationPanel);
535 g.setColor(Color.black);
536 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
542 * else if (annotationPanel.av.updatingConservation &&
543 * aa[i].label.equals("Conservation")) {
545 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
546 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
547 * annotationPanel.imgWidth, y, annotationPanel);
549 * g.setColor(Color.black); //
550 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
552 * continue; } else if (annotationPanel.av.updatingConservation &&
553 * aa[i].label.equals("Quality")) {
555 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
556 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
557 * annotationPanel.imgWidth, y, annotationPanel);
558 * g.setColor(Color.black); // /
559 * g.drawString("Calculating Quality....",20, y-row.height/2);
563 // first pass sets up state for drawing continuation from left-hand
566 x = (startRes == 0) ? 0 : -1;
567 while (x < endRes - startRes)
569 if (hasHiddenColumns)
571 column = columnSelection.adjustForHiddenColumns(startRes + x);
572 if (column > row_annotations.length - 1)
579 column = startRes + x;
582 if ((row_annotations == null)
583 || (row_annotations.length <= column)
584 || (row_annotations[column] == null))
592 final String displayChar = validRes ? row_annotations[column].displayCharacter
598 g.setColor(Color.red);
600 if (columnSelection != null)
602 for (int n = 0; n < columnSelection.size(); n++)
604 int v = columnSelection.columnAt(n);
608 g.fillRect(x * charWidth, y, charWidth, charHeight);
613 if (row.getInvalidStrucPos() > x)
615 g.setColor(Color.orange);
616 g.fillRect(x * charWidth, y, charWidth, charHeight);
618 else if (row.getInvalidStrucPos() == x)
620 g.setColor(Color.orange.darker());
621 g.fillRect(x * charWidth, y, charWidth, charHeight);
623 if (validCharWidth && validRes && displayChar != null
624 && (displayChar.length() > 0))
627 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
628 displayChar.length());
629 if (/* centreColLabels || */scaleColLabel)
631 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
632 // displayChar.length());
634 // if (scaleColLabel)
636 // justify the label and scale to fit in column
637 if (fmWidth > charWidth)
639 // scale only if the current font isn't already small enough
640 fmScaling = charWidth;
641 fmScaling /= fmWidth;
642 g.setFont(ofont.deriveFont(AffineTransform
643 .getScaleInstance(fmScaling, 1.0)));
644 // and update the label's width to reflect the scaling.
649 // TODO is it ok to use width of / show all characters here?
652 // fmWidth = fm.charWidth(displayChar.charAt(0));
654 charOffset = (int) ((charWidth - fmWidth) / 2f);
656 if (row_annotations[column].colour == null)
658 g.setColor(Color.black);
662 g.setColor(row_annotations[column].colour);
665 if (column == 0 || row.graph > 0)
667 g.drawString(displayChar, (x * charWidth) + charOffset, y
670 else if (row_annotations[column - 1] == null
673 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
674 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
676 g.drawString(displayChar, x * charWidth + charOffset, y
684 char ss = validRes ? row_annotations[column].secondaryStructure
689 // distinguish between forward/backward base-pairing
690 if (displayChar.indexOf(')') > -1)
699 if ((displayChar.indexOf(']') > -1))
707 // distinguish between forward/backward base-pairing
708 if (displayChar.indexOf('}') > -1)
716 // distinguish between forward/backward base-pairing
717 if (displayChar.indexOf('<') > -1)
725 // distinguish between forward/backward base-pairing
726 if (displayChar.indexOf(ss + 32) > -1)
729 ss = (char) (ss + 32);
734 if (!validRes || (ss != lastSS))
740 int nb_annot = x - temp;
741 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
744 case '(': // Stem case for RNA secondary structure
745 case ')': // and opposite direction
746 drawStemAnnot(g, row_annotations, lastSSX, x, y,
747 iconOffset, startRes, column, validRes, validEnd);
754 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
755 iconOffset, startRes, column, validRes,
763 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
764 iconOffset, startRes, column, validRes,
826 Color nonCanColor = getNotCanonicalColor(lastSS);
827 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
828 lastSSX, x, y, iconOffset, startRes, column,
833 g.setColor(Color.gray);
834 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
850 lastSSX = (x * charWidth);
857 if (column >= row_annotations.length)
859 column = row_annotations.length - 1;
866 if ((row_annotations == null) || (row_annotations.length <= column)
867 || (row_annotations[column] == null))
886 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
887 startRes, column, validRes, validEnd);
894 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
895 startRes, column, validRes, validEnd);
900 case ')': // Stem case for RNA secondary structure
902 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
903 startRes, column, validRes, validEnd);
960 // System.out.println(lastSS);
961 Color nonCanColor = getNotCanonicalColor(lastSS);
962 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
963 x, y, iconOffset, startRes, column, validRes, validEnd);
966 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
967 startRes, column, validRes, validEnd);
972 if (row.graph > 0 && row.graphHeight > 0)
974 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
976 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
978 // TODO: JAL-1291 revise rendering model so the graphGroup map is
979 // computed efficiently for all visible labels
980 float groupmax = -999999, groupmin = 9999999;
981 for (int gg = 0; gg < aa.length; gg++)
983 if (aa[gg].graphGroup != row.graphGroup)
990 aa[gg].visible = false;
992 if (aa[gg].graphMax > groupmax)
994 groupmax = aa[gg].graphMax;
996 if (aa[gg].graphMin < groupmin)
998 groupmin = aa[gg].graphMin;
1002 for (int gg = 0; gg < aa.length; gg++)
1004 if (aa[gg].graphGroup == row.graphGroup)
1006 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1007 endRes, y, groupmin, groupmax, row.graphHeight);
1011 graphGroupDrawn.set(row.graphGroup);
1015 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1016 row.graphMin, row.graphMax, row.graphHeight);
1019 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1021 drawBarGraph(g, row, row_annotations, startRes, endRes,
1022 row.graphMin, row.graphMax, y, renderHistogram,
1023 renderProfile, normaliseProfile);
1029 if (clipst && !clipend)
1033 }// end if_in_visible_region
1034 if (row.graph > 0 && row.hasText)
1050 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1055 System.err.println("End clip at : " + yto + " (index " + f_to
1060 System.err.println("Annotation Rendering time:"
1061 + (System.currentTimeMillis() - stime));
1068 public static final Color GLYPHLINE_COLOR = Color.gray;
1070 public static final Color SHEET_COLOUR = Color.green;
1072 public static final Color HELIX_COLOUR = Color.red;
1074 public static final Color STEM_COLOUR = Color.blue;
1076 private Color sdNOTCANONICAL_COLOUR;
1078 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1079 int x, int y, int iconOffset, int startRes, int column,
1080 boolean validRes, boolean validEnd)
1082 g.setColor(GLYPHLINE_COLOR);
1083 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1086 public void drawSheetAnnot(Graphics g, Annotation[] row,
1088 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1089 boolean validRes, boolean validEnd)
1091 g.setColor(SHEET_COLOUR);
1093 if (!validEnd || !validRes || row == null || row[column] == null
1094 || row[column].secondaryStructure != 'E')
1096 g.fillRect(lastSSX, y + 4 + iconOffset,
1097 (x * charWidth) - lastSSX - 4, 7);
1098 g.fillPolygon(new int[]
1099 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1101 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1106 g.fillRect(lastSSX, y + 4 + iconOffset,
1107 (x + 1) * charWidth - lastSSX, 7);
1112 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1113 int x, int y, int iconOffset, int startRes, int column,
1114 boolean validRes, boolean validEnd)
1116 g.setColor(HELIX_COLOUR);
1118 int sCol = (lastSSX / charWidth) + startRes;
1120 int x2 = (x * charWidth);
1124 int ofs = charWidth / 2;
1125 // Off by 1 offset when drawing rects and ovals
1126 // to offscreen image on the MAC
1127 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1128 if (sCol == 0 || row[sCol - 1] == null
1129 || row[sCol - 1].secondaryStructure != 'H')
1134 // g.setColor(Color.orange);
1135 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1138 if (!validRes || row[column] == null
1139 || row[column].secondaryStructure != 'H')
1145 // g.setColor(Color.magenta);
1146 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1154 if (sCol == 0 || row[sCol - 1] == null
1155 || row[sCol - 1].secondaryStructure != 'H')
1157 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1158 x1 += charWidth / 2;
1161 if (!validRes || row[column] == null
1162 || row[column].secondaryStructure != 'H')
1164 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1166 x2 -= charWidth / 2;
1169 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1172 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1173 Annotation[] aa_annotations, int sRes, int eRes, int y,
1174 float min, float max, int graphHeight)
1176 if (sRes > aa_annotations.length)
1183 // Adjustment for fastpaint to left
1189 eRes = Math.min(eRes, aa_annotations.length);
1197 float range = max - min;
1202 y2 = y - (int) ((0 - min / range) * graphHeight);
1205 g.setColor(Color.gray);
1206 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1208 eRes = Math.min(eRes, aa_annotations.length);
1211 int aaMax = aa_annotations.length - 1;
1213 while (x < eRes - sRes)
1216 if (hasHiddenColumns)
1218 column = columnSelection.adjustForHiddenColumns(column);
1226 if (aa_annotations[column] == null
1227 || aa_annotations[column - 1] == null)
1233 if (aa_annotations[column].colour == null)
1235 g.setColor(Color.black);
1239 g.setColor(aa_annotations[column].colour);
1243 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1245 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1247 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1248 + charWidth / 2, y2);
1252 if (_aa.threshold != null)
1254 g.setColor(_aa.threshold.colour);
1255 Graphics2D g2 = (Graphics2D) g;
1256 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1257 BasicStroke.JOIN_ROUND, 3f, new float[]
1260 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1261 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1262 g2.setStroke(new BasicStroke());
1266 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1267 Annotation[] aa_annotations, int sRes, int eRes, float min,
1268 float max, int y, boolean renderHistogram, boolean renderProfile,
1269 boolean normaliseProfile)
1271 if (sRes > aa_annotations.length)
1275 Font ofont = g.getFont();
1276 eRes = Math.min(eRes, aa_annotations.length);
1278 int x = 0, y1 = y, y2 = y;
1280 float range = max - min;
1284 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1287 g.setColor(Color.gray);
1289 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1292 int aaMax = aa_annotations.length - 1;
1293 while (x < eRes - sRes)
1296 if (hasHiddenColumns)
1298 column = columnSelection.adjustForHiddenColumns(column);
1306 if (aa_annotations[column] == null)
1311 if (aa_annotations[column].colour == null)
1313 g.setColor(Color.black);
1317 g.setColor(aa_annotations[column].colour);
1321 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1323 if (renderHistogram)
1327 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1331 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1334 // draw profile if available
1339 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1341 int profl[] = getProfileFor(_aa, column);
1343 // just try to draw the logo if profl is not null
1344 if (profl != null && profl[2] != 0)
1346 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1347 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1348 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1349 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1356 * Render a single base for a sequence profile, a base pair for
1357 * structure profile, and a triplet for a cdna profile
1359 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1361 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1362 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1363 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1367 * Traverse the character(s)/percentage data in the array
1370 int valuesProcessed = 0;
1371 // profl[1] is the number of values in the profile
1372 while (valuesProcessed < profl[1])
1374 if (isStructureProfile)
1376 // todo can we encode a structure pair as an int, like codons?
1377 dc[0] = (char) profl[c++];
1378 dc[1] = (char) profl[c++];
1380 else if (isCdnaProfile)
1382 dc = CodingUtils.decodeCodon(profl[c++]);
1386 dc[0] = (char) profl[c++];
1390 wdth /= fm.charsWidth(dc, 0, dc.length);
1393 // next profl[] position is profile % for the character(s)
1394 scl = htn * scale * profl[c++];
1395 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1396 .getFontRenderContext());
1397 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1398 wdth, scl / lm.getAscent())));
1399 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1401 // Debug - render boxes around characters
1402 // g.setColor(Color.red);
1403 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1405 // g.setColor(profcolour.findColour(dc[0]).darker());
1408 * Set character colour as per alignment colour scheme; use the
1409 * codon translation if a cDNA profile
1411 Color colour = null;
1414 final String codonTranslation = ResidueProperties
1415 .codonTranslate(new String(dc));
1416 colour = profcolour.findColour(codonTranslation.charAt(0),
1421 colour = profcolour.findColour(dc[0], column, null);
1423 g.setColor(colour == Color.white ? Color.lightGray : colour);
1425 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1426 .getBaselineIndex()]));
1428 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1436 if (_aa.threshold != null)
1438 g.setColor(_aa.threshold.colour);
1439 Graphics2D g2 = (Graphics2D) g;
1440 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1441 BasicStroke.JOIN_ROUND, 3f, new float[]
1444 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1446 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1447 g2.setStroke(new BasicStroke());
1451 // used by overview window
1452 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1453 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1455 eRes = Math.min(eRes, aa_annotations.length);
1456 g.setColor(Color.white);
1457 g.fillRect(0, 0, width, y);
1458 g.setColor(new Color(0, 0, 180));
1462 for (int j = sRes; j < eRes; j++)
1464 if (aa_annotations[j] != null)
1466 if (aa_annotations[j].colour == null)
1468 g.setColor(Color.black);
1472 g.setColor(aa_annotations[j].colour);
1475 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1481 g.fillRect(x, y - height, charWidth, height);
1487 Color getNotCanonicalColor(char lastss)
1493 return new Color(255, 125, 5);
1497 return new Color(245, 115, 10);
1501 return new Color(235, 135, 15);
1505 return new Color(225, 105, 20);
1509 return new Color(215, 145, 30);
1513 return new Color(205, 95, 35);
1517 return new Color(195, 155, 45);
1521 return new Color(185, 85, 55);
1525 return new Color(175, 165, 65);
1529 return new Color(170, 75, 75);
1533 return new Color(160, 175, 85);
1537 return new Color(150, 65, 95);
1541 return new Color(140, 185, 105);
1545 return new Color(130, 55, 110);
1549 return new Color(120, 195, 120);
1553 return new Color(110, 45, 130);
1557 return new Color(100, 205, 140);
1561 return new Color(90, 35, 150);
1565 return new Color(85, 215, 160);
1569 return new Color(75, 25, 170);
1573 return new Color(65, 225, 180);
1577 return new Color(55, 15, 185);
1581 return new Color(45, 235, 195);
1585 return new Color(35, 5, 205);
1589 return new Color(25, 245, 215);
1593 return new Color(15, 0, 225);
1597 return new Color(10, 255, 235);
1601 return new Color(5, 150, 245);
1605 return new Color(0, 80, 255);
1608 System.out.println("This is not a interaction : " + lastss);