2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.StructureFrequency;
25 import jalview.api.AlignViewportI;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.schemes.ColourSchemeI;
31 import java.awt.BasicStroke;
32 import java.awt.Color;
34 import java.awt.FontMetrics;
35 import java.awt.Graphics;
36 import java.awt.Graphics2D;
37 import java.awt.Image;
38 import java.awt.font.LineMetrics;
39 import java.awt.geom.AffineTransform;
40 import java.awt.image.ImageObserver;
41 import java.util.BitSet;
42 import java.util.Hashtable;
44 import com.stevesoft.pat.Regex;
46 public class AnnotationRenderer
49 * flag indicating if timing and redraw parameter info should be output
51 private final boolean debugRedraw;
53 public AnnotationRenderer()
58 * Create a new annotation Renderer
59 * @param debugRedraw flag indicating if timing and redraw parameter info should be output
61 public AnnotationRenderer(boolean debugRedraw)
63 this.debugRedraw=debugRedraw;
66 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
67 int lastSSX, int x, int y, int iconOffset, int startRes,
68 int column, boolean validRes, boolean validEnd)
70 g.setColor(STEM_COLOUR);
71 int sCol = (lastSSX / charWidth) + startRes;
73 int x2 = (x * charWidth);
74 Regex closeparen = new Regex("(\\))");
76 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
77 : row_annotations[column - 1].displayCharacter;
79 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
80 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
81 boolean diffdownstream = !validRes || !validEnd
82 || row_annotations[column] == null
83 || !dc.equals(row_annotations[column].displayCharacter);
84 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
85 // If a closing base pair half of the stem, display a backward arrow
86 if (column > 0 && closeparen.search(dc))
90 // if (validRes && column>1 && row_annotations[column-2]!=null &&
91 // dc.equals(row_annotations[column-2].displayCharacter))
93 g.fillPolygon(new int[]
94 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
95 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
106 // display a forward arrow
109 g.fillPolygon(new int[]
110 { x2 - 5, x2 - 5, x2 }, new int[]
111 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
120 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
123 private int charWidth, endRes, charHeight;
125 private boolean validCharWidth, hasHiddenColumns;
127 private FontMetrics fm;
129 private final boolean MAC = new jalview.util.Platform().isAMac();
131 boolean av_renderHistogram = true, av_renderProfile = true,
132 av_normaliseProfile = false;
134 ColourSchemeI profcolour = null;
136 private ColumnSelection columnSelection;
138 private Hashtable[] hconsensus;
140 private Hashtable[] hStrucConsensus;
142 private boolean av_ignoreGapsConsensus;
145 * attributes set from AwtRenderPanelI
148 * old image used when data is currently being calculated and cannot be
151 private Image fadedImage;
154 * panel being rendered into
156 private ImageObserver annotationPanel;
159 * width of image to render in panel
161 private int imgWidth;
163 * offset to beginning of visible area
167 * offset to end of visible area
169 private int visHeight;
171 * indicate if the renderer should only render the visible portion of the annotation given the current view settings
173 private boolean useClip=true;
175 * master flag indicating if renderer should ever try to clip. not enabled for jalview 2.8.1
177 private boolean canClip=false;
180 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations,
181 int lastSSX, int x, int y, int iconOffset, int startRes,
182 int column, boolean validRes, boolean validEnd)
184 //System.out.println(nonCanColor);
186 g.setColor(nonCanColor);
187 int sCol = (lastSSX / charWidth) + startRes;
189 int x2 = (x * charWidth);
190 Regex closeparen = new Regex("}|]|<|[a-z]");
192 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
193 : row_annotations[column - 1].displayCharacter;
195 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
196 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
197 boolean diffdownstream = !validRes || !validEnd
198 || row_annotations[column] == null
199 || !dc.equals(row_annotations[column].displayCharacter);
200 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
201 // If a closing base pair half of the stem, display a backward arrow
202 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
206 // if (validRes && column>1 && row_annotations[column-2]!=null &&
207 // dc.equals(row_annotations[column-2].displayCharacter))
209 g.fillPolygon(new int[]
210 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
211 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
222 // display a forward arrow
225 g.fillPolygon(new int[]
226 { x2 - 5, x2 - 5, x2 }, new int[]
227 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
236 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
238 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
240 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
243 fm = annotPanel.getFontMetrics();
244 annotationPanel = annotPanel;
245 fadedImage = annotPanel.getFadedImage();
246 imgWidth = annotPanel.getFadedImageWidth();
247 // visible area for rendering
248 int[] bounds=annotPanel.getVisibleVRange();
252 visHeight = bounds[1];
263 updateFromAlignViewport(av);
266 public void updateFromAlignViewport(AlignViewportI av)
268 charWidth = av.getCharWidth();
269 endRes = av.getEndRes();
270 charHeight = av.getCharHeight();
271 hasHiddenColumns = av.hasHiddenColumns();
272 validCharWidth = av.isValidCharWidth();
273 av_renderHistogram = av.isShowConsensusHistogram();
274 av_renderProfile = av.isShowSequenceLogo();
275 av_normaliseProfile = av.isNormaliseSequenceLogo();
276 profcolour = av.getGlobalColourScheme();
277 if (profcolour == null)
279 // Set the default colour for sequence logo if the alignnent has no
281 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
282 : new jalview.schemes.ZappoColourScheme();
284 columnSelection = av.getColumnSelection();
285 hconsensus = av.getSequenceConsensusHash();// hconsensus;
286 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
287 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
290 public int[] getProfileFor(AlignmentAnnotation aa, int column)
292 // TODO : consider refactoring the global alignment calculation
293 // properties/rendering attributes as a global 'alignment group' which holds
294 // all vis settings for the alignment as a whole rather than a subset
296 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
298 if (aa.groupRef != null && aa.groupRef.consensusData != null
299 && aa.groupRef.isShowSequenceLogo())
301 return AAFrequency.extractProfile(
302 aa.groupRef.consensusData[column],
303 aa.groupRef.getIgnoreGapsConsensus());
305 // TODO extend annotation row to enable dynamic and static profile data to
307 if (aa.groupRef == null && aa.sequenceRef == null)
309 return AAFrequency.extractProfile(hconsensus[column],
310 av_ignoreGapsConsensus);
315 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
317 // TODO implement group structure consensus
319 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
320 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
321 * group selections return StructureFrequency.extractProfile(
322 * aa.groupRef.consensusData[column], aa.groupRef
323 * .getIgnoreGapsConsensus()); }
325 // TODO extend annotation row to enable dynamic and static profile data
328 if (aa.groupRef == null && aa.sequenceRef == null
329 && hStrucConsensus != null
330 && hStrucConsensus.length > column)
332 return StructureFrequency.extractProfile(hStrucConsensus[column],
333 av_ignoreGapsConsensus);
341 * Render the annotation rows associated with an alignment.
346 * data and view settings to render
348 * destination for graphics
350 * row where a mouse event occured (or -1)
352 * first column that will be drawn
354 * last column that will be drawn
355 * @return true if the fadedImage was used for any alignment annotation rows
356 * currently being calculated
358 public boolean drawComponent(AwtRenderPanelI annotPanel,
359 AlignViewportI av, Graphics g, int activeRow, int startRes,
362 long stime=System.currentTimeMillis();
363 boolean usedFaded = false;
365 // AnnotationPanel needs to implement: ImageObserver, access to
367 updateFromAwtRenderPanel(annotPanel, av);
368 fm = g.getFontMetrics();
369 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
380 boolean validRes = false;
381 boolean validEnd = false;
382 boolean labelAllCols = false;
383 boolean centreColLabels, centreColLabelsDef = av
384 .getCentreColumnLabels();
385 boolean scaleColLabel = false;
386 AlignmentAnnotation consensusAnnot=av.getAlignmentConsensusAnnotation(),structConsensusAnnot=av.getAlignmentStrucConsensusAnnotation();
387 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
389 BitSet graphGroupDrawn = new BitSet();
390 int charOffset = 0; // offset for a label
391 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
393 Font ofont = g.getFont();
396 int yfrom=0,f_i=0,yto=0,f_to=0;
397 boolean clipst=false,clipend=false;
398 for (int i = 0; i < aa.length; i++)
400 AlignmentAnnotation row = aa[i];
402 // check if this is a consensus annotation row and set the display settings appropriately
403 // TODO: generalise this to have render styles for consensus/profile
405 if (row.groupRef != null && row == row.groupRef.getConsensus())
407 renderHistogram = row.groupRef.isShowConsensusHistogram();
408 renderProfile = row.groupRef.isShowSequenceLogo();
409 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
411 else if (row == consensusAnnot || row == structConsensusAnnot)
413 renderHistogram = av_renderHistogram;
414 renderProfile = av_renderProfile;
415 normaliseProfile = av_normaliseProfile;
417 renderHistogram = true;
418 // don't need to set render/normaliseProfile since they are not currently used in any other annotation track renderer
421 Annotation[] row_annotations = row.annotations;
426 centreColLabels = row.centreColLabels || centreColLabelsDef;
427 labelAllCols = row.showAllColLabels;
428 scaleColLabel = row.scaleColLabel;
432 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
433 {// if_in_visible_region
444 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
448 // this is so that we draw the characters below the graph
453 iconOffset = charHeight - fm.getDescent();
457 else if (row.hasText)
459 iconOffset = charHeight - fm.getDescent();
467 if (row.autoCalculated && av.isCalculationInProgress(row))
471 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
472 - row.height, imgWidth, y, annotationPanel);
473 g.setColor(Color.black);
474 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
480 * else if (annotationPanel.av.updatingConservation &&
481 * aa[i].label.equals("Conservation")) {
483 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
484 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
485 * annotationPanel.imgWidth, y, annotationPanel);
487 * g.setColor(Color.black); //
488 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
490 * continue; } else if (annotationPanel.av.updatingConservation &&
491 * aa[i].label.equals("Quality")) {
493 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
494 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
495 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
496 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
500 // first pass sets up state for drawing continuation from left-hand column
502 x = (startRes == 0) ? 0 : -1;
503 while (x < endRes - startRes)
505 if (hasHiddenColumns)
507 column = columnSelection.adjustForHiddenColumns(startRes + x);
508 if (column > row_annotations.length - 1)
515 column = startRes + x;
518 if ((row_annotations == null) || (row_annotations.length <= column)
519 || (row_annotations[column] == null))
531 g.setColor(Color.red);
533 if (columnSelection != null)
535 for (int n = 0; n < columnSelection.size(); n++)
537 int v = columnSelection.columnAt(n);
541 g.fillRect(x * charWidth, y, charWidth, charHeight);
546 if (!row.isValidStruc())
548 g.setColor(Color.orange);
549 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
550 charWidth, charHeight);
554 && row_annotations[column].displayCharacter != null
555 && (row_annotations[column].displayCharacter.length() > 0))
558 if (centreColLabels || scaleColLabel)
560 fmWidth = fm.charsWidth(
561 row_annotations[column].displayCharacter
563 row_annotations[column].displayCharacter.length());
567 // justify the label and scale to fit in column
568 if (fmWidth > charWidth)
570 // scale only if the current font isn't already small enough
571 fmScaling = charWidth;
572 fmScaling /= fmWidth;
573 g.setFont(ofont.deriveFont(AffineTransform
574 .getScaleInstance(fmScaling, 1.0)));
575 // and update the label's width to reflect the scaling.
583 .charWidth(row_annotations[column].displayCharacter
586 charOffset = (int) ((charWidth - fmWidth) / 2f);
588 if (row_annotations[column].colour == null)
589 g.setColor(Color.black);
591 g.setColor(row_annotations[column].colour);
593 if (column == 0 || row.graph > 0)
595 g.drawString(row_annotations[column].displayCharacter,
596 (x * charWidth) + charOffset, y + iconOffset);
598 else if (row_annotations[column - 1] == null
600 || !row_annotations[column].displayCharacter
601 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
602 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
604 g.drawString(row_annotations[column].displayCharacter
606 * charWidth + charOffset, y + iconOffset);
613 char ss = validRes ? row_annotations[column].secondaryStructure
618 // distinguish between forward/backward base-pairing
619 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
628 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
637 // distinguish between forward/backward base-pairing
638 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
647 // distinguish between forward/backward base-pairing
648 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
657 // distinguish between forward/backward base-pairing
658 if (row_annotations[column].displayCharacter.indexOf(ss+32) > -1)
668 if (!validRes || (ss != lastSS))
677 //System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
682 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
683 column, validRes, validEnd);
687 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
688 column, validRes, validEnd);
691 case '(': // Stem case for RNA secondary structure
692 case ')': // and opposite direction
693 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
694 column, validRes, validEnd);
756 Color nonCanColor= getNotCanonicalColor(lastSS);
757 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
758 column, validRes, validEnd);
762 g.setColor(Color.gray);
763 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
779 lastSSX = (x * charWidth);
786 if (column >= row_annotations.length)
788 column = row_annotations.length - 1;
795 if ((row_annotations == null) || (row_annotations.length <= column)
796 || (row_annotations[column] == null))
812 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
813 column, validRes, validEnd);
817 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
818 column, validRes, validEnd);
821 case 'S': // Stem case for RNA secondary structure
823 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
824 column, validRes, validEnd);
883 //System.out.println(lastSS);
884 Color nonCanColor = getNotCanonicalColor(lastSS);
885 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
886 column, validRes, validEnd);
889 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
890 column, validRes, validEnd);
895 if (row.graph > 0 && row.graphHeight > 0)
897 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
899 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
901 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
902 float groupmax = -999999, groupmin = 9999999;
903 for (int gg = 0; gg < aa.length; gg++)
905 if (aa[gg].graphGroup != row.graphGroup)
912 aa[gg].visible = false;
914 if (aa[gg].graphMax > groupmax)
916 groupmax = aa[gg].graphMax;
918 if (aa[gg].graphMin < groupmin)
920 groupmin = aa[gg].graphMin;
924 for (int gg = 0; gg < aa.length; gg++)
926 if (aa[gg].graphGroup == row.graphGroup)
928 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes, endRes, y, groupmin,
929 groupmax, row.graphHeight);
933 graphGroupDrawn.set(row.graphGroup);
937 drawLineGraph(g, row, row_annotations, startRes, endRes, y, row.graphMin,
938 row.graphMax, row.graphHeight);
941 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
943 drawBarGraph(g, row, row_annotations, startRes, endRes,
944 row.graphMin, row.graphMax, y, renderHistogram,renderProfile,normaliseProfile);
948 if (clipst && !clipend)
952 }// end if_in_visible_region
953 if (row.graph > 0 && row.hasText)
969 System.err.println("Start clip at : " + yfrom + " (index " + f_i
974 System.err.println("End clip at : " + yto + " (index " + f_to
979 System.err.println("Annotation Rendering time:"
980 + (System.currentTimeMillis() - stime));
987 private final Color GLYPHLINE_COLOR = Color.gray;
989 private final Color SHEET_COLOUR = Color.green;
991 private final Color HELIX_COLOUR = Color.red;
993 private final Color STEM_COLOUR = Color.blue;
995 private Color sdNOTCANONICAL_COLOUR;
997 public void drawGlyphLine(Graphics g, Annotation[] row,
998 int lastSSX, int x, int y, int iconOffset, int startRes,
999 int column, boolean validRes, boolean validEnd)
1001 g.setColor(GLYPHLINE_COLOR);
1002 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1005 public void drawSheetAnnot(Graphics g, Annotation[] row,
1007 int lastSSX, int x, int y, int iconOffset, int startRes,
1008 int column, boolean validRes, boolean validEnd)
1010 g.setColor(SHEET_COLOUR);
1012 if (!validEnd || !validRes || row == null || row[column] == null
1013 || row[column].secondaryStructure != 'E')
1015 g.fillRect(lastSSX, y + 4 + iconOffset,
1016 (x * charWidth) - lastSSX - 4, 7);
1017 g.fillPolygon(new int[]
1018 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1020 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1025 g.fillRect(lastSSX, y + 4 + iconOffset,
1026 (x + 1) * charWidth - lastSSX, 7);
1031 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1032 int x, int y, int iconOffset, int startRes, int column,
1033 boolean validRes, boolean validEnd)
1035 g.setColor(HELIX_COLOUR);
1037 int sCol = (lastSSX / charWidth) + startRes;
1039 int x2 = (x * charWidth);
1043 int ofs = charWidth / 2;
1044 // Off by 1 offset when drawing rects and ovals
1045 // to offscreen image on the MAC
1046 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1047 if (sCol == 0 || row[sCol - 1] == null
1048 || row[sCol - 1].secondaryStructure != 'H')
1053 // g.setColor(Color.orange);
1054 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1057 if (!validRes || row[column] == null
1058 || row[column].secondaryStructure != 'H')
1064 // g.setColor(Color.magenta);
1065 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1073 if (sCol == 0 || row[sCol - 1] == null
1074 || row[sCol - 1].secondaryStructure != 'H')
1076 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1077 x1 += charWidth / 2;
1080 if (!validRes || row[column] == null
1081 || row[column].secondaryStructure != 'H')
1083 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1085 x2 -= charWidth / 2;
1088 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1091 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1092 Annotation[] aa_annotations, int sRes, int eRes, int y,
1093 float min, float max, int graphHeight)
1095 if (sRes > aa_annotations.length)
1102 // Adjustment for fastpaint to left
1108 eRes = Math.min(eRes, aa_annotations.length);
1116 float range = max - min;
1121 y2 = y - (int) ((0 - min / range) * graphHeight);
1124 g.setColor(Color.gray);
1125 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1127 eRes = Math.min(eRes, aa_annotations.length);
1130 int aaMax = aa_annotations.length - 1;
1132 while (x < eRes - sRes)
1135 if (hasHiddenColumns)
1137 column = columnSelection.adjustForHiddenColumns(column);
1145 if (aa_annotations[column] == null
1146 || aa_annotations[column - 1] == null)
1152 if (aa_annotations[column].colour == null)
1153 g.setColor(Color.black);
1155 g.setColor(aa_annotations[column].colour);
1158 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1160 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1162 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1163 + charWidth / 2, y2);
1167 if (_aa.threshold != null)
1169 g.setColor(_aa.threshold.colour);
1170 Graphics2D g2 = (Graphics2D) g;
1171 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1172 BasicStroke.JOIN_ROUND, 3f, new float[]
1175 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1176 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1177 g2.setStroke(new BasicStroke());
1181 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1182 Annotation[] aa_annotations, int sRes, int eRes, float min,
1183 float max, int y, boolean renderHistogram,boolean renderProfile,boolean normaliseProfile)
1185 if (sRes > aa_annotations.length)
1189 Font ofont = g.getFont();
1190 eRes = Math.min(eRes, aa_annotations.length);
1192 int x = 0, y1 = y, y2 = y;
1194 float range = max - min;
1198 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1201 g.setColor(Color.gray);
1203 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1206 int aaMax = aa_annotations.length - 1;
1207 while (x < eRes - sRes)
1210 if (hasHiddenColumns)
1212 column = columnSelection.adjustForHiddenColumns(column);
1220 if (aa_annotations[column] == null)
1225 if (aa_annotations[column].colour == null)
1226 g.setColor(Color.black);
1228 g.setColor(aa_annotations[column].colour);
1231 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1233 if (renderHistogram)
1237 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1241 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1244 // draw profile if available
1248 int profl[] = getProfileFor(_aa, column);
1249 // just try to draw the logo if profl is not null
1250 if (profl != null && profl[1] != 0)
1252 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1253 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1260 * profl.length == 74 indicates that the profile of a secondary
1261 * structure conservation row was accesed. Therefore dc gets length 2,
1262 * to have space for a basepair instead of just a single nucleotide
1264 if (profl.length == 74)
1272 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1273 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1274 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1276 for (int c = 2; c < profl[0];)
1278 dc[0] = (char) profl[c++];
1280 if (_aa.label.startsWith("StrucConsensus"))
1282 dc[1] = (char) profl[c++];
1286 wdth /= fm.charsWidth(dc, 0, dc.length);
1290 scl = htn * scale * profl[c++];
1291 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1292 .getFontRenderContext());
1293 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1294 wdth, scl / lm.getAscent())));
1295 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1297 // Debug - render boxes around characters
1298 // g.setColor(Color.red);
1299 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1301 // g.setColor(profcolour.findColour(dc[0]).darker());
1302 g.setColor(profcolour.findColour(dc[0], column, null));
1304 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1305 .getBaselineIndex()]));
1307 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1315 if (_aa.threshold != null)
1317 g.setColor(_aa.threshold.colour);
1318 Graphics2D g2 = (Graphics2D) g;
1319 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1320 BasicStroke.JOIN_ROUND, 3f, new float[]
1323 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1325 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1326 g2.setStroke(new BasicStroke());
1330 // used by overview window
1331 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1332 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1334 eRes = Math.min(eRes, aa_annotations.length);
1335 g.setColor(Color.white);
1336 g.fillRect(0, 0, width, y);
1337 g.setColor(new Color(0, 0, 180));
1341 for (int j = sRes; j < eRes; j++)
1343 if (aa_annotations[j] != null)
1345 if (aa_annotations[j].colour == null)
1346 g.setColor(Color.black);
1348 g.setColor(aa_annotations[j].colour);
1350 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1356 g.fillRect(x, y - height, charWidth, height);
1363 Color getNotCanonicalColor(char lastss)
1369 return new Color(255,125,5);
1373 return new Color(245,115,10);
1377 return new Color(235,135,15);
1381 return new Color(225,105,20);
1385 return new Color(215,145,30);
1389 return new Color(205,95,35);
1393 return new Color(195,155,45);
1397 return new Color(185,85,55);
1401 return new Color(175,165,65);
1405 return new Color(170,75,75);
1409 return new Color(160,175,85);
1413 return new Color(150,65,95);
1417 return new Color(140,185,105);
1421 return new Color(130,55,110);
1425 return new Color(120,195,120);
1429 return new Color(110,45,130);
1433 return new Color(100,205,140);
1437 return new Color(90,35,150);
1441 return new Color(85,215,160);
1445 return new Color(75,25,170);
1449 return new Color(65,225,180);
1453 return new Color(55,15,185);
1457 return new Color(45,235,195);
1461 return new Color(35,5,205);
1465 return new Color(25,245,215);
1469 return new Color(15,0,225);
1473 return new Color(10,255,235);
1477 return new Color(5,150,245);
1481 return new Color(0,80,255);
1484 System.out.println("This is not a interaction : "+lastss);