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.NucleotideColourScheme;
32 import jalview.schemes.ResidueProperties;
33 import jalview.schemes.ZappoColourScheme;
34 import jalview.util.Platform;
36 import java.awt.BasicStroke;
37 import java.awt.Color;
39 import java.awt.FontMetrics;
40 import java.awt.Graphics;
41 import java.awt.Graphics2D;
42 import java.awt.Image;
43 import java.awt.font.LineMetrics;
44 import java.awt.geom.AffineTransform;
45 import java.awt.image.ImageObserver;
46 import java.util.BitSet;
47 import java.util.Hashtable;
49 import com.stevesoft.pat.Regex;
51 public class AnnotationRenderer
54 * flag indicating if timing and redraw parameter info should be output
56 private final boolean debugRedraw;
58 public AnnotationRenderer()
64 * Create a new annotation Renderer
67 * flag indicating if timing and redraw parameter info should be
70 public AnnotationRenderer(boolean debugRedraw)
72 this.debugRedraw = debugRedraw;
75 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
76 int lastSSX, int x, int y, int iconOffset, int startRes,
77 int column, boolean validRes, boolean validEnd)
79 g.setColor(STEM_COLOUR);
80 int sCol = (lastSSX / charWidth) + startRes;
82 int x2 = (x * charWidth);
83 Regex closeparen = new Regex("(\\))");
85 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
86 : row_annotations[column - 1].secondaryStructure;
88 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
89 || dc != row_annotations[sCol - 1].secondaryStructure;
90 boolean diffdownstream = !validRes || !validEnd
91 || row_annotations[column] == null
92 || dc != row_annotations[column].secondaryStructure;
93 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
94 // If a closing base pair half of the stem, display a backward arrow
95 if (column > 0 && ResidueProperties.isCloseParenRNA(dc))
99 // if (validRes && column>1 && row_annotations[column-2]!=null &&
100 // dc.equals(row_annotations[column-2].displayCharacter))
102 g.fillPolygon(new int[]
103 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
104 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
115 // display a forward arrow
118 g.fillPolygon(new int[]
119 { x2 - 5, x2 - 5, x2 }, new int[]
120 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
129 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
132 private int charWidth, endRes, charHeight;
134 private boolean validCharWidth, hasHiddenColumns;
136 private FontMetrics fm;
138 private final boolean MAC = Platform.isAMac();
140 boolean av_renderHistogram = true, av_renderProfile = true,
141 av_normaliseProfile = false;
143 ColourSchemeI profcolour = null;
145 private ColumnSelection columnSelection;
147 private Hashtable[] hconsensus;
149 private Hashtable[] complementConsensus;
151 private Hashtable[] hStrucConsensus;
153 private boolean av_ignoreGapsConsensus;
156 * attributes set from AwtRenderPanelI
159 * old image used when data is currently being calculated and cannot be
162 private Image fadedImage;
165 * panel being rendered into
167 private ImageObserver annotationPanel;
170 * width of image to render in panel
172 private int imgWidth;
175 * offset to beginning of visible area
180 * offset to end of visible area
182 private int visHeight;
185 * indicate if the renderer should only render the visible portion of the
186 * annotation given the current view settings
188 private boolean useClip = true;
191 * master flag indicating if renderer should ever try to clip. not enabled for
194 private boolean canClip = false;
196 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
197 Annotation[] row_annotations, int lastSSX, int x, int y,
198 int iconOffset, int startRes, int column, boolean validRes,
201 // System.out.println(nonCanColor);
203 g.setColor(nonCanColor);
204 int sCol = (lastSSX / charWidth) + startRes;
206 int x2 = (x * charWidth);
207 Regex closeparen = new Regex("}|]|<|[a-z]");
209 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
210 : row_annotations[column - 1].displayCharacter;
212 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
213 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
214 boolean diffdownstream = !validRes || !validEnd
215 || row_annotations[column] == null
216 || !dc.equals(row_annotations[column].displayCharacter);
217 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
218 // If a closing base pair half of the stem, display a backward arrow
219 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
224 // if (validRes && column>1 && row_annotations[column-2]!=null &&
225 // dc.equals(row_annotations[column-2].displayCharacter))
227 g.fillPolygon(new int[]
228 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
229 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
240 // display a forward arrow
243 g.fillPolygon(new int[]
244 { x2 - 5, x2 - 5, x2 }, new int[]
245 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
254 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
257 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
259 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
262 fm = annotPanel.getFontMetrics();
263 annotationPanel = annotPanel;
264 fadedImage = annotPanel.getFadedImage();
265 imgWidth = annotPanel.getFadedImageWidth();
266 // visible area for rendering
267 int[] bounds = annotPanel.getVisibleVRange();
271 visHeight = bounds[1];
286 updateFromAlignViewport(av);
289 public void updateFromAlignViewport(AlignViewportI av)
291 charWidth = av.getCharWidth();
292 endRes = av.getEndRes();
293 charHeight = av.getCharHeight();
294 hasHiddenColumns = av.hasHiddenColumns();
295 validCharWidth = av.isValidCharWidth();
296 av_renderHistogram = av.isShowConsensusHistogram();
297 av_renderProfile = av.isShowSequenceLogo();
298 av_normaliseProfile = av.isNormaliseSequenceLogo();
299 profcolour = av.getGlobalColourScheme();
300 if (profcolour == null)
302 // Set the default colour for sequence logo if the alignnent has no
304 profcolour = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
305 : new ZappoColourScheme();
307 columnSelection = av.getColumnSelection();
308 hconsensus = av.getSequenceConsensusHash();
309 complementConsensus = av.getComplementConsensusHash();
310 hStrucConsensus = av.getRnaStructureConsensusHash();
311 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
315 * Returns profile data; the first element is the profile type, the second is
316 * the number of distinct values, the third the total count, and the remainder
317 * depend on the profile type.
323 public int[] getProfileFor(AlignmentAnnotation aa, int column)
325 // TODO : consider refactoring the global alignment calculation
326 // properties/rendering attributes as a global 'alignment group' which holds
327 // all vis settings for the alignment as a whole rather than a subset
329 if (aa.autoCalculated
330 && (aa.label.startsWith("Consensus") || aa.label
331 .startsWith("cDNA Consensus")))
333 boolean forComplement = aa.label.startsWith("cDNA Consensus");
334 if (aa.groupRef != null && aa.groupRef.consensusData != null
335 && aa.groupRef.isShowSequenceLogo())
337 // TODO? group consensus for cDNA complement
338 return AAFrequency.extractProfile(
339 aa.groupRef.consensusData[column],
340 aa.groupRef.getIgnoreGapsConsensus());
342 // TODO extend annotation row to enable dynamic and static profile data to
344 if (aa.groupRef == null && aa.sequenceRef == null)
348 return AAFrequency.extractCdnaProfile(
349 complementConsensus[column], av_ignoreGapsConsensus);
353 return AAFrequency.extractProfile(hconsensus[column],
354 av_ignoreGapsConsensus);
360 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
362 // TODO implement group structure consensus
364 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
365 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
366 * group selections return StructureFrequency.extractProfile(
367 * aa.groupRef.consensusData[column], aa.groupRef
368 * .getIgnoreGapsConsensus()); }
370 // TODO extend annotation row to enable dynamic and static profile data
373 if (aa.groupRef == null && aa.sequenceRef == null
374 && hStrucConsensus != null
375 && hStrucConsensus.length > column)
377 return StructureFrequency.extractProfile(hStrucConsensus[column],
378 av_ignoreGapsConsensus);
388 * Render the annotation rows associated with an alignment.
393 * data and view settings to render
395 * destination for graphics
397 * row where a mouse event occured (or -1)
399 * first column that will be drawn
401 * last column that will be drawn
402 * @return true if the fadedImage was used for any alignment annotation rows
403 * currently being calculated
405 public boolean drawComponent(AwtRenderPanelI annotPanel,
406 AlignViewportI av, Graphics g, int activeRow, int startRes,
409 long stime = System.currentTimeMillis();
410 boolean usedFaded = false;
412 // AnnotationPanel needs to implement: ImageObserver, access to
414 updateFromAwtRenderPanel(annotPanel, av);
415 fm = g.getFontMetrics();
416 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
427 boolean validRes = false;
428 boolean validEnd = false;
429 boolean labelAllCols = false;
430 boolean centreColLabels;
431 boolean centreColLabelsDef = av.isCentreColumnLabels();
432 boolean scaleColLabel = false;
433 final AlignmentAnnotation consensusAnnot = av
434 .getAlignmentConsensusAnnotation();
435 final AlignmentAnnotation structConsensusAnnot = av
436 .getAlignmentStrucConsensusAnnotation();
437 final AlignmentAnnotation complementConsensusAnnot = av
438 .getComplementConsensusAnnotation();
439 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
441 BitSet graphGroupDrawn = new BitSet();
442 int charOffset = 0; // offset for a label
443 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
445 Font ofont = g.getFont();
448 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
449 boolean clipst = false, clipend = false;
450 for (int i = 0; i < aa.length; i++)
452 AlignmentAnnotation row = aa[i];
455 // check if this is a consensus annotation row and set the display
456 // settings appropriately
457 // TODO: generalise this to have render styles for consensus/profile
459 if (row.groupRef != null && row == row.groupRef.getConsensus())
461 renderHistogram = row.groupRef.isShowConsensusHistogram();
462 renderProfile = row.groupRef.isShowSequenceLogo();
463 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
465 else if (row == consensusAnnot || row == structConsensusAnnot
466 || row == complementConsensusAnnot)
468 renderHistogram = av_renderHistogram;
469 renderProfile = av_renderProfile;
470 normaliseProfile = av_normaliseProfile;
474 renderHistogram = true;
475 // don't need to set render/normaliseProfile since they are not
476 // currently used in any other annotation track renderer
479 Annotation[] row_annotations = row.annotations;
484 centreColLabels = row.centreColLabels || centreColLabelsDef;
485 labelAllCols = row.showAllColLabels;
486 scaleColLabel = row.scaleColLabel;
491 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
492 {// if_in_visible_region
503 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
508 // this is so that we draw the characters below the graph
513 iconOffset = charHeight - fm.getDescent();
517 else if (row.hasText)
519 iconOffset = charHeight - fm.getDescent();
527 if (row.autoCalculated && av.isCalculationInProgress(row))
531 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
532 - row.height, imgWidth, y, annotationPanel);
533 g.setColor(Color.black);
534 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
540 * else if (annotationPanel.av.updatingConservation &&
541 * aa[i].label.equals("Conservation")) {
543 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
544 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
545 * annotationPanel.imgWidth, y, annotationPanel);
547 * g.setColor(Color.black); //
548 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
550 * continue; } else if (annotationPanel.av.updatingConservation &&
551 * aa[i].label.equals("Quality")) {
553 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
554 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
555 * annotationPanel.imgWidth, y, annotationPanel);
556 * g.setColor(Color.black); // /
557 * g.drawString("Calculating Quality....",20, y-row.height/2);
561 // first pass sets up state for drawing continuation from left-hand
564 x = (startRes == 0) ? 0 : -1;
565 while (x < endRes - startRes)
567 if (hasHiddenColumns)
569 column = columnSelection.adjustForHiddenColumns(startRes + x);
570 if (column > row_annotations.length - 1)
577 column = startRes + x;
580 if ((row_annotations == null)
581 || (row_annotations.length <= column)
582 || (row_annotations[column] == null))
590 final String displayChar = validRes ? row_annotations[column].displayCharacter
596 g.setColor(Color.red);
598 if (columnSelection != null)
600 for (int n = 0; n < columnSelection.size(); n++)
602 int v = columnSelection.columnAt(n);
606 g.fillRect(x * charWidth, y, charWidth, charHeight);
611 if (row.getInvalidStrucPos() > x)
613 g.setColor(Color.orange);
614 g.fillRect(x * charWidth, y, charWidth, charHeight);
616 else if (row.getInvalidStrucPos() == x)
618 g.setColor(Color.orange.darker());
619 g.fillRect(x * charWidth, y, charWidth, charHeight);
621 if (validCharWidth && validRes && displayChar != null
622 && (displayChar.length() > 0))
625 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
626 displayChar.length());
627 if (/* centreColLabels || */scaleColLabel)
629 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
630 // displayChar.length());
632 // if (scaleColLabel)
634 // justify the label and scale to fit in column
635 if (fmWidth > charWidth)
637 // scale only if the current font isn't already small enough
638 fmScaling = charWidth;
639 fmScaling /= fmWidth;
640 g.setFont(ofont.deriveFont(AffineTransform
641 .getScaleInstance(fmScaling, 1.0)));
642 // and update the label's width to reflect the scaling.
647 // TODO is it ok to use width of / show all characters here?
650 // fmWidth = fm.charWidth(displayChar.charAt(0));
652 charOffset = (int) ((charWidth - fmWidth) / 2f);
654 if (row_annotations[column].colour == null)
656 g.setColor(Color.black);
660 g.setColor(row_annotations[column].colour);
663 if (column == 0 || row.graph > 0)
665 g.drawString(displayChar, (x * charWidth) + charOffset, y
668 else if (row_annotations[column - 1] == null
671 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
672 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
674 g.drawString(displayChar, x * charWidth + charOffset, y
682 char ss = validRes ? row_annotations[column].secondaryStructure
687 // distinguish between forward/backward base-pairing
688 if (displayChar.indexOf(')') > -1)
697 if ((displayChar.indexOf(']') > -1))
705 // distinguish between forward/backward base-pairing
706 if (displayChar.indexOf('}') > -1)
714 // distinguish between forward/backward base-pairing
715 if (displayChar.indexOf('<') > -1)
723 // distinguish between forward/backward base-pairing
724 if (displayChar.indexOf(ss + 32) > -1)
727 ss = (char) (ss + 32);
732 if (!validRes || (ss != lastSS))
738 int nb_annot = x - temp;
739 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
742 case '(': // Stem case for RNA secondary structure
743 case ')': // and opposite direction
744 drawStemAnnot(g, row_annotations, lastSSX, x, y,
745 iconOffset, startRes, column, validRes, validEnd);
752 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
753 iconOffset, startRes, column, validRes,
761 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
762 iconOffset, startRes, column, validRes,
824 Color nonCanColor = getNotCanonicalColor(lastSS);
825 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
826 lastSSX, x, y, iconOffset, startRes, column,
831 g.setColor(Color.gray);
832 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
848 lastSSX = (x * charWidth);
855 if (column >= row_annotations.length)
857 column = row_annotations.length - 1;
864 if ((row_annotations == null) || (row_annotations.length <= column)
865 || (row_annotations[column] == null))
884 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
885 startRes, column, validRes, validEnd);
892 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
893 startRes, column, validRes, validEnd);
898 case ')': // Stem case for RNA secondary structure
900 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
901 startRes, column, validRes, validEnd);
958 // System.out.println(lastSS);
959 Color nonCanColor = getNotCanonicalColor(lastSS);
960 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
961 x, y, iconOffset, startRes, column, validRes, validEnd);
964 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
965 startRes, column, validRes, validEnd);
970 if (row.graph > 0 && row.graphHeight > 0)
972 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
974 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
976 // TODO: JAL-1291 revise rendering model so the graphGroup map is
977 // computed efficiently for all visible labels
978 float groupmax = -999999, groupmin = 9999999;
979 for (int gg = 0; gg < aa.length; gg++)
981 if (aa[gg].graphGroup != row.graphGroup)
988 aa[gg].visible = false;
990 if (aa[gg].graphMax > groupmax)
992 groupmax = aa[gg].graphMax;
994 if (aa[gg].graphMin < groupmin)
996 groupmin = aa[gg].graphMin;
1000 for (int gg = 0; gg < aa.length; gg++)
1002 if (aa[gg].graphGroup == row.graphGroup)
1004 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1005 endRes, y, groupmin, groupmax, row.graphHeight);
1009 graphGroupDrawn.set(row.graphGroup);
1013 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1014 row.graphMin, row.graphMax, row.graphHeight);
1017 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1019 drawBarGraph(g, row, row_annotations, startRes, endRes,
1020 row.graphMin, row.graphMax, y, renderHistogram,
1021 renderProfile, normaliseProfile);
1027 if (clipst && !clipend)
1031 }// end if_in_visible_region
1032 if (row.graph > 0 && row.hasText)
1048 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1053 System.err.println("End clip at : " + yto + " (index " + f_to
1058 System.err.println("Annotation Rendering time:"
1059 + (System.currentTimeMillis() - stime));
1066 public static final Color GLYPHLINE_COLOR = Color.gray;
1068 public static final Color SHEET_COLOUR = Color.green;
1070 public static final Color HELIX_COLOUR = Color.red;
1072 public static final Color STEM_COLOUR = Color.blue;
1074 private Color sdNOTCANONICAL_COLOUR;
1076 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1077 int x, int y, int iconOffset, int startRes, int column,
1078 boolean validRes, boolean validEnd)
1080 g.setColor(GLYPHLINE_COLOR);
1081 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1084 public void drawSheetAnnot(Graphics g, Annotation[] row,
1086 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1087 boolean validRes, boolean validEnd)
1089 g.setColor(SHEET_COLOUR);
1091 if (!validEnd || !validRes || row == null || row[column] == null
1092 || row[column].secondaryStructure != 'E')
1094 g.fillRect(lastSSX, y + 4 + iconOffset,
1095 (x * charWidth) - lastSSX - 4, 7);
1096 g.fillPolygon(new int[]
1097 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1099 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1104 g.fillRect(lastSSX, y + 4 + iconOffset,
1105 (x + 1) * charWidth - lastSSX, 7);
1110 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1111 int x, int y, int iconOffset, int startRes, int column,
1112 boolean validRes, boolean validEnd)
1114 g.setColor(HELIX_COLOUR);
1116 int sCol = (lastSSX / charWidth) + startRes;
1118 int x2 = (x * charWidth);
1122 int ofs = charWidth / 2;
1123 // Off by 1 offset when drawing rects and ovals
1124 // to offscreen image on the MAC
1125 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1126 if (sCol == 0 || row[sCol - 1] == null
1127 || row[sCol - 1].secondaryStructure != 'H')
1132 // g.setColor(Color.orange);
1133 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1136 if (!validRes || row[column] == null
1137 || row[column].secondaryStructure != 'H')
1143 // g.setColor(Color.magenta);
1144 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1152 if (sCol == 0 || row[sCol - 1] == null
1153 || row[sCol - 1].secondaryStructure != 'H')
1155 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1156 x1 += charWidth / 2;
1159 if (!validRes || row[column] == null
1160 || row[column].secondaryStructure != 'H')
1162 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1164 x2 -= charWidth / 2;
1167 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1170 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1171 Annotation[] aa_annotations, int sRes, int eRes, int y,
1172 float min, float max, int graphHeight)
1174 if (sRes > aa_annotations.length)
1181 // Adjustment for fastpaint to left
1187 eRes = Math.min(eRes, aa_annotations.length);
1195 float range = max - min;
1200 y2 = y - (int) ((0 - min / range) * graphHeight);
1203 g.setColor(Color.gray);
1204 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1206 eRes = Math.min(eRes, aa_annotations.length);
1209 int aaMax = aa_annotations.length - 1;
1211 while (x < eRes - sRes)
1214 if (hasHiddenColumns)
1216 column = columnSelection.adjustForHiddenColumns(column);
1224 if (aa_annotations[column] == null
1225 || aa_annotations[column - 1] == null)
1231 if (aa_annotations[column].colour == null)
1233 g.setColor(Color.black);
1237 g.setColor(aa_annotations[column].colour);
1241 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1243 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1245 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1246 + charWidth / 2, y2);
1250 if (_aa.threshold != null)
1252 g.setColor(_aa.threshold.colour);
1253 Graphics2D g2 = (Graphics2D) g;
1254 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1255 BasicStroke.JOIN_ROUND, 3f, new float[]
1258 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1259 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1260 g2.setStroke(new BasicStroke());
1264 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1265 Annotation[] aa_annotations, int sRes, int eRes, float min,
1266 float max, int y, boolean renderHistogram, boolean renderProfile,
1267 boolean normaliseProfile)
1269 if (sRes > aa_annotations.length)
1273 Font ofont = g.getFont();
1274 eRes = Math.min(eRes, aa_annotations.length);
1276 int x = 0, y1 = y, y2 = y;
1278 float range = max - min;
1282 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1285 g.setColor(Color.gray);
1287 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1290 int aaMax = aa_annotations.length - 1;
1291 while (x < eRes - sRes)
1294 if (hasHiddenColumns)
1296 column = columnSelection.adjustForHiddenColumns(column);
1304 if (aa_annotations[column] == null)
1309 if (aa_annotations[column].colour == null)
1311 g.setColor(Color.black);
1315 g.setColor(aa_annotations[column].colour);
1319 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1321 if (renderHistogram)
1325 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1329 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1332 // draw profile if available
1337 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1339 int profl[] = getProfileFor(_aa, column);
1341 // just try to draw the logo if profl is not null
1342 if (profl != null && profl[2] != 0)
1344 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1345 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1346 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1347 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1354 * Render a single base for a sequence profile, a base pair for
1355 * structure profile, and a triplet for a cdna profile
1357 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1359 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1360 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1361 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1365 * Traverse the character(s)/percentage data in the array
1368 int valuesProcessed = 0;
1369 // profl[1] is the number of values in the profile
1370 while (valuesProcessed < profl[1])
1372 if (isStructureProfile)
1374 // todo can we encode a structure pair as an int, like codons?
1375 dc[0] = (char) profl[c++];
1376 dc[1] = (char) profl[c++];
1378 else if (isCdnaProfile)
1380 dc = CodingUtils.decodeCodon(profl[c++]);
1384 dc[0] = (char) profl[c++];
1388 wdth /= fm.charsWidth(dc, 0, dc.length);
1391 // next profl[] position is profile % for the character(s)
1392 scl = htn * scale * profl[c++];
1393 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1394 .getFontRenderContext());
1395 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1396 wdth, scl / lm.getAscent())));
1397 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1399 // Debug - render boxes around characters
1400 // g.setColor(Color.red);
1401 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1403 // g.setColor(profcolour.findColour(dc[0]).darker());
1406 * Set character colour as per alignment colour scheme; use the
1407 * codon translation if a cDNA profile
1409 Color colour = null;
1412 final String codonTranslation = ResidueProperties
1413 .codonTranslate(new String(dc));
1414 colour = profcolour.findColour(codonTranslation.charAt(0),
1419 colour = profcolour.findColour(dc[0], column, null);
1421 g.setColor(colour == Color.white ? Color.lightGray : colour);
1423 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1424 .getBaselineIndex()]));
1426 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1434 if (_aa.threshold != null)
1436 g.setColor(_aa.threshold.colour);
1437 Graphics2D g2 = (Graphics2D) g;
1438 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1439 BasicStroke.JOIN_ROUND, 3f, new float[]
1442 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1444 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1445 g2.setStroke(new BasicStroke());
1449 // used by overview window
1450 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1451 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1453 eRes = Math.min(eRes, aa_annotations.length);
1454 g.setColor(Color.white);
1455 g.fillRect(0, 0, width, y);
1456 g.setColor(new Color(0, 0, 180));
1460 for (int j = sRes; j < eRes; j++)
1462 if (aa_annotations[j] != null)
1464 if (aa_annotations[j].colour == null)
1466 g.setColor(Color.black);
1470 g.setColor(aa_annotations[j].colour);
1473 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1479 g.fillRect(x, y - height, charWidth, height);
1485 Color getNotCanonicalColor(char lastss)
1491 return new Color(255, 125, 5);
1495 return new Color(245, 115, 10);
1499 return new Color(235, 135, 15);
1503 return new Color(225, 105, 20);
1507 return new Color(215, 145, 30);
1511 return new Color(205, 95, 35);
1515 return new Color(195, 155, 45);
1519 return new Color(185, 85, 55);
1523 return new Color(175, 165, 65);
1527 return new Color(170, 75, 75);
1531 return new Color(160, 175, 85);
1535 return new Color(150, 65, 95);
1539 return new Color(140, 185, 105);
1543 return new Color(130, 55, 110);
1547 return new Color(120, 195, 120);
1551 return new Color(110, 45, 130);
1555 return new Color(100, 205, 140);
1559 return new Color(90, 35, 150);
1563 return new Color(85, 215, 160);
1567 return new Color(75, 25, 170);
1571 return new Color(65, 225, 180);
1575 return new Color(55, 15, 185);
1579 return new Color(45, 235, 195);
1583 return new Color(35, 5, 205);
1587 return new Color(25, 245, 215);
1591 return new Color(15, 0, 225);
1595 return new Color(10, 255, 235);
1599 return new Color(5, 150, 245);
1603 return new Color(0, 80, 255);
1606 System.out.println("This is not a interaction : " + lastss);