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)
55 g.setColor(STEM_COLOUR);
56 int sCol = (lastSSX / charWidth) + startRes;
58 int x2 = (x * charWidth);
59 Regex closeparen = new Regex("(\\))");
61 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
62 : row_annotations[column - 1].displayCharacter;
64 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
65 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
66 boolean diffdownstream = !validRes || !validEnd
67 || row_annotations[column] == null
68 || !dc.equals(row_annotations[column].displayCharacter);
69 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
70 // If a closing base pair half of the stem, display a backward arrow
71 if (column > 0 && closeparen.search(dc))
75 // if (validRes && column>1 && row_annotations[column-2]!=null &&
76 // dc.equals(row_annotations[column-2].displayCharacter))
78 g.fillPolygon(new int[]
79 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
80 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
91 // display a forward arrow
94 g.fillPolygon(new int[]
95 { x2 - 5, x2 - 5, x2 }, new int[]
96 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
105 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
108 private int charWidth, endRes, charHeight;
110 private boolean validCharWidth, hasHiddenColumns;
112 private FontMetrics fm;
114 private final boolean MAC = new jalview.util.Platform().isAMac();
116 boolean av_renderHistogram = true, av_renderProfile = true,
117 av_normaliseProfile = false;
119 ColourSchemeI profcolour = null;
121 private ColumnSelection columnSelection;
123 private Hashtable[] hconsensus;
125 private Hashtable[] hStrucConsensus;
127 private boolean av_ignoreGapsConsensus;
130 * attributes set from AwtRenderPanelI
133 * old image used when data is currently being calculated and cannot be
136 private Image fadedImage;
139 * panel being rendered into
141 private ImageObserver annotationPanel;
144 * width of image to render in panel
146 private int imgWidth;
149 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations,
150 int lastSSX, int x, int y, int iconOffset, int startRes,
151 int column, boolean validRes, boolean validEnd)
153 //System.out.println(nonCanColor);
155 g.setColor(nonCanColor);
156 int sCol = (lastSSX / charWidth) + startRes;
158 int x2 = (x * charWidth);
159 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");
161 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
162 : row_annotations[column - 1].displayCharacter;
164 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
165 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
166 boolean diffdownstream = !validRes || !validEnd
167 || row_annotations[column] == null
168 || !dc.equals(row_annotations[column].displayCharacter);
169 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
170 // If a closing base pair half of the stem, display a backward arrow
171 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
175 // if (validRes && column>1 && row_annotations[column-2]!=null &&
176 // dc.equals(row_annotations[column-2].displayCharacter))
178 g.fillPolygon(new int[]
179 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
180 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
191 // display a forward arrow
194 g.fillPolygon(new int[]
195 { x2 - 5, x2 - 5, x2 }, new int[]
196 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
205 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
207 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
209 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
212 fm = annotPanel.getFontMetrics();
213 annotationPanel = annotPanel;
214 fadedImage = annotPanel.getFadedImage();
215 imgWidth = annotPanel.getFadedImageWidth();
216 updateFromAlignViewport(av);
219 public void updateFromAlignViewport(AlignViewportI av)
221 charWidth = av.getCharWidth();
222 endRes = av.getEndRes();
223 charHeight = av.getCharHeight();
224 hasHiddenColumns = av.hasHiddenColumns();
225 validCharWidth = av.isValidCharWidth();
226 av_renderHistogram = av.isShowConsensusHistogram();
227 av_renderProfile = av.isShowSequenceLogo();
228 av_normaliseProfile = av.isNormaliseSequenceLogo();
229 profcolour = av.getGlobalColourScheme();
230 if (profcolour == null)
232 // Set the default colour for sequence logo if the alignnent has no
234 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
235 : new jalview.schemes.ZappoColourScheme();
237 columnSelection = av.getColumnSelection();
238 hconsensus = av.getSequenceConsensusHash();// hconsensus;
239 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
240 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
243 public int[] getProfileFor(AlignmentAnnotation aa, int column)
245 // TODO : consider refactoring the global alignment calculation
246 // properties/rendering attributes as a global 'alignment group' which holds
247 // all vis settings for the alignment as a whole rather than a subset
249 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
251 if (aa.groupRef != null && aa.groupRef.consensusData != null
252 && aa.groupRef.isShowSequenceLogo())
254 return AAFrequency.extractProfile(
255 aa.groupRef.consensusData[column],
256 aa.groupRef.getIgnoreGapsConsensus());
258 // TODO extend annotation row to enable dynamic and static profile data to
260 if (aa.groupRef == null && aa.sequenceRef == null && av_renderProfile)
262 return AAFrequency.extractProfile(hconsensus[column],
263 av_ignoreGapsConsensus);
268 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
270 // TODO implement group structure consensus
272 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
273 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
274 * group selections return StructureFrequency.extractProfile(
275 * aa.groupRef.consensusData[column], aa.groupRef
276 * .getIgnoreGapsConsensus()); }
278 // TODO extend annotation row to enable dynamic and static profile data
281 if (aa.groupRef == null && aa.sequenceRef == null
282 && av_renderProfile && hStrucConsensus != null
283 && hStrucConsensus.length > column)
285 return StructureFrequency.extractProfile(hStrucConsensus[column],
286 av_ignoreGapsConsensus);
294 * Render the annotation rows associated with an alignment.
299 * data and view settings to render
301 * destination for graphics
303 * row where a mouse event occured (or -1)
305 * first column that will be drawn
307 * last column that will be drawn
308 * @return true if the fadedImage was used for any alignment annotation rows
309 * currently being calculated
311 public boolean drawComponent(AwtRenderPanelI annotPanel,
312 AlignViewportI av, Graphics g, int activeRow, int startRes,
315 boolean usedFaded = false;
317 // AnnotationPanel needs to implement: ImageObserver, access to
319 updateFromAwtRenderPanel(annotPanel, av);
320 fm = g.getFontMetrics();
321 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
328 boolean validRes = false;
329 boolean validEnd = false;
330 boolean labelAllCols = false;
331 boolean centreColLabels, centreColLabelsDef = av
332 .getCentreColumnLabels();
333 boolean scaleColLabel = false;
334 boolean[] graphGroupDrawn = new boolean[aa.length];
335 int charOffset = 0; // offset for a label
336 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
338 Font ofont = g.getFont();
340 for (int i = 0; i < aa.length; i++)
342 AlignmentAnnotation row = aa[i];
343 Annotation[] row_annotations = row.annotations;
348 centreColLabels = row.centreColLabels || centreColLabelsDef;
349 labelAllCols = row.showAllColLabels;
350 scaleColLabel = row.scaleColLabel;
355 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
360 // this is so that we draw the characters below the graph
365 iconOffset = charHeight - fm.getDescent();
369 else if (row.hasText)
371 iconOffset = charHeight - fm.getDescent();
379 if (row.autoCalculated && av.isCalculationInProgress(row))
383 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
384 - row.height, imgWidth, y, annotationPanel);
385 g.setColor(Color.black);
386 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
392 * else if (annotationPanel.av.updatingConservation &&
393 * aa[i].label.equals("Conservation")) {
395 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
396 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
397 * annotationPanel.imgWidth, y, annotationPanel);
399 * g.setColor(Color.black); //
400 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
402 * continue; } else if (annotationPanel.av.updatingConservation &&
403 * aa[i].label.equals("Quality")) {
405 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
406 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
407 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
408 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
412 // first pass sets up state for drawing continuation from left-hand column
414 x = (startRes == 0) ? 0 : -1;
415 while (x < endRes - startRes)
417 if (hasHiddenColumns)
419 column = columnSelection.adjustForHiddenColumns(startRes + x);
420 if (column > row_annotations.length - 1)
427 column = startRes + x;
430 if ((row_annotations == null) || (row_annotations.length <= column)
431 || (row_annotations[column] == null))
443 g.setColor(Color.red);
445 if (columnSelection != null)
447 for (int n = 0; n < columnSelection.size(); n++)
449 int v = columnSelection.columnAt(n);
453 g.fillRect(x * charWidth, y, charWidth, charHeight);
458 if (!row.isValidStruc())
460 g.setColor(Color.orange);
461 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
462 charWidth, charHeight);
466 && row_annotations[column].displayCharacter != null
467 && (row_annotations[column].displayCharacter.length() > 0))
470 if (centreColLabels || scaleColLabel)
472 fmWidth = fm.charsWidth(
473 row_annotations[column].displayCharacter
475 row_annotations[column].displayCharacter.length());
479 // justify the label and scale to fit in column
480 if (fmWidth > charWidth)
482 // scale only if the current font isn't already small enough
483 fmScaling = charWidth;
484 fmScaling /= fmWidth;
485 g.setFont(ofont.deriveFont(AffineTransform
486 .getScaleInstance(fmScaling, 1.0)));
487 // and update the label's width to reflect the scaling.
495 .charWidth(row_annotations[column].displayCharacter
498 charOffset = (int) ((charWidth - fmWidth) / 2f);
500 if (row_annotations[column].colour == null)
501 g.setColor(Color.black);
503 g.setColor(row_annotations[column].colour);
505 if (column == 0 || row.graph > 0)
507 g.drawString(row_annotations[column].displayCharacter,
508 (x * charWidth) + charOffset, y + iconOffset);
510 else if (row_annotations[column - 1] == null
512 || !row_annotations[column].displayCharacter
513 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
514 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
516 g.drawString(row_annotations[column].displayCharacter
518 * charWidth + charOffset, y + iconOffset);
525 char ss = validRes ? row_annotations[column].secondaryStructure
530 // distinguish between forward/backward base-pairing
531 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
540 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
549 // distinguish between forward/backward base-pairing
550 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
559 // distinguish between forward/backward base-pairing
560 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
569 // distinguish between forward/backward base-pairing
570 if (row_annotations[column].displayCharacter.indexOf('a') > -1)
580 // distinguish between forward/backward base-pairing
581 if (row_annotations[column].displayCharacter.indexOf('b') > -1)
590 // distinguish between forward/backward base-pairing
591 if (row_annotations[column].displayCharacter.indexOf('c') > -1)
599 // distinguish between forward/backward base-pairing
600 if (row_annotations[column].displayCharacter.indexOf('d') > -1)
608 // distinguish between forward/backward base-pairing
609 if (row_annotations[column].displayCharacter.indexOf('e') > -1)
617 // distinguish between forward/backward base-pairing
618 if (row_annotations[column].displayCharacter.indexOf('f') > -1)
626 // distinguish between forward/backward base-pairing
627 if (row_annotations[column].displayCharacter.indexOf('g') > -1)
635 // distinguish between forward/backward base-pairing
636 if (row_annotations[column].displayCharacter.indexOf('h') > -1)
644 // distinguish between forward/backward base-pairing
645 if (row_annotations[column].displayCharacter.indexOf('i') > -1)
653 // distinguish between forward/backward base-pairing
654 if (row_annotations[column].displayCharacter.indexOf('j') > -1)
662 // distinguish between forward/backward base-pairing
663 if (row_annotations[column].displayCharacter.indexOf('k') > -1)
671 // distinguish between forward/backward base-pairing
672 if (row_annotations[column].displayCharacter.indexOf('l') > -1)
680 // distinguish between forward/backward base-pairing
681 if (row_annotations[column].displayCharacter.indexOf('m') > -1)
689 // distinguish between forward/backward base-pairing
690 if (row_annotations[column].displayCharacter.indexOf('n') > -1)
698 // distinguish between forward/backward base-pairing
699 if (row_annotations[column].displayCharacter.indexOf('o') > -1)
707 // distinguish between forward/backward base-pairing
708 if (row_annotations[column].displayCharacter.indexOf('p') > -1)
716 // distinguish between forward/backward base-pairing
717 if (row_annotations[column].displayCharacter.indexOf('q') > -1)
725 // distinguish between forward/backward base-pairing
726 if (row_annotations[column].displayCharacter.indexOf('r') > -1)
734 // distinguish between forward/backward base-pairing
735 if (row_annotations[column].displayCharacter.indexOf('s') > -1)
743 // distinguish between forward/backward base-pairing
744 if (row_annotations[column].displayCharacter.indexOf('t') > -1)
752 // distinguish between forward/backward base-pairing
753 if (row_annotations[column].displayCharacter.indexOf('u') > -1)
761 // distinguish between forward/backward base-pairing
762 if (row_annotations[column].displayCharacter.indexOf('v') > -1)
770 // distinguish between forward/backward base-pairing
771 if (row_annotations[column].displayCharacter.indexOf('w') > -1)
779 // distinguish between forward/backward base-pairing
780 if (row_annotations[column].displayCharacter.indexOf('x') > -1)
788 // distinguish between forward/backward base-pairing
789 if (row_annotations[column].displayCharacter.indexOf('y') > -1)
797 // distinguish between forward/backward base-pairing
798 if (row_annotations[column].displayCharacter.indexOf('z') > -1)
804 if (!validRes || (ss != lastSS))
811 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
812 iconOffset, startRes, column, validRes, validEnd);
816 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
817 iconOffset, startRes, column, validRes, validEnd);
820 case '(': // Stem case for RNA secondary structure
821 case ')': // and opposite direction
822 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
823 column, validRes, validEnd);
824 // case 'S': // Stem case for RNA secondary structure
825 // case 's': // and opposite direction
826 // drawStemAnnot(g, row_annotations, lastSSX, x, y,
827 // iconOffset, startRes, column, validRes, validEnd);
887 //System.out.println(lastSS);
888 Color nonCanColor= getNotCanonicalColor(lastSS);
889 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
890 column, validRes, validEnd);
893 g.setColor(Color.gray);
894 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
910 lastSSX = (x * charWidth);
917 if (column >= row_annotations.length)
919 column = row_annotations.length - 1;
926 if ((row_annotations == null) || (row_annotations.length <= column)
927 || (row_annotations[column] == null))
943 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
944 startRes, column, validRes, validEnd);
948 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
949 startRes, column, validRes, validEnd);
952 case 'S': // Stem case for RNA secondary structure
953 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
954 startRes, column, validRes, validEnd);
1012 //System.out.println(lastSS);
1013 Color nonCanColor = getNotCanonicalColor(lastSS);
1014 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
1015 column, validRes, validEnd);
1018 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1019 startRes, column, validRes, validEnd);
1024 if (row.graph > 0 && row.graphHeight > 0)
1026 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1028 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1030 float groupmax = -999999, groupmin = 9999999;
1031 for (int gg = 0; gg < aa.length; gg++)
1033 if (aa[gg].graphGroup != row.graphGroup)
1040 aa[gg].visible = false;
1042 if (aa[gg].graphMax > groupmax)
1044 groupmax = aa[gg].graphMax;
1046 if (aa[gg].graphMin < groupmin)
1048 groupmin = aa[gg].graphMin;
1052 for (int gg = 0; gg < aa.length; gg++)
1054 if (aa[gg].graphGroup == row.graphGroup)
1056 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1057 endRes, y, groupmin, groupmax, row.graphHeight);
1061 graphGroupDrawn[row.graphGroup] = true;
1065 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1066 row.graphMin, row.graphMax, row.graphHeight);
1069 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1071 drawBarGraph(g, row, row_annotations, startRes, endRes,
1072 row.graphMin, row.graphMax, y);
1076 if (row.graph > 0 && row.hasText)
1089 private final Color GLYPHLINE_COLOR = Color.gray;
1091 private final Color SHEET_COLOUR = Color.green;
1093 private final Color HELIX_COLOUR = Color.red;
1095 private final Color STEM_COLOUR = Color.blue;
1097 private Color sdNOTCANONICAL_COLOUR;
1099 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1100 int x, int y, int iconOffset, int startRes, int column,
1101 boolean validRes, boolean validEnd)
1103 g.setColor(GLYPHLINE_COLOR);
1104 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1107 public void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX,
1108 int x, int y, int iconOffset, int startRes, int column,
1109 boolean validRes, boolean validEnd)
1111 g.setColor(SHEET_COLOUR);
1113 if (!validEnd || !validRes || row == null || row[column] == null
1114 || row[column].secondaryStructure != 'E')
1116 g.fillRect(lastSSX, y + 4 + iconOffset,
1117 (x * charWidth) - lastSSX - 4, 7);
1118 g.fillPolygon(new int[]
1119 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1121 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1126 g.fillRect(lastSSX, y + 4 + iconOffset,
1127 (x + 1) * charWidth - lastSSX, 7);
1132 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1133 int x, int y, int iconOffset, int startRes, int column,
1134 boolean validRes, boolean validEnd)
1136 g.setColor(HELIX_COLOUR);
1138 int sCol = (lastSSX / charWidth) + startRes;
1140 int x2 = (x * charWidth);
1144 int ofs = charWidth / 2;
1145 // Off by 1 offset when drawing rects and ovals
1146 // to offscreen image on the MAC
1147 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1148 if (sCol == 0 || row[sCol - 1] == null
1149 || row[sCol - 1].secondaryStructure != 'H')
1154 // g.setColor(Color.orange);
1155 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1158 if (!validRes || row[column] == null
1159 || row[column].secondaryStructure != 'H')
1165 // g.setColor(Color.magenta);
1166 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1174 if (sCol == 0 || row[sCol - 1] == null
1175 || row[sCol - 1].secondaryStructure != 'H')
1177 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1178 x1 += charWidth / 2;
1181 if (!validRes || row[column] == null
1182 || row[column].secondaryStructure != 'H')
1184 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1186 x2 -= charWidth / 2;
1189 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1192 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1193 Annotation[] aa_annotations, int sRes, int eRes, int y,
1194 float min, float max, int graphHeight)
1196 if (sRes > aa_annotations.length)
1203 // Adjustment for fastpaint to left
1209 eRes = Math.min(eRes, aa_annotations.length);
1217 float range = max - min;
1222 y2 = y - (int) ((0 - min / range) * graphHeight);
1225 g.setColor(Color.gray);
1226 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1228 eRes = Math.min(eRes, aa_annotations.length);
1231 int aaMax = aa_annotations.length - 1;
1233 while (x < eRes - sRes)
1236 if (hasHiddenColumns)
1238 column = columnSelection.adjustForHiddenColumns(column);
1246 if (aa_annotations[column] == null
1247 || aa_annotations[column - 1] == null)
1253 if (aa_annotations[column].colour == null)
1254 g.setColor(Color.black);
1256 g.setColor(aa_annotations[column].colour);
1259 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1261 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1263 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1264 + charWidth / 2, y2);
1268 if (_aa.threshold != null)
1270 g.setColor(_aa.threshold.colour);
1271 Graphics2D g2 = (Graphics2D) g;
1272 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1273 BasicStroke.JOIN_ROUND, 3f, new float[]
1276 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1277 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1278 g2.setStroke(new BasicStroke());
1282 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1283 Annotation[] aa_annotations, int sRes, int eRes, float min,
1286 if (sRes > aa_annotations.length)
1290 Font ofont = g.getFont();
1291 eRes = Math.min(eRes, aa_annotations.length);
1293 int x = 0, y1 = y, y2 = y;
1295 float range = max - min;
1299 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1302 g.setColor(Color.gray);
1304 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1307 int aaMax = aa_annotations.length - 1;
1308 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
1309 // if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1311 // TODO: generalise this to have render styles for consensus/profile data
1312 if (_aa.groupRef != null)
1314 renderHistogram = _aa.groupRef.isShowConsensusHistogram();
1315 renderProfile = _aa.groupRef.isShowSequenceLogo();
1316 normaliseProfile = _aa.groupRef.isNormaliseSequenceLogo();
1320 renderHistogram = av_renderHistogram;
1321 renderProfile = av_renderProfile;
1322 normaliseProfile = av_normaliseProfile;
1325 while (x < eRes - sRes)
1328 if (hasHiddenColumns)
1330 column = columnSelection.adjustForHiddenColumns(column);
1338 if (aa_annotations[column] == null)
1343 if (aa_annotations[column].colour == null)
1344 g.setColor(Color.black);
1346 g.setColor(aa_annotations[column].colour);
1349 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1351 if (renderHistogram)
1355 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1359 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1362 // draw profile if available
1366 int profl[] = getProfileFor(_aa, column);
1367 // just try to draw the logo if profl is not null
1368 if (profl != null && profl[1] != 0)
1370 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1371 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1378 * profl.length == 74 indicates that the profile of a secondary
1379 * structure conservation row was accesed. Therefore dc gets length 2,
1380 * to have space for a basepair instead of just a single nucleotide
1382 if (profl.length == 74)
1390 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1391 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1392 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1394 for (int c = 2; c < profl[0];)
1396 dc[0] = (char) profl[c++];
1398 if (_aa.label.startsWith("StrucConsensus"))
1400 dc[1] = (char) profl[c++];
1404 wdth /= fm.charsWidth(dc, 0, dc.length);
1408 scl = htn * scale * profl[c++];
1409 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1410 .getFontRenderContext());
1411 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1412 wdth, scl / lm.getAscent())));
1413 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1415 // Debug - render boxes around characters
1416 // g.setColor(Color.red);
1417 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1419 // g.setColor(profcolour.findColour(dc[0]).darker());
1420 g.setColor(profcolour.findColour(dc[0], column, null));
1422 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1423 .getBaselineIndex()]));
1425 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1433 if (_aa.threshold != null)
1435 g.setColor(_aa.threshold.colour);
1436 Graphics2D g2 = (Graphics2D) g;
1437 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1438 BasicStroke.JOIN_ROUND, 3f, new float[]
1441 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1443 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1444 g2.setStroke(new BasicStroke());
1448 // used by overview window
1449 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1450 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1452 eRes = Math.min(eRes, aa_annotations.length);
1453 g.setColor(Color.white);
1454 g.fillRect(0, 0, width, y);
1455 g.setColor(new Color(0, 0, 180));
1459 for (int j = sRes; j < eRes; j++)
1461 if (aa_annotations[j] != null)
1463 if (aa_annotations[j].colour == null)
1464 g.setColor(Color.black);
1466 g.setColor(aa_annotations[j].colour);
1468 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1474 g.fillRect(x, y - height, charWidth, height);
1481 Color getNotCanonicalColor(char lastss)
1495 return Color.magenta;
1499 return Color.orange;
1511 return Color.yellow;
1519 return Color.darkGray;
1527 return Color.lightGray;
1539 return Color.magenta;
1543 return Color.orange;
1551 return Color.yellow;
1571 return Color.magenta;
1575 return Color.darkGray;
1579 return Color.yellow;
1587 return Color.orange;
1591 return Color.magenta;
1602 System.out.println("This is not a interaction");