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()
59 * Create a new annotation Renderer
62 * flag indicating if timing and redraw parameter info should be
65 public AnnotationRenderer(boolean debugRedraw)
67 this.debugRedraw = debugRedraw;
70 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
71 int lastSSX, int x, int y, int iconOffset, int startRes,
72 int column, boolean validRes, boolean validEnd)
74 g.setColor(STEM_COLOUR);
75 int sCol = (lastSSX / charWidth) + startRes;
77 int x2 = (x * charWidth);
78 Regex closeparen = new Regex("(\\))");
80 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
81 : row_annotations[column - 1].displayCharacter;
83 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
84 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
85 boolean diffdownstream = !validRes || !validEnd
86 || row_annotations[column] == null
87 || !dc.equals(row_annotations[column].displayCharacter);
88 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
89 // If a closing base pair half of the stem, display a backward arrow
90 if (column > 0 && closeparen.search(dc))
94 // if (validRes && column>1 && row_annotations[column-2]!=null &&
95 // dc.equals(row_annotations[column-2].displayCharacter))
97 g.fillPolygon(new int[]
98 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
99 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
110 // display a forward arrow
113 g.fillPolygon(new int[]
114 { x2 - 5, x2 - 5, x2 }, new int[]
115 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
124 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
127 private int charWidth, endRes, charHeight;
129 private boolean validCharWidth, hasHiddenColumns;
131 private FontMetrics fm;
133 private final boolean MAC = new jalview.util.Platform().isAMac();
135 boolean av_renderHistogram = true, av_renderProfile = true,
136 av_normaliseProfile = false;
138 ColourSchemeI profcolour = null;
140 private ColumnSelection columnSelection;
142 private Hashtable[] hconsensus;
144 private Hashtable[] hStrucConsensus;
146 private boolean av_ignoreGapsConsensus;
149 * attributes set from AwtRenderPanelI
152 * old image used when data is currently being calculated and cannot be
155 private Image fadedImage;
158 * panel being rendered into
160 private ImageObserver annotationPanel;
163 * width of image to render in panel
165 private int imgWidth;
168 * offset to beginning of visible area
173 * offset to end of visible area
175 private int visHeight;
178 * indicate if the renderer should only render the visible portion of the
179 * annotation given the current view settings
181 private boolean useClip = true;
184 * master flag indicating if renderer should ever try to clip. not enabled for
187 private boolean canClip = false;
189 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
190 Annotation[] row_annotations, int lastSSX, int x, int y,
191 int iconOffset, int startRes, int column, boolean validRes,
194 // System.out.println(nonCanColor);
196 g.setColor(nonCanColor);
197 int sCol = (lastSSX / charWidth) + startRes;
199 int x2 = (x * charWidth);
200 Regex closeparen = new Regex("}|]|<|[a-z]");
202 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
203 : row_annotations[column - 1].displayCharacter;
205 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
206 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
207 boolean diffdownstream = !validRes || !validEnd
208 || row_annotations[column] == null
209 || !dc.equals(row_annotations[column].displayCharacter);
210 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
211 // If a closing base pair half of the stem, display a backward arrow
212 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
217 // if (validRes && column>1 && row_annotations[column-2]!=null &&
218 // dc.equals(row_annotations[column-2].displayCharacter))
220 g.fillPolygon(new int[]
221 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
222 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
233 // display a forward arrow
236 g.fillPolygon(new int[]
237 { x2 - 5, x2 - 5, x2 }, new int[]
238 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
247 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
250 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
252 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
255 fm = annotPanel.getFontMetrics();
256 annotationPanel = annotPanel;
257 fadedImage = annotPanel.getFadedImage();
258 imgWidth = annotPanel.getFadedImageWidth();
259 // visible area for rendering
260 int[] bounds = annotPanel.getVisibleVRange();
264 visHeight = bounds[1];
279 updateFromAlignViewport(av);
282 public void updateFromAlignViewport(AlignViewportI av)
284 charWidth = av.getCharWidth();
285 endRes = av.getEndRes();
286 charHeight = av.getCharHeight();
287 hasHiddenColumns = av.hasHiddenColumns();
288 validCharWidth = av.isValidCharWidth();
289 av_renderHistogram = av.isShowConsensusHistogram();
290 av_renderProfile = av.isShowSequenceLogo();
291 av_normaliseProfile = av.isNormaliseSequenceLogo();
292 profcolour = av.getGlobalColourScheme();
293 if (profcolour == null)
295 // Set the default colour for sequence logo if the alignnent has no
297 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
298 : new jalview.schemes.ZappoColourScheme();
300 boolean rna = av.getAlignment().isNucleotide();
301 columnSelection = av.getColumnSelection();
302 hconsensus = av.getSequenceConsensusHash();// hconsensus;
303 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
304 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
307 public int[] getProfileFor(AlignmentAnnotation aa, int column)
309 // TODO : consider refactoring the global alignment calculation
310 // properties/rendering attributes as a global 'alignment group' which holds
311 // all vis settings for the alignment as a whole rather than a subset
313 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
315 if (aa.groupRef != null && aa.groupRef.consensusData != null
316 && aa.groupRef.isShowSequenceLogo())
318 return AAFrequency.extractProfile(
319 aa.groupRef.consensusData[column],
320 aa.groupRef.getIgnoreGapsConsensus());
322 // TODO extend annotation row to enable dynamic and static profile data to
324 if (aa.groupRef == null && aa.sequenceRef == null)
326 return AAFrequency.extractProfile(hconsensus[column],
327 av_ignoreGapsConsensus);
332 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
334 // TODO implement group structure consensus
336 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
337 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
338 * group selections return StructureFrequency.extractProfile(
339 * aa.groupRef.consensusData[column], aa.groupRef
340 * .getIgnoreGapsConsensus()); }
342 // TODO extend annotation row to enable dynamic and static profile data
345 if (aa.groupRef == null && aa.sequenceRef == null
346 && hStrucConsensus != null
347 && hStrucConsensus.length > column)
349 return StructureFrequency.extractProfile(hStrucConsensus[column],
350 av_ignoreGapsConsensus);
360 * Render the annotation rows associated with an alignment.
365 * data and view settings to render
367 * destination for graphics
369 * row where a mouse event occured (or -1)
371 * first column that will be drawn
373 * last column that will be drawn
374 * @return true if the fadedImage was used for any alignment annotation rows
375 * currently being calculated
377 public boolean drawComponent(AwtRenderPanelI annotPanel,
378 AlignViewportI av, Graphics g, int activeRow, int startRes,
381 long stime = System.currentTimeMillis();
382 boolean usedFaded = false;
384 // AnnotationPanel needs to implement: ImageObserver, access to
386 updateFromAwtRenderPanel(annotPanel, av);
387 fm = g.getFontMetrics();
388 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
399 boolean validRes = false;
400 boolean validEnd = false;
401 boolean labelAllCols = false;
402 boolean centreColLabels, centreColLabelsDef = av
403 .getCentreColumnLabels();
404 boolean scaleColLabel = false;
405 AlignmentAnnotation consensusAnnot = av
406 .getAlignmentConsensusAnnotation(), structConsensusAnnot = av
407 .getAlignmentStrucConsensusAnnotation();
408 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
410 BitSet graphGroupDrawn = new BitSet();
411 int charOffset = 0; // offset for a label
412 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
414 Font ofont = g.getFont();
417 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
418 boolean clipst = false, clipend = false;
419 for (int i = 0; i < aa.length; i++)
421 AlignmentAnnotation row = aa[i];
424 // check if this is a consensus annotation row and set the display
425 // settings appropriately
426 // TODO: generalise this to have render styles for consensus/profile
428 if (row.groupRef != null && row == row.groupRef.getConsensus())
430 renderHistogram = row.groupRef.isShowConsensusHistogram();
431 renderProfile = row.groupRef.isShowSequenceLogo();
432 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
434 else if (row == consensusAnnot || row == structConsensusAnnot)
436 renderHistogram = av_renderHistogram;
437 renderProfile = av_renderProfile;
438 normaliseProfile = av_normaliseProfile;
442 renderHistogram = true;
443 // don't need to set render/normaliseProfile since they are not
444 // currently used in any other annotation track renderer
447 Annotation[] row_annotations = row.annotations;
452 centreColLabels = row.centreColLabels || centreColLabelsDef;
453 labelAllCols = row.showAllColLabels;
454 scaleColLabel = row.scaleColLabel;
459 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
460 {// if_in_visible_region
471 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
476 // this is so that we draw the characters below the graph
481 iconOffset = charHeight - fm.getDescent();
485 else if (row.hasText)
487 iconOffset = charHeight - fm.getDescent();
495 if (row.autoCalculated && av.isCalculationInProgress(row))
499 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
500 - row.height, imgWidth, y, annotationPanel);
501 g.setColor(Color.black);
502 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
508 * else if (annotationPanel.av.updatingConservation &&
509 * aa[i].label.equals("Conservation")) {
511 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
512 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
513 * annotationPanel.imgWidth, y, annotationPanel);
515 * g.setColor(Color.black); //
516 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
518 * continue; } else if (annotationPanel.av.updatingConservation &&
519 * aa[i].label.equals("Quality")) {
521 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
522 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
523 * annotationPanel.imgWidth, y, annotationPanel);
524 * g.setColor(Color.black); // /
525 * g.drawString("Calculating Quality....",20, y-row.height/2);
529 // first pass sets up state for drawing continuation from left-hand
532 x = (startRes == 0) ? 0 : -1;
533 while (x < endRes - startRes)
535 if (hasHiddenColumns)
537 column = columnSelection.adjustForHiddenColumns(startRes + x);
538 if (column > row_annotations.length - 1)
545 column = startRes + x;
548 if ((row_annotations == null)
549 || (row_annotations.length <= column)
550 || (row_annotations[column] == null))
562 g.setColor(Color.red);
564 if (columnSelection != null)
566 for (int n = 0; n < columnSelection.size(); n++)
568 int v = columnSelection.columnAt(n);
572 g.fillRect(x * charWidth, y, charWidth, charHeight);
577 if (!row.isValidStruc())
579 g.setColor(Color.orange);
580 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
581 charWidth, charHeight);
585 && row_annotations[column].displayCharacter != null
586 && (row_annotations[column].displayCharacter.length() > 0))
589 if (centreColLabels || scaleColLabel)
591 fmWidth = fm.charsWidth(
592 row_annotations[column].displayCharacter
594 row_annotations[column].displayCharacter.length());
598 // justify the label and scale to fit in column
599 if (fmWidth > charWidth)
601 // scale only if the current font isn't already small enough
602 fmScaling = charWidth;
603 fmScaling /= fmWidth;
604 g.setFont(ofont.deriveFont(AffineTransform
605 .getScaleInstance(fmScaling, 1.0)));
606 // and update the label's width to reflect the scaling.
614 .charWidth(row_annotations[column].displayCharacter
617 charOffset = (int) ((charWidth - fmWidth) / 2f);
619 if (row_annotations[column].colour == null)
620 g.setColor(Color.black);
622 g.setColor(row_annotations[column].colour);
624 if (column == 0 || row.graph > 0)
626 g.drawString(row_annotations[column].displayCharacter,
627 (x * charWidth) + charOffset, y + iconOffset);
629 else if (row_annotations[column - 1] == null
631 || !row_annotations[column].displayCharacter
632 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
633 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
635 g.drawString(row_annotations[column].displayCharacter, x
636 * charWidth + charOffset, y + iconOffset);
643 char ss = validRes ? row_annotations[column].secondaryStructure
648 // distinguish between forward/backward base-pairing
649 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
658 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
666 // distinguish between forward/backward base-pairing
667 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
675 // distinguish between forward/backward base-pairing
676 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
684 // distinguish between forward/backward base-pairing
685 if (row_annotations[column].displayCharacter.indexOf(ss + 32) > -1)
688 ss = (char) (ss + 32);
693 if (!validRes || (ss != lastSS))
699 int nb_annot = x - temp;
700 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
703 case '(': // Stem case for RNA secondary structure
704 case ')': // and opposite direction
705 drawStemAnnot(g, row_annotations, lastSSX, x, y,
706 iconOffset, startRes, column, validRes, validEnd);
713 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
714 iconOffset, startRes, column, validRes,
722 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
723 iconOffset, startRes, column, validRes,
785 Color nonCanColor = getNotCanonicalColor(lastSS);
786 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
787 lastSSX, x, y, iconOffset, startRes, column,
792 g.setColor(Color.gray);
793 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
809 lastSSX = (x * charWidth);
816 if (column >= row_annotations.length)
818 column = row_annotations.length - 1;
825 if ((row_annotations == null) || (row_annotations.length <= column)
826 || (row_annotations[column] == null))
845 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
846 startRes, column, validRes, validEnd);
853 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
854 startRes, column, validRes, validEnd);
859 case ')': // Stem case for RNA secondary structure
861 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
862 startRes, column, validRes, validEnd);
919 // System.out.println(lastSS);
920 Color nonCanColor = getNotCanonicalColor(lastSS);
921 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
922 x, y, iconOffset, startRes, column, validRes, validEnd);
925 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
926 startRes, column, validRes, validEnd);
931 if (row.graph > 0 && row.graphHeight > 0)
933 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
935 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
937 // TODO: JAL-1291 revise rendering model so the graphGroup map is
938 // computed efficiently for all visible labels
939 float groupmax = -999999, groupmin = 9999999;
940 for (int gg = 0; gg < aa.length; gg++)
942 if (aa[gg].graphGroup != row.graphGroup)
949 aa[gg].visible = false;
951 if (aa[gg].graphMax > groupmax)
953 groupmax = aa[gg].graphMax;
955 if (aa[gg].graphMin < groupmin)
957 groupmin = aa[gg].graphMin;
961 for (int gg = 0; gg < aa.length; gg++)
963 if (aa[gg].graphGroup == row.graphGroup)
965 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
966 endRes, y, groupmin, groupmax, row.graphHeight);
970 graphGroupDrawn.set(row.graphGroup);
974 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
975 row.graphMin, row.graphMax, row.graphHeight);
978 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
980 drawBarGraph(g, row, row_annotations, startRes, endRes,
981 row.graphMin, row.graphMax, y, renderHistogram,
982 renderProfile, normaliseProfile);
988 if (clipst && !clipend)
992 }// end if_in_visible_region
993 if (row.graph > 0 && row.hasText)
1009 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1014 System.err.println("End clip at : " + yto + " (index " + f_to
1019 System.err.println("Annotation Rendering time:"
1020 + (System.currentTimeMillis() - stime));
1027 public static final Color GLYPHLINE_COLOR = Color.gray;
1029 public static final Color SHEET_COLOUR = Color.green;
1031 public static final Color HELIX_COLOUR = Color.red;
1033 public static final Color STEM_COLOUR = Color.blue;
1035 private Color sdNOTCANONICAL_COLOUR;
1037 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1038 int x, int y, int iconOffset, int startRes, int column,
1039 boolean validRes, boolean validEnd)
1041 g.setColor(GLYPHLINE_COLOR);
1042 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1045 public void drawSheetAnnot(Graphics g, Annotation[] row,
1047 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1048 boolean validRes, boolean validEnd)
1050 g.setColor(SHEET_COLOUR);
1052 if (!validEnd || !validRes || row == null || row[column] == null
1053 || row[column].secondaryStructure != 'E')
1055 g.fillRect(lastSSX, y + 4 + iconOffset,
1056 (x * charWidth) - lastSSX - 4, 7);
1057 g.fillPolygon(new int[]
1058 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1060 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1065 g.fillRect(lastSSX, y + 4 + iconOffset,
1066 (x + 1) * charWidth - lastSSX, 7);
1071 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1072 int x, int y, int iconOffset, int startRes, int column,
1073 boolean validRes, boolean validEnd)
1075 g.setColor(HELIX_COLOUR);
1077 int sCol = (lastSSX / charWidth) + startRes;
1079 int x2 = (x * charWidth);
1083 int ofs = charWidth / 2;
1084 // Off by 1 offset when drawing rects and ovals
1085 // to offscreen image on the MAC
1086 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1087 if (sCol == 0 || row[sCol - 1] == null
1088 || row[sCol - 1].secondaryStructure != 'H')
1093 // g.setColor(Color.orange);
1094 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1097 if (!validRes || row[column] == null
1098 || row[column].secondaryStructure != 'H')
1104 // g.setColor(Color.magenta);
1105 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1113 if (sCol == 0 || row[sCol - 1] == null
1114 || row[sCol - 1].secondaryStructure != 'H')
1116 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1117 x1 += charWidth / 2;
1120 if (!validRes || row[column] == null
1121 || row[column].secondaryStructure != 'H')
1123 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1125 x2 -= charWidth / 2;
1128 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1131 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1132 Annotation[] aa_annotations, int sRes, int eRes, int y,
1133 float min, float max, int graphHeight)
1135 if (sRes > aa_annotations.length)
1142 // Adjustment for fastpaint to left
1148 eRes = Math.min(eRes, aa_annotations.length);
1156 float range = max - min;
1161 y2 = y - (int) ((0 - min / range) * graphHeight);
1164 g.setColor(Color.gray);
1165 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1167 eRes = Math.min(eRes, aa_annotations.length);
1170 int aaMax = aa_annotations.length - 1;
1172 while (x < eRes - sRes)
1175 if (hasHiddenColumns)
1177 column = columnSelection.adjustForHiddenColumns(column);
1185 if (aa_annotations[column] == null
1186 || aa_annotations[column - 1] == null)
1192 if (aa_annotations[column].colour == null)
1193 g.setColor(Color.black);
1195 g.setColor(aa_annotations[column].colour);
1198 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1200 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1202 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1203 + charWidth / 2, y2);
1207 if (_aa.threshold != null)
1209 g.setColor(_aa.threshold.colour);
1210 Graphics2D g2 = (Graphics2D) g;
1211 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1212 BasicStroke.JOIN_ROUND, 3f, new float[]
1215 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1216 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1217 g2.setStroke(new BasicStroke());
1221 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1222 Annotation[] aa_annotations, int sRes, int eRes, float min,
1223 float max, int y, boolean renderHistogram, boolean renderProfile,
1224 boolean normaliseProfile)
1226 if (sRes > aa_annotations.length)
1230 Font ofont = g.getFont();
1231 eRes = Math.min(eRes, aa_annotations.length);
1233 int x = 0, y1 = y, y2 = y;
1235 float range = max - min;
1239 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1242 g.setColor(Color.gray);
1244 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1247 int aaMax = aa_annotations.length - 1;
1248 while (x < eRes - sRes)
1251 if (hasHiddenColumns)
1253 column = columnSelection.adjustForHiddenColumns(column);
1261 if (aa_annotations[column] == null)
1266 if (aa_annotations[column].colour == null)
1267 g.setColor(Color.black);
1269 g.setColor(aa_annotations[column].colour);
1272 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1274 if (renderHistogram)
1278 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1282 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1285 // draw profile if available
1289 int profl[] = getProfileFor(_aa, column);
1290 // just try to draw the logo if profl is not null
1291 if (profl != null && profl[1] != 0)
1293 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1294 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1301 * profl.length == 74 indicates that the profile of a secondary
1302 * structure conservation row was accesed. Therefore dc gets length 2,
1303 * to have space for a basepair instead of just a single nucleotide
1305 if (profl.length == 74)
1313 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1314 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1315 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1317 for (int c = 2; c < profl[0];)
1319 dc[0] = (char) profl[c++];
1321 if (_aa.label.startsWith("StrucConsensus"))
1323 dc[1] = (char) profl[c++];
1327 wdth /= fm.charsWidth(dc, 0, dc.length);
1331 scl = htn * scale * profl[c++];
1332 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1333 .getFontRenderContext());
1334 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1335 wdth, scl / lm.getAscent())));
1336 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1338 // Debug - render boxes around characters
1339 // g.setColor(Color.red);
1340 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1342 // g.setColor(profcolour.findColour(dc[0]).darker());
1343 g.setColor(profcolour.findColour(dc[0], column, null));
1345 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1346 .getBaselineIndex()]));
1348 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1356 if (_aa.threshold != null)
1358 g.setColor(_aa.threshold.colour);
1359 Graphics2D g2 = (Graphics2D) g;
1360 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1361 BasicStroke.JOIN_ROUND, 3f, new float[]
1364 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1366 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1367 g2.setStroke(new BasicStroke());
1371 // used by overview window
1372 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1373 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1375 eRes = Math.min(eRes, aa_annotations.length);
1376 g.setColor(Color.white);
1377 g.fillRect(0, 0, width, y);
1378 g.setColor(new Color(0, 0, 180));
1382 for (int j = sRes; j < eRes; j++)
1384 if (aa_annotations[j] != null)
1386 if (aa_annotations[j].colour == null)
1387 g.setColor(Color.black);
1389 g.setColor(aa_annotations[j].colour);
1391 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1397 g.fillRect(x, y - height, charWidth, height);
1403 Color getNotCanonicalColor(char lastss)
1409 return new Color(255, 125, 5);
1413 return new Color(245, 115, 10);
1417 return new Color(235, 135, 15);
1421 return new Color(225, 105, 20);
1425 return new Color(215, 145, 30);
1429 return new Color(205, 95, 35);
1433 return new Color(195, 155, 45);
1437 return new Color(185, 85, 55);
1441 return new Color(175, 165, 65);
1445 return new Color(170, 75, 75);
1449 return new Color(160, 175, 85);
1453 return new Color(150, 65, 95);
1457 return new Color(140, 185, 105);
1461 return new Color(130, 55, 110);
1465 return new Color(120, 195, 120);
1469 return new Color(110, 45, 130);
1473 return new Color(100, 205, 140);
1477 return new Color(90, 35, 150);
1481 return new Color(85, 215, 160);
1485 return new Color(75, 25, 170);
1489 return new Color(65, 225, 180);
1493 return new Color(55, 15, 185);
1497 return new Color(45, 235, 195);
1501 return new Color(35, 5, 205);
1505 return new Color(25, 245, 215);
1509 return new Color(15, 0, 225);
1513 return new Color(10, 255, 235);
1517 return new Color(5, 150, 245);
1521 return new Color(0, 80, 255);
1524 System.out.println("This is not a interaction : " + lastss);