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.Hashtable;
40 import com.stevesoft.pat.Regex;
42 public class AnnotationRenderer
45 public AnnotationRenderer()
47 // TODO Auto-generated constructor stub
50 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
51 int lastSSX, int x, int y, int iconOffset, int startRes,
52 int column, boolean validRes, boolean validEnd)
54 g.setColor(STEM_COLOUR);
55 int sCol = (lastSSX / charWidth) + startRes;
57 int x2 = (x * charWidth);
58 Regex closeparen = new Regex("(\\))");
60 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
61 : row_annotations[column - 1].displayCharacter;
63 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
64 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
65 boolean diffdownstream = !validRes || !validEnd
66 || row_annotations[column] == null
67 || !dc.equals(row_annotations[column].displayCharacter);
68 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
69 // If a closing base pair half of the stem, display a backward arrow
70 if (column > 0 && closeparen.search(dc))
74 // if (validRes && column>1 && row_annotations[column-2]!=null &&
75 // dc.equals(row_annotations[column-2].displayCharacter))
77 g.fillPolygon(new int[]
78 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
79 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
90 // display a forward arrow
93 g.fillPolygon(new int[]
94 { x2 - 5, x2 - 5, x2 }, new int[]
95 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
104 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
107 private int charWidth, endRes, charHeight;
109 private boolean validCharWidth, hasHiddenColumns;
111 private FontMetrics fm;
113 private final boolean MAC = new jalview.util.Platform().isAMac();
115 boolean av_renderHistogram = true, av_renderProfile = true,
116 av_normaliseProfile = false;
118 ColourSchemeI profcolour = null;
120 private ColumnSelection columnSelection;
122 private Hashtable[] hconsensus;
124 private Hashtable[] hStrucConsensus;
126 private boolean av_ignoreGapsConsensus;
129 * attributes set from AwtRenderPanelI
132 * old image used when data is currently being calculated and cannot be
135 private Image fadedImage;
138 * panel being rendered into
140 private ImageObserver annotationPanel;
143 * width of image to render in panel
145 private int imgWidth;
148 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations,
149 int lastSSX, int x, int y, int iconOffset, int startRes,
150 int column, boolean validRes, boolean validEnd)
152 //System.out.println(nonCanColor);
154 g.setColor(nonCanColor);
155 int sCol = (lastSSX / charWidth) + startRes;
157 int x2 = (x * charWidth);
158 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");
160 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
161 : row_annotations[column - 1].displayCharacter;
163 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
164 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
165 boolean diffdownstream = !validRes || !validEnd
166 || row_annotations[column] == null
167 || !dc.equals(row_annotations[column].displayCharacter);
168 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
169 // If a closing base pair half of the stem, display a backward arrow
170 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
174 // if (validRes && column>1 && row_annotations[column-2]!=null &&
175 // dc.equals(row_annotations[column-2].displayCharacter))
177 g.fillPolygon(new int[]
178 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
179 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
190 // display a forward arrow
193 g.fillPolygon(new int[]
194 { x2 - 5, x2 - 5, x2 }, new int[]
195 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
204 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
206 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
208 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
211 fm = annotPanel.getFontMetrics();
212 annotationPanel = annotPanel;
213 fadedImage = annotPanel.getFadedImage();
214 imgWidth = annotPanel.getFadedImageWidth();
215 updateFromAlignViewport(av);
218 public void updateFromAlignViewport(AlignViewportI av)
220 charWidth = av.getCharWidth();
221 endRes = av.getEndRes();
222 charHeight = av.getCharHeight();
223 hasHiddenColumns = av.hasHiddenColumns();
224 validCharWidth = av.isValidCharWidth();
225 av_renderHistogram = av.isShowConsensusHistogram();
226 av_renderProfile = av.isShowSequenceLogo();
227 av_normaliseProfile = av.isNormaliseSequenceLogo();
228 profcolour = av.getGlobalColourScheme();
229 if (profcolour == null)
231 // Set the default colour for sequence logo if the alignnent has no
233 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
234 : new jalview.schemes.ZappoColourScheme();
236 columnSelection = av.getColumnSelection();
237 hconsensus = av.getSequenceConsensusHash();// hconsensus;
238 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
239 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
242 public int[] getProfileFor(AlignmentAnnotation aa, int column)
244 // TODO : consider refactoring the global alignment calculation
245 // properties/rendering attributes as a global 'alignment group' which holds
246 // all vis settings for the alignment as a whole rather than a subset
248 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
250 if (aa.groupRef != null && aa.groupRef.consensusData != null
251 && aa.groupRef.isShowSequenceLogo())
253 return AAFrequency.extractProfile(
254 aa.groupRef.consensusData[column],
255 aa.groupRef.getIgnoreGapsConsensus());
257 // TODO extend annotation row to enable dynamic and static profile data to
259 if (aa.groupRef == null && aa.sequenceRef == null && av_renderProfile)
261 return AAFrequency.extractProfile(hconsensus[column],
262 av_ignoreGapsConsensus);
267 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
269 // TODO implement group structure consensus
271 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
272 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
273 * group selections return StructureFrequency.extractProfile(
274 * aa.groupRef.consensusData[column], aa.groupRef
275 * .getIgnoreGapsConsensus()); }
277 // TODO extend annotation row to enable dynamic and static profile data
280 if (aa.groupRef == null && aa.sequenceRef == null
281 && av_renderProfile && hStrucConsensus != null
282 && hStrucConsensus.length > column)
284 return StructureFrequency.extractProfile(hStrucConsensus[column],
285 av_ignoreGapsConsensus);
293 * Render the annotation rows associated with an alignment.
298 * data and view settings to render
300 * destination for graphics
302 * row where a mouse event occured (or -1)
304 * first column that will be drawn
306 * last column that will be drawn
307 * @return true if the fadedImage was used for any alignment annotation rows
308 * currently being calculated
310 public boolean drawComponent(AwtRenderPanelI annotPanel,
311 AlignViewportI av, Graphics g, int activeRow, int startRes,
314 boolean usedFaded = false;
316 // AnnotationPanel needs to implement: ImageObserver, access to
318 updateFromAwtRenderPanel(annotPanel, av);
319 fm = g.getFontMetrics();
320 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
330 boolean validRes = false;
331 boolean validEnd = false;
332 boolean labelAllCols = false;
333 boolean centreColLabels, centreColLabelsDef = av
334 .getCentreColumnLabels();
335 boolean scaleColLabel = false;
336 boolean[] graphGroupDrawn = new boolean[aa.length];
337 int charOffset = 0; // offset for a label
338 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
340 Font ofont = g.getFont();
342 for (int i = 0; i < aa.length; i++)
344 AlignmentAnnotation row = aa[i];
345 Annotation[] row_annotations = row.annotations;
350 centreColLabels = row.centreColLabels || centreColLabelsDef;
351 labelAllCols = row.showAllColLabels;
352 scaleColLabel = row.scaleColLabel;
357 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
362 // this is so that we draw the characters below the graph
367 iconOffset = charHeight - fm.getDescent();
371 else if (row.hasText)
373 iconOffset = charHeight - fm.getDescent();
381 if (row.autoCalculated && av.isCalculationInProgress(row))
385 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
386 - row.height, imgWidth, y, annotationPanel);
387 g.setColor(Color.black);
388 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
394 * else if (annotationPanel.av.updatingConservation &&
395 * aa[i].label.equals("Conservation")) {
397 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
398 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
399 * annotationPanel.imgWidth, y, annotationPanel);
401 * g.setColor(Color.black); //
402 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
404 * continue; } else if (annotationPanel.av.updatingConservation &&
405 * aa[i].label.equals("Quality")) {
407 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
408 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
409 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
410 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
414 // first pass sets up state for drawing continuation from left-hand column
416 x = (startRes == 0) ? 0 : -1;
417 while (x < endRes - startRes)
419 if (hasHiddenColumns)
421 column = columnSelection.adjustForHiddenColumns(startRes + x);
422 if (column > row_annotations.length - 1)
429 column = startRes + x;
432 if ((row_annotations == null) || (row_annotations.length <= column)
433 || (row_annotations[column] == null))
445 g.setColor(Color.red);
447 if (columnSelection != null)
449 for (int n = 0; n < columnSelection.size(); n++)
451 int v = columnSelection.columnAt(n);
455 g.fillRect(x * charWidth, y, charWidth, charHeight);
460 if (!row.isValidStruc())
462 g.setColor(Color.orange);
463 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
464 charWidth, charHeight);
468 && row_annotations[column].displayCharacter != null
469 && (row_annotations[column].displayCharacter.length() > 0))
472 if (centreColLabels || scaleColLabel)
474 fmWidth = fm.charsWidth(
475 row_annotations[column].displayCharacter
477 row_annotations[column].displayCharacter.length());
481 // justify the label and scale to fit in column
482 if (fmWidth > charWidth)
484 // scale only if the current font isn't already small enough
485 fmScaling = charWidth;
486 fmScaling /= fmWidth;
487 g.setFont(ofont.deriveFont(AffineTransform
488 .getScaleInstance(fmScaling, 1.0)));
489 // and update the label's width to reflect the scaling.
497 .charWidth(row_annotations[column].displayCharacter
500 charOffset = (int) ((charWidth - fmWidth) / 2f);
502 if (row_annotations[column].colour == null)
503 g.setColor(Color.black);
505 g.setColor(row_annotations[column].colour);
507 if (column == 0 || row.graph > 0)
509 g.drawString(row_annotations[column].displayCharacter,
510 (x * charWidth) + charOffset, y + iconOffset);
512 else if (row_annotations[column - 1] == null
514 || !row_annotations[column].displayCharacter
515 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
516 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
518 g.drawString(row_annotations[column].displayCharacter
520 * charWidth + charOffset, y + iconOffset);
527 char ss = validRes ? row_annotations[column].secondaryStructure
532 // distinguish between forward/backward base-pairing
533 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
542 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
551 // distinguish between forward/backward base-pairing
552 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
561 // distinguish between forward/backward base-pairing
562 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
571 // distinguish between forward/backward base-pairing
572 if (row_annotations[column].displayCharacter.indexOf('a') > -1)
582 // distinguish between forward/backward base-pairing
583 if (row_annotations[column].displayCharacter.indexOf('b') > -1)
592 // distinguish between forward/backward base-pairing
593 if (row_annotations[column].displayCharacter.indexOf('c') > -1)
601 // distinguish between forward/backward base-pairing
602 if (row_annotations[column].displayCharacter.indexOf('d') > -1)
610 // distinguish between forward/backward base-pairing
611 if (row_annotations[column].displayCharacter.indexOf('e') > -1)
619 // distinguish between forward/backward base-pairing
620 if (row_annotations[column].displayCharacter.indexOf('f') > -1)
628 // distinguish between forward/backward base-pairing
629 if (row_annotations[column].displayCharacter.indexOf('g') > -1)
637 // distinguish between forward/backward base-pairing
638 if (row_annotations[column].displayCharacter.indexOf('h') > -1)
646 // distinguish between forward/backward base-pairing
647 if (row_annotations[column].displayCharacter.indexOf('i') > -1)
655 // distinguish between forward/backward base-pairing
656 if (row_annotations[column].displayCharacter.indexOf('j') > -1)
664 // distinguish between forward/backward base-pairing
665 if (row_annotations[column].displayCharacter.indexOf('k') > -1)
673 // distinguish between forward/backward base-pairing
674 if (row_annotations[column].displayCharacter.indexOf('l') > -1)
682 // distinguish between forward/backward base-pairing
683 if (row_annotations[column].displayCharacter.indexOf('m') > -1)
691 // distinguish between forward/backward base-pairing
692 if (row_annotations[column].displayCharacter.indexOf('n') > -1)
700 // distinguish between forward/backward base-pairing
701 if (row_annotations[column].displayCharacter.indexOf('o') > -1)
709 // distinguish between forward/backward base-pairing
710 if (row_annotations[column].displayCharacter.indexOf('p') > -1)
718 // distinguish between forward/backward base-pairing
719 if (row_annotations[column].displayCharacter.indexOf('q') > -1)
727 // distinguish between forward/backward base-pairing
728 if (row_annotations[column].displayCharacter.indexOf('r') > -1)
736 // distinguish between forward/backward base-pairing
737 if (row_annotations[column].displayCharacter.indexOf('s') > -1)
745 // distinguish between forward/backward base-pairing
746 if (row_annotations[column].displayCharacter.indexOf('t') > -1)
754 // distinguish between forward/backward base-pairing
755 if (row_annotations[column].displayCharacter.indexOf('u') > -1)
763 // distinguish between forward/backward base-pairing
764 if (row_annotations[column].displayCharacter.indexOf('v') > -1)
772 // distinguish between forward/backward base-pairing
773 if (row_annotations[column].displayCharacter.indexOf('w') > -1)
781 // distinguish between forward/backward base-pairing
782 if (row_annotations[column].displayCharacter.indexOf('x') > -1)
790 // distinguish between forward/backward base-pairing
791 if (row_annotations[column].displayCharacter.indexOf('y') > -1)
799 // distinguish between forward/backward base-pairing
800 if (row_annotations[column].displayCharacter.indexOf('z') > -1)
806 if (!validRes || (ss != lastSS))
813 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
814 iconOffset, startRes, column, validRes, validEnd);
818 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
819 iconOffset, startRes, column, validRes, validEnd);
822 case '(': // Stem case for RNA secondary structure
823 case ')': // and opposite direction
824 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
825 column, validRes, validEnd);
826 // case 'S': // Stem case for RNA secondary structure
827 // case 's': // and opposite direction
828 // drawStemAnnot(g, row_annotations, lastSSX, x, y,
829 // iconOffset, startRes, column, validRes, validEnd);
889 //System.out.println(lastSS);
890 Color nonCanColor= getNotCanonicalColor(lastSS);
891 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
892 column, validRes, validEnd);
895 g.setColor(Color.gray);
896 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
912 lastSSX = (x * charWidth);
919 if (column >= row_annotations.length)
921 column = row_annotations.length - 1;
928 if ((row_annotations == null) || (row_annotations.length <= column)
929 || (row_annotations[column] == null))
945 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
946 startRes, column, validRes, validEnd);
950 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
951 startRes, column, validRes, validEnd);
954 case 'S': // Stem case for RNA secondary structure
955 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
956 startRes, column, validRes, validEnd);
1014 //System.out.println(lastSS);
1015 Color nonCanColor = getNotCanonicalColor(lastSS);
1016 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
1017 column, validRes, validEnd);
1020 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1021 startRes, column, validRes, validEnd);
1026 if (row.graph > 0 && row.graphHeight > 0)
1028 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1030 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1032 float groupmax = -999999, groupmin = 9999999;
1033 for (int gg = 0; gg < aa.length; gg++)
1035 if (aa[gg].graphGroup != row.graphGroup)
1042 aa[gg].visible = false;
1044 if (aa[gg].graphMax > groupmax)
1046 groupmax = aa[gg].graphMax;
1048 if (aa[gg].graphMin < groupmin)
1050 groupmin = aa[gg].graphMin;
1054 for (int gg = 0; gg < aa.length; gg++)
1056 if (aa[gg].graphGroup == row.graphGroup)
1058 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1059 endRes, y, groupmin, groupmax, row.graphHeight);
1063 graphGroupDrawn[row.graphGroup] = true;
1067 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1068 row.graphMin, row.graphMax, row.graphHeight);
1071 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1073 drawBarGraph(g, row, row_annotations, startRes, endRes,
1074 row.graphMin, row.graphMax, y);
1078 if (row.graph > 0 && row.hasText)
1091 private final Color GLYPHLINE_COLOR = Color.gray;
1093 private final Color SHEET_COLOUR = Color.green;
1095 private final Color HELIX_COLOUR = Color.red;
1097 private final Color STEM_COLOUR = Color.blue;
1099 private Color sdNOTCANONICAL_COLOUR;
1101 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1102 int x, int y, int iconOffset, int startRes, int column,
1103 boolean validRes, boolean validEnd)
1105 g.setColor(GLYPHLINE_COLOR);
1106 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1109 public void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX,
1110 int x, int y, int iconOffset, int startRes, int column,
1111 boolean validRes, boolean validEnd)
1113 g.setColor(SHEET_COLOUR);
1115 if (!validEnd || !validRes || row == null || row[column] == null
1116 || row[column].secondaryStructure != 'E')
1118 g.fillRect(lastSSX, y + 4 + iconOffset,
1119 (x * charWidth) - lastSSX - 4, 7);
1120 g.fillPolygon(new int[]
1121 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1123 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1128 g.fillRect(lastSSX, y + 4 + iconOffset,
1129 (x + 1) * charWidth - lastSSX, 7);
1134 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1135 int x, int y, int iconOffset, int startRes, int column,
1136 boolean validRes, boolean validEnd)
1138 g.setColor(HELIX_COLOUR);
1140 int sCol = (lastSSX / charWidth) + startRes;
1142 int x2 = (x * charWidth);
1146 int ofs = charWidth / 2;
1147 // Off by 1 offset when drawing rects and ovals
1148 // to offscreen image on the MAC
1149 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1150 if (sCol == 0 || row[sCol - 1] == null
1151 || row[sCol - 1].secondaryStructure != 'H')
1156 // g.setColor(Color.orange);
1157 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1160 if (!validRes || row[column] == null
1161 || row[column].secondaryStructure != 'H')
1167 // g.setColor(Color.magenta);
1168 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1176 if (sCol == 0 || row[sCol - 1] == null
1177 || row[sCol - 1].secondaryStructure != 'H')
1179 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1180 x1 += charWidth / 2;
1183 if (!validRes || row[column] == null
1184 || row[column].secondaryStructure != 'H')
1186 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1188 x2 -= charWidth / 2;
1191 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1194 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1195 Annotation[] aa_annotations, int sRes, int eRes, int y,
1196 float min, float max, int graphHeight)
1198 if (sRes > aa_annotations.length)
1205 // Adjustment for fastpaint to left
1211 eRes = Math.min(eRes, aa_annotations.length);
1219 float range = max - min;
1224 y2 = y - (int) ((0 - min / range) * graphHeight);
1227 g.setColor(Color.gray);
1228 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1230 eRes = Math.min(eRes, aa_annotations.length);
1233 int aaMax = aa_annotations.length - 1;
1235 while (x < eRes - sRes)
1238 if (hasHiddenColumns)
1240 column = columnSelection.adjustForHiddenColumns(column);
1248 if (aa_annotations[column] == null
1249 || aa_annotations[column - 1] == null)
1255 if (aa_annotations[column].colour == null)
1256 g.setColor(Color.black);
1258 g.setColor(aa_annotations[column].colour);
1261 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1263 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1265 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1266 + charWidth / 2, y2);
1270 if (_aa.threshold != null)
1272 g.setColor(_aa.threshold.colour);
1273 Graphics2D g2 = (Graphics2D) g;
1274 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1275 BasicStroke.JOIN_ROUND, 3f, new float[]
1278 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1279 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1280 g2.setStroke(new BasicStroke());
1284 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1285 Annotation[] aa_annotations, int sRes, int eRes, float min,
1288 if (sRes > aa_annotations.length)
1292 Font ofont = g.getFont();
1293 eRes = Math.min(eRes, aa_annotations.length);
1295 int x = 0, y1 = y, y2 = y;
1297 float range = max - min;
1301 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1304 g.setColor(Color.gray);
1306 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1309 int aaMax = aa_annotations.length - 1;
1310 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
1311 // if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1313 // TODO: generalise this to have render styles for consensus/profile data
1314 if (_aa.groupRef != null)
1316 renderHistogram = _aa.groupRef.isShowConsensusHistogram();
1317 renderProfile = _aa.groupRef.isShowSequenceLogo();
1318 normaliseProfile = _aa.groupRef.isNormaliseSequenceLogo();
1322 renderHistogram = av_renderHistogram;
1323 renderProfile = av_renderProfile;
1324 normaliseProfile = av_normaliseProfile;
1327 while (x < eRes - sRes)
1330 if (hasHiddenColumns)
1332 column = columnSelection.adjustForHiddenColumns(column);
1340 if (aa_annotations[column] == null)
1345 if (aa_annotations[column].colour == null)
1346 g.setColor(Color.black);
1348 g.setColor(aa_annotations[column].colour);
1351 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1353 if (renderHistogram)
1357 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1361 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1364 // draw profile if available
1368 int profl[] = getProfileFor(_aa, column);
1369 // just try to draw the logo if profl is not null
1370 if (profl != null && profl[1] != 0)
1372 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1373 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1380 * profl.length == 74 indicates that the profile of a secondary
1381 * structure conservation row was accesed. Therefore dc gets length 2,
1382 * to have space for a basepair instead of just a single nucleotide
1384 if (profl.length == 74)
1392 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1393 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1394 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1396 for (int c = 2; c < profl[0];)
1398 dc[0] = (char) profl[c++];
1400 if (_aa.label.startsWith("StrucConsensus"))
1402 dc[1] = (char) profl[c++];
1406 wdth /= fm.charsWidth(dc, 0, dc.length);
1410 scl = htn * scale * profl[c++];
1411 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1412 .getFontRenderContext());
1413 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1414 wdth, scl / lm.getAscent())));
1415 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1417 // Debug - render boxes around characters
1418 // g.setColor(Color.red);
1419 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1421 // g.setColor(profcolour.findColour(dc[0]).darker());
1422 g.setColor(profcolour.findColour(dc[0], column, null));
1424 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1425 .getBaselineIndex()]));
1427 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1435 if (_aa.threshold != null)
1437 g.setColor(_aa.threshold.colour);
1438 Graphics2D g2 = (Graphics2D) g;
1439 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1440 BasicStroke.JOIN_ROUND, 3f, new float[]
1443 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1445 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1446 g2.setStroke(new BasicStroke());
1450 // used by overview window
1451 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1452 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1454 eRes = Math.min(eRes, aa_annotations.length);
1455 g.setColor(Color.white);
1456 g.fillRect(0, 0, width, y);
1457 g.setColor(new Color(0, 0, 180));
1461 for (int j = sRes; j < eRes; j++)
1463 if (aa_annotations[j] != null)
1465 if (aa_annotations[j].colour == null)
1466 g.setColor(Color.black);
1468 g.setColor(aa_annotations[j].colour);
1470 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1476 g.fillRect(x, y - height, charWidth, height);
1483 Color getNotCanonicalColor(char lastss)
1497 return Color.magenta;
1501 return Color.orange;
1513 return Color.yellow;
1521 return Color.darkGray;
1529 return Color.lightGray;
1541 return Color.magenta;
1545 return Color.orange;
1553 return Color.yellow;
1573 return Color.magenta;
1577 return Color.darkGray;
1581 return Color.yellow;
1589 return Color.orange;
1593 return Color.magenta;
1604 System.out.println("This is not a interaction");