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
51 * flag indicating if timing and redraw parameter info should be output
53 private final boolean debugRedraw;
55 public AnnotationRenderer()
61 * Create a new annotation Renderer
64 * flag indicating if timing and redraw parameter info should be
67 public AnnotationRenderer(boolean debugRedraw)
69 this.debugRedraw = debugRedraw;
72 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
73 int lastSSX, int x, int y, int iconOffset, int startRes,
74 int column, boolean validRes, boolean validEnd)
76 g.setColor(STEM_COLOUR);
77 int sCol = (lastSSX / charWidth) + startRes;
79 int x2 = (x * charWidth);
80 Regex closeparen = new Regex("(\\))");
82 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
83 : row_annotations[column - 1].secondaryStructure;
85 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
86 || dc != row_annotations[sCol - 1].secondaryStructure;
87 boolean diffdownstream = !validRes || !validEnd
88 || row_annotations[column] == null
89 || dc != row_annotations[column].secondaryStructure;
90 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
91 // If a closing base pair half of the stem, display a backward arrow
92 if (column > 0 && ResidueProperties.isCloseParenRNA(dc))
96 // if (validRes && column>1 && row_annotations[column-2]!=null &&
97 // dc.equals(row_annotations[column-2].displayCharacter))
99 g.fillPolygon(new int[]
100 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
101 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
112 // display a forward arrow
115 g.fillPolygon(new int[]
116 { x2 - 5, x2 - 5, x2 }, new int[]
117 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
126 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
129 private int charWidth, endRes, charHeight;
131 private boolean validCharWidth, hasHiddenColumns;
133 private FontMetrics fm;
135 private final boolean MAC = new jalview.util.Platform().isAMac();
137 boolean av_renderHistogram = true, av_renderProfile = true,
138 av_normaliseProfile = false;
140 ColourSchemeI profcolour = null;
142 private ColumnSelection columnSelection;
144 private Hashtable[] hconsensus;
146 private Hashtable[] complementConsensus;
148 private Hashtable[] hStrucConsensus;
150 private boolean av_ignoreGapsConsensus;
153 * attributes set from AwtRenderPanelI
156 * old image used when data is currently being calculated and cannot be
159 private Image fadedImage;
162 * panel being rendered into
164 private ImageObserver annotationPanel;
167 * width of image to render in panel
169 private int imgWidth;
172 * offset to beginning of visible area
177 * offset to end of visible area
179 private int visHeight;
182 * indicate if the renderer should only render the visible portion of the
183 * annotation given the current view settings
185 private boolean useClip = true;
188 * master flag indicating if renderer should ever try to clip. not enabled for
191 private boolean canClip = false;
193 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
194 Annotation[] row_annotations, int lastSSX, int x, int y,
195 int iconOffset, int startRes, int column, boolean validRes,
198 // System.out.println(nonCanColor);
200 g.setColor(nonCanColor);
201 int sCol = (lastSSX / charWidth) + startRes;
203 int x2 = (x * charWidth);
204 Regex closeparen = new Regex("}|]|<|[a-z]");
206 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
207 : row_annotations[column - 1].displayCharacter;
209 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
210 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
211 boolean diffdownstream = !validRes || !validEnd
212 || row_annotations[column] == null
213 || !dc.equals(row_annotations[column].displayCharacter);
214 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
215 // If a closing base pair half of the stem, display a backward arrow
216 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
221 // if (validRes && column>1 && row_annotations[column-2]!=null &&
222 // dc.equals(row_annotations[column-2].displayCharacter))
224 g.fillPolygon(new int[]
225 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
226 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
237 // display a forward arrow
240 g.fillPolygon(new int[]
241 { x2 - 5, x2 - 5, x2 }, new int[]
242 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
251 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
254 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
256 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
259 fm = annotPanel.getFontMetrics();
260 annotationPanel = annotPanel;
261 fadedImage = annotPanel.getFadedImage();
262 imgWidth = annotPanel.getFadedImageWidth();
263 // visible area for rendering
264 int[] bounds = annotPanel.getVisibleVRange();
268 visHeight = bounds[1];
283 updateFromAlignViewport(av);
286 public void updateFromAlignViewport(AlignViewportI av)
288 charWidth = av.getCharWidth();
289 endRes = av.getEndRes();
290 charHeight = av.getCharHeight();
291 hasHiddenColumns = av.hasHiddenColumns();
292 validCharWidth = av.isValidCharWidth();
293 av_renderHistogram = av.isShowConsensusHistogram();
294 av_renderProfile = av.isShowSequenceLogo();
295 av_normaliseProfile = av.isNormaliseSequenceLogo();
296 profcolour = av.getGlobalColourScheme();
297 if (profcolour == null)
299 // Set the default colour for sequence logo if the alignnent has no
301 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
302 : new jalview.schemes.ZappoColourScheme();
304 columnSelection = av.getColumnSelection();
305 hconsensus = av.getSequenceConsensusHash();
306 complementConsensus = av.getComplementConsensusHash();
307 hStrucConsensus = av.getRnaStructureConsensusHash();
308 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
312 * Returns profile data; the first element is the profile type, the second is
313 * the number of distinct values, the third the total count, and the remainder
314 * depend on the profile type.
320 public int[] getProfileFor(AlignmentAnnotation aa, int column)
322 // TODO : consider refactoring the global alignment calculation
323 // properties/rendering attributes as a global 'alignment group' which holds
324 // all vis settings for the alignment as a whole rather than a subset
326 if (aa.autoCalculated
327 && (aa.label.startsWith("Consensus") || aa.label
328 .startsWith("cDNA Consensus")))
330 boolean forComplement = aa.label.startsWith("cDNA Consensus");
331 if (aa.groupRef != null && aa.groupRef.consensusData != null
332 && aa.groupRef.isShowSequenceLogo())
334 // TODO? group consensus for cDNA complement
335 return AAFrequency.extractProfile(
336 aa.groupRef.consensusData[column],
337 aa.groupRef.getIgnoreGapsConsensus());
339 // TODO extend annotation row to enable dynamic and static profile data to
341 if (aa.groupRef == null && aa.sequenceRef == null)
345 return AAFrequency.extractCdnaProfile(
346 complementConsensus[column], av_ignoreGapsConsensus);
350 return AAFrequency.extractProfile(hconsensus[column],
351 av_ignoreGapsConsensus);
357 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
359 // TODO implement group structure consensus
361 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
362 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
363 * group selections return StructureFrequency.extractProfile(
364 * aa.groupRef.consensusData[column], aa.groupRef
365 * .getIgnoreGapsConsensus()); }
367 // TODO extend annotation row to enable dynamic and static profile data
370 if (aa.groupRef == null && aa.sequenceRef == null
371 && hStrucConsensus != null
372 && hStrucConsensus.length > column)
374 return StructureFrequency.extractProfile(hStrucConsensus[column],
375 av_ignoreGapsConsensus);
385 * Render the annotation rows associated with an alignment.
390 * data and view settings to render
392 * destination for graphics
394 * row where a mouse event occured (or -1)
396 * first column that will be drawn
398 * last column that will be drawn
399 * @return true if the fadedImage was used for any alignment annotation rows
400 * currently being calculated
402 public boolean drawComponent(AwtRenderPanelI annotPanel,
403 AlignViewportI av, Graphics g, int activeRow, int startRes,
406 long stime = System.currentTimeMillis();
407 boolean usedFaded = false;
409 // AnnotationPanel needs to implement: ImageObserver, access to
411 updateFromAwtRenderPanel(annotPanel, av);
412 fm = g.getFontMetrics();
413 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
424 boolean validRes = false;
425 boolean validEnd = false;
426 boolean labelAllCols = false;
427 boolean centreColLabels;
428 boolean centreColLabelsDef = av.isCentreColumnLabels();
429 boolean scaleColLabel = false;
430 final AlignmentAnnotation consensusAnnot = av
431 .getAlignmentConsensusAnnotation();
432 final AlignmentAnnotation structConsensusAnnot = av
433 .getAlignmentStrucConsensusAnnotation();
434 final AlignmentAnnotation complementConsensusAnnot = av
435 .getComplementConsensusAnnotation();
436 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
438 BitSet graphGroupDrawn = new BitSet();
439 int charOffset = 0; // offset for a label
440 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
442 Font ofont = g.getFont();
445 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
446 boolean clipst = false, clipend = false;
447 for (int i = 0; i < aa.length; i++)
449 AlignmentAnnotation row = aa[i];
452 // check if this is a consensus annotation row and set the display
453 // settings appropriately
454 // TODO: generalise this to have render styles for consensus/profile
456 if (row.groupRef != null && row == row.groupRef.getConsensus())
458 renderHistogram = row.groupRef.isShowConsensusHistogram();
459 renderProfile = row.groupRef.isShowSequenceLogo();
460 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
462 else if (row == consensusAnnot || row == structConsensusAnnot
463 || row == complementConsensusAnnot)
465 renderHistogram = av_renderHistogram;
466 renderProfile = av_renderProfile;
467 normaliseProfile = av_normaliseProfile;
471 renderHistogram = true;
472 // don't need to set render/normaliseProfile since they are not
473 // currently used in any other annotation track renderer
476 Annotation[] row_annotations = row.annotations;
481 centreColLabels = row.centreColLabels || centreColLabelsDef;
482 labelAllCols = row.showAllColLabels;
483 scaleColLabel = row.scaleColLabel;
488 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
489 {// if_in_visible_region
500 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
505 // this is so that we draw the characters below the graph
510 iconOffset = charHeight - fm.getDescent();
514 else if (row.hasText)
516 iconOffset = charHeight - fm.getDescent();
524 if (row.autoCalculated && av.isCalculationInProgress(row))
528 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
529 - row.height, imgWidth, y, annotationPanel);
530 g.setColor(Color.black);
531 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
537 * else if (annotationPanel.av.updatingConservation &&
538 * aa[i].label.equals("Conservation")) {
540 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
541 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
542 * annotationPanel.imgWidth, y, annotationPanel);
544 * g.setColor(Color.black); //
545 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
547 * continue; } else if (annotationPanel.av.updatingConservation &&
548 * aa[i].label.equals("Quality")) {
550 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
551 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
552 * annotationPanel.imgWidth, y, annotationPanel);
553 * g.setColor(Color.black); // /
554 * g.drawString("Calculating Quality....",20, y-row.height/2);
558 // first pass sets up state for drawing continuation from left-hand
561 x = (startRes == 0) ? 0 : -1;
562 while (x < endRes - startRes)
564 if (hasHiddenColumns)
566 column = columnSelection.adjustForHiddenColumns(startRes + x);
567 if (column > row_annotations.length - 1)
574 column = startRes + x;
577 if ((row_annotations == null)
578 || (row_annotations.length <= column)
579 || (row_annotations[column] == null))
587 final String displayChar = validRes ? row_annotations[column].displayCharacter
593 g.setColor(Color.red);
595 if (columnSelection != null)
597 for (int n = 0; n < columnSelection.size(); n++)
599 int v = columnSelection.columnAt(n);
603 g.fillRect(x * charWidth, y, charWidth, charHeight);
608 if (row.getInvalidStrucPos() > x)
610 g.setColor(Color.orange);
611 g.fillRect(x * charWidth, y, charWidth, charHeight);
613 else if (row.getInvalidStrucPos() == x)
615 g.setColor(Color.orange.darker());
616 g.fillRect(x * charWidth, y, charWidth, charHeight);
618 if (validCharWidth && validRes && displayChar != null
619 && (displayChar.length() > 0))
622 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
623 displayChar.length());
624 if (/* centreColLabels || */scaleColLabel)
626 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
627 // displayChar.length());
629 // if (scaleColLabel)
631 // justify the label and scale to fit in column
632 if (fmWidth > charWidth)
634 // scale only if the current font isn't already small enough
635 fmScaling = charWidth;
636 fmScaling /= fmWidth;
637 g.setFont(ofont.deriveFont(AffineTransform
638 .getScaleInstance(fmScaling, 1.0)));
639 // and update the label's width to reflect the scaling.
644 // TODO is it ok to use width of / show all characters here?
647 // fmWidth = fm.charWidth(displayChar.charAt(0));
649 charOffset = (int) ((charWidth - fmWidth) / 2f);
651 if (row_annotations[column].colour == null)
653 g.setColor(Color.black);
657 g.setColor(row_annotations[column].colour);
660 if (column == 0 || row.graph > 0)
662 g.drawString(displayChar, (x * charWidth) + charOffset, y
665 else if (row_annotations[column - 1] == null
668 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
669 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
671 g.drawString(displayChar, x * charWidth + charOffset, y
679 char ss = validRes ? row_annotations[column].secondaryStructure
684 // distinguish between forward/backward base-pairing
685 if (displayChar.indexOf(')') > -1)
694 if ((displayChar.indexOf(']') > -1))
702 // distinguish between forward/backward base-pairing
703 if (displayChar.indexOf('}') > -1)
711 // distinguish between forward/backward base-pairing
712 if (displayChar.indexOf('<') > -1)
720 // distinguish between forward/backward base-pairing
721 if (displayChar.indexOf(ss + 32) > -1)
724 ss = (char) (ss + 32);
729 if (!validRes || (ss != lastSS))
735 int nb_annot = x - temp;
736 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
739 case '(': // Stem case for RNA secondary structure
740 case ')': // and opposite direction
741 drawStemAnnot(g, row_annotations, lastSSX, x, y,
742 iconOffset, startRes, column, validRes, validEnd);
749 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
750 iconOffset, startRes, column, validRes,
758 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
759 iconOffset, startRes, column, validRes,
821 Color nonCanColor = getNotCanonicalColor(lastSS);
822 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
823 lastSSX, x, y, iconOffset, startRes, column,
828 g.setColor(Color.gray);
829 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
845 lastSSX = (x * charWidth);
852 if (column >= row_annotations.length)
854 column = row_annotations.length - 1;
861 if ((row_annotations == null) || (row_annotations.length <= column)
862 || (row_annotations[column] == null))
881 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
882 startRes, column, validRes, validEnd);
889 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
890 startRes, column, validRes, validEnd);
895 case ')': // Stem case for RNA secondary structure
897 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
898 startRes, column, validRes, validEnd);
955 // System.out.println(lastSS);
956 Color nonCanColor = getNotCanonicalColor(lastSS);
957 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
958 x, y, iconOffset, startRes, column, validRes, validEnd);
961 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
962 startRes, column, validRes, validEnd);
967 if (row.graph > 0 && row.graphHeight > 0)
969 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
971 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
973 // TODO: JAL-1291 revise rendering model so the graphGroup map is
974 // computed efficiently for all visible labels
975 float groupmax = -999999, groupmin = 9999999;
976 for (int gg = 0; gg < aa.length; gg++)
978 if (aa[gg].graphGroup != row.graphGroup)
985 aa[gg].visible = false;
987 if (aa[gg].graphMax > groupmax)
989 groupmax = aa[gg].graphMax;
991 if (aa[gg].graphMin < groupmin)
993 groupmin = aa[gg].graphMin;
997 for (int gg = 0; gg < aa.length; gg++)
999 if (aa[gg].graphGroup == row.graphGroup)
1001 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1002 endRes, y, groupmin, groupmax, row.graphHeight);
1006 graphGroupDrawn.set(row.graphGroup);
1010 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1011 row.graphMin, row.graphMax, row.graphHeight);
1014 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1016 drawBarGraph(g, row, row_annotations, startRes, endRes,
1017 row.graphMin, row.graphMax, y, renderHistogram,
1018 renderProfile, normaliseProfile);
1024 if (clipst && !clipend)
1028 }// end if_in_visible_region
1029 if (row.graph > 0 && row.hasText)
1045 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1050 System.err.println("End clip at : " + yto + " (index " + f_to
1055 System.err.println("Annotation Rendering time:"
1056 + (System.currentTimeMillis() - stime));
1063 public static final Color GLYPHLINE_COLOR = Color.gray;
1065 public static final Color SHEET_COLOUR = Color.green;
1067 public static final Color HELIX_COLOUR = Color.red;
1069 public static final Color STEM_COLOUR = Color.blue;
1071 private Color sdNOTCANONICAL_COLOUR;
1073 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1074 int x, int y, int iconOffset, int startRes, int column,
1075 boolean validRes, boolean validEnd)
1077 g.setColor(GLYPHLINE_COLOR);
1078 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1081 public void drawSheetAnnot(Graphics g, Annotation[] row,
1083 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1084 boolean validRes, boolean validEnd)
1086 g.setColor(SHEET_COLOUR);
1088 if (!validEnd || !validRes || row == null || row[column] == null
1089 || row[column].secondaryStructure != 'E')
1091 g.fillRect(lastSSX, y + 4 + iconOffset,
1092 (x * charWidth) - lastSSX - 4, 7);
1093 g.fillPolygon(new int[]
1094 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1096 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
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[]
1255 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1256 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1257 g2.setStroke(new BasicStroke());
1261 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1262 Annotation[] aa_annotations, int sRes, int eRes, float min,
1263 float max, int y, boolean renderHistogram, boolean renderProfile,
1264 boolean normaliseProfile)
1266 if (sRes > aa_annotations.length)
1270 Font ofont = g.getFont();
1271 eRes = Math.min(eRes, aa_annotations.length);
1273 int x = 0, y1 = y, y2 = y;
1275 float range = max - min;
1279 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1282 g.setColor(Color.gray);
1284 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1287 int aaMax = aa_annotations.length - 1;
1288 while (x < eRes - sRes)
1291 if (hasHiddenColumns)
1293 column = columnSelection.adjustForHiddenColumns(column);
1301 if (aa_annotations[column] == null)
1306 if (aa_annotations[column].colour == null)
1308 g.setColor(Color.black);
1312 g.setColor(aa_annotations[column].colour);
1316 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1318 if (renderHistogram)
1322 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1326 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1329 // draw profile if available
1334 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1336 int profl[] = getProfileFor(_aa, column);
1338 // just try to draw the logo if profl is not null
1339 if (profl != null && profl[2] != 0)
1341 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1342 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1343 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1344 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1351 * Render a single base for a sequence profile, a base pair for
1352 * structure profile, and a triplet for a cdna profile
1354 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1356 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1357 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1358 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1362 * Traverse the character(s)/percentage data in the array
1365 int valuesProcessed = 0;
1366 // profl[1] is the number of values in the profile
1367 while (valuesProcessed < profl[1])
1369 if (isStructureProfile)
1371 // todo can we encode a structure pair as an int, like codons?
1372 dc[0] = (char) profl[c++];
1373 dc[1] = (char) profl[c++];
1375 else if (isCdnaProfile)
1377 dc = CodingUtils.decodeCodon(profl[c++]);
1381 dc[0] = (char) profl[c++];
1385 wdth /= fm.charsWidth(dc, 0, dc.length);
1388 // next profl[] position is profile % for the character(s)
1389 scl = htn * scale * profl[c++];
1390 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1391 .getFontRenderContext());
1392 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1393 wdth, scl / lm.getAscent())));
1394 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1396 // Debug - render boxes around characters
1397 // g.setColor(Color.red);
1398 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1400 // g.setColor(profcolour.findColour(dc[0]).darker());
1403 * Set character colour as per alignment colour scheme; use the
1404 * codon translation if a cDNA profile
1406 Color colour = null;
1409 final String codonTranslation = ResidueProperties
1410 .codonTranslate(new String(dc));
1411 colour = profcolour.findColour(codonTranslation.charAt(0),
1416 colour = profcolour.findColour(dc[0], column, null);
1418 g.setColor(colour == Color.white ? Color.lightGray : colour);
1420 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1421 .getBaselineIndex()]));
1423 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1431 if (_aa.threshold != null)
1433 g.setColor(_aa.threshold.colour);
1434 Graphics2D g2 = (Graphics2D) g;
1435 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1436 BasicStroke.JOIN_ROUND, 3f, new float[]
1439 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1441 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1442 g2.setStroke(new BasicStroke());
1446 // used by overview window
1447 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1448 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1450 eRes = Math.min(eRes, aa_annotations.length);
1451 g.setColor(Color.white);
1452 g.fillRect(0, 0, width, y);
1453 g.setColor(new Color(0, 0, 180));
1457 for (int j = sRes; j < eRes; j++)
1459 if (aa_annotations[j] != null)
1461 if (aa_annotations[j].colour == null)
1463 g.setColor(Color.black);
1467 g.setColor(aa_annotations[j].colour);
1470 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1476 g.fillRect(x, y - height, charWidth, height);
1482 Color getNotCanonicalColor(char lastss)
1488 return new Color(255, 125, 5);
1492 return new Color(245, 115, 10);
1496 return new Color(235, 135, 15);
1500 return new Color(225, 105, 20);
1504 return new Color(215, 145, 30);
1508 return new Color(205, 95, 35);
1512 return new Color(195, 155, 45);
1516 return new Color(185, 85, 55);
1520 return new Color(175, 165, 65);
1524 return new Color(170, 75, 75);
1528 return new Color(160, 175, 85);
1532 return new Color(150, 65, 95);
1536 return new Color(140, 185, 105);
1540 return new Color(130, 55, 110);
1544 return new Color(120, 195, 120);
1548 return new Color(110, 45, 130);
1552 return new Color(100, 205, 140);
1556 return new Color(90, 35, 150);
1560 return new Color(85, 215, 160);
1564 return new Color(75, 25, 170);
1568 return new Color(65, 225, 180);
1572 return new Color(55, 15, 185);
1576 return new Color(45, 235, 195);
1580 return new Color(35, 5, 205);
1584 return new Color(25, 245, 215);
1588 return new Color(15, 0, 225);
1592 return new Color(10, 255, 235);
1596 return new Color(5, 150, 245);
1600 return new Color(0, 80, 255);
1603 System.out.println("This is not a interaction : " + lastss);