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.HiddenColumns;
32 import jalview.datamodel.HiddenMarkovModel;
33 import jalview.datamodel.ProfilesI;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.NucleotideColourScheme;
36 import jalview.schemes.ResidueProperties;
37 import jalview.schemes.ZappoColourScheme;
38 import jalview.util.Platform;
40 import java.awt.BasicStroke;
41 import java.awt.Color;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.Image;
47 import java.awt.font.LineMetrics;
48 import java.awt.geom.AffineTransform;
49 import java.awt.image.ImageObserver;
50 import java.util.BitSet;
51 import java.util.Hashtable;
53 public class AnnotationRenderer
55 private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
57 private static final int CHAR_A = 'A'; // 65
59 private static final int CHAR_Z = 'Z'; // 90
62 * flag indicating if timing and redraw parameter info should be output
64 private final boolean debugRedraw;
66 private int charWidth, endRes, charHeight;
68 private boolean validCharWidth, hasHiddenColumns;
70 private FontMetrics fm;
72 private final boolean MAC = Platform.isAMac();
74 boolean av_renderHistogram = true, av_renderProfile = true,
75 av_normaliseProfile = false;
77 boolean av_renderInformationHistogram = true, av_renderHMMProfile = true,
78 av_normaliseHMMProfile = false;
80 ResidueShaderI profcolour = null;
82 private ColumnSelection columnSelection;
84 private HiddenColumns hiddenColumns;
86 private ProfilesI hconsensus;
88 private Hashtable[] complementConsensus;
90 private Hashtable[] hStrucConsensus;
92 private boolean av_ignoreGapsConsensus;
94 private boolean av_ignoreBelowBackground;
97 * attributes set from AwtRenderPanelI
100 * old image used when data is currently being calculated and cannot be
103 private Image fadedImage;
106 * panel being rendered into
108 private ImageObserver annotationPanel;
111 * width of image to render in panel
113 private int imgWidth;
116 * offset to beginning of visible area
121 * offset to end of visible area
123 private int visHeight;
126 * indicate if the renderer should only render the visible portion of the
127 * annotation given the current view settings
129 private boolean useClip = true;
132 * master flag indicating if renderer should ever try to clip. not enabled for
135 private boolean canClip = false;
137 public AnnotationRenderer()
143 * Create a new annotation Renderer
146 * flag indicating if timing and redraw parameter info should be
149 public AnnotationRenderer(boolean debugRedraw)
151 this.debugRedraw = debugRedraw;
155 * Remove any references and resources when this object is no longer required
157 public void dispose()
160 complementConsensus = null;
161 hStrucConsensus = null;
163 annotationPanel = null;
166 void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
167 int x, int y, int iconOffset, int startRes, int column,
168 boolean validRes, boolean validEnd)
170 g.setColor(STEM_COLOUR);
171 int sCol = (lastSSX / charWidth) + startRes;
173 int x2 = (x * charWidth);
175 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
176 : row_annotations[column - 1].secondaryStructure;
178 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
179 || dc != row_annotations[sCol - 1].secondaryStructure;
180 boolean diffdownstream = !validRes || !validEnd
181 || row_annotations[column] == null
182 || dc != row_annotations[column].secondaryStructure;
184 if (column > 0 && Rna.isClosingParenthesis(dc))
187 // if (validRes && column>1 && row_annotations[column-2]!=null &&
188 // dc.equals(row_annotations[column-2].displayCharacter))
191 * if new annotation with a closing base pair half of the stem,
192 * display a backward arrow
194 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
195 new int[] { y + iconOffset, y + 14 + iconOffset,
196 y + 8 + iconOffset }, 3);
206 // display a forward arrow
210 * if annotation ending with an opeing base pair half of the stem,
211 * display a forward arrow
213 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
214 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
223 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
226 void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
227 Annotation[] row_annotations, int lastSSX, int x, int y,
228 int iconOffset, int startRes, int column, boolean validRes,
231 // System.out.println(nonCanColor);
233 g.setColor(nonCanColor);
234 int sCol = (lastSSX / charWidth) + startRes;
236 int x2 = (x * charWidth);
238 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
239 : row_annotations[column - 1].displayCharacter;
241 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
242 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
243 boolean diffdownstream = !validRes || !validEnd
244 || row_annotations[column] == null
245 || !dc.equals(row_annotations[column].displayCharacter);
246 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
247 // If a closing base pair half of the stem, display a backward arrow
248 if (column > 0 && Rna.isClosingParenthesis(dc))
252 // if (validRes && column>1 && row_annotations[column-2]!=null &&
253 // dc.equals(row_annotations[column-2].displayCharacter))
255 g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
256 new int[] { y + iconOffset, y + 14 + iconOffset,
257 y + 8 + iconOffset }, 3);
268 // display a forward arrow
271 g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] {
272 y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
281 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
284 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
286 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
289 fm = annotPanel.getFontMetrics();
290 annotationPanel = annotPanel;
291 fadedImage = annotPanel.getFadedImage();
292 imgWidth = annotPanel.getFadedImageWidth();
293 // visible area for rendering
294 int[] bounds = annotPanel.getVisibleVRange();
298 visHeight = bounds[1];
313 updateFromAlignViewport(av);
316 public void updateFromAlignViewport(AlignViewportI av)
318 charWidth = av.getCharWidth();
319 endRes = av.getRanges().getEndRes();
320 charHeight = av.getCharHeight();
321 hasHiddenColumns = av.hasHiddenColumns();
322 validCharWidth = av.isValidCharWidth();
323 av_renderHistogram = av.isShowConsensusHistogram();
324 av_renderProfile = av.isShowSequenceLogo();
325 av_normaliseProfile = av.isNormaliseSequenceLogo();
326 av_renderInformationHistogram = av.isShowInformationHistogram();
327 av_renderHMMProfile = av.isShowHMMSequenceLogo();
328 av_normaliseHMMProfile = av.isNormaliseHMMSequenceLogo();
329 profcolour = av.getResidueShading();
330 if (profcolour == null || profcolour.getColourScheme() == null)
333 * Use default colour for sequence logo if
334 * the alignment has no colourscheme set
335 * (would like to use user preference but n/a for applet)
337 ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
338 : new ZappoColourScheme();
339 profcolour = new ResidueShader(col);
341 columnSelection = av.getColumnSelection();
342 hiddenColumns = av.getAlignment().getHiddenColumns();
343 hconsensus = av.getSequenceConsensusHash();
344 complementConsensus = av.getComplementConsensusHash();
345 hStrucConsensus = av.getRnaStructureConsensusHash();
346 av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
347 av_ignoreBelowBackground = av.isIgnoreBelowBackground();
353 * Returns profile data; the first element is the profile type, the second is
354 * the number of distinct values, the third the total count, and the remainder
355 * depend on the profile type.
361 int[] getProfileFor(AlignmentAnnotation aa, int column)
363 // TODO : consider refactoring the global alignment calculation
364 // properties/rendering attributes as a global 'alignment group' which holds
365 // all vis settings for the alignment as a whole rather than a subset
367 if (aa.label.contains("_HMM"))
369 HiddenMarkovModel hmm = aa.sequenceRef.getHMM();
370 return AAFrequency.extractHMMProfile(hmm, column,
371 av_ignoreBelowBackground); // TODO check if this follows standard
374 if (aa.autoCalculated
375 && (aa.label.startsWith("Consensus") || aa.label
376 .startsWith("cDNA Consensus")))
378 boolean forComplement = aa.label.startsWith("cDNA Consensus");
379 if (aa.groupRef != null && aa.groupRef.consensusData != null
380 && aa.groupRef.isShowSequenceLogo())
382 // TODO? group consensus for cDNA complement
383 return AAFrequency.extractProfile(
384 aa.groupRef.consensusData.get(column),
385 aa.groupRef.getIgnoreGapsConsensus());
387 // TODO extend annotation row to enable dynamic and static profile data to
389 if (aa.groupRef == null && aa.sequenceRef == null)
393 return AAFrequency.extractCdnaProfile(
394 complementConsensus[column], av_ignoreGapsConsensus);
398 return AAFrequency.extractProfile(
399 hconsensus.get(column),
400 av_ignoreGapsConsensus);
406 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
408 // TODO implement group structure consensus
410 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
411 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
412 * group selections return StructureFrequency.extractProfile(
413 * aa.groupRef.consensusData[column], aa.groupRef
414 * .getIgnoreGapsConsensus()); }
416 // TODO extend annotation row to enable dynamic and static profile data
419 if (aa.groupRef == null && aa.sequenceRef == null
420 && hStrucConsensus != null
421 && hStrucConsensus.length > column)
423 return StructureFrequency.extractProfile(hStrucConsensus[column],
424 av_ignoreGapsConsensus);
434 * Render the annotation rows associated with an alignment.
439 * data and view settings to render
441 * destination for graphics
443 * row where a mouse event occured (or -1)
445 * first column that will be drawn
447 * last column that will be drawn
448 * @return true if the fadedImage was used for any alignment annotation rows
449 * currently being calculated
451 public boolean drawComponent(AwtRenderPanelI annotPanel,
452 AlignViewportI av, Graphics g, int activeRow, int startRes,
455 long stime = System.currentTimeMillis();
456 boolean usedFaded = false;
458 // AnnotationPanel needs to implement: ImageObserver, access to
460 updateFromAwtRenderPanel(annotPanel, av);
461 fm = g.getFontMetrics();
462 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
473 boolean validRes = false;
474 boolean validEnd = false;
475 boolean labelAllCols = false;
476 boolean centreColLabels;
477 boolean centreColLabelsDef = av.isCentreColumnLabels();
478 boolean scaleColLabel = false;
479 final AlignmentAnnotation consensusAnnot = av
480 .getAlignmentConsensusAnnotation();
481 final AlignmentAnnotation structConsensusAnnot = av
482 .getAlignmentStrucConsensusAnnotation();
483 final AlignmentAnnotation complementConsensusAnnot = av
484 .getComplementConsensusAnnotation();
485 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
487 BitSet graphGroupDrawn = new BitSet();
488 int charOffset = 0; // offset for a label
489 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
491 Font ofont = g.getFont();
494 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
495 boolean clipst = false, clipend = false;
496 for (int i = 0; i < aa.length; i++)
498 AlignmentAnnotation row = aa[i];
501 // check if this is a consensus annotation row and set the display
502 // settings appropriately
503 // TODO: generalise this to have render styles for consensus/profile
505 if (row.groupRef != null && row == row.groupRef.getConsensus())
507 renderHistogram = row.groupRef.isShowConsensusHistogram();
508 renderProfile = row.groupRef.isShowSequenceLogo();
509 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
511 else if (row == consensusAnnot || row == structConsensusAnnot
512 || row == complementConsensusAnnot)
514 renderHistogram = av_renderHistogram;
515 renderProfile = av_renderProfile;
516 normaliseProfile = av_normaliseProfile;
518 else if (row.label.contains("_HMM"))
520 renderHistogram = av_renderInformationHistogram;
521 renderProfile = av_renderHMMProfile;
522 normaliseProfile = av_normaliseHMMProfile;
526 renderHistogram = true;
527 // don't need to set render/normaliseProfile since they are not
528 // currently used in any other annotation track renderer
531 Annotation[] row_annotations = row.annotations;
536 centreColLabels = row.centreColLabels || centreColLabelsDef;
537 labelAllCols = row.showAllColLabels;
538 scaleColLabel = row.scaleColLabel;
543 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
544 {// if_in_visible_region
555 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
560 // this is so that we draw the characters below the graph
565 iconOffset = charHeight - fm.getDescent();
569 else if (row.hasText)
571 iconOffset = charHeight - fm.getDescent();
579 if (row.autoCalculated && av.isCalculationInProgress(row))
583 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
584 - row.height, imgWidth, y, annotationPanel);
585 g.setColor(Color.black);
586 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
592 * else if (annotationPanel.av.updatingConservation &&
593 * aa[i].label.equals("Conservation")) {
595 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
596 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
597 * annotationPanel.imgWidth, y, annotationPanel);
599 * g.setColor(Color.black); //
600 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
602 * continue; } else if (annotationPanel.av.updatingConservation &&
603 * aa[i].label.equals("Quality")) {
605 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
606 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
607 * annotationPanel.imgWidth, y, annotationPanel);
608 * g.setColor(Color.black); // /
609 * g.drawString("Calculating Quality....",20, y-row.height/2);
613 // first pass sets up state for drawing continuation from left-hand
616 x = (startRes == 0) ? 0 : -1;
617 while (x < endRes - startRes)
619 if (hasHiddenColumns)
621 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
622 if (column > row_annotations.length - 1)
629 column = startRes + x;
632 if ((row_annotations == null)
633 || (row_annotations.length <= column)
634 || (row_annotations[column] == null))
642 final String displayChar = validRes ? row_annotations[column].displayCharacter
648 g.setColor(Color.red);
650 if (columnSelection != null)
652 if (columnSelection.contains(column))
654 g.fillRect(x * charWidth, y, charWidth, charHeight);
658 if (row.getInvalidStrucPos() > x)
660 g.setColor(Color.orange);
661 g.fillRect(x * charWidth, y, charWidth, charHeight);
663 else if (row.getInvalidStrucPos() == x)
665 g.setColor(Color.orange.darker());
666 g.fillRect(x * charWidth, y, charWidth, charHeight);
668 if (validCharWidth && validRes && displayChar != null
669 && (displayChar.length() > 0))
672 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
673 displayChar.length());
674 if (/* centreColLabels || */scaleColLabel)
676 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
677 // displayChar.length());
679 // if (scaleColLabel)
681 // justify the label and scale to fit in column
682 if (fmWidth > charWidth)
684 // scale only if the current font isn't already small enough
685 fmScaling = charWidth;
686 fmScaling /= fmWidth;
687 g.setFont(ofont.deriveFont(AffineTransform
688 .getScaleInstance(fmScaling, 1.0)));
689 // and update the label's width to reflect the scaling.
694 // TODO is it ok to use width of / show all characters here?
697 // fmWidth = fm.charWidth(displayChar.charAt(0));
699 charOffset = (int) ((charWidth - fmWidth) / 2f);
701 if (row_annotations[column].colour == null)
703 g.setColor(Color.black);
707 g.setColor(row_annotations[column].colour);
710 if (column == 0 || row.graph > 0)
712 g.drawString(displayChar, (x * charWidth) + charOffset, y
715 else if (row_annotations[column - 1] == null
718 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
719 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
721 g.drawString(displayChar, x * charWidth + charOffset, y
729 char ss = validRes ? row_annotations[column].secondaryStructure
734 // distinguish between forward/backward base-pairing
735 if (displayChar.indexOf(')') > -1)
744 if ((displayChar.indexOf(']') > -1))
752 // distinguish between forward/backward base-pairing
753 if (displayChar.indexOf('}') > -1)
761 // distinguish between forward/backward base-pairing
762 if (displayChar.indexOf('<') > -1)
768 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
770 // distinguish between forward/backward base-pairing
771 int ssLowerCase = ss + UPPER_TO_LOWER;
772 // TODO would .equals() be safer here? or charAt(0)?
773 if (displayChar.indexOf(ssLowerCase) > -1)
775 ss = (char) ssLowerCase;
779 if (!validRes || (ss != lastSS))
785 int nb_annot = x - temp;
786 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
789 case '(': // Stem case for RNA secondary structure
790 case ')': // and opposite direction
791 drawStemAnnot(g, row_annotations, lastSSX, x, y,
792 iconOffset, startRes, column, validRes, validEnd);
799 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
800 iconOffset, startRes, column, validRes,
804 // no break if isRNA - falls through to drawNotCanonicalAnnot!
808 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
809 iconOffset, startRes, column, validRes,
813 // no break if isRNA - fall through to drawNotCanonicalAnnot!
872 Color nonCanColor = getNotCanonicalColor(lastSS);
873 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
874 lastSSX, x, y, iconOffset, startRes, column,
879 g.setColor(Color.gray);
880 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
896 lastSSX = (x * charWidth);
903 if (column >= row_annotations.length)
905 column = row_annotations.length - 1;
912 if ((row_annotations == null) || (row_annotations.length <= column)
913 || (row_annotations[column] == null))
931 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
932 startRes, column, validRes, validEnd);
935 // no break if isRNA - fall through to drawNotCanonicalAnnot!
940 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
941 startRes, column, validRes, validEnd);
944 // no break if isRNA - fall through to drawNotCanonicalAnnot!
947 case ')': // Stem case for RNA secondary structure
949 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
950 startRes, column, validRes, validEnd);
1007 // System.out.println(lastSS);
1008 Color nonCanColor = getNotCanonicalColor(lastSS);
1009 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1010 x, y, iconOffset, startRes, column, validRes, validEnd);
1013 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1014 startRes, column, validRes, validEnd);
1019 if (row.graph > 0 && row.graphHeight > 0)
1021 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1023 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1025 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1026 // computed efficiently for all visible labels
1027 float groupmax = -999999, groupmin = 9999999;
1028 for (int gg = 0; gg < aa.length; gg++)
1030 if (aa[gg].graphGroup != row.graphGroup)
1037 aa[gg].visible = false;
1039 if (aa[gg].graphMax > groupmax)
1041 groupmax = aa[gg].graphMax;
1043 if (aa[gg].graphMin < groupmin)
1045 groupmin = aa[gg].graphMin;
1049 for (int gg = 0; gg < aa.length; gg++)
1051 if (aa[gg].graphGroup == row.graphGroup)
1053 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1054 endRes, y, groupmin, groupmax, row.graphHeight);
1058 graphGroupDrawn.set(row.graphGroup);
1062 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1063 row.graphMin, row.graphMax, row.graphHeight);
1066 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1068 drawBarGraph(g, row, row_annotations, startRes, endRes,
1069 row.graphMin, row.graphMax, y, renderHistogram,
1070 renderProfile, normaliseProfile);
1076 if (clipst && !clipend)
1080 }// end if_in_visible_region
1081 if (row.graph > 0 && row.hasText)
1097 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1102 System.err.println("End clip at : " + yto + " (index " + f_to
1107 System.err.println("Annotation Rendering time:"
1108 + (System.currentTimeMillis() - stime));
1115 public static final Color GLYPHLINE_COLOR = Color.gray;
1117 public static final Color SHEET_COLOUR = Color.green;
1119 public static final Color HELIX_COLOUR = Color.red;
1121 public static final Color STEM_COLOUR = Color.blue;
1123 private Color sdNOTCANONICAL_COLOUR;
1125 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1126 int y, int iconOffset, int startRes, int column,
1127 boolean validRes, boolean validEnd)
1129 g.setColor(GLYPHLINE_COLOR);
1130 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1133 void drawSheetAnnot(Graphics g, Annotation[] row,
1135 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1136 boolean validRes, boolean validEnd)
1138 g.setColor(SHEET_COLOUR);
1140 if (!validEnd || !validRes || row == null || row[column] == null
1141 || row[column].secondaryStructure != 'E')
1143 g.fillRect(lastSSX, y + 4 + iconOffset,
1144 (x * charWidth) - lastSSX - 4, 7);
1145 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1146 (x * charWidth) }, new int[] { y + iconOffset,
1147 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1151 g.fillRect(lastSSX, y + 4 + iconOffset,
1152 (x + 1) * charWidth - lastSSX, 7);
1157 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1158 int y, int iconOffset, int startRes, int column,
1159 boolean validRes, boolean validEnd)
1161 g.setColor(HELIX_COLOUR);
1163 int sCol = (lastSSX / charWidth) + startRes;
1165 int x2 = (x * charWidth);
1169 int ofs = charWidth / 2;
1170 // Off by 1 offset when drawing rects and ovals
1171 // to offscreen image on the MAC
1172 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1173 if (sCol == 0 || row[sCol - 1] == null
1174 || row[sCol - 1].secondaryStructure != 'H')
1179 // g.setColor(Color.orange);
1180 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1183 if (!validRes || row[column] == null
1184 || row[column].secondaryStructure != 'H')
1190 // g.setColor(Color.magenta);
1191 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1199 if (sCol == 0 || row[sCol - 1] == null
1200 || row[sCol - 1].secondaryStructure != 'H')
1202 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1203 x1 += charWidth / 2;
1206 if (!validRes || row[column] == null
1207 || row[column].secondaryStructure != 'H')
1209 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1211 x2 -= charWidth / 2;
1214 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1217 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1218 Annotation[] aa_annotations, int sRes, int eRes, int y,
1219 float min, float max, int graphHeight)
1221 if (sRes > aa_annotations.length)
1228 // Adjustment for fastpaint to left
1234 eRes = Math.min(eRes, aa_annotations.length);
1242 float range = max - min;
1247 y2 = y - (int) ((0 - min / range) * graphHeight);
1250 g.setColor(Color.gray);
1251 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1253 eRes = Math.min(eRes, aa_annotations.length);
1256 int aaMax = aa_annotations.length - 1;
1258 while (x < eRes - sRes)
1261 if (hasHiddenColumns)
1263 column = hiddenColumns.adjustForHiddenColumns(column);
1271 if (aa_annotations[column] == null
1272 || aa_annotations[column - 1] == null)
1278 if (aa_annotations[column].colour == null)
1280 g.setColor(Color.black);
1284 g.setColor(aa_annotations[column].colour);
1288 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1290 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1292 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1293 + charWidth / 2, y2);
1297 if (_aa.threshold != null)
1299 g.setColor(_aa.threshold.colour);
1300 Graphics2D g2 = (Graphics2D) g;
1301 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1302 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1304 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1305 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1306 g2.setStroke(new BasicStroke());
1310 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1311 Annotation[] aa_annotations, int sRes, int eRes, float min,
1312 float max, int y, boolean renderHistogram, boolean renderProfile,
1313 boolean normaliseProfile)
1315 if (sRes > aa_annotations.length)
1319 Font ofont = g.getFont();
1320 eRes = Math.min(eRes, aa_annotations.length);
1322 int x = 0, y1 = y, y2 = y;
1324 float range = max - min;
1328 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1331 g.setColor(Color.gray);
1333 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1336 int aaMax = aa_annotations.length - 1;
1337 while (x < eRes - sRes)
1340 if (hasHiddenColumns)
1342 column = hiddenColumns.adjustForHiddenColumns(column);
1350 if (aa_annotations[column] == null)
1355 if (aa_annotations[column].colour == null)
1357 g.setColor(Color.black);
1361 g.setColor(aa_annotations[column].colour);
1365 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1367 if (renderHistogram)
1371 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1375 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1378 // draw profile if available
1383 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1385 int profl[] = getProfileFor(_aa, column);
1387 // just try to draw the logo if profl is not null
1388 if (profl != null && profl[2] != 0)
1390 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1391 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1392 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1393 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1400 * Render a single base for a sequence profile, a base pair for
1401 * structure profile, and a triplet for a cdna profile
1403 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1405 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1406 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1407 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1411 * Traverse the character(s)/percentage data in the array
1414 int valuesProcessed = 0;
1415 // profl[1] is the number of values in the profile
1416 while (valuesProcessed < profl[1])
1418 if (isStructureProfile)
1420 // todo can we encode a structure pair as an int, like codons?
1421 dc[0] = (char) profl[c++];
1422 dc[1] = (char) profl[c++];
1424 else if (isCdnaProfile)
1426 dc = CodingUtils.decodeCodon(profl[c++]);
1430 dc[0] = (char) profl[c++];
1434 wdth /= fm.charsWidth(dc, 0, dc.length);
1437 // next profl[] position is profile % for the character(s)
1438 scl = htn * scale * profl[c++];
1439 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1440 .getFontRenderContext());
1441 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1442 wdth, scl / lm.getAscent()));
1444 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1446 // Debug - render boxes around characters
1447 // g.setColor(Color.red);
1448 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1450 // g.setColor(profcolour.findColour(dc[0]).darker());
1453 * Set character colour as per alignment colour scheme; use the
1454 * codon translation if a cDNA profile
1456 Color colour = null;
1459 final String codonTranslation = ResidueProperties
1460 .codonTranslate(new String(dc));
1461 colour = profcolour.findColour(codonTranslation.charAt(0),
1466 colour = profcolour.findColour(dc[0], column, null);
1468 g.setColor(colour == Color.white ? Color.lightGray : colour);
1470 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1471 .getBaselineIndex()]));
1473 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1481 if (_aa.threshold != null)
1483 g.setColor(_aa.threshold.colour);
1484 Graphics2D g2 = (Graphics2D) g;
1485 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1486 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1488 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1490 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1491 g2.setStroke(new BasicStroke());
1495 // used by overview window
1496 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1497 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1499 eRes = Math.min(eRes, aa_annotations.length);
1500 g.setColor(Color.white);
1501 g.fillRect(0, 0, width, y);
1502 g.setColor(new Color(0, 0, 180));
1506 for (int j = sRes; j < eRes; j++)
1508 if (aa_annotations[j] != null)
1510 if (aa_annotations[j].colour == null)
1512 g.setColor(Color.black);
1516 g.setColor(aa_annotations[j].colour);
1519 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1525 g.fillRect(x, y - height, charWidth, height);
1531 Color getNotCanonicalColor(char lastss)
1537 return new Color(255, 125, 5);
1541 return new Color(245, 115, 10);
1545 return new Color(235, 135, 15);
1549 return new Color(225, 105, 20);
1553 return new Color(215, 145, 30);
1557 return new Color(205, 95, 35);
1561 return new Color(195, 155, 45);
1565 return new Color(185, 85, 55);
1569 return new Color(175, 165, 65);
1573 return new Color(170, 75, 75);
1577 return new Color(160, 175, 85);
1581 return new Color(150, 65, 95);
1585 return new Color(140, 185, 105);
1589 return new Color(130, 55, 110);
1593 return new Color(120, 195, 120);
1597 return new Color(110, 45, 130);
1601 return new Color(100, 205, 140);
1605 return new Color(90, 35, 150);
1609 return new Color(85, 215, 160);
1613 return new Color(75, 25, 170);
1617 return new Color(65, 225, 180);
1621 return new Color(55, 15, 185);
1625 return new Color(45, 235, 195);
1629 return new Color(35, 5, 205);
1633 return new Color(25, 245, 215);
1637 return new Color(15, 0, 225);
1641 return new Color(10, 255, 235);
1645 return new Color(5, 150, 245);
1649 return new Color(0, 80, 255);
1652 System.out.println("This is not a interaction : " + lastss);