2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.renderer;
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.StructureFrequency;
22 import jalview.api.AlignViewportI;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.schemes.ColourSchemeI;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.Image;
35 import java.awt.font.LineMetrics;
36 import java.awt.geom.AffineTransform;
37 import java.awt.image.ImageObserver;
38 import java.util.BitSet;
39 import java.util.Hashtable;
41 import com.stevesoft.pat.Regex;
43 public class AnnotationRenderer
46 * flag indicating if timing and redraw parameter info should be output
48 private final boolean debugRedraw;
50 public AnnotationRenderer()
55 * Create a new annotation Renderer
56 * @param debugRedraw flag indicating if timing and redraw parameter info should be output
58 public AnnotationRenderer(boolean debugRedraw)
60 this.debugRedraw=debugRedraw;
63 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
64 int lastSSX, int x, int y, int iconOffset, int startRes,
65 int column, boolean validRes, boolean validEnd)
67 g.setColor(STEM_COLOUR);
68 int sCol = (lastSSX / charWidth) + startRes;
70 int x2 = (x * charWidth);
71 Regex closeparen = new Regex("(\\))");
73 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
74 : row_annotations[column - 1].displayCharacter;
76 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
77 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
78 boolean diffdownstream = !validRes || !validEnd
79 || row_annotations[column] == null
80 || !dc.equals(row_annotations[column].displayCharacter);
81 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
82 // If a closing base pair half of the stem, display a backward arrow
83 if (column > 0 && closeparen.search(dc))
87 // if (validRes && column>1 && row_annotations[column-2]!=null &&
88 // dc.equals(row_annotations[column-2].displayCharacter))
90 g.fillPolygon(new int[]
91 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
92 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
103 // display a forward arrow
106 g.fillPolygon(new int[]
107 { x2 - 5, x2 - 5, x2 }, new int[]
108 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
117 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
120 private int charWidth, endRes, charHeight;
122 private boolean validCharWidth, hasHiddenColumns;
124 private FontMetrics fm;
126 private final boolean MAC = new jalview.util.Platform().isAMac();
128 boolean av_renderHistogram = true, av_renderProfile = true,
129 av_normaliseProfile = false;
131 ColourSchemeI profcolour = null;
133 private ColumnSelection columnSelection;
135 private Hashtable[] hconsensus;
137 private Hashtable[] hStrucConsensus;
139 private boolean av_ignoreGapsConsensus;
142 * attributes set from AwtRenderPanelI
145 * old image used when data is currently being calculated and cannot be
148 private Image fadedImage;
151 * panel being rendered into
153 private ImageObserver annotationPanel;
156 * width of image to render in panel
158 private int imgWidth;
160 * offset to beginning of visible area
164 * offset to end of visible area
166 private int visHeight;
168 * indicate if the renderer should only render the visible portion of the annotation given the current view settings
170 private boolean useClip=true;
172 * master flag indicating if renderer should ever try to clip. not enabled for jalview 2.8.1
174 private boolean canClip=false;
177 public void drawPseudoNode(Graphics g, Color nonCanColor, Annotation[] row_annotations,
178 int lastSSX, int x, int y, int iconOffset, int startRes,
179 int column, boolean validRes, boolean validEnd)
181 //System.out.println(nonCanColor);
183 g.setColor(nonCanColor);
184 int sCol = (lastSSX / charWidth) + startRes;
186 int x2 = (x * charWidth);
187 Regex closeparen = new Regex("}|]|<|[a-z]");
189 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
190 : row_annotations[column - 1].displayCharacter;
192 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
193 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
194 boolean diffdownstream = !validRes || !validEnd
195 || row_annotations[column] == null
196 || !dc.equals(row_annotations[column].displayCharacter);
197 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
198 // If a closing base pair half of the stem, display a backward arrow
199 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
203 // if (validRes && column>1 && row_annotations[column-2]!=null &&
204 // dc.equals(row_annotations[column-2].displayCharacter))
206 g.fillPolygon(new int[]
207 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
208 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
219 // display a forward arrow
222 g.fillPolygon(new int[]
223 { x2 - 5, x2 - 5, x2 }, new int[]
224 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
233 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
235 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
237 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
240 fm = annotPanel.getFontMetrics();
241 annotationPanel = annotPanel;
242 fadedImage = annotPanel.getFadedImage();
243 imgWidth = annotPanel.getFadedImageWidth();
244 // visible area for rendering
245 int[] bounds=annotPanel.getVisibleVRange();
249 visHeight = bounds[1];
260 updateFromAlignViewport(av);
263 public void updateFromAlignViewport(AlignViewportI av)
265 charWidth = av.getCharWidth();
266 endRes = av.getEndRes();
267 charHeight = av.getCharHeight();
268 hasHiddenColumns = av.hasHiddenColumns();
269 validCharWidth = av.isValidCharWidth();
270 av_renderHistogram = av.isShowConsensusHistogram();
271 av_renderProfile = av.isShowSequenceLogo();
272 av_normaliseProfile = av.isNormaliseSequenceLogo();
273 profcolour = av.getGlobalColourScheme();
274 if (profcolour == null)
276 // Set the default colour for sequence logo if the alignnent has no
278 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
279 : new jalview.schemes.ZappoColourScheme();
281 columnSelection = av.getColumnSelection();
282 hconsensus = av.getSequenceConsensusHash();// hconsensus;
283 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
284 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
287 public int[] getProfileFor(AlignmentAnnotation aa, int column)
289 // TODO : consider refactoring the global alignment calculation
290 // properties/rendering attributes as a global 'alignment group' which holds
291 // all vis settings for the alignment as a whole rather than a subset
293 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
295 if (aa.groupRef != null && aa.groupRef.consensusData != null
296 && aa.groupRef.isShowSequenceLogo())
298 return AAFrequency.extractProfile(
299 aa.groupRef.consensusData[column],
300 aa.groupRef.getIgnoreGapsConsensus());
302 // TODO extend annotation row to enable dynamic and static profile data to
304 if (aa.groupRef == null && aa.sequenceRef == null && av_renderProfile)
306 return AAFrequency.extractProfile(hconsensus[column],
307 av_ignoreGapsConsensus);
312 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
314 // TODO implement group structure consensus
316 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
317 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
318 * group selections return StructureFrequency.extractProfile(
319 * aa.groupRef.consensusData[column], aa.groupRef
320 * .getIgnoreGapsConsensus()); }
322 // TODO extend annotation row to enable dynamic and static profile data
325 if (aa.groupRef == null && aa.sequenceRef == null
326 && av_renderProfile && hStrucConsensus != null
327 && hStrucConsensus.length > column)
329 return StructureFrequency.extractProfile(hStrucConsensus[column],
330 av_ignoreGapsConsensus);
338 * Render the annotation rows associated with an alignment.
343 * data and view settings to render
345 * destination for graphics
347 * row where a mouse event occured (or -1)
349 * first column that will be drawn
351 * last column that will be drawn
352 * @return true if the fadedImage was used for any alignment annotation rows
353 * currently being calculated
355 public boolean drawComponent(AwtRenderPanelI annotPanel,
356 AlignViewportI av, Graphics g, int activeRow, int startRes,
359 long stime=System.currentTimeMillis();
360 boolean usedFaded = false;
362 // AnnotationPanel needs to implement: ImageObserver, access to
364 updateFromAwtRenderPanel(annotPanel, av);
365 fm = g.getFontMetrics();
366 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
377 boolean validRes = false;
378 boolean validEnd = false;
379 boolean labelAllCols = false;
380 boolean centreColLabels, centreColLabelsDef = av
381 .getCentreColumnLabels();
382 boolean scaleColLabel = false;
384 BitSet graphGroupDrawn = new BitSet();
385 int charOffset = 0; // offset for a label
386 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
388 Font ofont = g.getFont();
391 int yfrom=0,f_i=0,yto=0,f_to=0;
392 boolean clipst=false,clipend=false;
393 for (int i = 0; i < aa.length; i++)
395 AlignmentAnnotation row = aa[i];
396 Annotation[] row_annotations = row.annotations;
401 centreColLabels = row.centreColLabels || centreColLabelsDef;
402 labelAllCols = row.showAllColLabels;
403 scaleColLabel = row.scaleColLabel;
407 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
408 {// if_in_visible_region
419 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
423 // this is so that we draw the characters below the graph
428 iconOffset = charHeight - fm.getDescent();
432 else if (row.hasText)
434 iconOffset = charHeight - fm.getDescent();
442 if (row.autoCalculated && av.isCalculationInProgress(row))
446 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
447 - row.height, imgWidth, y, annotationPanel);
448 g.setColor(Color.black);
449 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
455 * else if (annotationPanel.av.updatingConservation &&
456 * aa[i].label.equals("Conservation")) {
458 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
459 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
460 * annotationPanel.imgWidth, y, annotationPanel);
462 * g.setColor(Color.black); //
463 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
465 * continue; } else if (annotationPanel.av.updatingConservation &&
466 * aa[i].label.equals("Quality")) {
468 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
469 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
470 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
471 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
475 // first pass sets up state for drawing continuation from left-hand column
477 x = (startRes == 0) ? 0 : -1;
478 while (x < endRes - startRes)
480 if (hasHiddenColumns)
482 column = columnSelection.adjustForHiddenColumns(startRes + x);
483 if (column > row_annotations.length - 1)
490 column = startRes + x;
493 if ((row_annotations == null) || (row_annotations.length <= column)
494 || (row_annotations[column] == null))
506 g.setColor(Color.red);
508 if (columnSelection != null)
510 for (int n = 0; n < columnSelection.size(); n++)
512 int v = columnSelection.columnAt(n);
516 g.fillRect(x * charWidth, y, charWidth, charHeight);
521 if (!row.isValidStruc())
523 g.setColor(Color.orange);
524 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
525 charWidth, charHeight);
529 && row_annotations[column].displayCharacter != null
530 && (row_annotations[column].displayCharacter.length() > 0))
533 if (centreColLabels || scaleColLabel)
535 fmWidth = fm.charsWidth(
536 row_annotations[column].displayCharacter
538 row_annotations[column].displayCharacter.length());
542 // justify the label and scale to fit in column
543 if (fmWidth > charWidth)
545 // scale only if the current font isn't already small enough
546 fmScaling = charWidth;
547 fmScaling /= fmWidth;
548 g.setFont(ofont.deriveFont(AffineTransform
549 .getScaleInstance(fmScaling, 1.0)));
550 // and update the label's width to reflect the scaling.
558 .charWidth(row_annotations[column].displayCharacter
561 charOffset = (int) ((charWidth - fmWidth) / 2f);
563 if (row_annotations[column].colour == null)
564 g.setColor(Color.black);
566 g.setColor(row_annotations[column].colour);
568 if (column == 0 || row.graph > 0)
570 g.drawString(row_annotations[column].displayCharacter,
571 (x * charWidth) + charOffset, y + iconOffset);
573 else if (row_annotations[column - 1] == null
575 || !row_annotations[column].displayCharacter
576 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
577 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
579 g.drawString(row_annotations[column].displayCharacter
581 * charWidth + charOffset, y + iconOffset);
588 char ss = validRes ? row_annotations[column].secondaryStructure
593 // distinguish between forward/backward base-pairing
594 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
603 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
612 // distinguish between forward/backward base-pairing
613 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
622 // distinguish between forward/backward base-pairing
623 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
632 // System.out.println("ss="+ss);
633 // distinguish between forward/backward base-pairing
634 if (row_annotations[column].displayCharacter.indexOf(ss+32) > -1)
644 if (!validRes || (ss != lastSS))
653 //System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
658 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
659 column, validRes, validEnd);
663 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
664 column, validRes, validEnd);
667 case '(': // Stem case for RNA secondary structure
668 case ')': // and opposite direction
671 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
672 column, validRes, validEnd);
734 Color nonCanColor= getNotCanonicalColor(lastSS);
735 drawPseudoNode(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
736 column, validRes, validEnd);
740 g.setColor(Color.gray);
741 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
757 lastSSX = (x * charWidth);
764 if (column >= row_annotations.length)
766 column = row_annotations.length - 1;
773 if ((row_annotations == null) || (row_annotations.length <= column)
774 || (row_annotations[column] == null))
790 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
791 column, validRes, validEnd);
795 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
796 column, validRes, validEnd);
799 case 'S': // Stem case for RNA secondary structure
801 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
802 column, validRes, validEnd);
861 //System.out.println(lastSS);
863 Color nonCanColor = getNotCanonicalColor(lastSS);
864 drawPseudoNode(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
865 column, validRes, validEnd);
870 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
871 column, validRes, validEnd);
876 if (row.graph > 0 && row.graphHeight > 0)
878 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
880 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
882 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
883 float groupmax = -999999, groupmin = 9999999;
884 for (int gg = 0; gg < aa.length; gg++)
886 if (aa[gg].graphGroup != row.graphGroup)
893 aa[gg].visible = false;
896 if (aa[gg].graphMax > groupmax)
898 groupmax = aa[gg].graphMax;
900 if (aa[gg].graphMin < groupmin)
902 groupmin = aa[gg].graphMin;
906 for (int gg = 0; gg < aa.length; gg++)
908 if (aa[gg].graphGroup == row.graphGroup)
910 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes, endRes, y, groupmin,
911 groupmax, row.graphHeight);
915 graphGroupDrawn.set(row.graphGroup);
919 drawLineGraph(g, row, row_annotations, startRes, endRes, y, row.graphMin,
920 row.graphMax, row.graphHeight);
923 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
925 drawBarGraph(g, row, row_annotations, startRes, endRes, row.graphMin,
930 if (clipst && !clipend)
934 }// end if_in_visible_region
935 if (row.graph > 0 && row.hasText)
951 System.err.println("Start clip at : " + yfrom + " (index " + f_i
956 System.err.println("End clip at : " + yto + " (index " + f_to
961 System.err.println("Annotation Rendering time:"
962 + (System.currentTimeMillis() - stime));
969 private final Color GLYPHLINE_COLOR = Color.gray;
971 private final Color SHEET_COLOUR = Color.green;
973 private final Color HELIX_COLOUR = Color.red;
975 private final Color STEM_COLOUR = Color.blue;
977 private Color sdNOTCANONICAL_COLOUR;
979 public void drawGlyphLine(Graphics g, Annotation[] row,
980 int lastSSX, int x, int y, int iconOffset, int startRes,
981 int column, boolean validRes, boolean validEnd)
983 g.setColor(GLYPHLINE_COLOR);
984 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
987 public void drawSheetAnnot(Graphics g, Annotation[] row,
989 int lastSSX, int x, int y, int iconOffset, int startRes,
990 int column, boolean validRes, boolean validEnd)
992 g.setColor(SHEET_COLOUR);
994 if (!validEnd || !validRes || row == null || row[column] == null
995 || row[column].secondaryStructure != 'E')
997 g.fillRect(lastSSX, y + 4 + iconOffset,
998 (x * charWidth) - lastSSX - 4, 7);
999 g.fillPolygon(new int[]
1000 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1002 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1007 g.fillRect(lastSSX, y + 4 + iconOffset,
1008 (x + 1) * charWidth - lastSSX, 7);
1013 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1014 int x, int y, int iconOffset, int startRes, int column,
1015 boolean validRes, boolean validEnd)
1017 g.setColor(HELIX_COLOUR);
1019 int sCol = (lastSSX / charWidth) + startRes;
1021 int x2 = (x * charWidth);
1025 int ofs = charWidth / 2;
1026 // Off by 1 offset when drawing rects and ovals
1027 // to offscreen image on the MAC
1028 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1029 if (sCol == 0 || row[sCol - 1] == null
1030 || row[sCol - 1].secondaryStructure != 'H')
1035 // g.setColor(Color.orange);
1036 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1039 if (!validRes || row[column] == null
1040 || row[column].secondaryStructure != 'H')
1046 // g.setColor(Color.magenta);
1047 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1055 if (sCol == 0 || row[sCol - 1] == null
1056 || row[sCol - 1].secondaryStructure != 'H')
1058 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1059 x1 += charWidth / 2;
1062 if (!validRes || row[column] == null
1063 || row[column].secondaryStructure != 'H')
1065 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1067 x2 -= charWidth / 2;
1070 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1073 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1074 Annotation[] aa_annotations, int sRes, int eRes, int y,
1075 float min, float max, int graphHeight)
1077 if (sRes > aa_annotations.length)
1084 // Adjustment for fastpaint to left
1090 eRes = Math.min(eRes, aa_annotations.length);
1098 float range = max - min;
1103 y2 = y - (int) ((0 - min / range) * graphHeight);
1106 g.setColor(Color.gray);
1107 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1109 eRes = Math.min(eRes, aa_annotations.length);
1112 int aaMax = aa_annotations.length - 1;
1114 while (x < eRes - sRes)
1117 if (hasHiddenColumns)
1119 column = columnSelection.adjustForHiddenColumns(column);
1127 if (aa_annotations[column] == null
1128 || aa_annotations[column - 1] == null)
1134 if (aa_annotations[column].colour == null)
1135 g.setColor(Color.black);
1137 g.setColor(aa_annotations[column].colour);
1140 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1142 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1144 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1145 + charWidth / 2, y2);
1149 if (_aa.threshold != null)
1151 g.setColor(_aa.threshold.colour);
1152 Graphics2D g2 = (Graphics2D) g;
1153 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1154 BasicStroke.JOIN_ROUND, 3f, new float[]
1157 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1158 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1159 g2.setStroke(new BasicStroke());
1163 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1164 Annotation[] aa_annotations, int sRes, int eRes, float min,
1167 if (sRes > aa_annotations.length)
1171 Font ofont = g.getFont();
1172 eRes = Math.min(eRes, aa_annotations.length);
1174 int x = 0, y1 = y, y2 = y;
1176 float range = max - min;
1180 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1183 g.setColor(Color.gray);
1185 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1188 int aaMax = aa_annotations.length - 1;
1189 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
1190 // if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1192 // TODO: generalise this to have render styles for consensus/profile data
1193 if (_aa.groupRef != null)
1195 renderHistogram = _aa.groupRef.isShowConsensusHistogram();
1196 renderProfile = _aa.groupRef.isShowSequenceLogo();
1197 normaliseProfile = _aa.groupRef.isNormaliseSequenceLogo();
1201 renderHistogram = av_renderHistogram;
1202 renderProfile = av_renderProfile;
1203 normaliseProfile = av_normaliseProfile;
1206 while (x < eRes - sRes)
1209 if (hasHiddenColumns)
1211 column = columnSelection.adjustForHiddenColumns(column);
1219 if (aa_annotations[column] == null)
1224 if (aa_annotations[column].colour == null)
1225 g.setColor(Color.black);
1227 g.setColor(aa_annotations[column].colour);
1230 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1232 if (renderHistogram)
1236 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1240 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1243 // draw profile if available
1247 int profl[] = getProfileFor(_aa, column);
1248 // just try to draw the logo if profl is not null
1249 if (profl != null && profl[1] != 0)
1251 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1252 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1259 * profl.length == 74 indicates that the profile of a secondary
1260 * structure conservation row was accesed. Therefore dc gets length 2,
1261 * to have space for a basepair instead of just a single nucleotide
1263 if (profl.length == 74)
1271 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1272 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1273 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1275 for (int c = 2; c < profl[0];)
1277 dc[0] = (char) profl[c++];
1279 if (_aa.label.startsWith("StrucConsensus"))
1281 dc[1] = (char) profl[c++];
1285 wdth /= fm.charsWidth(dc, 0, dc.length);
1289 scl = htn * scale * profl[c++];
1290 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1291 .getFontRenderContext());
1292 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1293 wdth, scl / lm.getAscent())));
1294 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1296 // Debug - render boxes around characters
1297 // g.setColor(Color.red);
1298 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1300 // g.setColor(profcolour.findColour(dc[0]).darker());
1301 g.setColor(profcolour.findColour(dc[0], column, null));
1303 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1304 .getBaselineIndex()]));
1306 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1314 if (_aa.threshold != null)
1316 g.setColor(_aa.threshold.colour);
1317 Graphics2D g2 = (Graphics2D) g;
1318 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1319 BasicStroke.JOIN_ROUND, 3f, new float[]
1322 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1324 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1325 g2.setStroke(new BasicStroke());
1329 // used by overview window
1330 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1331 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1333 eRes = Math.min(eRes, aa_annotations.length);
1334 g.setColor(Color.white);
1335 g.fillRect(0, 0, width, y);
1336 g.setColor(new Color(0, 0, 180));
1340 for (int j = sRes; j < eRes; j++)
1342 if (aa_annotations[j] != null)
1344 if (aa_annotations[j].colour == null)
1345 g.setColor(Color.black);
1347 g.setColor(aa_annotations[j].colour);
1349 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1355 g.fillRect(x, y - height, charWidth, height);
1362 Color getNotCanonicalColor(char lastss)
1368 return new Color(255,125,5);
1372 return new Color(245,115,10);
1376 return new Color(235,135,15);
1380 return new Color(225,105,20);
1384 return new Color(215,145,30);
1388 return new Color(205,95,35);
1392 return new Color(195,155,45);
1396 return new Color(185,85,55);
1400 return new Color(175,165,65);
1404 return new Color(170,75,75);
1408 return new Color(160,175,85);
1412 return new Color(150,65,95);
1416 return new Color(140,185,105);
1420 return new Color(130,55,110);
1424 return new Color(120,195,120);
1428 return new Color(110,45,130);
1432 return new Color(100,205,140);
1436 return new Color(90,35,150);
1440 return new Color(85,215,160);
1444 return new Color(75,25,170);
1448 return new Color(65,225,180);
1452 return new Color(55,15,185);
1456 return new Color(45,235,195);
1460 return new Color(35,5,205);
1464 return new Color(25,245,215);
1468 return new Color(15,0,225);
1472 return new Color(10,255,235);
1476 return new Color(5,150,245);
1480 return new Color(0,80,255);
1483 System.out.println("This is not a interaction : "+lastss);