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.ProfileI;
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 ProfileI[] 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[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(hconsensus[column],
370 av_ignoreGapsConsensus);
376 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
378 // TODO implement group structure consensus
380 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
381 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
382 * group selections return StructureFrequency.extractProfile(
383 * aa.groupRef.consensusData[column], aa.groupRef
384 * .getIgnoreGapsConsensus()); }
386 // TODO extend annotation row to enable dynamic and static profile data
389 if (aa.groupRef == null && aa.sequenceRef == null
390 && hStrucConsensus != null
391 && hStrucConsensus.length > column)
393 return StructureFrequency.extractProfile(hStrucConsensus[column],
394 av_ignoreGapsConsensus);
404 * Render the annotation rows associated with an alignment.
409 * data and view settings to render
411 * destination for graphics
413 * row where a mouse event occured (or -1)
415 * first column that will be drawn
417 * last column that will be drawn
418 * @return true if the fadedImage was used for any alignment annotation rows
419 * currently being calculated
421 public boolean drawComponent(AwtRenderPanelI annotPanel,
422 AlignViewportI av, Graphics g, int activeRow, int startRes,
425 long stime = System.currentTimeMillis();
426 boolean usedFaded = false;
428 // AnnotationPanel needs to implement: ImageObserver, access to
430 updateFromAwtRenderPanel(annotPanel, av);
431 fm = g.getFontMetrics();
432 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
443 boolean validRes = false;
444 boolean validEnd = false;
445 boolean labelAllCols = false;
446 boolean centreColLabels;
447 boolean centreColLabelsDef = av.isCentreColumnLabels();
448 boolean scaleColLabel = false;
449 final AlignmentAnnotation consensusAnnot = av
450 .getAlignmentConsensusAnnotation();
451 final AlignmentAnnotation structConsensusAnnot = av
452 .getAlignmentStrucConsensusAnnotation();
453 final AlignmentAnnotation complementConsensusAnnot = av
454 .getComplementConsensusAnnotation();
455 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
457 BitSet graphGroupDrawn = new BitSet();
458 int charOffset = 0; // offset for a label
459 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
461 Font ofont = g.getFont();
464 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
465 boolean clipst = false, clipend = false;
466 for (int i = 0; i < aa.length; i++)
468 AlignmentAnnotation row = aa[i];
471 // check if this is a consensus annotation row and set the display
472 // settings appropriately
473 // TODO: generalise this to have render styles for consensus/profile
475 if (row.groupRef != null && row == row.groupRef.getConsensus())
477 renderHistogram = row.groupRef.isShowConsensusHistogram();
478 renderProfile = row.groupRef.isShowSequenceLogo();
479 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
481 else if (row == consensusAnnot || row == structConsensusAnnot
482 || row == complementConsensusAnnot)
484 renderHistogram = av_renderHistogram;
485 renderProfile = av_renderProfile;
486 normaliseProfile = av_normaliseProfile;
490 renderHistogram = true;
491 // don't need to set render/normaliseProfile since they are not
492 // currently used in any other annotation track renderer
495 Annotation[] row_annotations = row.annotations;
500 centreColLabels = row.centreColLabels || centreColLabelsDef;
501 labelAllCols = row.showAllColLabels;
502 scaleColLabel = row.scaleColLabel;
507 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
508 {// if_in_visible_region
519 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
524 // this is so that we draw the characters below the graph
529 iconOffset = charHeight - fm.getDescent();
533 else if (row.hasText)
535 iconOffset = charHeight - fm.getDescent();
543 if (row.autoCalculated && av.isCalculationInProgress(row))
547 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
548 - row.height, imgWidth, y, annotationPanel);
549 g.setColor(Color.black);
550 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
556 * else if (annotationPanel.av.updatingConservation &&
557 * aa[i].label.equals("Conservation")) {
559 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
560 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
561 * annotationPanel.imgWidth, y, annotationPanel);
563 * g.setColor(Color.black); //
564 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
566 * continue; } else if (annotationPanel.av.updatingConservation &&
567 * aa[i].label.equals("Quality")) {
569 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
570 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
571 * annotationPanel.imgWidth, y, annotationPanel);
572 * g.setColor(Color.black); // /
573 * g.drawString("Calculating Quality....",20, y-row.height/2);
577 // first pass sets up state for drawing continuation from left-hand
580 x = (startRes == 0) ? 0 : -1;
581 while (x < endRes - startRes)
583 if (hasHiddenColumns)
585 column = columnSelection.adjustForHiddenColumns(startRes + x);
586 if (column > row_annotations.length - 1)
593 column = startRes + x;
596 if ((row_annotations == null)
597 || (row_annotations.length <= column)
598 || (row_annotations[column] == null))
606 final String displayChar = validRes ? row_annotations[column].displayCharacter
612 g.setColor(Color.red);
614 if (columnSelection != null)
616 if (columnSelection.contains(column))
618 g.fillRect(x * charWidth, y, charWidth, charHeight);
622 if (row.getInvalidStrucPos() > x)
624 g.setColor(Color.orange);
625 g.fillRect(x * charWidth, y, charWidth, charHeight);
627 else if (row.getInvalidStrucPos() == x)
629 g.setColor(Color.orange.darker());
630 g.fillRect(x * charWidth, y, charWidth, charHeight);
632 if (validCharWidth && validRes && displayChar != null
633 && (displayChar.length() > 0))
636 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
637 displayChar.length());
638 if (/* centreColLabels || */scaleColLabel)
640 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
641 // displayChar.length());
643 // if (scaleColLabel)
645 // justify the label and scale to fit in column
646 if (fmWidth > charWidth)
648 // scale only if the current font isn't already small enough
649 fmScaling = charWidth;
650 fmScaling /= fmWidth;
651 g.setFont(ofont.deriveFont(AffineTransform
652 .getScaleInstance(fmScaling, 1.0)));
653 // and update the label's width to reflect the scaling.
658 // TODO is it ok to use width of / show all characters here?
661 // fmWidth = fm.charWidth(displayChar.charAt(0));
663 charOffset = (int) ((charWidth - fmWidth) / 2f);
665 if (row_annotations[column].colour == null)
667 g.setColor(Color.black);
671 g.setColor(row_annotations[column].colour);
674 if (column == 0 || row.graph > 0)
676 g.drawString(displayChar, (x * charWidth) + charOffset, y
679 else if (row_annotations[column - 1] == null
682 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
683 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
685 g.drawString(displayChar, x * charWidth + charOffset, y
693 char ss = validRes ? row_annotations[column].secondaryStructure
698 // distinguish between forward/backward base-pairing
699 if (displayChar.indexOf(')') > -1)
708 if ((displayChar.indexOf(']') > -1))
716 // distinguish between forward/backward base-pairing
717 if (displayChar.indexOf('}') > -1)
725 // distinguish between forward/backward base-pairing
726 if (displayChar.indexOf('<') > -1)
732 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
734 // distinguish between forward/backward base-pairing
735 int ssLowerCase = ss + UPPER_TO_LOWER;
736 // TODO would .equals() be safer here? or charAt(0)?
737 if (displayChar.indexOf(ssLowerCase) > -1)
739 ss = (char) ssLowerCase;
743 if (!validRes || (ss != lastSS))
749 int nb_annot = x - temp;
750 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
753 case '(': // Stem case for RNA secondary structure
754 case ')': // and opposite direction
755 drawStemAnnot(g, row_annotations, lastSSX, x, y,
756 iconOffset, startRes, column, validRes, validEnd);
763 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
764 iconOffset, startRes, column, validRes,
768 // no break if isRNA - falls through to drawNotCanonicalAnnot!
772 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
773 iconOffset, startRes, column, validRes,
777 // no break if isRNA - fall through to drawNotCanonicalAnnot!
836 Color nonCanColor = getNotCanonicalColor(lastSS);
837 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
838 lastSSX, x, y, iconOffset, startRes, column,
843 g.setColor(Color.gray);
844 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
860 lastSSX = (x * charWidth);
867 if (column >= row_annotations.length)
869 column = row_annotations.length - 1;
876 if ((row_annotations == null) || (row_annotations.length <= column)
877 || (row_annotations[column] == null))
895 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
896 startRes, column, validRes, validEnd);
899 // no break if isRNA - fall through to drawNotCanonicalAnnot!
904 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
905 startRes, column, validRes, validEnd);
908 // no break if isRNA - fall through to drawNotCanonicalAnnot!
911 case ')': // Stem case for RNA secondary structure
913 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
914 startRes, column, validRes, validEnd);
971 // System.out.println(lastSS);
972 Color nonCanColor = getNotCanonicalColor(lastSS);
973 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
974 x, y, iconOffset, startRes, column, validRes, validEnd);
977 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
978 startRes, column, validRes, validEnd);
983 if (row.graph > 0 && row.graphHeight > 0)
985 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
987 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
989 // TODO: JAL-1291 revise rendering model so the graphGroup map is
990 // computed efficiently for all visible labels
991 float groupmax = -999999, groupmin = 9999999;
992 for (int gg = 0; gg < aa.length; gg++)
994 if (aa[gg].graphGroup != row.graphGroup)
1001 aa[gg].visible = false;
1003 if (aa[gg].graphMax > groupmax)
1005 groupmax = aa[gg].graphMax;
1007 if (aa[gg].graphMin < groupmin)
1009 groupmin = aa[gg].graphMin;
1013 for (int gg = 0; gg < aa.length; gg++)
1015 if (aa[gg].graphGroup == row.graphGroup)
1017 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1018 endRes, y, groupmin, groupmax, row.graphHeight);
1022 graphGroupDrawn.set(row.graphGroup);
1026 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1027 row.graphMin, row.graphMax, row.graphHeight);
1030 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1032 drawBarGraph(g, row, row_annotations, startRes, endRes,
1033 row.graphMin, row.graphMax, y, renderHistogram,
1034 renderProfile, normaliseProfile);
1040 if (clipst && !clipend)
1044 }// end if_in_visible_region
1045 if (row.graph > 0 && row.hasText)
1061 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1066 System.err.println("End clip at : " + yto + " (index " + f_to
1071 System.err.println("Annotation Rendering time:"
1072 + (System.currentTimeMillis() - stime));
1079 public static final Color GLYPHLINE_COLOR = Color.gray;
1081 public static final Color SHEET_COLOUR = Color.green;
1083 public static final Color HELIX_COLOUR = Color.red;
1085 public static final Color STEM_COLOUR = Color.blue;
1087 private Color sdNOTCANONICAL_COLOUR;
1089 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1090 int y, int iconOffset, int startRes, int column,
1091 boolean validRes, boolean validEnd)
1093 g.setColor(GLYPHLINE_COLOR);
1094 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1097 void drawSheetAnnot(Graphics g, Annotation[] row,
1099 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1100 boolean validRes, boolean validEnd)
1102 g.setColor(SHEET_COLOUR);
1104 if (!validEnd || !validRes || row == null || row[column] == null
1105 || row[column].secondaryStructure != 'E')
1107 g.fillRect(lastSSX, y + 4 + iconOffset,
1108 (x * charWidth) - lastSSX - 4, 7);
1109 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1110 (x * charWidth) }, new int[] { y + iconOffset,
1111 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1115 g.fillRect(lastSSX, y + 4 + iconOffset,
1116 (x + 1) * charWidth - lastSSX, 7);
1121 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1122 int y, int iconOffset, int startRes, int column,
1123 boolean validRes, boolean validEnd)
1125 g.setColor(HELIX_COLOUR);
1127 int sCol = (lastSSX / charWidth) + startRes;
1129 int x2 = (x * charWidth);
1133 int ofs = charWidth / 2;
1134 // Off by 1 offset when drawing rects and ovals
1135 // to offscreen image on the MAC
1136 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1137 if (sCol == 0 || row[sCol - 1] == null
1138 || row[sCol - 1].secondaryStructure != 'H')
1143 // g.setColor(Color.orange);
1144 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1147 if (!validRes || row[column] == null
1148 || row[column].secondaryStructure != 'H')
1154 // g.setColor(Color.magenta);
1155 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1163 if (sCol == 0 || row[sCol - 1] == null
1164 || row[sCol - 1].secondaryStructure != 'H')
1166 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1167 x1 += charWidth / 2;
1170 if (!validRes || row[column] == null
1171 || row[column].secondaryStructure != 'H')
1173 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1175 x2 -= charWidth / 2;
1178 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1181 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1182 Annotation[] aa_annotations, int sRes, int eRes, int y,
1183 float min, float max, int graphHeight)
1185 if (sRes > aa_annotations.length)
1192 // Adjustment for fastpaint to left
1198 eRes = Math.min(eRes, aa_annotations.length);
1206 float range = max - min;
1211 y2 = y - (int) ((0 - min / range) * graphHeight);
1214 g.setColor(Color.gray);
1215 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1217 eRes = Math.min(eRes, aa_annotations.length);
1220 int aaMax = aa_annotations.length - 1;
1222 while (x < eRes - sRes)
1225 if (hasHiddenColumns)
1227 column = columnSelection.adjustForHiddenColumns(column);
1235 if (aa_annotations[column] == null
1236 || aa_annotations[column - 1] == null)
1242 if (aa_annotations[column].colour == null)
1244 g.setColor(Color.black);
1248 g.setColor(aa_annotations[column].colour);
1252 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1254 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1256 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1257 + charWidth / 2, y2);
1261 if (_aa.threshold != null)
1263 g.setColor(_aa.threshold.colour);
1264 Graphics2D g2 = (Graphics2D) g;
1265 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1266 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1268 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1269 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1270 g2.setStroke(new BasicStroke());
1274 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1275 Annotation[] aa_annotations, int sRes, int eRes, float min,
1276 float max, int y, boolean renderHistogram, boolean renderProfile,
1277 boolean normaliseProfile)
1279 if (sRes > aa_annotations.length)
1283 Font ofont = g.getFont();
1284 eRes = Math.min(eRes, aa_annotations.length);
1286 int x = 0, y1 = y, y2 = y;
1288 float range = max - min;
1292 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1295 g.setColor(Color.gray);
1297 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1300 int aaMax = aa_annotations.length - 1;
1301 while (x < eRes - sRes)
1304 if (hasHiddenColumns)
1306 column = columnSelection.adjustForHiddenColumns(column);
1314 if (aa_annotations[column] == null)
1319 if (aa_annotations[column].colour == null)
1321 g.setColor(Color.black);
1325 g.setColor(aa_annotations[column].colour);
1329 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1331 if (renderHistogram)
1335 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1339 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1342 // draw profile if available
1347 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1349 int profl[] = getProfileFor(_aa, column);
1351 // just try to draw the logo if profl is not null
1352 if (profl != null && profl[2] != 0)
1354 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1355 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1356 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1357 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1364 * Render a single base for a sequence profile, a base pair for
1365 * structure profile, and a triplet for a cdna profile
1367 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1369 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1370 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1371 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1375 * Traverse the character(s)/percentage data in the array
1378 int valuesProcessed = 0;
1379 // profl[1] is the number of values in the profile
1380 while (valuesProcessed < profl[1])
1382 if (isStructureProfile)
1384 // todo can we encode a structure pair as an int, like codons?
1385 dc[0] = (char) profl[c++];
1386 dc[1] = (char) profl[c++];
1388 else if (isCdnaProfile)
1390 dc = CodingUtils.decodeCodon(profl[c++]);
1394 dc[0] = (char) profl[c++];
1398 wdth /= fm.charsWidth(dc, 0, dc.length);
1401 // next profl[] position is profile % for the character(s)
1402 scl = htn * scale * profl[c++];
1403 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1404 .getFontRenderContext());
1405 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1406 wdth, scl / lm.getAscent()));
1408 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1410 // Debug - render boxes around characters
1411 // g.setColor(Color.red);
1412 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1414 // g.setColor(profcolour.findColour(dc[0]).darker());
1417 * Set character colour as per alignment colour scheme; use the
1418 * codon translation if a cDNA profile
1420 Color colour = null;
1423 final String codonTranslation = ResidueProperties
1424 .codonTranslate(new String(dc));
1425 colour = profcolour.findColour(codonTranslation.charAt(0),
1430 colour = profcolour.findColour(dc[0], column, null);
1432 g.setColor(colour == Color.white ? Color.lightGray : colour);
1434 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1435 .getBaselineIndex()]));
1437 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1445 if (_aa.threshold != null)
1447 g.setColor(_aa.threshold.colour);
1448 Graphics2D g2 = (Graphics2D) g;
1449 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1450 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1452 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1454 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1455 g2.setStroke(new BasicStroke());
1459 // used by overview window
1460 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1461 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1463 eRes = Math.min(eRes, aa_annotations.length);
1464 g.setColor(Color.white);
1465 g.fillRect(0, 0, width, y);
1466 g.setColor(new Color(0, 0, 180));
1470 for (int j = sRes; j < eRes; j++)
1472 if (aa_annotations[j] != null)
1474 if (aa_annotations[j].colour == null)
1476 g.setColor(Color.black);
1480 g.setColor(aa_annotations[j].colour);
1483 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1489 g.fillRect(x, y - height, charWidth, height);
1495 Color getNotCanonicalColor(char lastss)
1501 return new Color(255, 125, 5);
1505 return new Color(245, 115, 10);
1509 return new Color(235, 135, 15);
1513 return new Color(225, 105, 20);
1517 return new Color(215, 145, 30);
1521 return new Color(205, 95, 35);
1525 return new Color(195, 155, 45);
1529 return new Color(185, 85, 55);
1533 return new Color(175, 165, 65);
1537 return new Color(170, 75, 75);
1541 return new Color(160, 175, 85);
1545 return new Color(150, 65, 95);
1549 return new Color(140, 185, 105);
1553 return new Color(130, 55, 110);
1557 return new Color(120, 195, 120);
1561 return new Color(110, 45, 130);
1565 return new Color(100, 205, 140);
1569 return new Color(90, 35, 150);
1573 return new Color(85, 215, 160);
1577 return new Color(75, 25, 170);
1581 return new Color(65, 225, 180);
1585 return new Color(55, 15, 185);
1589 return new Color(45, 235, 195);
1593 return new Color(35, 5, 205);
1597 return new Color(25, 245, 215);
1601 return new Color(15, 0, 225);
1605 return new Color(10, 255, 235);
1609 return new Color(5, 150, 245);
1613 return new Color(0, 80, 255);
1616 System.out.println("This is not a interaction : " + lastss);