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();
327 boolean validRes = false;
328 boolean validEnd = false;
329 boolean labelAllCols = false;
330 boolean centreColLabels, centreColLabelsDef = av
331 .getCentreColumnLabels();
332 boolean scaleColLabel = false;
333 boolean[] graphGroupDrawn = new boolean[aa.length];
334 int charOffset = 0; // offset for a label
335 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
337 Font ofont = g.getFont();
339 for (int i = 0; i < aa.length; i++)
341 AlignmentAnnotation row = aa[i];
342 Annotation[] row_annotations = row.annotations;
347 centreColLabels = row.centreColLabels || centreColLabelsDef;
348 labelAllCols = row.showAllColLabels;
349 scaleColLabel = row.scaleColLabel;
354 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
359 // this is so that we draw the characters below the graph
364 iconOffset = charHeight - fm.getDescent();
368 else if (row.hasText)
370 iconOffset = charHeight - fm.getDescent();
378 if (row.autoCalculated && av.isCalculationInProgress(row))
382 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
383 - row.height, imgWidth, y, annotationPanel);
384 g.setColor(Color.black);
385 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
391 * else if (annotationPanel.av.updatingConservation &&
392 * aa[i].label.equals("Conservation")) {
394 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
395 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
396 * annotationPanel.imgWidth, y, annotationPanel);
398 * g.setColor(Color.black); //
399 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
401 * continue; } else if (annotationPanel.av.updatingConservation &&
402 * aa[i].label.equals("Quality")) {
404 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
405 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
406 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
407 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
411 // first pass sets up state for drawing continuation from left-hand column
413 x = (startRes == 0) ? 0 : -1;
414 while (x < endRes - startRes)
416 if (hasHiddenColumns)
418 column = columnSelection.adjustForHiddenColumns(startRes + x);
419 if (column > row_annotations.length - 1)
426 column = startRes + x;
429 if ((row_annotations == null) || (row_annotations.length <= column)
430 || (row_annotations[column] == null))
442 g.setColor(Color.red);
444 if (columnSelection != null)
446 for (int n = 0; n < columnSelection.size(); n++)
448 int v = columnSelection.columnAt(n);
452 g.fillRect(x * charWidth, y, charWidth, charHeight);
457 if (!row.isValidStruc())
459 g.setColor(Color.orange);
460 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
461 charWidth, charHeight);
465 && row_annotations[column].displayCharacter != null
466 && (row_annotations[column].displayCharacter.length() > 0))
469 if (centreColLabels || scaleColLabel)
471 fmWidth = fm.charsWidth(
472 row_annotations[column].displayCharacter
474 row_annotations[column].displayCharacter.length());
478 // justify the label and scale to fit in column
479 if (fmWidth > charWidth)
481 // scale only if the current font isn't already small enough
482 fmScaling = charWidth;
483 fmScaling /= fmWidth;
484 g.setFont(ofont.deriveFont(AffineTransform
485 .getScaleInstance(fmScaling, 1.0)));
486 // and update the label's width to reflect the scaling.
494 .charWidth(row_annotations[column].displayCharacter
497 charOffset = (int) ((charWidth - fmWidth) / 2f);
499 if (row_annotations[column].colour == null)
500 g.setColor(Color.black);
502 g.setColor(row_annotations[column].colour);
504 if (column == 0 || row.graph > 0)
506 g.drawString(row_annotations[column].displayCharacter,
507 (x * charWidth) + charOffset, y + iconOffset);
509 else if (row_annotations[column - 1] == null
511 || !row_annotations[column].displayCharacter
512 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
513 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
515 g.drawString(row_annotations[column].displayCharacter
517 * charWidth + charOffset, y + iconOffset);
524 char ss = validRes ? row_annotations[column].secondaryStructure
529 // distinguish between forward/backward base-pairing
530 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
539 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
548 // distinguish between forward/backward base-pairing
549 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
558 // distinguish between forward/backward base-pairing
559 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
568 // distinguish between forward/backward base-pairing
569 if (row_annotations[column].displayCharacter.indexOf('a') > -1)
579 // distinguish between forward/backward base-pairing
580 if (row_annotations[column].displayCharacter.indexOf('b') > -1)
589 // distinguish between forward/backward base-pairing
590 if (row_annotations[column].displayCharacter.indexOf('c') > -1)
598 // distinguish between forward/backward base-pairing
599 if (row_annotations[column].displayCharacter.indexOf('d') > -1)
607 // distinguish between forward/backward base-pairing
608 if (row_annotations[column].displayCharacter.indexOf('e') > -1)
616 // distinguish between forward/backward base-pairing
617 if (row_annotations[column].displayCharacter.indexOf('f') > -1)
625 // distinguish between forward/backward base-pairing
626 if (row_annotations[column].displayCharacter.indexOf('g') > -1)
634 // distinguish between forward/backward base-pairing
635 if (row_annotations[column].displayCharacter.indexOf('h') > -1)
643 // distinguish between forward/backward base-pairing
644 if (row_annotations[column].displayCharacter.indexOf('i') > -1)
652 // distinguish between forward/backward base-pairing
653 if (row_annotations[column].displayCharacter.indexOf('j') > -1)
661 // distinguish between forward/backward base-pairing
662 if (row_annotations[column].displayCharacter.indexOf('k') > -1)
670 // distinguish between forward/backward base-pairing
671 if (row_annotations[column].displayCharacter.indexOf('l') > -1)
679 // distinguish between forward/backward base-pairing
680 if (row_annotations[column].displayCharacter.indexOf('m') > -1)
688 // distinguish between forward/backward base-pairing
689 if (row_annotations[column].displayCharacter.indexOf('n') > -1)
697 // distinguish between forward/backward base-pairing
698 if (row_annotations[column].displayCharacter.indexOf('o') > -1)
706 // distinguish between forward/backward base-pairing
707 if (row_annotations[column].displayCharacter.indexOf('p') > -1)
715 // distinguish between forward/backward base-pairing
716 if (row_annotations[column].displayCharacter.indexOf('q') > -1)
724 // distinguish between forward/backward base-pairing
725 if (row_annotations[column].displayCharacter.indexOf('r') > -1)
733 // distinguish between forward/backward base-pairing
734 if (row_annotations[column].displayCharacter.indexOf('s') > -1)
742 // distinguish between forward/backward base-pairing
743 if (row_annotations[column].displayCharacter.indexOf('t') > -1)
751 // distinguish between forward/backward base-pairing
752 if (row_annotations[column].displayCharacter.indexOf('u') > -1)
760 // distinguish between forward/backward base-pairing
761 if (row_annotations[column].displayCharacter.indexOf('v') > -1)
769 // distinguish between forward/backward base-pairing
770 if (row_annotations[column].displayCharacter.indexOf('w') > -1)
778 // distinguish between forward/backward base-pairing
779 if (row_annotations[column].displayCharacter.indexOf('x') > -1)
787 // distinguish between forward/backward base-pairing
788 if (row_annotations[column].displayCharacter.indexOf('y') > -1)
796 // distinguish between forward/backward base-pairing
797 if (row_annotations[column].displayCharacter.indexOf('z') > -1)
803 if (!validRes || (ss != lastSS))
810 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
811 iconOffset, startRes, column, validRes, validEnd);
815 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
816 iconOffset, startRes, column, validRes, validEnd);
819 case '(': // Stem case for RNA secondary structure
820 case ')': // and opposite direction
821 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
822 column, validRes, validEnd);
823 // case 'S': // Stem case for RNA secondary structure
824 // case 's': // and opposite direction
825 // drawStemAnnot(g, row_annotations, lastSSX, x, y,
826 // iconOffset, startRes, column, validRes, validEnd);
886 //System.out.println(lastSS);
887 Color nonCanColor= getNotCanonicalColor(lastSS);
888 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
889 column, validRes, validEnd);
892 g.setColor(Color.gray);
893 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
909 lastSSX = (x * charWidth);
916 if (column >= row_annotations.length)
918 column = row_annotations.length - 1;
925 if ((row_annotations == null) || (row_annotations.length <= column)
926 || (row_annotations[column] == null))
942 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
943 startRes, column, validRes, validEnd);
947 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
948 startRes, column, validRes, validEnd);
951 case 'S': // Stem case for RNA secondary structure
952 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
953 startRes, column, validRes, validEnd);
1011 //System.out.println(lastSS);
1012 Color nonCanColor = getNotCanonicalColor(lastSS);
1013 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
1014 column, validRes, validEnd);
1017 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1018 startRes, column, validRes, validEnd);
1023 if (row.graph > 0 && row.graphHeight > 0)
1025 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1027 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1029 float groupmax = -999999, groupmin = 9999999;
1030 for (int gg = 0; gg < aa.length; gg++)
1032 if (aa[gg].graphGroup != row.graphGroup)
1039 aa[gg].visible = false;
1041 if (aa[gg].graphMax > groupmax)
1043 groupmax = aa[gg].graphMax;
1045 if (aa[gg].graphMin < groupmin)
1047 groupmin = aa[gg].graphMin;
1051 for (int gg = 0; gg < aa.length; gg++)
1053 if (aa[gg].graphGroup == row.graphGroup)
1055 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1056 endRes, y, groupmin, groupmax, row.graphHeight);
1060 graphGroupDrawn[row.graphGroup] = true;
1064 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1065 row.graphMin, row.graphMax, row.graphHeight);
1068 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1070 drawBarGraph(g, row, row_annotations, startRes, endRes,
1071 row.graphMin, row.graphMax, y);
1075 if (row.graph > 0 && row.hasText)
1088 private final Color GLYPHLINE_COLOR = Color.gray;
1090 private final Color SHEET_COLOUR = Color.green;
1092 private final Color HELIX_COLOUR = Color.red;
1094 private final Color STEM_COLOUR = Color.blue;
1096 private Color sdNOTCANONICAL_COLOUR;
1098 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1099 int x, int y, int iconOffset, int startRes, int column,
1100 boolean validRes, boolean validEnd)
1102 g.setColor(GLYPHLINE_COLOR);
1103 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1106 public void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX,
1107 int x, int y, int iconOffset, int startRes, int column,
1108 boolean validRes, boolean validEnd)
1110 g.setColor(SHEET_COLOUR);
1112 if (!validEnd || !validRes || row == null || row[column] == null
1113 || row[column].secondaryStructure != 'E')
1115 g.fillRect(lastSSX, y + 4 + iconOffset,
1116 (x * charWidth) - lastSSX - 4, 7);
1117 g.fillPolygon(new int[]
1118 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1120 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1125 g.fillRect(lastSSX, y + 4 + iconOffset,
1126 (x + 1) * charWidth - lastSSX, 7);
1131 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1132 int x, int y, int iconOffset, int startRes, int column,
1133 boolean validRes, boolean validEnd)
1135 g.setColor(HELIX_COLOUR);
1137 int sCol = (lastSSX / charWidth) + startRes;
1139 int x2 = (x * charWidth);
1143 int ofs = charWidth / 2;
1144 // Off by 1 offset when drawing rects and ovals
1145 // to offscreen image on the MAC
1146 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1147 if (sCol == 0 || row[sCol - 1] == null
1148 || row[sCol - 1].secondaryStructure != 'H')
1153 // g.setColor(Color.orange);
1154 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1157 if (!validRes || row[column] == null
1158 || row[column].secondaryStructure != 'H')
1164 // g.setColor(Color.magenta);
1165 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1173 if (sCol == 0 || row[sCol - 1] == null
1174 || row[sCol - 1].secondaryStructure != 'H')
1176 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1177 x1 += charWidth / 2;
1180 if (!validRes || row[column] == null
1181 || row[column].secondaryStructure != 'H')
1183 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1185 x2 -= charWidth / 2;
1188 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1191 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1192 Annotation[] aa_annotations, int sRes, int eRes, int y,
1193 float min, float max, int graphHeight)
1195 if (sRes > aa_annotations.length)
1202 // Adjustment for fastpaint to left
1208 eRes = Math.min(eRes, aa_annotations.length);
1216 float range = max - min;
1221 y2 = y - (int) ((0 - min / range) * graphHeight);
1224 g.setColor(Color.gray);
1225 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1227 eRes = Math.min(eRes, aa_annotations.length);
1230 int aaMax = aa_annotations.length - 1;
1232 while (x < eRes - sRes)
1235 if (hasHiddenColumns)
1237 column = columnSelection.adjustForHiddenColumns(column);
1245 if (aa_annotations[column] == null
1246 || aa_annotations[column - 1] == null)
1252 if (aa_annotations[column].colour == null)
1253 g.setColor(Color.black);
1255 g.setColor(aa_annotations[column].colour);
1258 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1260 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1262 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1263 + charWidth / 2, y2);
1267 if (_aa.threshold != null)
1269 g.setColor(_aa.threshold.colour);
1270 Graphics2D g2 = (Graphics2D) g;
1271 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1272 BasicStroke.JOIN_ROUND, 3f, new float[]
1275 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1276 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1277 g2.setStroke(new BasicStroke());
1281 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1282 Annotation[] aa_annotations, int sRes, int eRes, float min,
1285 if (sRes > aa_annotations.length)
1289 Font ofont = g.getFont();
1290 eRes = Math.min(eRes, aa_annotations.length);
1292 int x = 0, y1 = y, y2 = y;
1294 float range = max - min;
1298 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1301 g.setColor(Color.gray);
1303 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1306 int aaMax = aa_annotations.length - 1;
1307 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
1308 // if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1310 // TODO: generalise this to have render styles for consensus/profile data
1311 if (_aa.groupRef != null)
1313 renderHistogram = _aa.groupRef.isShowConsensusHistogram();
1314 renderProfile = _aa.groupRef.isShowSequenceLogo();
1315 normaliseProfile = _aa.groupRef.isNormaliseSequenceLogo();
1319 renderHistogram = av_renderHistogram;
1320 renderProfile = av_renderProfile;
1321 normaliseProfile = av_normaliseProfile;
1324 while (x < eRes - sRes)
1327 if (hasHiddenColumns)
1329 column = columnSelection.adjustForHiddenColumns(column);
1337 if (aa_annotations[column] == 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].value - min) / (range)) * _aa.graphHeight);
1350 if (renderHistogram)
1354 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1358 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1361 // draw profile if available
1365 int profl[] = getProfileFor(_aa, column);
1366 // just try to draw the logo if profl is not null
1367 if (profl != null && profl[1] != 0)
1369 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1370 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1377 * profl.length == 74 indicates that the profile of a secondary
1378 * structure conservation row was accesed. Therefore dc gets length 2,
1379 * to have space for a basepair instead of just a single nucleotide
1381 if (profl.length == 74)
1389 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1390 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1391 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1393 for (int c = 2; c < profl[0];)
1395 dc[0] = (char) profl[c++];
1397 if (_aa.label.startsWith("StrucConsensus"))
1399 dc[1] = (char) profl[c++];
1403 wdth /= fm.charsWidth(dc, 0, dc.length);
1407 scl = htn * scale * profl[c++];
1408 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1409 .getFontRenderContext());
1410 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1411 wdth, scl / lm.getAscent())));
1412 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1414 // Debug - render boxes around characters
1415 // g.setColor(Color.red);
1416 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1418 // g.setColor(profcolour.findColour(dc[0]).darker());
1419 g.setColor(profcolour.findColour(dc[0], column, null));
1421 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1422 .getBaselineIndex()]));
1424 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1432 if (_aa.threshold != null)
1434 g.setColor(_aa.threshold.colour);
1435 Graphics2D g2 = (Graphics2D) g;
1436 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1437 BasicStroke.JOIN_ROUND, 3f, new float[]
1440 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1442 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1443 g2.setStroke(new BasicStroke());
1447 // used by overview window
1448 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1449 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1451 eRes = Math.min(eRes, aa_annotations.length);
1452 g.setColor(Color.white);
1453 g.fillRect(0, 0, width, y);
1454 g.setColor(new Color(0, 0, 180));
1458 for (int j = sRes; j < eRes; j++)
1460 if (aa_annotations[j] != null)
1462 if (aa_annotations[j].colour == null)
1463 g.setColor(Color.black);
1465 g.setColor(aa_annotations[j].colour);
1467 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1473 g.fillRect(x, y - height, charWidth, height);
1480 Color getNotCanonicalColor(char lastss)
1494 return Color.magenta;
1498 return Color.orange;
1510 return Color.yellow;
1518 return Color.darkGray;
1526 return Color.lightGray;
1538 return Color.magenta;
1542 return Color.orange;
1550 return Color.yellow;
1570 return Color.magenta;
1574 return Color.darkGray;
1578 return Color.yellow;
1586 return Color.orange;
1590 return Color.magenta;
1601 System.out.println("This is not a interaction");