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.Rna;
26 import jalview.analysis.StructureFrequency;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.ProfilesI;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ResidueProperties;
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 public class AnnotationRenderer
51 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
53 private static final int CHAR_A = 'A'; // 65
55 private static final int CHAR_Z = 'Z'; // 90
58 * flag indicating if timing and redraw parameter info should be output
60 private final boolean debugRedraw;
62 private int charWidth, endRes, charHeight;
64 private boolean validCharWidth, hasHiddenColumns;
66 private FontMetrics fm;
68 private final boolean MAC = Platform.isAMac();
70 boolean av_renderHistogram = true, av_renderProfile = true,
71 av_normaliseProfile = false;
73 ColourSchemeI profcolour = null;
75 private ColumnSelection columnSelection;
77 private ProfilesI hconsensus;
79 private Hashtable[] complementConsensus;
81 private Hashtable[] hStrucConsensus;
83 private boolean av_ignoreGapsConsensus;
86 * attributes set from AwtRenderPanelI
89 * old image used when data is currently being calculated and cannot be
92 private Image fadedImage;
95 * panel being rendered into
97 private ImageObserver annotationPanel;
100 * width of image to render in panel
102 private int imgWidth;
105 * offset to beginning of visible area
110 * offset to end of visible area
112 private int visHeight;
115 * indicate if the renderer should only render the visible portion of the
116 * annotation given the current view settings
118 private boolean useClip = true;
121 * master flag indicating if renderer should ever try to clip. not enabled for
124 private boolean canClip = false;
126 public AnnotationRenderer()
132 * Create a new annotation Renderer
135 * flag indicating if timing and redraw parameter info should be
138 public AnnotationRenderer(boolean debugRedraw)
140 this.debugRedraw = debugRedraw;
144 * Remove any references and resources when this object is no longer required
146 public void dispose()
149 complementConsensus = null;
150 hStrucConsensus = null;
152 annotationPanel = null;
155 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
156 int x, int y, int iconOffset, int startRes, int column,
157 boolean validRes, boolean validEnd)
159 g.setColor(STEM_COLOUR);
160 int sCol = (lastSSX / charWidth) + startRes;
162 int x2 = (x * charWidth);
164 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
165 : row_annotations[column - 1].secondaryStructure;
167 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
168 || dc != row_annotations[sCol - 1].secondaryStructure;
169 boolean diffdownstream = !validRes || !validEnd
170 || row_annotations[column] == null
171 || dc != row_annotations[column].secondaryStructure;
173 if (column > 0 && Rna.isClosingParenthesis(dc))
176 // if (validRes && column>1 && row_annotations[column-2]!=null &&
177 // dc.equals(row_annotations[column-2].displayCharacter))
180 * if new annotation with a closing base pair half of the stem,
181 * display a backward arrow
183 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
184 new int[] { y + iconOffset, y + 14 + iconOffset,
185 y + 8 + iconOffset }, 3);
195 // display a forward arrow
199 * if annotation ending with an opeing base pair half of the stem,
200 * display a forward arrow
202 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
203 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
212 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
215 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
216 Annotation[] row_annotations, int lastSSX, int x, int y,
217 int iconOffset, int startRes, int column, boolean validRes,
220 // System.out.println(nonCanColor);
222 g.setColor(nonCanColor);
223 int sCol = (lastSSX / charWidth) + startRes;
225 int x2 = (x * charWidth);
227 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
228 : row_annotations[column - 1].displayCharacter;
230 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
231 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
232 boolean diffdownstream = !validRes || !validEnd
233 || row_annotations[column] == null
234 || !dc.equals(row_annotations[column].displayCharacter);
235 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
236 // If a closing base pair half of the stem, display a backward arrow
237 if (column > 0 && Rna.isClosingParenthesis(dc))
241 // if (validRes && column>1 && row_annotations[column-2]!=null &&
242 // dc.equals(row_annotations[column-2].displayCharacter))
244 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
245 new int[] { y + iconOffset, y + 14 + iconOffset,
246 y + 8 + iconOffset }, 3);
257 // display a forward arrow
260 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
261 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
270 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
273 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
275 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
278 fm = annotPanel.getFontMetrics();
279 annotationPanel = annotPanel;
280 fadedImage = annotPanel.getFadedImage();
281 imgWidth = annotPanel.getFadedImageWidth();
282 // visible area for rendering
283 int[] bounds = annotPanel.getVisibleVRange();
287 visHeight = bounds[1];
302 updateFromAlignViewport(av);
305 public void updateFromAlignViewport(AlignViewportI av)
307 charWidth = av.getCharWidth();
308 endRes = av.getEndRes();
309 charHeight = av.getCharHeight();
310 hasHiddenColumns = av.hasHiddenColumns();
311 validCharWidth = av.isValidCharWidth();
312 av_renderHistogram = av.isShowConsensusHistogram();
313 av_renderProfile = av.isShowSequenceLogo();
314 av_normaliseProfile = av.isNormaliseSequenceLogo();
315 profcolour = av.getGlobalColourScheme();
316 if (profcolour == null)
318 // Set the default colour for sequence logo if the alignnent has no
320 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
321 : new jalview.schemes.ZappoColourScheme();
323 columnSelection = av.getColumnSelection();
324 hconsensus = av.getSequenceConsensusHash();
325 complementConsensus = av.getComplementConsensusHash();
326 hStrucConsensus = av.getRnaStructureConsensusHash();
327 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
331 * Returns profile data; the first element is the profile type, the second is
332 * the number of distinct values, the third the total count, and the remainder
333 * depend on the profile type.
339 int[] getProfileFor(AlignmentAnnotation aa, int column)
341 // TODO : consider refactoring the global alignment calculation
342 // properties/rendering attributes as a global 'alignment group' which holds
343 // all vis settings for the alignment as a whole rather than a subset
345 if (aa.autoCalculated
346 && (aa.label.startsWith("Consensus") || aa.label
347 .startsWith("cDNA Consensus")))
349 boolean forComplement = aa.label.startsWith("cDNA Consensus");
350 if (aa.groupRef != null && aa.groupRef.consensusData != null
351 && aa.groupRef.isShowSequenceLogo())
353 // TODO? group consensus for cDNA complement
354 return AAFrequency.extractProfile(
355 aa.groupRef.consensusData.get(column),
356 aa.groupRef.getIgnoreGapsConsensus());
358 // TODO extend annotation row to enable dynamic and static profile data to
360 if (aa.groupRef == null && aa.sequenceRef == null)
364 return AAFrequency.extractCdnaProfile(
365 complementConsensus[column], av_ignoreGapsConsensus);
369 return AAFrequency.extractProfile(
370 hconsensus.get(column),
371 av_ignoreGapsConsensus);
377 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
379 // TODO implement group structure consensus
381 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
382 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
383 * group selections return StructureFrequency.extractProfile(
384 * aa.groupRef.consensusData[column], aa.groupRef
385 * .getIgnoreGapsConsensus()); }
387 // TODO extend annotation row to enable dynamic and static profile data
390 if (aa.groupRef == null && aa.sequenceRef == null
391 && hStrucConsensus != null
392 && hStrucConsensus.length > column)
394 return StructureFrequency.extractProfile(hStrucConsensus[column],
395 av_ignoreGapsConsensus);
405 * Render the annotation rows associated with an alignment.
410 * data and view settings to render
412 * destination for graphics
414 * row where a mouse event occured (or -1)
416 * first column that will be drawn
418 * last column that will be drawn
419 * @return true if the fadedImage was used for any alignment annotation rows
420 * currently being calculated
422 public boolean drawComponent(AwtRenderPanelI annotPanel,
423 AlignViewportI av, Graphics g, int activeRow, int startRes,
426 long stime = System.currentTimeMillis();
427 boolean usedFaded = false;
429 // AnnotationPanel needs to implement: ImageObserver, access to
431 updateFromAwtRenderPanel(annotPanel, av);
432 fm = g.getFontMetrics();
433 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
444 boolean validRes = false;
445 boolean validEnd = false;
446 boolean labelAllCols = false;
447 boolean centreColLabels;
448 boolean centreColLabelsDef = av.isCentreColumnLabels();
449 boolean scaleColLabel = false;
450 final AlignmentAnnotation consensusAnnot = av
451 .getAlignmentConsensusAnnotation();
452 final AlignmentAnnotation structConsensusAnnot = av
453 .getAlignmentStrucConsensusAnnotation();
454 final AlignmentAnnotation complementConsensusAnnot = av
455 .getComplementConsensusAnnotation();
456 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
458 BitSet graphGroupDrawn = new BitSet();
459 int charOffset = 0; // offset for a label
460 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
462 Font ofont = g.getFont();
465 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
466 boolean clipst = false, clipend = false;
467 for (int i = 0; i < aa.length; i++)
469 AlignmentAnnotation row = aa[i];
472 // check if this is a consensus annotation row and set the display
473 // settings appropriately
474 // TODO: generalise this to have render styles for consensus/profile
476 if (row.groupRef != null && row == row.groupRef.getConsensus())
478 renderHistogram = row.groupRef.isShowConsensusHistogram();
479 renderProfile = row.groupRef.isShowSequenceLogo();
480 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
482 else if (row == consensusAnnot || row == structConsensusAnnot
483 || row == complementConsensusAnnot)
485 renderHistogram = av_renderHistogram;
486 renderProfile = av_renderProfile;
487 normaliseProfile = av_normaliseProfile;
491 renderHistogram = true;
492 // don't need to set render/normaliseProfile since they are not
493 // currently used in any other annotation track renderer
496 Annotation[] row_annotations = row.annotations;
501 centreColLabels = row.centreColLabels || centreColLabelsDef;
502 labelAllCols = row.showAllColLabels;
503 scaleColLabel = row.scaleColLabel;
508 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
509 {// if_in_visible_region
520 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
525 // this is so that we draw the characters below the graph
530 iconOffset = charHeight - fm.getDescent();
534 else if (row.hasText)
536 iconOffset = charHeight - fm.getDescent();
544 if (row.autoCalculated && av.isCalculationInProgress(row))
548 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
549 - row.height, imgWidth, y, annotationPanel);
550 g.setColor(Color.black);
551 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
557 * else if (annotationPanel.av.updatingConservation &&
558 * aa[i].label.equals("Conservation")) {
560 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
561 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
562 * annotationPanel.imgWidth, y, annotationPanel);
564 * g.setColor(Color.black); //
565 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
567 * continue; } else if (annotationPanel.av.updatingConservation &&
568 * aa[i].label.equals("Quality")) {
570 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
571 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
572 * annotationPanel.imgWidth, y, annotationPanel);
573 * g.setColor(Color.black); // /
574 * g.drawString("Calculating Quality....",20, y-row.height/2);
578 // first pass sets up state for drawing continuation from left-hand
581 x = (startRes == 0) ? 0 : -1;
582 while (x < endRes - startRes)
584 if (hasHiddenColumns)
586 column = columnSelection.adjustForHiddenColumns(startRes + x);
587 if (column > row_annotations.length - 1)
594 column = startRes + x;
597 if ((row_annotations == null)
598 || (row_annotations.length <= column)
599 || (row_annotations[column] == null))
607 final String displayChar = validRes ? row_annotations[column].displayCharacter
613 g.setColor(Color.red);
615 if (columnSelection != null)
617 if (columnSelection.contains(column))
619 g.fillRect(x * charWidth, y, charWidth, charHeight);
623 if (row.getInvalidStrucPos() > x)
625 g.setColor(Color.orange);
626 g.fillRect(x * charWidth, y, charWidth, charHeight);
628 else if (row.getInvalidStrucPos() == x)
630 g.setColor(Color.orange.darker());
631 g.fillRect(x * charWidth, y, charWidth, charHeight);
633 if (validCharWidth && validRes && displayChar != null
634 && (displayChar.length() > 0))
637 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
638 displayChar.length());
639 if (/* centreColLabels || */scaleColLabel)
641 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
642 // displayChar.length());
644 // if (scaleColLabel)
646 // justify the label and scale to fit in column
647 if (fmWidth > charWidth)
649 // scale only if the current font isn't already small enough
650 fmScaling = charWidth;
651 fmScaling /= fmWidth;
652 g.setFont(ofont.deriveFont(AffineTransform
653 .getScaleInstance(fmScaling, 1.0)));
654 // and update the label's width to reflect the scaling.
659 // TODO is it ok to use width of / show all characters here?
662 // fmWidth = fm.charWidth(displayChar.charAt(0));
664 charOffset = (int) ((charWidth - fmWidth) / 2f);
666 if (row_annotations[column].colour == null)
668 g.setColor(Color.black);
672 g.setColor(row_annotations[column].colour);
675 if (column == 0 || row.graph > 0)
677 g.drawString(displayChar, (x * charWidth) + charOffset, y
680 else if (row_annotations[column - 1] == null
683 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
684 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
686 g.drawString(displayChar, x * charWidth + charOffset, y
694 char ss = validRes ? row_annotations[column].secondaryStructure
699 // distinguish between forward/backward base-pairing
700 if (displayChar.indexOf(')') > -1)
709 if ((displayChar.indexOf(']') > -1))
717 // distinguish between forward/backward base-pairing
718 if (displayChar.indexOf('}') > -1)
726 // distinguish between forward/backward base-pairing
727 if (displayChar.indexOf('<') > -1)
733 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
735 // distinguish between forward/backward base-pairing
736 int ssLowerCase = ss + UPPER_TO_LOWER;
737 // TODO would .equals() be safer here? or charAt(0)?
738 if (displayChar.indexOf(ssLowerCase) > -1)
740 ss = (char) ssLowerCase;
744 if (!validRes || (ss != lastSS))
750 int nb_annot = x - temp;
751 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
754 case '(': // Stem case for RNA secondary structure
755 case ')': // and opposite direction
756 drawStemAnnot(g, row_annotations, lastSSX, x, y,
757 iconOffset, startRes, column, validRes, validEnd);
764 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
765 iconOffset, startRes, column, validRes,
769 // no break if isRNA - falls through to drawNotCanonicalAnnot!
773 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
774 iconOffset, startRes, column, validRes,
778 // no break if isRNA - fall through to drawNotCanonicalAnnot!
837 Color nonCanColor = getNotCanonicalColor(lastSS);
838 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
839 lastSSX, x, y, iconOffset, startRes, column,
844 g.setColor(Color.gray);
845 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
861 lastSSX = (x * charWidth);
868 if (column >= row_annotations.length)
870 column = row_annotations.length - 1;
877 if ((row_annotations == null) || (row_annotations.length <= column)
878 || (row_annotations[column] == null))
896 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
897 startRes, column, validRes, validEnd);
900 // no break if isRNA - fall through to drawNotCanonicalAnnot!
905 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
906 startRes, column, validRes, validEnd);
909 // no break if isRNA - fall through to drawNotCanonicalAnnot!
912 case ')': // Stem case for RNA secondary structure
914 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
915 startRes, column, validRes, validEnd);
972 // System.out.println(lastSS);
973 Color nonCanColor = getNotCanonicalColor(lastSS);
974 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
975 x, y, iconOffset, startRes, column, validRes, validEnd);
978 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
979 startRes, column, validRes, validEnd);
984 if (row.graph > 0 && row.graphHeight > 0)
986 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
988 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
990 // TODO: JAL-1291 revise rendering model so the graphGroup map is
991 // computed efficiently for all visible labels
992 float groupmax = -999999, groupmin = 9999999;
993 for (int gg = 0; gg < aa.length; gg++)
995 if (aa[gg].graphGroup != row.graphGroup)
1002 aa[gg].visible = false;
1004 if (aa[gg].graphMax > groupmax)
1006 groupmax = aa[gg].graphMax;
1008 if (aa[gg].graphMin < groupmin)
1010 groupmin = aa[gg].graphMin;
1014 for (int gg = 0; gg < aa.length; gg++)
1016 if (aa[gg].graphGroup == row.graphGroup)
1018 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1019 endRes, y, groupmin, groupmax, row.graphHeight);
1023 graphGroupDrawn.set(row.graphGroup);
1027 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1028 row.graphMin, row.graphMax, row.graphHeight);
1031 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1033 drawBarGraph(g, row, row_annotations, startRes, endRes,
1034 row.graphMin, row.graphMax, y, renderHistogram,
1035 renderProfile, normaliseProfile);
1041 if (clipst && !clipend)
1045 }// end if_in_visible_region
1046 if (row.graph > 0 && row.hasText)
1062 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1067 System.err.println("End clip at : " + yto + " (index " + f_to
1072 System.err.println("Annotation Rendering time:"
1073 + (System.currentTimeMillis() - stime));
1080 public static final Color GLYPHLINE_COLOR = Color.gray;
1082 public static final Color SHEET_COLOUR = Color.green;
1084 public static final Color HELIX_COLOUR = Color.red;
1086 public static final Color STEM_COLOUR = Color.blue;
1088 private Color sdNOTCANONICAL_COLOUR;
1090 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1091 int y, int iconOffset, int startRes, int column,
1092 boolean validRes, boolean validEnd)
1094 g.setColor(GLYPHLINE_COLOR);
1095 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1098 void drawSheetAnnot(Graphics g, Annotation[] row,
1100 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1101 boolean validRes, boolean validEnd)
1103 g.setColor(SHEET_COLOUR);
1105 if (!validEnd || !validRes || row == null || row[column] == null
1106 || row[column].secondaryStructure != 'E')
1108 g.fillRect(lastSSX, y + 4 + iconOffset,
1109 (x * charWidth) - lastSSX - 4, 7);
1110 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1111 (x * charWidth) }, new int[] { y + iconOffset,
1112 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1116 g.fillRect(lastSSX, y + 4 + iconOffset,
1117 (x + 1) * charWidth - lastSSX, 7);
1122 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1123 int y, int iconOffset, int startRes, int column,
1124 boolean validRes, boolean validEnd)
1126 g.setColor(HELIX_COLOUR);
1128 int sCol = (lastSSX / charWidth) + startRes;
1130 int x2 = (x * charWidth);
1134 int ofs = charWidth / 2;
1135 // Off by 1 offset when drawing rects and ovals
1136 // to offscreen image on the MAC
1137 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1138 if (sCol == 0 || row[sCol - 1] == null
1139 || row[sCol - 1].secondaryStructure != 'H')
1144 // g.setColor(Color.orange);
1145 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1148 if (!validRes || row[column] == null
1149 || row[column].secondaryStructure != 'H')
1155 // g.setColor(Color.magenta);
1156 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1164 if (sCol == 0 || row[sCol - 1] == null
1165 || row[sCol - 1].secondaryStructure != 'H')
1167 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1168 x1 += charWidth / 2;
1171 if (!validRes || row[column] == null
1172 || row[column].secondaryStructure != 'H')
1174 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1176 x2 -= charWidth / 2;
1179 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1182 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1183 Annotation[] aa_annotations, int sRes, int eRes, int y,
1184 float min, float max, int graphHeight)
1186 if (sRes > aa_annotations.length)
1193 // Adjustment for fastpaint to left
1199 eRes = Math.min(eRes, aa_annotations.length);
1207 float range = max - min;
1212 y2 = y - (int) ((0 - min / range) * graphHeight);
1215 g.setColor(Color.gray);
1216 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1218 eRes = Math.min(eRes, aa_annotations.length);
1221 int aaMax = aa_annotations.length - 1;
1223 while (x < eRes - sRes)
1226 if (hasHiddenColumns)
1228 column = columnSelection.adjustForHiddenColumns(column);
1236 if (aa_annotations[column] == null
1237 || aa_annotations[column - 1] == null)
1243 if (aa_annotations[column].colour == null)
1245 g.setColor(Color.black);
1249 g.setColor(aa_annotations[column].colour);
1253 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1255 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1257 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1258 + charWidth / 2, y2);
1262 if (_aa.threshold != null)
1264 g.setColor(_aa.threshold.colour);
1265 Graphics2D g2 = (Graphics2D) g;
1266 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1267 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1269 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1270 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1271 g2.setStroke(new BasicStroke());
1275 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1276 Annotation[] aa_annotations, int sRes, int eRes, float min,
1277 float max, int y, boolean renderHistogram, boolean renderProfile,
1278 boolean normaliseProfile)
1280 if (sRes > aa_annotations.length)
1284 Font ofont = g.getFont();
1285 eRes = Math.min(eRes, aa_annotations.length);
1287 int x = 0, y1 = y, y2 = y;
1289 float range = max - min;
1293 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1296 g.setColor(Color.gray);
1298 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1301 int aaMax = aa_annotations.length - 1;
1302 while (x < eRes - sRes)
1305 if (hasHiddenColumns)
1307 column = columnSelection.adjustForHiddenColumns(column);
1315 if (aa_annotations[column] == null)
1320 if (aa_annotations[column].colour == null)
1322 g.setColor(Color.black);
1326 g.setColor(aa_annotations[column].colour);
1330 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1332 if (renderHistogram)
1336 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1340 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1343 // draw profile if available
1348 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1350 int profl[] = getProfileFor(_aa, column);
1352 // just try to draw the logo if profl is not null
1353 if (profl != null && profl[2] != 0)
1355 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1356 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1357 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1358 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1365 * Render a single base for a sequence profile, a base pair for
1366 * structure profile, and a triplet for a cdna profile
1368 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1370 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1371 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1372 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1376 * Traverse the character(s)/percentage data in the array
1379 int valuesProcessed = 0;
1380 // profl[1] is the number of values in the profile
1381 while (valuesProcessed < profl[1])
1383 if (isStructureProfile)
1385 // todo can we encode a structure pair as an int, like codons?
1386 dc[0] = (char) profl[c++];
1387 dc[1] = (char) profl[c++];
1389 else if (isCdnaProfile)
1391 dc = CodingUtils.decodeCodon(profl[c++]);
1395 dc[0] = (char) profl[c++];
1399 wdth /= fm.charsWidth(dc, 0, dc.length);
1402 // next profl[] position is profile % for the character(s)
1403 scl = htn * scale * profl[c++];
1404 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1405 .getFontRenderContext());
1406 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1407 wdth, scl / lm.getAscent()));
1409 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1411 // Debug - render boxes around characters
1412 // g.setColor(Color.red);
1413 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1415 // g.setColor(profcolour.findColour(dc[0]).darker());
1418 * Set character colour as per alignment colour scheme; use the
1419 * codon translation if a cDNA profile
1421 Color colour = null;
1424 final String codonTranslation = ResidueProperties
1425 .codonTranslate(new String(dc));
1426 colour = profcolour.findColour(codonTranslation.charAt(0),
1431 colour = profcolour.findColour(dc[0], column, null);
1433 g.setColor(colour == Color.white ? Color.lightGray : colour);
1435 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1436 .getBaselineIndex()]));
1438 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1446 if (_aa.threshold != null)
1448 g.setColor(_aa.threshold.colour);
1449 Graphics2D g2 = (Graphics2D) g;
1450 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1451 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1453 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1455 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1456 g2.setStroke(new BasicStroke());
1460 // used by overview window
1461 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1462 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1464 eRes = Math.min(eRes, aa_annotations.length);
1465 g.setColor(Color.white);
1466 g.fillRect(0, 0, width, y);
1467 g.setColor(new Color(0, 0, 180));
1471 for (int j = sRes; j < eRes; j++)
1473 if (aa_annotations[j] != null)
1475 if (aa_annotations[j].colour == null)
1477 g.setColor(Color.black);
1481 g.setColor(aa_annotations[j].colour);
1484 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1490 g.fillRect(x, y - height, charWidth, height);
1496 Color getNotCanonicalColor(char lastss)
1502 return new Color(255, 125, 5);
1506 return new Color(245, 115, 10);
1510 return new Color(235, 135, 15);
1514 return new Color(225, 105, 20);
1518 return new Color(215, 145, 30);
1522 return new Color(205, 95, 35);
1526 return new Color(195, 155, 45);
1530 return new Color(185, 85, 55);
1534 return new Color(175, 165, 65);
1538 return new Color(170, 75, 75);
1542 return new Color(160, 175, 85);
1546 return new Color(150, 65, 95);
1550 return new Color(140, 185, 105);
1554 return new Color(130, 55, 110);
1558 return new Color(120, 195, 120);
1562 return new Color(110, 45, 130);
1566 return new Color(100, 205, 140);
1570 return new Color(90, 35, 150);
1574 return new Color(85, 215, 160);
1578 return new Color(75, 25, 170);
1582 return new Color(65, 225, 180);
1586 return new Color(55, 15, 185);
1590 return new Color(45, 235, 195);
1594 return new Color(35, 5, 205);
1598 return new Color(25, 245, 215);
1602 return new Color(15, 0, 225);
1606 return new Color(10, 255, 235);
1610 return new Color(5, 150, 245);
1614 return new Color(0, 80, 255);
1617 System.out.println("This is not a interaction : " + lastss);