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[]
106 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
107 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
118 // display a forward arrow
121 g.fillPolygon(new int[]
122 { x2 - 5, x2 - 5, x2 }, new int[]
123 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
132 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
135 private int charWidth, endRes, charHeight;
137 private boolean validCharWidth, hasHiddenColumns;
139 private FontMetrics fm;
141 private final boolean MAC = jalview.util.Platform.isAMac();
143 boolean av_renderHistogram = true, av_renderProfile = true,
144 av_normaliseProfile = false;
146 ColourSchemeI profcolour = null;
148 private ColumnSelection columnSelection;
150 private Hashtable[] hconsensus;
152 private Hashtable[] complementConsensus;
154 private Hashtable[] hStrucConsensus;
156 private boolean av_ignoreGapsConsensus;
159 * attributes set from AwtRenderPanelI
162 * old image used when data is currently being calculated and cannot be
165 private Image fadedImage;
168 * panel being rendered into
170 private ImageObserver annotationPanel;
173 * width of image to render in panel
175 private int imgWidth;
178 * offset to beginning of visible area
183 * offset to end of visible area
185 private int visHeight;
188 * indicate if the renderer should only render the visible portion of the
189 * annotation given the current view settings
191 private boolean useClip = true;
194 * master flag indicating if renderer should ever try to clip. not enabled for
197 private boolean canClip = false;
199 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
200 Annotation[] row_annotations, int lastSSX, int x, int y,
201 int iconOffset, int startRes, int column, boolean validRes,
204 // System.out.println(nonCanColor);
206 g.setColor(nonCanColor);
207 int sCol = (lastSSX / charWidth) + startRes;
209 int x2 = (x * charWidth);
210 Regex closeparen = new Regex("}|]|<|[a-z]");
212 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
213 : row_annotations[column - 1].displayCharacter;
215 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
216 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
217 boolean diffdownstream = !validRes || !validEnd
218 || row_annotations[column] == null
219 || !dc.equals(row_annotations[column].displayCharacter);
220 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
221 // If a closing base pair half of the stem, display a backward arrow
222 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
227 // if (validRes && column>1 && row_annotations[column-2]!=null &&
228 // dc.equals(row_annotations[column-2].displayCharacter))
230 g.fillPolygon(new int[]
231 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
232 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
243 // display a forward arrow
246 g.fillPolygon(new int[]
247 { x2 - 5, x2 - 5, x2 }, new int[]
248 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
257 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
260 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
262 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
265 fm = annotPanel.getFontMetrics();
266 annotationPanel = annotPanel;
267 fadedImage = annotPanel.getFadedImage();
268 imgWidth = annotPanel.getFadedImageWidth();
269 // visible area for rendering
270 int[] bounds = annotPanel.getVisibleVRange();
274 visHeight = bounds[1];
289 updateFromAlignViewport(av);
292 public void updateFromAlignViewport(AlignViewportI av)
294 charWidth = av.getCharWidth();
295 endRes = av.getEndRes();
296 charHeight = av.getCharHeight();
297 hasHiddenColumns = av.hasHiddenColumns();
298 validCharWidth = av.isValidCharWidth();
299 av_renderHistogram = av.isShowConsensusHistogram();
300 av_renderProfile = av.isShowSequenceLogo();
301 av_normaliseProfile = av.isNormaliseSequenceLogo();
302 profcolour = av.getGlobalColourScheme();
303 if (profcolour == null)
305 // Set the default colour for sequence logo if the alignnent has no
307 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
308 : new jalview.schemes.ZappoColourScheme();
310 columnSelection = av.getColumnSelection();
311 hconsensus = av.getSequenceConsensusHash();
312 complementConsensus = av.getComplementConsensusHash();
313 hStrucConsensus = av.getRnaStructureConsensusHash();
314 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
318 * Returns profile data; the first element is the profile type, the second is
319 * the number of distinct values, the third the total count, and the remainder
320 * depend on the profile type.
326 public int[] getProfileFor(AlignmentAnnotation aa, int column)
328 // TODO : consider refactoring the global alignment calculation
329 // properties/rendering attributes as a global 'alignment group' which holds
330 // all vis settings for the alignment as a whole rather than a subset
332 if (aa.autoCalculated
333 && (aa.label.startsWith("Consensus") || aa.label
334 .startsWith("cDNA Consensus")))
336 boolean forComplement = aa.label.startsWith("cDNA Consensus");
337 if (aa.groupRef != null && aa.groupRef.consensusData != null
338 && aa.groupRef.isShowSequenceLogo())
340 // TODO? group consensus for cDNA complement
341 return AAFrequency.extractProfile(
342 aa.groupRef.consensusData[column],
343 aa.groupRef.getIgnoreGapsConsensus());
345 // TODO extend annotation row to enable dynamic and static profile data to
347 if (aa.groupRef == null && aa.sequenceRef == null)
351 return AAFrequency.extractCdnaProfile(
352 complementConsensus[column], av_ignoreGapsConsensus);
356 return AAFrequency.extractProfile(hconsensus[column],
357 av_ignoreGapsConsensus);
363 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
365 // TODO implement group structure consensus
367 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
368 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
369 * group selections return StructureFrequency.extractProfile(
370 * aa.groupRef.consensusData[column], aa.groupRef
371 * .getIgnoreGapsConsensus()); }
373 // TODO extend annotation row to enable dynamic and static profile data
376 if (aa.groupRef == null && aa.sequenceRef == null
377 && hStrucConsensus != null
378 && hStrucConsensus.length > column)
380 return StructureFrequency.extractProfile(hStrucConsensus[column],
381 av_ignoreGapsConsensus);
391 * Render the annotation rows associated with an alignment.
396 * data and view settings to render
398 * destination for graphics
400 * row where a mouse event occured (or -1)
402 * first column that will be drawn
404 * last column that will be drawn
405 * @return true if the fadedImage was used for any alignment annotation rows
406 * currently being calculated
408 public boolean drawComponent(AwtRenderPanelI annotPanel,
409 AlignViewportI av, Graphics g, int activeRow, int startRes,
412 long stime = System.currentTimeMillis();
413 boolean usedFaded = false;
415 // AnnotationPanel needs to implement: ImageObserver, access to
417 updateFromAwtRenderPanel(annotPanel, av);
418 fm = g.getFontMetrics();
419 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
430 boolean validRes = false;
431 boolean validEnd = false;
432 boolean labelAllCols = false;
433 boolean centreColLabels;
434 boolean centreColLabelsDef = av.isCentreColumnLabels();
435 boolean scaleColLabel = false;
436 final AlignmentAnnotation consensusAnnot = av
437 .getAlignmentConsensusAnnotation();
438 final AlignmentAnnotation structConsensusAnnot = av
439 .getAlignmentStrucConsensusAnnotation();
440 final AlignmentAnnotation complementConsensusAnnot = av
441 .getComplementConsensusAnnotation();
442 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
444 BitSet graphGroupDrawn = new BitSet();
445 int charOffset = 0; // offset for a label
446 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
448 Font ofont = g.getFont();
451 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
452 boolean clipst = false, clipend = false;
453 for (int i = 0; i < aa.length; i++)
455 AlignmentAnnotation row = aa[i];
458 // check if this is a consensus annotation row and set the display
459 // settings appropriately
460 // TODO: generalise this to have render styles for consensus/profile
462 if (row.groupRef != null && row == row.groupRef.getConsensus())
464 renderHistogram = row.groupRef.isShowConsensusHistogram();
465 renderProfile = row.groupRef.isShowSequenceLogo();
466 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
468 else if (row == consensusAnnot || row == structConsensusAnnot
469 || row == complementConsensusAnnot)
471 renderHistogram = av_renderHistogram;
472 renderProfile = av_renderProfile;
473 normaliseProfile = av_normaliseProfile;
477 renderHistogram = true;
478 // don't need to set render/normaliseProfile since they are not
479 // currently used in any other annotation track renderer
482 Annotation[] row_annotations = row.annotations;
487 centreColLabels = row.centreColLabels || centreColLabelsDef;
488 labelAllCols = row.showAllColLabels;
489 scaleColLabel = row.scaleColLabel;
494 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
495 {// if_in_visible_region
506 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
511 // this is so that we draw the characters below the graph
516 iconOffset = charHeight - fm.getDescent();
520 else if (row.hasText)
522 iconOffset = charHeight - fm.getDescent();
530 if (row.autoCalculated && av.isCalculationInProgress(row))
534 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
535 - row.height, imgWidth, y, annotationPanel);
536 g.setColor(Color.black);
537 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
543 * else if (annotationPanel.av.updatingConservation &&
544 * aa[i].label.equals("Conservation")) {
546 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
547 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
548 * annotationPanel.imgWidth, y, annotationPanel);
550 * g.setColor(Color.black); //
551 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
553 * continue; } else if (annotationPanel.av.updatingConservation &&
554 * aa[i].label.equals("Quality")) {
556 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
557 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
558 * annotationPanel.imgWidth, y, annotationPanel);
559 * g.setColor(Color.black); // /
560 * g.drawString("Calculating Quality....",20, y-row.height/2);
564 // first pass sets up state for drawing continuation from left-hand
567 x = (startRes == 0) ? 0 : -1;
568 while (x < endRes - startRes)
570 if (hasHiddenColumns)
572 column = columnSelection.adjustForHiddenColumns(startRes + x);
573 if (column > row_annotations.length - 1)
580 column = startRes + x;
583 if ((row_annotations == null)
584 || (row_annotations.length <= column)
585 || (row_annotations[column] == null))
593 final String displayChar = validRes ? row_annotations[column].displayCharacter
599 g.setColor(Color.red);
601 if (columnSelection != null)
603 for (int n = 0; n < columnSelection.size(); n++)
605 int v = columnSelection.columnAt(n);
609 g.fillRect(x * charWidth, y, charWidth, charHeight);
614 if (row.getInvalidStrucPos() > x)
616 g.setColor(Color.orange);
617 g.fillRect(x * charWidth, y, charWidth, charHeight);
619 else if (row.getInvalidStrucPos() == x)
621 g.setColor(Color.orange.darker());
622 g.fillRect(x * charWidth, y, charWidth, charHeight);
624 if (validCharWidth && validRes && displayChar != null
625 && (displayChar.length() > 0))
628 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
629 displayChar.length());
630 if (/* centreColLabels || */scaleColLabel)
632 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
633 // displayChar.length());
635 // if (scaleColLabel)
637 // justify the label and scale to fit in column
638 if (fmWidth > charWidth)
640 // scale only if the current font isn't already small enough
641 fmScaling = charWidth;
642 fmScaling /= fmWidth;
643 g.setFont(ofont.deriveFont(AffineTransform
644 .getScaleInstance(fmScaling, 1.0)));
645 // and update the label's width to reflect the scaling.
650 // TODO is it ok to use width of / show all characters here?
653 // fmWidth = fm.charWidth(displayChar.charAt(0));
655 charOffset = (int) ((charWidth - fmWidth) / 2f);
657 if (row_annotations[column].colour == null)
659 g.setColor(Color.black);
663 g.setColor(row_annotations[column].colour);
666 if (column == 0 || row.graph > 0)
668 g.drawString(displayChar, (x * charWidth) + charOffset, y
671 else if (row_annotations[column - 1] == null
674 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
675 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
677 g.drawString(displayChar, x * charWidth + charOffset, y
685 char ss = validRes ? row_annotations[column].secondaryStructure
690 // distinguish between forward/backward base-pairing
691 if (displayChar.indexOf(')') > -1)
700 if ((displayChar.indexOf(']') > -1))
708 // distinguish between forward/backward base-pairing
709 if (displayChar.indexOf('}') > -1)
717 // distinguish between forward/backward base-pairing
718 if (displayChar.indexOf('<') > -1)
724 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
726 // distinguish between forward/backward base-pairing
727 int ssLowerCase = ss + UPPER_TO_LOWER;
728 // TODO would .equals() be safer here? or charAt(0)?
729 if (displayChar.indexOf(ssLowerCase) > -1)
731 ss = (char) ssLowerCase;
735 if (!validRes || (ss != lastSS))
741 int nb_annot = x - temp;
742 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
745 case '(': // Stem case for RNA secondary structure
746 case ')': // and opposite direction
747 drawStemAnnot(g, row_annotations, lastSSX, x, y,
748 iconOffset, startRes, column, validRes, validEnd);
755 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
756 iconOffset, startRes, column, validRes,
764 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
765 iconOffset, startRes, column, validRes,
827 Color nonCanColor = getNotCanonicalColor(lastSS);
828 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
829 lastSSX, x, y, iconOffset, startRes, column,
834 g.setColor(Color.gray);
835 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
851 lastSSX = (x * charWidth);
858 if (column >= row_annotations.length)
860 column = row_annotations.length - 1;
867 if ((row_annotations == null) || (row_annotations.length <= column)
868 || (row_annotations[column] == null))
887 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
888 startRes, column, validRes, validEnd);
895 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
896 startRes, column, validRes, validEnd);
901 case ')': // Stem case for RNA secondary structure
903 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
904 startRes, column, validRes, validEnd);
961 // System.out.println(lastSS);
962 Color nonCanColor = getNotCanonicalColor(lastSS);
963 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
964 x, y, iconOffset, startRes, column, validRes, validEnd);
967 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
968 startRes, column, validRes, validEnd);
973 if (row.graph > 0 && row.graphHeight > 0)
975 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
977 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
979 // TODO: JAL-1291 revise rendering model so the graphGroup map is
980 // computed efficiently for all visible labels
981 float groupmax = -999999, groupmin = 9999999;
982 for (int gg = 0; gg < aa.length; gg++)
984 if (aa[gg].graphGroup != row.graphGroup)
991 aa[gg].visible = false;
993 if (aa[gg].graphMax > groupmax)
995 groupmax = aa[gg].graphMax;
997 if (aa[gg].graphMin < groupmin)
999 groupmin = aa[gg].graphMin;
1003 for (int gg = 0; gg < aa.length; gg++)
1005 if (aa[gg].graphGroup == row.graphGroup)
1007 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1008 endRes, y, groupmin, groupmax, row.graphHeight);
1012 graphGroupDrawn.set(row.graphGroup);
1016 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1017 row.graphMin, row.graphMax, row.graphHeight);
1020 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1022 drawBarGraph(g, row, row_annotations, startRes, endRes,
1023 row.graphMin, row.graphMax, y, renderHistogram,
1024 renderProfile, normaliseProfile);
1030 if (clipst && !clipend)
1034 }// end if_in_visible_region
1035 if (row.graph > 0 && row.hasText)
1051 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1056 System.err.println("End clip at : " + yto + " (index " + f_to
1061 System.err.println("Annotation Rendering time:"
1062 + (System.currentTimeMillis() - stime));
1069 public static final Color GLYPHLINE_COLOR = Color.gray;
1071 public static final Color SHEET_COLOUR = Color.green;
1073 public static final Color HELIX_COLOUR = Color.red;
1075 public static final Color STEM_COLOUR = Color.blue;
1077 private Color sdNOTCANONICAL_COLOUR;
1079 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1080 int x, int y, int iconOffset, int startRes, int column,
1081 boolean validRes, boolean validEnd)
1083 g.setColor(GLYPHLINE_COLOR);
1084 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1087 public void drawSheetAnnot(Graphics g, Annotation[] row,
1089 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1090 boolean validRes, boolean validEnd)
1092 g.setColor(SHEET_COLOUR);
1094 if (!validEnd || !validRes || row == null || row[column] == null
1095 || row[column].secondaryStructure != 'E')
1097 g.fillRect(lastSSX, y + 4 + iconOffset,
1098 (x * charWidth) - lastSSX - 4, 7);
1099 g.fillPolygon(new int[]
1100 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1102 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1107 g.fillRect(lastSSX, y + 4 + iconOffset,
1108 (x + 1) * charWidth - lastSSX, 7);
1113 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1114 int x, int y, int iconOffset, int startRes, int column,
1115 boolean validRes, boolean validEnd)
1117 g.setColor(HELIX_COLOUR);
1119 int sCol = (lastSSX / charWidth) + startRes;
1121 int x2 = (x * charWidth);
1125 int ofs = charWidth / 2;
1126 // Off by 1 offset when drawing rects and ovals
1127 // to offscreen image on the MAC
1128 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1129 if (sCol == 0 || row[sCol - 1] == null
1130 || row[sCol - 1].secondaryStructure != 'H')
1135 // g.setColor(Color.orange);
1136 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1139 if (!validRes || row[column] == null
1140 || row[column].secondaryStructure != 'H')
1146 // g.setColor(Color.magenta);
1147 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1155 if (sCol == 0 || row[sCol - 1] == null
1156 || row[sCol - 1].secondaryStructure != 'H')
1158 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1159 x1 += charWidth / 2;
1162 if (!validRes || row[column] == null
1163 || row[column].secondaryStructure != 'H')
1165 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1167 x2 -= charWidth / 2;
1170 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1173 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1174 Annotation[] aa_annotations, int sRes, int eRes, int y,
1175 float min, float max, int graphHeight)
1177 if (sRes > aa_annotations.length)
1184 // Adjustment for fastpaint to left
1190 eRes = Math.min(eRes, aa_annotations.length);
1198 float range = max - min;
1203 y2 = y - (int) ((0 - min / range) * graphHeight);
1206 g.setColor(Color.gray);
1207 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1209 eRes = Math.min(eRes, aa_annotations.length);
1212 int aaMax = aa_annotations.length - 1;
1214 while (x < eRes - sRes)
1217 if (hasHiddenColumns)
1219 column = columnSelection.adjustForHiddenColumns(column);
1227 if (aa_annotations[column] == null
1228 || aa_annotations[column - 1] == null)
1234 if (aa_annotations[column].colour == null)
1236 g.setColor(Color.black);
1240 g.setColor(aa_annotations[column].colour);
1244 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1246 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1248 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1249 + charWidth / 2, y2);
1253 if (_aa.threshold != null)
1255 g.setColor(_aa.threshold.colour);
1256 Graphics2D g2 = (Graphics2D) g;
1257 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1258 BasicStroke.JOIN_ROUND, 3f, new float[]
1261 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1262 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1263 g2.setStroke(new BasicStroke());
1267 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1268 Annotation[] aa_annotations, int sRes, int eRes, float min,
1269 float max, int y, boolean renderHistogram, boolean renderProfile,
1270 boolean normaliseProfile)
1272 if (sRes > aa_annotations.length)
1276 Font ofont = g.getFont();
1277 eRes = Math.min(eRes, aa_annotations.length);
1279 int x = 0, y1 = y, y2 = y;
1281 float range = max - min;
1285 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1288 g.setColor(Color.gray);
1290 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1293 int aaMax = aa_annotations.length - 1;
1294 while (x < eRes - sRes)
1297 if (hasHiddenColumns)
1299 column = columnSelection.adjustForHiddenColumns(column);
1307 if (aa_annotations[column] == null)
1312 if (aa_annotations[column].colour == null)
1314 g.setColor(Color.black);
1318 g.setColor(aa_annotations[column].colour);
1322 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1324 if (renderHistogram)
1328 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1332 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1335 // draw profile if available
1340 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1342 int profl[] = getProfileFor(_aa, column);
1344 // just try to draw the logo if profl is not null
1345 if (profl != null && profl[2] != 0)
1347 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1348 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1349 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1350 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1357 * Render a single base for a sequence profile, a base pair for
1358 * structure profile, and a triplet for a cdna profile
1360 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1362 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1363 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1364 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1368 * Traverse the character(s)/percentage data in the array
1371 int valuesProcessed = 0;
1372 // profl[1] is the number of values in the profile
1373 while (valuesProcessed < profl[1])
1375 if (isStructureProfile)
1377 // todo can we encode a structure pair as an int, like codons?
1378 dc[0] = (char) profl[c++];
1379 dc[1] = (char) profl[c++];
1381 else if (isCdnaProfile)
1383 dc = CodingUtils.decodeCodon(profl[c++]);
1387 dc[0] = (char) profl[c++];
1391 wdth /= fm.charsWidth(dc, 0, dc.length);
1394 // next profl[] position is profile % for the character(s)
1395 scl = htn * scale * profl[c++];
1396 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1397 .getFontRenderContext());
1398 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1399 wdth, scl / lm.getAscent())));
1400 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1402 // Debug - render boxes around characters
1403 // g.setColor(Color.red);
1404 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1406 // g.setColor(profcolour.findColour(dc[0]).darker());
1409 * Set character colour as per alignment colour scheme; use the
1410 * codon translation if a cDNA profile
1412 Color colour = null;
1415 final String codonTranslation = ResidueProperties
1416 .codonTranslate(new String(dc));
1417 colour = profcolour.findColour(codonTranslation.charAt(0),
1422 colour = profcolour.findColour(dc[0], column, null);
1424 g.setColor(colour == Color.white ? Color.lightGray : colour);
1426 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1427 .getBaselineIndex()]));
1429 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1437 if (_aa.threshold != null)
1439 g.setColor(_aa.threshold.colour);
1440 Graphics2D g2 = (Graphics2D) g;
1441 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1442 BasicStroke.JOIN_ROUND, 3f, new float[]
1445 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1447 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1448 g2.setStroke(new BasicStroke());
1452 // used by overview window
1453 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1454 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1456 eRes = Math.min(eRes, aa_annotations.length);
1457 g.setColor(Color.white);
1458 g.fillRect(0, 0, width, y);
1459 g.setColor(new Color(0, 0, 180));
1463 for (int j = sRes; j < eRes; j++)
1465 if (aa_annotations[j] != null)
1467 if (aa_annotations[j].colour == null)
1469 g.setColor(Color.black);
1473 g.setColor(aa_annotations[j].colour);
1476 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1482 g.fillRect(x, y - height, charWidth, height);
1488 Color getNotCanonicalColor(char lastss)
1494 return new Color(255, 125, 5);
1498 return new Color(245, 115, 10);
1502 return new Color(235, 135, 15);
1506 return new Color(225, 105, 20);
1510 return new Color(215, 145, 30);
1514 return new Color(205, 95, 35);
1518 return new Color(195, 155, 45);
1522 return new Color(185, 85, 55);
1526 return new Color(175, 165, 65);
1530 return new Color(170, 75, 75);
1534 return new Color(160, 175, 85);
1538 return new Color(150, 65, 95);
1542 return new Color(140, 185, 105);
1546 return new Color(130, 55, 110);
1550 return new Color(120, 195, 120);
1554 return new Color(110, 45, 130);
1558 return new Color(100, 205, 140);
1562 return new Color(90, 35, 150);
1566 return new Color(85, 215, 160);
1570 return new Color(75, 25, 170);
1574 return new Color(65, 225, 180);
1578 return new Color(55, 15, 185);
1582 return new Color(45, 235, 195);
1586 return new Color(35, 5, 205);
1590 return new Color(25, 245, 215);
1594 return new Color(15, 0, 225);
1598 return new Color(10, 255, 235);
1602 return new Color(5, 150, 245);
1606 return new Color(0, 80, 255);
1609 System.out.println("This is not a interaction : " + lastss);