2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.renderer;
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.StructureFrequency;
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.Annotation;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.schemes.ColourSchemeI;
29 import java.awt.BasicStroke;
30 import java.awt.Color;
32 import java.awt.FontMetrics;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.Image;
36 import java.awt.font.LineMetrics;
37 import java.awt.geom.AffineTransform;
38 import java.awt.image.ImageObserver;
39 import java.util.BitSet;
40 import java.util.Hashtable;
42 import com.stevesoft.pat.Regex;
44 public class AnnotationRenderer
47 * flag indicating if timing and redraw parameter info should be output
49 private final boolean debugRedraw;
51 public AnnotationRenderer()
56 * Create a new annotation Renderer
57 * @param debugRedraw flag indicating if timing and redraw parameter info should be output
59 public AnnotationRenderer(boolean debugRedraw)
61 this.debugRedraw=debugRedraw;
64 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
65 int lastSSX, int x, int y, int iconOffset, int startRes,
66 int column, boolean validRes, boolean validEnd)
68 g.setColor(STEM_COLOUR);
69 int sCol = (lastSSX / charWidth) + startRes;
71 int x2 = (x * charWidth);
72 Regex closeparen = new Regex("(\\))");
74 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
75 : row_annotations[column - 1].displayCharacter;
77 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
78 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
79 boolean diffdownstream = !validRes || !validEnd
80 || row_annotations[column] == null
81 || !dc.equals(row_annotations[column].displayCharacter);
82 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
83 // If a closing base pair half of the stem, display a backward arrow
84 if (column > 0 && closeparen.search(dc))
88 // if (validRes && column>1 && row_annotations[column-2]!=null &&
89 // dc.equals(row_annotations[column-2].displayCharacter))
91 g.fillPolygon(new int[]
92 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
93 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
104 // display a forward arrow
107 g.fillPolygon(new int[]
108 { x2 - 5, x2 - 5, x2 }, new int[]
109 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
118 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
121 private int charWidth, endRes, charHeight;
123 private boolean validCharWidth, hasHiddenColumns;
125 private FontMetrics fm;
127 private final boolean MAC = new jalview.util.Platform().isAMac();
129 boolean av_renderHistogram = true, av_renderProfile = true,
130 av_normaliseProfile = false;
132 ColourSchemeI profcolour = null;
134 private ColumnSelection columnSelection;
136 private Hashtable[] hconsensus;
138 private Hashtable[] hStrucConsensus;
140 private boolean av_ignoreGapsConsensus;
143 * attributes set from AwtRenderPanelI
146 * old image used when data is currently being calculated and cannot be
149 private Image fadedImage;
152 * panel being rendered into
154 private ImageObserver annotationPanel;
157 * width of image to render in panel
159 private int imgWidth;
161 * offset to beginning of visible area
165 * offset to end of visible area
167 private int visHeight;
169 * indicate if the renderer should only render the visible portion of the annotation given the current view settings
171 private boolean useClip=true;
173 * master flag indicating if renderer should ever try to clip. not enabled for jalview 2.8.1
175 private boolean canClip=false;
178 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations,
179 int lastSSX, int x, int y, int iconOffset, int startRes,
180 int column, boolean validRes, boolean validEnd)
182 //System.out.println(nonCanColor);
184 g.setColor(nonCanColor);
185 int sCol = (lastSSX / charWidth) + startRes;
187 int x2 = (x * charWidth);
188 Regex closeparen = new Regex("}|]|<|[a-z]");
190 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
191 : row_annotations[column - 1].displayCharacter;
193 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
194 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
195 boolean diffdownstream = !validRes || !validEnd
196 || row_annotations[column] == null
197 || !dc.equals(row_annotations[column].displayCharacter);
198 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
199 // If a closing base pair half of the stem, display a backward arrow
200 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
204 // if (validRes && column>1 && row_annotations[column-2]!=null &&
205 // dc.equals(row_annotations[column-2].displayCharacter))
207 g.fillPolygon(new int[]
208 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
209 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
220 // display a forward arrow
223 g.fillPolygon(new int[]
224 { x2 - 5, x2 - 5, x2 }, new int[]
225 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
234 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
236 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
238 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
241 fm = annotPanel.getFontMetrics();
242 annotationPanel = annotPanel;
243 fadedImage = annotPanel.getFadedImage();
244 imgWidth = annotPanel.getFadedImageWidth();
245 // visible area for rendering
246 int[] bounds=annotPanel.getVisibleVRange();
250 visHeight = bounds[1];
261 updateFromAlignViewport(av);
264 public void updateFromAlignViewport(AlignViewportI av)
266 charWidth = av.getCharWidth();
267 endRes = av.getEndRes();
268 charHeight = av.getCharHeight();
269 hasHiddenColumns = av.hasHiddenColumns();
270 validCharWidth = av.isValidCharWidth();
271 av_renderHistogram = av.isShowConsensusHistogram();
272 av_renderProfile = av.isShowSequenceLogo();
273 av_normaliseProfile = av.isNormaliseSequenceLogo();
274 profcolour = av.getGlobalColourScheme();
275 if (profcolour == null)
277 // Set the default colour for sequence logo if the alignnent has no
279 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
280 : new jalview.schemes.ZappoColourScheme();
282 columnSelection = av.getColumnSelection();
283 hconsensus = av.getSequenceConsensusHash();// hconsensus;
284 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
285 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
288 public int[] getProfileFor(AlignmentAnnotation aa, int column)
290 // TODO : consider refactoring the global alignment calculation
291 // properties/rendering attributes as a global 'alignment group' which holds
292 // all vis settings for the alignment as a whole rather than a subset
294 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
296 if (aa.groupRef != null && aa.groupRef.consensusData != null
297 && aa.groupRef.isShowSequenceLogo())
299 return AAFrequency.extractProfile(
300 aa.groupRef.consensusData[column],
301 aa.groupRef.getIgnoreGapsConsensus());
303 // TODO extend annotation row to enable dynamic and static profile data to
305 if (aa.groupRef == null && aa.sequenceRef == null)
307 return AAFrequency.extractProfile(hconsensus[column],
308 av_ignoreGapsConsensus);
313 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
315 // TODO implement group structure consensus
317 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
318 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
319 * group selections return StructureFrequency.extractProfile(
320 * aa.groupRef.consensusData[column], aa.groupRef
321 * .getIgnoreGapsConsensus()); }
323 // TODO extend annotation row to enable dynamic and static profile data
326 if (aa.groupRef == null && aa.sequenceRef == null
327 && hStrucConsensus != null
328 && hStrucConsensus.length > column)
330 return StructureFrequency.extractProfile(hStrucConsensus[column],
331 av_ignoreGapsConsensus);
339 * Render the annotation rows associated with an alignment.
344 * data and view settings to render
346 * destination for graphics
348 * row where a mouse event occured (or -1)
350 * first column that will be drawn
352 * last column that will be drawn
353 * @return true if the fadedImage was used for any alignment annotation rows
354 * currently being calculated
356 public boolean drawComponent(AwtRenderPanelI annotPanel,
357 AlignViewportI av, Graphics g, int activeRow, int startRes,
360 long stime=System.currentTimeMillis();
361 boolean usedFaded = false;
363 // AnnotationPanel needs to implement: ImageObserver, access to
365 updateFromAwtRenderPanel(annotPanel, av);
366 fm = g.getFontMetrics();
367 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
378 boolean validRes = false;
379 boolean validEnd = false;
380 boolean labelAllCols = false;
381 boolean centreColLabels, centreColLabelsDef = av
382 .getCentreColumnLabels();
383 boolean scaleColLabel = false;
384 AlignmentAnnotation consensusAnnot=av.getAlignmentConsensusAnnotation(),structConsensusAnnot=av.getAlignmentStrucConsensusAnnotation();
385 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
387 BitSet graphGroupDrawn = new BitSet();
388 int charOffset = 0; // offset for a label
389 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
391 Font ofont = g.getFont();
394 int yfrom=0,f_i=0,yto=0,f_to=0;
395 boolean clipst=false,clipend=false;
396 for (int i = 0; i < aa.length; i++)
398 AlignmentAnnotation row = aa[i];
400 // check if this is a consensus annotation row and set the display settings appropriately
401 // TODO: generalise this to have render styles for consensus/profile
403 if (row.groupRef != null && row == row.groupRef.getConsensus())
405 renderHistogram = row.groupRef.isShowConsensusHistogram();
406 renderProfile = row.groupRef.isShowSequenceLogo();
407 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
409 else if (row == consensusAnnot || row == structConsensusAnnot)
411 renderHistogram = av_renderHistogram;
412 renderProfile = av_renderProfile;
413 normaliseProfile = av_normaliseProfile;
415 renderHistogram = true;
416 // don't need to set render/normaliseProfile since they are not currently used in any other annotation track renderer
419 Annotation[] row_annotations = row.annotations;
424 centreColLabels = row.centreColLabels || centreColLabelsDef;
425 labelAllCols = row.showAllColLabels;
426 scaleColLabel = row.scaleColLabel;
430 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
431 {// if_in_visible_region
442 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
446 // this is so that we draw the characters below the graph
451 iconOffset = charHeight - fm.getDescent();
455 else if (row.hasText)
457 iconOffset = charHeight - fm.getDescent();
465 if (row.autoCalculated && av.isCalculationInProgress(row))
469 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
470 - row.height, imgWidth, y, annotationPanel);
471 g.setColor(Color.black);
472 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
478 * else if (annotationPanel.av.updatingConservation &&
479 * aa[i].label.equals("Conservation")) {
481 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
482 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
483 * annotationPanel.imgWidth, y, annotationPanel);
485 * g.setColor(Color.black); //
486 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
488 * continue; } else if (annotationPanel.av.updatingConservation &&
489 * aa[i].label.equals("Quality")) {
491 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
492 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
493 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
494 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
498 // first pass sets up state for drawing continuation from left-hand column
500 x = (startRes == 0) ? 0 : -1;
501 while (x < endRes - startRes)
503 if (hasHiddenColumns)
505 column = columnSelection.adjustForHiddenColumns(startRes + x);
506 if (column > row_annotations.length - 1)
513 column = startRes + x;
516 if ((row_annotations == null) || (row_annotations.length <= column)
517 || (row_annotations[column] == null))
529 g.setColor(Color.red);
531 if (columnSelection != null)
533 for (int n = 0; n < columnSelection.size(); n++)
535 int v = columnSelection.columnAt(n);
539 g.fillRect(x * charWidth, y, charWidth, charHeight);
544 if (!row.isValidStruc())
546 g.setColor(Color.orange);
547 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
548 charWidth, charHeight);
552 && row_annotations[column].displayCharacter != null
553 && (row_annotations[column].displayCharacter.length() > 0))
556 if (centreColLabels || scaleColLabel)
558 fmWidth = fm.charsWidth(
559 row_annotations[column].displayCharacter
561 row_annotations[column].displayCharacter.length());
565 // justify the label and scale to fit in column
566 if (fmWidth > charWidth)
568 // scale only if the current font isn't already small enough
569 fmScaling = charWidth;
570 fmScaling /= fmWidth;
571 g.setFont(ofont.deriveFont(AffineTransform
572 .getScaleInstance(fmScaling, 1.0)));
573 // and update the label's width to reflect the scaling.
581 .charWidth(row_annotations[column].displayCharacter
584 charOffset = (int) ((charWidth - fmWidth) / 2f);
586 if (row_annotations[column].colour == null)
587 g.setColor(Color.black);
589 g.setColor(row_annotations[column].colour);
591 if (column == 0 || row.graph > 0)
593 g.drawString(row_annotations[column].displayCharacter,
594 (x * charWidth) + charOffset, y + iconOffset);
596 else if (row_annotations[column - 1] == null
598 || !row_annotations[column].displayCharacter
599 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
600 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
602 g.drawString(row_annotations[column].displayCharacter
604 * charWidth + charOffset, y + iconOffset);
611 char ss = validRes ? row_annotations[column].secondaryStructure
616 // distinguish between forward/backward base-pairing
617 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
626 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
635 // distinguish between forward/backward base-pairing
636 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
645 // distinguish between forward/backward base-pairing
646 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
655 // distinguish between forward/backward base-pairing
656 if (row_annotations[column].displayCharacter.indexOf(ss+32) > -1)
666 if (!validRes || (ss != lastSS))
675 //System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
680 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
681 column, validRes, validEnd);
685 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
686 column, validRes, validEnd);
689 case '(': // Stem case for RNA secondary structure
690 case ')': // and opposite direction
691 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
692 column, validRes, validEnd);
754 Color nonCanColor= getNotCanonicalColor(lastSS);
755 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
756 column, validRes, validEnd);
760 g.setColor(Color.gray);
761 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
777 lastSSX = (x * charWidth);
784 if (column >= row_annotations.length)
786 column = row_annotations.length - 1;
793 if ((row_annotations == null) || (row_annotations.length <= column)
794 || (row_annotations[column] == null))
810 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
811 column, validRes, validEnd);
815 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
816 column, validRes, validEnd);
819 case 'S': // Stem case for RNA secondary structure
821 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
822 column, validRes, validEnd);
881 //System.out.println(lastSS);
882 Color nonCanColor = getNotCanonicalColor(lastSS);
883 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
884 column, validRes, validEnd);
887 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
888 column, validRes, validEnd);
893 if (row.graph > 0 && row.graphHeight > 0)
895 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
897 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
899 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
900 float groupmax = -999999, groupmin = 9999999;
901 for (int gg = 0; gg < aa.length; gg++)
903 if (aa[gg].graphGroup != row.graphGroup)
910 aa[gg].visible = false;
912 if (aa[gg].graphMax > groupmax)
914 groupmax = aa[gg].graphMax;
916 if (aa[gg].graphMin < groupmin)
918 groupmin = aa[gg].graphMin;
922 for (int gg = 0; gg < aa.length; gg++)
924 if (aa[gg].graphGroup == row.graphGroup)
926 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes, endRes, y, groupmin,
927 groupmax, row.graphHeight);
931 graphGroupDrawn.set(row.graphGroup);
935 drawLineGraph(g, row, row_annotations, startRes, endRes, y, row.graphMin,
936 row.graphMax, row.graphHeight);
939 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
941 drawBarGraph(g, row, row_annotations, startRes, endRes,
942 row.graphMin, row.graphMax, y, renderHistogram,renderProfile,normaliseProfile);
946 if (clipst && !clipend)
950 }// end if_in_visible_region
951 if (row.graph > 0 && row.hasText)
967 System.err.println("Start clip at : " + yfrom + " (index " + f_i
972 System.err.println("End clip at : " + yto + " (index " + f_to
977 System.err.println("Annotation Rendering time:"
978 + (System.currentTimeMillis() - stime));
985 private final Color GLYPHLINE_COLOR = Color.gray;
987 private final Color SHEET_COLOUR = Color.green;
989 private final Color HELIX_COLOUR = Color.red;
991 private final Color STEM_COLOUR = Color.blue;
993 private Color sdNOTCANONICAL_COLOUR;
995 public void drawGlyphLine(Graphics g, Annotation[] row,
996 int lastSSX, int x, int y, int iconOffset, int startRes,
997 int column, boolean validRes, boolean validEnd)
999 g.setColor(GLYPHLINE_COLOR);
1000 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1003 public void drawSheetAnnot(Graphics g, Annotation[] row,
1005 int lastSSX, int x, int y, int iconOffset, int startRes,
1006 int column, boolean validRes, boolean validEnd)
1008 g.setColor(SHEET_COLOUR);
1010 if (!validEnd || !validRes || row == null || row[column] == null
1011 || row[column].secondaryStructure != 'E')
1013 g.fillRect(lastSSX, y + 4 + iconOffset,
1014 (x * charWidth) - lastSSX - 4, 7);
1015 g.fillPolygon(new int[]
1016 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1018 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1023 g.fillRect(lastSSX, y + 4 + iconOffset,
1024 (x + 1) * charWidth - lastSSX, 7);
1029 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1030 int x, int y, int iconOffset, int startRes, int column,
1031 boolean validRes, boolean validEnd)
1033 g.setColor(HELIX_COLOUR);
1035 int sCol = (lastSSX / charWidth) + startRes;
1037 int x2 = (x * charWidth);
1041 int ofs = charWidth / 2;
1042 // Off by 1 offset when drawing rects and ovals
1043 // to offscreen image on the MAC
1044 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1045 if (sCol == 0 || row[sCol - 1] == null
1046 || row[sCol - 1].secondaryStructure != 'H')
1051 // g.setColor(Color.orange);
1052 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1055 if (!validRes || row[column] == null
1056 || row[column].secondaryStructure != 'H')
1062 // g.setColor(Color.magenta);
1063 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1071 if (sCol == 0 || row[sCol - 1] == null
1072 || row[sCol - 1].secondaryStructure != 'H')
1074 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1075 x1 += charWidth / 2;
1078 if (!validRes || row[column] == null
1079 || row[column].secondaryStructure != 'H')
1081 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1083 x2 -= charWidth / 2;
1086 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1089 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1090 Annotation[] aa_annotations, int sRes, int eRes, int y,
1091 float min, float max, int graphHeight)
1093 if (sRes > aa_annotations.length)
1100 // Adjustment for fastpaint to left
1106 eRes = Math.min(eRes, aa_annotations.length);
1114 float range = max - min;
1119 y2 = y - (int) ((0 - min / range) * graphHeight);
1122 g.setColor(Color.gray);
1123 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1125 eRes = Math.min(eRes, aa_annotations.length);
1128 int aaMax = aa_annotations.length - 1;
1130 while (x < eRes - sRes)
1133 if (hasHiddenColumns)
1135 column = columnSelection.adjustForHiddenColumns(column);
1143 if (aa_annotations[column] == null
1144 || aa_annotations[column - 1] == null)
1150 if (aa_annotations[column].colour == null)
1151 g.setColor(Color.black);
1153 g.setColor(aa_annotations[column].colour);
1156 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1158 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1160 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1161 + charWidth / 2, y2);
1165 if (_aa.threshold != null)
1167 g.setColor(_aa.threshold.colour);
1168 Graphics2D g2 = (Graphics2D) g;
1169 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1170 BasicStroke.JOIN_ROUND, 3f, new float[]
1173 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1174 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1175 g2.setStroke(new BasicStroke());
1179 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1180 Annotation[] aa_annotations, int sRes, int eRes, float min,
1181 float max, int y, boolean renderHistogram,boolean renderProfile,boolean normaliseProfile)
1183 if (sRes > aa_annotations.length)
1187 Font ofont = g.getFont();
1188 eRes = Math.min(eRes, aa_annotations.length);
1190 int x = 0, y1 = y, y2 = y;
1192 float range = max - min;
1196 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1199 g.setColor(Color.gray);
1201 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1204 int aaMax = aa_annotations.length - 1;
1205 while (x < eRes - sRes)
1208 if (hasHiddenColumns)
1210 column = columnSelection.adjustForHiddenColumns(column);
1218 if (aa_annotations[column] == null)
1223 if (aa_annotations[column].colour == null)
1224 g.setColor(Color.black);
1226 g.setColor(aa_annotations[column].colour);
1229 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1231 if (renderHistogram)
1235 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1239 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1242 // draw profile if available
1246 int profl[] = getProfileFor(_aa, column);
1247 // just try to draw the logo if profl is not null
1248 if (profl != null && profl[1] != 0)
1250 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1251 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1258 * profl.length == 74 indicates that the profile of a secondary
1259 * structure conservation row was accesed. Therefore dc gets length 2,
1260 * to have space for a basepair instead of just a single nucleotide
1262 if (profl.length == 74)
1270 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1271 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1272 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1274 for (int c = 2; c < profl[0];)
1276 dc[0] = (char) profl[c++];
1278 if (_aa.label.startsWith("StrucConsensus"))
1280 dc[1] = (char) profl[c++];
1284 wdth /= fm.charsWidth(dc, 0, dc.length);
1288 scl = htn * scale * profl[c++];
1289 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1290 .getFontRenderContext());
1291 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1292 wdth, scl / lm.getAscent())));
1293 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1295 // Debug - render boxes around characters
1296 // g.setColor(Color.red);
1297 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1299 // g.setColor(profcolour.findColour(dc[0]).darker());
1300 g.setColor(profcolour.findColour(dc[0], column, null));
1302 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1303 .getBaselineIndex()]));
1305 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1313 if (_aa.threshold != null)
1315 g.setColor(_aa.threshold.colour);
1316 Graphics2D g2 = (Graphics2D) g;
1317 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1318 BasicStroke.JOIN_ROUND, 3f, new float[]
1321 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1323 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1324 g2.setStroke(new BasicStroke());
1328 // used by overview window
1329 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1330 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1332 eRes = Math.min(eRes, aa_annotations.length);
1333 g.setColor(Color.white);
1334 g.fillRect(0, 0, width, y);
1335 g.setColor(new Color(0, 0, 180));
1339 for (int j = sRes; j < eRes; j++)
1341 if (aa_annotations[j] != null)
1343 if (aa_annotations[j].colour == null)
1344 g.setColor(Color.black);
1346 g.setColor(aa_annotations[j].colour);
1348 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1354 g.fillRect(x, y - height, charWidth, height);
1361 Color getNotCanonicalColor(char lastss)
1367 return new Color(255,125,5);
1371 return new Color(245,115,10);
1375 return new Color(235,135,15);
1379 return new Color(225,105,20);
1383 return new Color(215,145,30);
1387 return new Color(205,95,35);
1391 return new Color(195,155,45);
1395 return new Color(185,85,55);
1399 return new Color(175,165,65);
1403 return new Color(170,75,75);
1407 return new Color(160,175,85);
1411 return new Color(150,65,95);
1415 return new Color(140,185,105);
1419 return new Color(130,55,110);
1423 return new Color(120,195,120);
1427 return new Color(110,45,130);
1431 return new Color(100,205,140);
1435 return new Color(90,35,150);
1439 return new Color(85,215,160);
1443 return new Color(75,25,170);
1447 return new Color(65,225,180);
1451 return new Color(55,15,185);
1455 return new Color(45,235,195);
1459 return new Color(35,5,205);
1463 return new Color(25,245,215);
1467 return new Color(15,0,225);
1471 return new Color(10,255,235);
1475 return new Color(5,150,245);
1479 return new Color(0,80,255);
1482 System.out.println("This is not a interaction : "+lastss);