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.startsWith("Information"))
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 informationAnnot = av
482 .getAlignmentInformationAnnotation();
483 final AlignmentAnnotation structConsensusAnnot = av
484 .getAlignmentStrucConsensusAnnotation();
485 final AlignmentAnnotation complementConsensusAnnot = av
486 .getComplementConsensusAnnotation();
487 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
489 BitSet graphGroupDrawn = new BitSet();
490 int charOffset = 0; // offset for a label
491 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
493 Font ofont = g.getFont();
496 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
497 boolean clipst = false, clipend = false;
498 for (int i = 0; i < aa.length; i++)
500 AlignmentAnnotation row = aa[i];
503 // check if this is a consensus annotation row and set the display
504 // settings appropriately
505 // TODO: generalise this to have render styles for consensus/profile
507 if (row.groupRef != null && row == row.groupRef.getConsensus())
509 renderHistogram = row.groupRef.isShowConsensusHistogram();
510 renderProfile = row.groupRef.isShowSequenceLogo();
511 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
513 else if (row == consensusAnnot || row == structConsensusAnnot
514 || row == complementConsensusAnnot)
516 renderHistogram = av_renderHistogram;
517 renderProfile = av_renderProfile;
518 normaliseProfile = av_normaliseProfile;
520 else if (row == informationAnnot)
522 renderHistogram = av_renderInformationHistogram;
523 renderProfile = av_renderHMMProfile;
524 normaliseProfile = av_normaliseHMMProfile;
528 renderHistogram = true;
529 // don't need to set render/normaliseProfile since they are not
530 // currently used in any other annotation track renderer
533 Annotation[] row_annotations = row.annotations;
538 centreColLabels = row.centreColLabels || centreColLabelsDef;
539 labelAllCols = row.showAllColLabels;
540 scaleColLabel = row.scaleColLabel;
545 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
546 {// if_in_visible_region
557 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
562 // this is so that we draw the characters below the graph
567 iconOffset = charHeight - fm.getDescent();
571 else if (row.hasText)
573 iconOffset = charHeight - fm.getDescent();
581 if (row.autoCalculated && av.isCalculationInProgress(row))
585 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
586 - row.height, imgWidth, y, annotationPanel);
587 g.setColor(Color.black);
588 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
594 * else if (annotationPanel.av.updatingConservation &&
595 * aa[i].label.equals("Conservation")) {
597 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
598 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
599 * annotationPanel.imgWidth, y, annotationPanel);
601 * g.setColor(Color.black); //
602 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
604 * continue; } else if (annotationPanel.av.updatingConservation &&
605 * aa[i].label.equals("Quality")) {
607 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
608 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
609 * annotationPanel.imgWidth, y, annotationPanel);
610 * g.setColor(Color.black); // /
611 * g.drawString("Calculating Quality....",20, y-row.height/2);
615 // first pass sets up state for drawing continuation from left-hand
618 x = (startRes == 0) ? 0 : -1;
619 while (x < endRes - startRes)
621 if (hasHiddenColumns)
623 column = hiddenColumns.adjustForHiddenColumns(startRes + x);
624 if (column > row_annotations.length - 1)
631 column = startRes + x;
634 if ((row_annotations == null)
635 || (row_annotations.length <= column)
636 || (row_annotations[column] == null))
644 final String displayChar = validRes ? row_annotations[column].displayCharacter
650 g.setColor(Color.red);
652 if (columnSelection != null)
654 if (columnSelection.contains(column))
656 g.fillRect(x * charWidth, y, charWidth, charHeight);
660 if (row.getInvalidStrucPos() > x)
662 g.setColor(Color.orange);
663 g.fillRect(x * charWidth, y, charWidth, charHeight);
665 else if (row.getInvalidStrucPos() == x)
667 g.setColor(Color.orange.darker());
668 g.fillRect(x * charWidth, y, charWidth, charHeight);
670 if (validCharWidth && validRes && displayChar != null
671 && (displayChar.length() > 0))
674 fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
675 displayChar.length());
676 if (/* centreColLabels || */scaleColLabel)
678 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
679 // displayChar.length());
681 // if (scaleColLabel)
683 // justify the label and scale to fit in column
684 if (fmWidth > charWidth)
686 // scale only if the current font isn't already small enough
687 fmScaling = charWidth;
688 fmScaling /= fmWidth;
689 g.setFont(ofont.deriveFont(AffineTransform
690 .getScaleInstance(fmScaling, 1.0)));
691 // and update the label's width to reflect the scaling.
696 // TODO is it ok to use width of / show all characters here?
699 // fmWidth = fm.charWidth(displayChar.charAt(0));
701 charOffset = (int) ((charWidth - fmWidth) / 2f);
703 if (row_annotations[column].colour == null)
705 g.setColor(Color.black);
709 g.setColor(row_annotations[column].colour);
712 if (column == 0 || row.graph > 0)
714 g.drawString(displayChar, (x * charWidth) + charOffset, y
717 else if (row_annotations[column - 1] == null
720 .equals(row_annotations[column - 1].displayCharacter) || (displayChar
721 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
723 g.drawString(displayChar, x * charWidth + charOffset, y
731 char ss = validRes ? row_annotations[column].secondaryStructure
736 // distinguish between forward/backward base-pairing
737 if (displayChar.indexOf(')') > -1)
746 if ((displayChar.indexOf(']') > -1))
754 // distinguish between forward/backward base-pairing
755 if (displayChar.indexOf('}') > -1)
763 // distinguish between forward/backward base-pairing
764 if (displayChar.indexOf('<') > -1)
770 if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
772 // distinguish between forward/backward base-pairing
773 int ssLowerCase = ss + UPPER_TO_LOWER;
774 // TODO would .equals() be safer here? or charAt(0)?
775 if (displayChar.indexOf(ssLowerCase) > -1)
777 ss = (char) ssLowerCase;
781 if (!validRes || (ss != lastSS))
787 int nb_annot = x - temp;
788 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
791 case '(': // Stem case for RNA secondary structure
792 case ')': // and opposite direction
793 drawStemAnnot(g, row_annotations, lastSSX, x, y,
794 iconOffset, startRes, column, validRes, validEnd);
801 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
802 iconOffset, startRes, column, validRes,
806 // no break if isRNA - falls through to drawNotCanonicalAnnot!
810 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
811 iconOffset, startRes, column, validRes,
815 // no break if isRNA - fall through to drawNotCanonicalAnnot!
874 Color nonCanColor = getNotCanonicalColor(lastSS);
875 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
876 lastSSX, x, y, iconOffset, startRes, column,
881 g.setColor(Color.gray);
882 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
898 lastSSX = (x * charWidth);
905 if (column >= row_annotations.length)
907 column = row_annotations.length - 1;
914 if ((row_annotations == null) || (row_annotations.length <= column)
915 || (row_annotations[column] == null))
933 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
934 startRes, column, validRes, validEnd);
937 // no break if isRNA - fall through to drawNotCanonicalAnnot!
942 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
943 startRes, column, validRes, validEnd);
946 // no break if isRNA - fall through to drawNotCanonicalAnnot!
949 case ')': // Stem case for RNA secondary structure
951 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
952 startRes, column, validRes, validEnd);
1009 // System.out.println(lastSS);
1010 Color nonCanColor = getNotCanonicalColor(lastSS);
1011 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1012 x, y, iconOffset, startRes, column, validRes, validEnd);
1015 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1016 startRes, column, validRes, validEnd);
1021 if (row.graph > 0 && row.graphHeight > 0)
1023 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1025 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1027 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1028 // computed efficiently for all visible labels
1029 float groupmax = -999999, groupmin = 9999999;
1030 for (int gg = 0; gg < aa.length; gg++)
1032 if (aa[gg].graphGroup != row.graphGroup)
1039 aa[gg].visible = false;
1041 if (aa[gg].graphMax > groupmax)
1043 groupmax = aa[gg].graphMax;
1045 if (aa[gg].graphMin < groupmin)
1047 groupmin = aa[gg].graphMin;
1051 for (int gg = 0; gg < aa.length; gg++)
1053 if (aa[gg].graphGroup == row.graphGroup)
1055 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1056 endRes, y, groupmin, groupmax, row.graphHeight);
1060 graphGroupDrawn.set(row.graphGroup);
1064 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1065 row.graphMin, row.graphMax, row.graphHeight);
1068 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1070 drawBarGraph(g, row, row_annotations, startRes, endRes,
1071 row.graphMin, row.graphMax, y, renderHistogram,
1072 renderProfile, normaliseProfile);
1078 if (clipst && !clipend)
1082 }// end if_in_visible_region
1083 if (row.graph > 0 && row.hasText)
1099 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1104 System.err.println("End clip at : " + yto + " (index " + f_to
1109 System.err.println("Annotation Rendering time:"
1110 + (System.currentTimeMillis() - stime));
1117 public static final Color GLYPHLINE_COLOR = Color.gray;
1119 public static final Color SHEET_COLOUR = Color.green;
1121 public static final Color HELIX_COLOUR = Color.red;
1123 public static final Color STEM_COLOUR = Color.blue;
1125 private Color sdNOTCANONICAL_COLOUR;
1127 void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1128 int y, int iconOffset, int startRes, int column,
1129 boolean validRes, boolean validEnd)
1131 g.setColor(GLYPHLINE_COLOR);
1132 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1135 void drawSheetAnnot(Graphics g, Annotation[] row,
1137 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1138 boolean validRes, boolean validEnd)
1140 g.setColor(SHEET_COLOUR);
1142 if (!validEnd || !validRes || row == null || row[column] == null
1143 || row[column].secondaryStructure != 'E')
1145 g.fillRect(lastSSX, y + 4 + iconOffset,
1146 (x * charWidth) - lastSSX - 4, 7);
1147 g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1148 (x * charWidth) }, new int[] { y + iconOffset,
1149 y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1153 g.fillRect(lastSSX, y + 4 + iconOffset,
1154 (x + 1) * charWidth - lastSSX, 7);
1159 void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1160 int y, int iconOffset, int startRes, int column,
1161 boolean validRes, boolean validEnd)
1163 g.setColor(HELIX_COLOUR);
1165 int sCol = (lastSSX / charWidth) + startRes;
1167 int x2 = (x * charWidth);
1171 int ofs = charWidth / 2;
1172 // Off by 1 offset when drawing rects and ovals
1173 // to offscreen image on the MAC
1174 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1175 if (sCol == 0 || row[sCol - 1] == null
1176 || row[sCol - 1].secondaryStructure != 'H')
1181 // g.setColor(Color.orange);
1182 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1185 if (!validRes || row[column] == null
1186 || row[column].secondaryStructure != 'H')
1192 // g.setColor(Color.magenta);
1193 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1201 if (sCol == 0 || row[sCol - 1] == null
1202 || row[sCol - 1].secondaryStructure != 'H')
1204 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1205 x1 += charWidth / 2;
1208 if (!validRes || row[column] == null
1209 || row[column].secondaryStructure != 'H')
1211 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1213 x2 -= charWidth / 2;
1216 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1219 void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1220 Annotation[] aa_annotations, int sRes, int eRes, int y,
1221 float min, float max, int graphHeight)
1223 if (sRes > aa_annotations.length)
1230 // Adjustment for fastpaint to left
1236 eRes = Math.min(eRes, aa_annotations.length);
1244 float range = max - min;
1249 y2 = y - (int) ((0 - min / range) * graphHeight);
1252 g.setColor(Color.gray);
1253 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1255 eRes = Math.min(eRes, aa_annotations.length);
1258 int aaMax = aa_annotations.length - 1;
1260 while (x < eRes - sRes)
1263 if (hasHiddenColumns)
1265 column = hiddenColumns.adjustForHiddenColumns(column);
1273 if (aa_annotations[column] == null
1274 || aa_annotations[column - 1] == null)
1280 if (aa_annotations[column].colour == null)
1282 g.setColor(Color.black);
1286 g.setColor(aa_annotations[column].colour);
1290 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1292 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1294 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1295 + charWidth / 2, y2);
1299 if (_aa.threshold != null)
1301 g.setColor(_aa.threshold.colour);
1302 Graphics2D g2 = (Graphics2D) g;
1303 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1304 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1306 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1307 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1308 g2.setStroke(new BasicStroke());
1312 void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1313 Annotation[] aa_annotations, int sRes, int eRes, float min,
1314 float max, int y, boolean renderHistogram, boolean renderProfile,
1315 boolean normaliseProfile)
1317 if (sRes > aa_annotations.length)
1321 Font ofont = g.getFont();
1322 eRes = Math.min(eRes, aa_annotations.length);
1324 int x = 0, y1 = y, y2 = y;
1326 float range = max - min;
1330 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1333 g.setColor(Color.gray);
1335 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1338 int aaMax = aa_annotations.length - 1;
1339 while (x < eRes - sRes)
1342 if (hasHiddenColumns)
1344 column = hiddenColumns.adjustForHiddenColumns(column);
1352 if (aa_annotations[column] == null)
1357 if (aa_annotations[column].colour == null)
1359 g.setColor(Color.black);
1363 g.setColor(aa_annotations[column].colour);
1367 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1369 if (renderHistogram)
1373 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1377 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1380 // draw profile if available
1385 * {profile type, #values, total count, char1, pct1, char2, pct2...}
1387 int profl[] = getProfileFor(_aa, column);
1389 // just try to draw the logo if profl is not null
1390 if (profl != null && profl[2] != 0)
1392 boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1393 boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1394 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1395 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1402 * Render a single base for a sequence profile, a base pair for
1403 * structure profile, and a triplet for a cdna profile
1405 dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1407 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1408 double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1409 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1413 * Traverse the character(s)/percentage data in the array
1416 int valuesProcessed = 0;
1417 // profl[1] is the number of values in the profile
1418 while (valuesProcessed < profl[1])
1420 if (isStructureProfile)
1422 // todo can we encode a structure pair as an int, like codons?
1423 dc[0] = (char) profl[c++];
1424 dc[1] = (char) profl[c++];
1426 else if (isCdnaProfile)
1428 dc = CodingUtils.decodeCodon(profl[c++]);
1432 dc[0] = (char) profl[c++];
1436 wdth /= fm.charsWidth(dc, 0, dc.length);
1439 // next profl[] position is profile % for the character(s)
1440 scl = htn * scale * profl[c++];
1441 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1442 .getFontRenderContext());
1443 Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1444 wdth, scl / lm.getAscent()));
1446 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1448 // Debug - render boxes around characters
1449 // g.setColor(Color.red);
1450 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1452 // g.setColor(profcolour.findColour(dc[0]).darker());
1455 * Set character colour as per alignment colour scheme; use the
1456 * codon translation if a cDNA profile
1458 Color colour = null;
1461 final String codonTranslation = ResidueProperties
1462 .codonTranslate(new String(dc));
1463 colour = profcolour.findColour(codonTranslation.charAt(0),
1468 colour = profcolour.findColour(dc[0], column, null);
1470 g.setColor(colour == Color.white ? Color.lightGray : colour);
1472 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1473 .getBaselineIndex()]));
1475 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1483 if (_aa.threshold != null)
1485 g.setColor(_aa.threshold.colour);
1486 Graphics2D g2 = (Graphics2D) g;
1487 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1488 BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1490 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1492 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1493 g2.setStroke(new BasicStroke());
1497 // used by overview window
1498 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1499 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1501 eRes = Math.min(eRes, aa_annotations.length);
1502 g.setColor(Color.white);
1503 g.fillRect(0, 0, width, y);
1504 g.setColor(new Color(0, 0, 180));
1508 for (int j = sRes; j < eRes; j++)
1510 if (aa_annotations[j] != null)
1512 if (aa_annotations[j].colour == null)
1514 g.setColor(Color.black);
1518 g.setColor(aa_annotations[j].colour);
1521 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1527 g.fillRect(x, y - height, charWidth, height);
1533 Color getNotCanonicalColor(char lastss)
1539 return new Color(255, 125, 5);
1543 return new Color(245, 115, 10);
1547 return new Color(235, 135, 15);
1551 return new Color(225, 105, 20);
1555 return new Color(215, 145, 30);
1559 return new Color(205, 95, 35);
1563 return new Color(195, 155, 45);
1567 return new Color(185, 85, 55);
1571 return new Color(175, 165, 65);
1575 return new Color(170, 75, 75);
1579 return new Color(160, 175, 85);
1583 return new Color(150, 65, 95);
1587 return new Color(140, 185, 105);
1591 return new Color(130, 55, 110);
1595 return new Color(120, 195, 120);
1599 return new Color(110, 45, 130);
1603 return new Color(100, 205, 140);
1607 return new Color(90, 35, 150);
1611 return new Color(85, 215, 160);
1615 return new Color(75, 25, 170);
1619 return new Color(65, 225, 180);
1623 return new Color(55, 15, 185);
1627 return new Color(45, 235, 195);
1631 return new Color(35, 5, 205);
1635 return new Color(25, 245, 215);
1639 return new Color(15, 0, 225);
1643 return new Color(10, 255, 235);
1647 return new Color(5, 150, 245);
1651 return new Color(0, 80, 255);
1654 System.out.println("This is not a interaction : " + lastss);