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 drawNotCanonicalAnnot(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|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|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();
376 boolean validRes = false;
377 boolean validEnd = false;
378 boolean labelAllCols = false;
379 boolean centreColLabels, centreColLabelsDef = av
380 .getCentreColumnLabels();
381 boolean scaleColLabel = false;
383 BitSet graphGroupDrawn = new BitSet();
384 int charOffset = 0; // offset for a label
385 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
387 Font ofont = g.getFont();
390 int yfrom=0,f_i=0,yto=0,f_to=0;
391 boolean clipst=false,clipend=false;
392 for (int i = 0; i < aa.length; i++)
394 AlignmentAnnotation row = aa[i];
395 Annotation[] row_annotations = row.annotations;
400 centreColLabels = row.centreColLabels || centreColLabelsDef;
401 labelAllCols = row.showAllColLabels;
402 scaleColLabel = row.scaleColLabel;
406 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
407 {// if_in_visible_region
418 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
422 // this is so that we draw the characters below the graph
427 iconOffset = charHeight - fm.getDescent();
431 else if (row.hasText)
433 iconOffset = charHeight - fm.getDescent();
441 if (row.autoCalculated && av.isCalculationInProgress(row))
445 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
446 - row.height, imgWidth, y, annotationPanel);
447 g.setColor(Color.black);
448 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
454 * else if (annotationPanel.av.updatingConservation &&
455 * aa[i].label.equals("Conservation")) {
457 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
458 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
459 * annotationPanel.imgWidth, y, annotationPanel);
461 * g.setColor(Color.black); //
462 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
464 * continue; } else if (annotationPanel.av.updatingConservation &&
465 * aa[i].label.equals("Quality")) {
467 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
468 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
469 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
470 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
474 // first pass sets up state for drawing continuation from left-hand column
476 x = (startRes == 0) ? 0 : -1;
477 while (x < endRes - startRes)
479 if (hasHiddenColumns)
481 column = columnSelection.adjustForHiddenColumns(startRes + x);
482 if (column > row_annotations.length - 1)
489 column = startRes + x;
492 if ((row_annotations == null) || (row_annotations.length <= column)
493 || (row_annotations[column] == null))
505 g.setColor(Color.red);
507 if (columnSelection != null)
509 for (int n = 0; n < columnSelection.size(); n++)
511 int v = columnSelection.columnAt(n);
515 g.fillRect(x * charWidth, y, charWidth, charHeight);
520 if (!row.isValidStruc())
522 g.setColor(Color.orange);
523 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
524 charWidth, charHeight);
528 && row_annotations[column].displayCharacter != null
529 && (row_annotations[column].displayCharacter.length() > 0))
532 if (centreColLabels || scaleColLabel)
534 fmWidth = fm.charsWidth(
535 row_annotations[column].displayCharacter
537 row_annotations[column].displayCharacter.length());
541 // justify the label and scale to fit in column
542 if (fmWidth > charWidth)
544 // scale only if the current font isn't already small enough
545 fmScaling = charWidth;
546 fmScaling /= fmWidth;
547 g.setFont(ofont.deriveFont(AffineTransform
548 .getScaleInstance(fmScaling, 1.0)));
549 // and update the label's width to reflect the scaling.
557 .charWidth(row_annotations[column].displayCharacter
560 charOffset = (int) ((charWidth - fmWidth) / 2f);
562 if (row_annotations[column].colour == null)
563 g.setColor(Color.black);
565 g.setColor(row_annotations[column].colour);
567 if (column == 0 || row.graph > 0)
569 g.drawString(row_annotations[column].displayCharacter,
570 (x * charWidth) + charOffset, y + iconOffset);
572 else if (row_annotations[column - 1] == null
574 || !row_annotations[column].displayCharacter
575 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
576 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
578 g.drawString(row_annotations[column].displayCharacter
580 * charWidth + charOffset, y + iconOffset);
587 char ss = validRes ? row_annotations[column].secondaryStructure
592 // distinguish between forward/backward base-pairing
593 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
602 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
611 // distinguish between forward/backward base-pairing
612 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
621 // distinguish between forward/backward base-pairing
622 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
631 // distinguish between forward/backward base-pairing
632 if (row_annotations[column].displayCharacter.indexOf('a') > -1)
642 // distinguish between forward/backward base-pairing
643 if (row_annotations[column].displayCharacter.indexOf('b') > -1)
652 // distinguish between forward/backward base-pairing
653 if (row_annotations[column].displayCharacter.indexOf('c') > -1)
661 // distinguish between forward/backward base-pairing
662 if (row_annotations[column].displayCharacter.indexOf('d') > -1)
670 // distinguish between forward/backward base-pairing
671 if (row_annotations[column].displayCharacter.indexOf('e') > -1)
679 // distinguish between forward/backward base-pairing
680 if (row_annotations[column].displayCharacter.indexOf('f') > -1)
688 // distinguish between forward/backward base-pairing
689 if (row_annotations[column].displayCharacter.indexOf('g') > -1)
697 // distinguish between forward/backward base-pairing
698 if (row_annotations[column].displayCharacter.indexOf('h') > -1)
706 // distinguish between forward/backward base-pairing
707 if (row_annotations[column].displayCharacter.indexOf('i') > -1)
715 // distinguish between forward/backward base-pairing
716 if (row_annotations[column].displayCharacter.indexOf('j') > -1)
724 // distinguish between forward/backward base-pairing
725 if (row_annotations[column].displayCharacter.indexOf('k') > -1)
733 // distinguish between forward/backward base-pairing
734 if (row_annotations[column].displayCharacter.indexOf('l') > -1)
742 // distinguish between forward/backward base-pairing
743 if (row_annotations[column].displayCharacter.indexOf('m') > -1)
751 // distinguish between forward/backward base-pairing
752 if (row_annotations[column].displayCharacter.indexOf('n') > -1)
760 // distinguish between forward/backward base-pairing
761 if (row_annotations[column].displayCharacter.indexOf('o') > -1)
769 // distinguish between forward/backward base-pairing
770 if (row_annotations[column].displayCharacter.indexOf('p') > -1)
778 // distinguish between forward/backward base-pairing
779 if (row_annotations[column].displayCharacter.indexOf('q') > -1)
787 // distinguish between forward/backward base-pairing
788 if (row_annotations[column].displayCharacter.indexOf('r') > -1)
796 // distinguish between forward/backward base-pairing
797 if (row_annotations[column].displayCharacter.indexOf('s') > -1)
805 // distinguish between forward/backward base-pairing
806 if (row_annotations[column].displayCharacter.indexOf('t') > -1)
814 // distinguish between forward/backward base-pairing
815 if (row_annotations[column].displayCharacter.indexOf('u') > -1)
823 // distinguish between forward/backward base-pairing
824 if (row_annotations[column].displayCharacter.indexOf('v') > -1)
832 // distinguish between forward/backward base-pairing
833 if (row_annotations[column].displayCharacter.indexOf('w') > -1)
841 // distinguish between forward/backward base-pairing
842 if (row_annotations[column].displayCharacter.indexOf('x') > -1)
850 // distinguish between forward/backward base-pairing
851 if (row_annotations[column].displayCharacter.indexOf('y') > -1)
859 // distinguish between forward/backward base-pairing
860 if (row_annotations[column].displayCharacter.indexOf('z') > -1)
866 if (!validRes || (ss != lastSS))
873 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
874 iconOffset, startRes, column, validRes, validEnd);
878 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
879 iconOffset, startRes, column, validRes, validEnd);
882 case '(': // Stem case for RNA secondary structure
883 case ')': // and opposite direction
884 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
885 column, validRes, validEnd);
886 // case 'S': // Stem case for RNA secondary structure
887 // case 's': // and opposite direction
888 // drawStemAnnot(g, row_annotations, lastSSX, x, y,
889 // iconOffset, startRes, column, validRes, validEnd);
949 //System.out.println(lastSS);
950 Color nonCanColor= getNotCanonicalColor(lastSS);
951 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
952 column, validRes, validEnd);
955 g.setColor(Color.gray);
956 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
972 lastSSX = (x * charWidth);
979 if (column >= row_annotations.length)
981 column = row_annotations.length - 1;
988 if ((row_annotations == null) || (row_annotations.length <= column)
989 || (row_annotations[column] == null))
1005 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
1006 startRes, column, validRes, validEnd);
1010 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
1011 startRes, column, validRes, validEnd);
1014 case 'S': // Stem case for RNA secondary structure
1015 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
1016 startRes, column, validRes, validEnd);
1074 //System.out.println(lastSS);
1075 Color nonCanColor = getNotCanonicalColor(lastSS);
1076 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
1077 column, validRes, validEnd);
1080 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1081 startRes, column, validRes, validEnd);
1086 if (row.graph > 0 && row.graphHeight > 0)
1088 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1090 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1092 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
1093 float groupmax = -999999, groupmin = 9999999;
1094 for (int gg = 0; gg < aa.length; gg++)
1096 if (aa[gg].graphGroup != row.graphGroup)
1103 aa[gg].visible = false;
1105 if (aa[gg].graphMax > groupmax)
1107 groupmax = aa[gg].graphMax;
1109 if (aa[gg].graphMin < groupmin)
1111 groupmin = aa[gg].graphMin;
1115 for (int gg = 0; gg < aa.length; gg++)
1117 if (aa[gg].graphGroup == row.graphGroup)
1119 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1120 endRes, y, groupmin, groupmax, row.graphHeight);
1124 graphGroupDrawn.set(row.graphGroup);
1128 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1129 row.graphMin, row.graphMax, row.graphHeight);
1132 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1134 drawBarGraph(g, row, row_annotations, startRes, endRes,
1135 row.graphMin, row.graphMax, y);
1139 if (clipst && !clipend)
1143 }// end if_in_visible_region
1144 if (row.graph > 0 && row.hasText)
1160 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1165 System.err.println("End clip at : " + yto + " (index " + f_to
1170 System.err.println("Annotation Rendering time:"
1171 + (System.currentTimeMillis() - stime));
1178 private final Color GLYPHLINE_COLOR = Color.gray;
1180 private final Color SHEET_COLOUR = Color.green;
1182 private final Color HELIX_COLOUR = Color.red;
1184 private final Color STEM_COLOUR = Color.blue;
1186 private Color sdNOTCANONICAL_COLOUR;
1188 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1189 int x, int y, int iconOffset, int startRes, int column,
1190 boolean validRes, boolean validEnd)
1192 g.setColor(GLYPHLINE_COLOR);
1193 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1196 public void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX,
1197 int x, int y, int iconOffset, int startRes, int column,
1198 boolean validRes, boolean validEnd)
1200 g.setColor(SHEET_COLOUR);
1202 if (!validEnd || !validRes || row == null || row[column] == null
1203 || row[column].secondaryStructure != 'E')
1205 g.fillRect(lastSSX, y + 4 + iconOffset,
1206 (x * charWidth) - lastSSX - 4, 7);
1207 g.fillPolygon(new int[]
1208 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1210 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1215 g.fillRect(lastSSX, y + 4 + iconOffset,
1216 (x + 1) * charWidth - lastSSX, 7);
1221 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1222 int x, int y, int iconOffset, int startRes, int column,
1223 boolean validRes, boolean validEnd)
1225 g.setColor(HELIX_COLOUR);
1227 int sCol = (lastSSX / charWidth) + startRes;
1229 int x2 = (x * charWidth);
1233 int ofs = charWidth / 2;
1234 // Off by 1 offset when drawing rects and ovals
1235 // to offscreen image on the MAC
1236 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1237 if (sCol == 0 || row[sCol - 1] == null
1238 || row[sCol - 1].secondaryStructure != 'H')
1243 // g.setColor(Color.orange);
1244 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1247 if (!validRes || row[column] == null
1248 || row[column].secondaryStructure != 'H')
1254 // g.setColor(Color.magenta);
1255 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1263 if (sCol == 0 || row[sCol - 1] == null
1264 || row[sCol - 1].secondaryStructure != 'H')
1266 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1267 x1 += charWidth / 2;
1270 if (!validRes || row[column] == null
1271 || row[column].secondaryStructure != 'H')
1273 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1275 x2 -= charWidth / 2;
1278 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1281 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1282 Annotation[] aa_annotations, int sRes, int eRes, int y,
1283 float min, float max, int graphHeight)
1285 if (sRes > aa_annotations.length)
1292 // Adjustment for fastpaint to left
1298 eRes = Math.min(eRes, aa_annotations.length);
1306 float range = max - min;
1311 y2 = y - (int) ((0 - min / range) * graphHeight);
1314 g.setColor(Color.gray);
1315 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1317 eRes = Math.min(eRes, aa_annotations.length);
1320 int aaMax = aa_annotations.length - 1;
1322 while (x < eRes - sRes)
1325 if (hasHiddenColumns)
1327 column = columnSelection.adjustForHiddenColumns(column);
1335 if (aa_annotations[column] == null
1336 || aa_annotations[column - 1] == null)
1342 if (aa_annotations[column].colour == null)
1343 g.setColor(Color.black);
1345 g.setColor(aa_annotations[column].colour);
1348 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1350 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1352 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1353 + charWidth / 2, y2);
1357 if (_aa.threshold != null)
1359 g.setColor(_aa.threshold.colour);
1360 Graphics2D g2 = (Graphics2D) g;
1361 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1362 BasicStroke.JOIN_ROUND, 3f, new float[]
1365 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1366 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1367 g2.setStroke(new BasicStroke());
1371 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1372 Annotation[] aa_annotations, int sRes, int eRes, float min,
1375 if (sRes > aa_annotations.length)
1379 Font ofont = g.getFont();
1380 eRes = Math.min(eRes, aa_annotations.length);
1382 int x = 0, y1 = y, y2 = y;
1384 float range = max - min;
1388 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1391 g.setColor(Color.gray);
1393 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1396 int aaMax = aa_annotations.length - 1;
1397 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
1398 // if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1400 // TODO: generalise this to have render styles for consensus/profile data
1401 if (_aa.groupRef != null)
1403 renderHistogram = _aa.groupRef.isShowConsensusHistogram();
1404 renderProfile = _aa.groupRef.isShowSequenceLogo();
1405 normaliseProfile = _aa.groupRef.isNormaliseSequenceLogo();
1409 renderHistogram = av_renderHistogram;
1410 renderProfile = av_renderProfile;
1411 normaliseProfile = av_normaliseProfile;
1414 while (x < eRes - sRes)
1417 if (hasHiddenColumns)
1419 column = columnSelection.adjustForHiddenColumns(column);
1427 if (aa_annotations[column] == null)
1432 if (aa_annotations[column].colour == null)
1433 g.setColor(Color.black);
1435 g.setColor(aa_annotations[column].colour);
1438 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1440 if (renderHistogram)
1444 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1448 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1451 // draw profile if available
1455 int profl[] = getProfileFor(_aa, column);
1456 // just try to draw the logo if profl is not null
1457 if (profl != null && profl[1] != 0)
1459 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1460 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1467 * profl.length == 74 indicates that the profile of a secondary
1468 * structure conservation row was accesed. Therefore dc gets length 2,
1469 * to have space for a basepair instead of just a single nucleotide
1471 if (profl.length == 74)
1479 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1480 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1481 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1483 for (int c = 2; c < profl[0];)
1485 dc[0] = (char) profl[c++];
1487 if (_aa.label.startsWith("StrucConsensus"))
1489 dc[1] = (char) profl[c++];
1493 wdth /= fm.charsWidth(dc, 0, dc.length);
1497 scl = htn * scale * profl[c++];
1498 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1499 .getFontRenderContext());
1500 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1501 wdth, scl / lm.getAscent())));
1502 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1504 // Debug - render boxes around characters
1505 // g.setColor(Color.red);
1506 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1508 // g.setColor(profcolour.findColour(dc[0]).darker());
1509 g.setColor(profcolour.findColour(dc[0], column, null));
1511 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1512 .getBaselineIndex()]));
1514 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1522 if (_aa.threshold != null)
1524 g.setColor(_aa.threshold.colour);
1525 Graphics2D g2 = (Graphics2D) g;
1526 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1527 BasicStroke.JOIN_ROUND, 3f, new float[]
1530 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1532 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1533 g2.setStroke(new BasicStroke());
1537 // used by overview window
1538 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1539 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1541 eRes = Math.min(eRes, aa_annotations.length);
1542 g.setColor(Color.white);
1543 g.fillRect(0, 0, width, y);
1544 g.setColor(new Color(0, 0, 180));
1548 for (int j = sRes; j < eRes; j++)
1550 if (aa_annotations[j] != null)
1552 if (aa_annotations[j].colour == null)
1553 g.setColor(Color.black);
1555 g.setColor(aa_annotations[j].colour);
1557 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1563 g.fillRect(x, y - height, charWidth, height);
1570 Color getNotCanonicalColor(char lastss)
1584 return Color.magenta;
1588 return Color.orange;
1600 return Color.yellow;
1608 return Color.darkGray;
1616 return Color.lightGray;
1628 return Color.magenta;
1632 return Color.orange;
1640 return Color.yellow;
1660 return Color.magenta;
1664 return Color.darkGray;
1668 return Color.yellow;
1676 return Color.orange;
1680 return Color.magenta;
1691 System.out.println("This is not a interaction");