2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.renderer;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.StructureFrequency;
25 import jalview.api.AlignViewportI;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.schemes.ColourSchemeI;
30 import jalview.schemes.ResidueProperties;
32 import java.awt.BasicStroke;
33 import java.awt.Color;
35 import java.awt.FontMetrics;
36 import java.awt.Graphics;
37 import java.awt.Graphics2D;
38 import java.awt.Image;
39 import java.awt.font.LineMetrics;
40 import java.awt.geom.AffineTransform;
41 import java.awt.image.ImageObserver;
42 import java.util.BitSet;
43 import java.util.Hashtable;
45 import com.stevesoft.pat.Regex;
47 public class AnnotationRenderer
50 * flag indicating if timing and redraw parameter info should be output
52 private final boolean debugRedraw;
54 public AnnotationRenderer()
60 * Create a new annotation Renderer
63 * flag indicating if timing and redraw parameter info should be
66 public AnnotationRenderer(boolean debugRedraw)
68 this.debugRedraw = debugRedraw;
71 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
72 int lastSSX, int x, int y, int iconOffset, int startRes,
73 int column, boolean validRes, boolean validEnd)
75 g.setColor(STEM_COLOUR);
76 int sCol = (lastSSX / charWidth) + startRes;
78 int x2 = (x * charWidth);
79 Regex closeparen = new Regex("(\\))");
81 char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
82 : row_annotations[column - 1].secondaryStructure;
84 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
85 || dc != row_annotations[sCol - 1].secondaryStructure;
86 boolean diffdownstream = !validRes || !validEnd
87 || row_annotations[column] == null
88 || dc != row_annotations[column].secondaryStructure;
89 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
90 // If a closing base pair half of the stem, display a backward arrow
91 if (column > 0 && ResidueProperties.isCloseParenRNA(dc))
95 // if (validRes && column>1 && row_annotations[column-2]!=null &&
96 // dc.equals(row_annotations[column-2].displayCharacter))
98 g.fillPolygon(new int[]
99 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
100 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
111 // display a forward arrow
114 g.fillPolygon(new int[]
115 { x2 - 5, x2 - 5, x2 }, new int[]
116 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
125 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
128 private int charWidth, endRes, charHeight;
130 private boolean validCharWidth, hasHiddenColumns;
132 private FontMetrics fm;
134 private final boolean MAC = new jalview.util.Platform().isAMac();
136 boolean av_renderHistogram = true, av_renderProfile = true,
137 av_normaliseProfile = false;
139 ColourSchemeI profcolour = null;
141 private ColumnSelection columnSelection;
143 private Hashtable[] hconsensus;
145 private Hashtable[] hStrucConsensus;
147 private boolean av_ignoreGapsConsensus;
150 * attributes set from AwtRenderPanelI
153 * old image used when data is currently being calculated and cannot be
156 private Image fadedImage;
159 * panel being rendered into
161 private ImageObserver annotationPanel;
164 * width of image to render in panel
166 private int imgWidth;
169 * offset to beginning of visible area
174 * offset to end of visible area
176 private int visHeight;
179 * indicate if the renderer should only render the visible portion of the
180 * annotation given the current view settings
182 private boolean useClip = true;
185 * master flag indicating if renderer should ever try to clip. not enabled for
188 private boolean canClip = false;
190 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
191 Annotation[] row_annotations, int lastSSX, int x, int y,
192 int iconOffset, int startRes, int column, boolean validRes,
195 // System.out.println(nonCanColor);
197 g.setColor(nonCanColor);
198 int sCol = (lastSSX / charWidth) + startRes;
200 int x2 = (x * charWidth);
201 Regex closeparen = new Regex("}|]|<|[a-z]");
203 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
204 : row_annotations[column - 1].displayCharacter;
206 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
207 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
208 boolean diffdownstream = !validRes || !validEnd
209 || row_annotations[column] == null
210 || !dc.equals(row_annotations[column].displayCharacter);
211 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
212 // If a closing base pair half of the stem, display a backward arrow
213 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc))
218 // if (validRes && column>1 && row_annotations[column-2]!=null &&
219 // dc.equals(row_annotations[column-2].displayCharacter))
221 g.fillPolygon(new int[]
222 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
223 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
234 // display a forward arrow
237 g.fillPolygon(new int[]
238 { x2 - 5, x2 - 5, x2 }, new int[]
239 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
248 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
251 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
253 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
256 fm = annotPanel.getFontMetrics();
257 annotationPanel = annotPanel;
258 fadedImage = annotPanel.getFadedImage();
259 imgWidth = annotPanel.getFadedImageWidth();
260 // visible area for rendering
261 int[] bounds = annotPanel.getVisibleVRange();
265 visHeight = bounds[1];
280 updateFromAlignViewport(av);
283 public void updateFromAlignViewport(AlignViewportI av)
285 charWidth = av.getCharWidth();
286 endRes = av.getEndRes();
287 charHeight = av.getCharHeight();
288 hasHiddenColumns = av.hasHiddenColumns();
289 validCharWidth = av.isValidCharWidth();
290 av_renderHistogram = av.isShowConsensusHistogram();
291 av_renderProfile = av.isShowSequenceLogo();
292 av_normaliseProfile = av.isNormaliseSequenceLogo();
293 profcolour = av.getGlobalColourScheme();
294 if (profcolour == null)
296 // Set the default colour for sequence logo if the alignnent has no
298 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
299 : new jalview.schemes.ZappoColourScheme();
301 boolean rna = av.getAlignment().isNucleotide();
302 columnSelection = av.getColumnSelection();
303 hconsensus = av.getSequenceConsensusHash();// hconsensus;
304 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
305 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
308 public int[] getProfileFor(AlignmentAnnotation aa, int column)
310 // TODO : consider refactoring the global alignment calculation
311 // properties/rendering attributes as a global 'alignment group' which holds
312 // all vis settings for the alignment as a whole rather than a subset
314 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
316 if (aa.groupRef != null && aa.groupRef.consensusData != null
317 && aa.groupRef.isShowSequenceLogo())
319 return AAFrequency.extractProfile(
320 aa.groupRef.consensusData[column],
321 aa.groupRef.getIgnoreGapsConsensus());
323 // TODO extend annotation row to enable dynamic and static profile data to
325 if (aa.groupRef == null && aa.sequenceRef == null)
327 return AAFrequency.extractProfile(hconsensus[column],
328 av_ignoreGapsConsensus);
333 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
335 // TODO implement group structure consensus
337 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
338 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
339 * group selections return StructureFrequency.extractProfile(
340 * aa.groupRef.consensusData[column], aa.groupRef
341 * .getIgnoreGapsConsensus()); }
343 // TODO extend annotation row to enable dynamic and static profile data
346 if (aa.groupRef == null && aa.sequenceRef == null
347 && hStrucConsensus != null
348 && hStrucConsensus.length > column)
350 return StructureFrequency.extractProfile(hStrucConsensus[column],
351 av_ignoreGapsConsensus);
361 * Render the annotation rows associated with an alignment.
366 * data and view settings to render
368 * destination for graphics
370 * row where a mouse event occured (or -1)
372 * first column that will be drawn
374 * last column that will be drawn
375 * @return true if the fadedImage was used for any alignment annotation rows
376 * currently being calculated
378 public boolean drawComponent(AwtRenderPanelI annotPanel,
379 AlignViewportI av, Graphics g, int activeRow, int startRes,
382 long stime = System.currentTimeMillis();
383 boolean usedFaded = false;
385 // AnnotationPanel needs to implement: ImageObserver, access to
387 updateFromAwtRenderPanel(annotPanel, av);
388 fm = g.getFontMetrics();
389 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
400 boolean validRes = false;
401 boolean validEnd = false;
402 boolean labelAllCols = false;
403 boolean centreColLabels, centreColLabelsDef = av
404 .getCentreColumnLabels();
405 boolean scaleColLabel = false;
406 AlignmentAnnotation consensusAnnot = av
407 .getAlignmentConsensusAnnotation(), structConsensusAnnot = av
408 .getAlignmentStrucConsensusAnnotation();
409 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
411 BitSet graphGroupDrawn = new BitSet();
412 int charOffset = 0; // offset for a label
413 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
415 Font ofont = g.getFont();
418 int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
419 boolean clipst = false, clipend = false;
420 for (int i = 0; i < aa.length; i++)
422 AlignmentAnnotation row = aa[i];
425 // check if this is a consensus annotation row and set the display
426 // settings appropriately
427 // TODO: generalise this to have render styles for consensus/profile
429 if (row.groupRef != null && row == row.groupRef.getConsensus())
431 renderHistogram = row.groupRef.isShowConsensusHistogram();
432 renderProfile = row.groupRef.isShowSequenceLogo();
433 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
435 else if (row == consensusAnnot || row == structConsensusAnnot)
437 renderHistogram = av_renderHistogram;
438 renderProfile = av_renderProfile;
439 normaliseProfile = av_normaliseProfile;
443 renderHistogram = true;
444 // don't need to set render/normaliseProfile since they are not
445 // currently used in any other annotation track renderer
448 Annotation[] row_annotations = row.annotations;
453 centreColLabels = row.centreColLabels || centreColLabelsDef;
454 labelAllCols = row.showAllColLabels;
455 scaleColLabel = row.scaleColLabel;
460 || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
461 {// if_in_visible_region
472 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
477 // this is so that we draw the characters below the graph
482 iconOffset = charHeight - fm.getDescent();
486 else if (row.hasText)
488 iconOffset = charHeight - fm.getDescent();
496 if (row.autoCalculated && av.isCalculationInProgress(row))
500 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
501 - row.height, imgWidth, y, annotationPanel);
502 g.setColor(Color.black);
503 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
509 * else if (annotationPanel.av.updatingConservation &&
510 * aa[i].label.equals("Conservation")) {
512 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
513 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
514 * annotationPanel.imgWidth, y, annotationPanel);
516 * g.setColor(Color.black); //
517 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
519 * continue; } else if (annotationPanel.av.updatingConservation &&
520 * aa[i].label.equals("Quality")) {
522 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
523 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
524 * annotationPanel.imgWidth, y, annotationPanel);
525 * g.setColor(Color.black); // /
526 * g.drawString("Calculating Quality....",20, y-row.height/2);
530 // first pass sets up state for drawing continuation from left-hand
533 x = (startRes == 0) ? 0 : -1;
534 while (x < endRes - startRes)
536 if (hasHiddenColumns)
538 column = columnSelection.adjustForHiddenColumns(startRes + x);
539 if (column > row_annotations.length - 1)
546 column = startRes + x;
549 if ((row_annotations == null)
550 || (row_annotations.length <= column)
551 || (row_annotations[column] == null))
563 g.setColor(Color.red);
565 if (columnSelection != null)
567 for (int n = 0; n < columnSelection.size(); n++)
569 int v = columnSelection.columnAt(n);
573 g.fillRect(x * charWidth, y, charWidth, charHeight);
578 if (row.getInvalidStrucPos() > x)
580 g.setColor(Color.orange);
581 g.fillRect(x * charWidth, y, charWidth, charHeight);
583 else if (row.getInvalidStrucPos() == x)
585 g.setColor(Color.orange.darker());
586 g.fillRect(x * charWidth, y, charWidth, charHeight);
590 && row_annotations[column].displayCharacter != null
591 && (row_annotations[column].displayCharacter.length() > 0))
594 if (centreColLabels || scaleColLabel)
596 fmWidth = fm.charsWidth(
597 row_annotations[column].displayCharacter
599 row_annotations[column].displayCharacter.length());
603 // justify the label and scale to fit in column
604 if (fmWidth > charWidth)
606 // scale only if the current font isn't already small enough
607 fmScaling = charWidth;
608 fmScaling /= fmWidth;
609 g.setFont(ofont.deriveFont(AffineTransform
610 .getScaleInstance(fmScaling, 1.0)));
611 // and update the label's width to reflect the scaling.
619 .charWidth(row_annotations[column].displayCharacter
622 charOffset = (int) ((charWidth - fmWidth) / 2f);
624 if (row_annotations[column].colour == null)
626 g.setColor(Color.black);
630 g.setColor(row_annotations[column].colour);
633 if (column == 0 || row.graph > 0)
635 g.drawString(row_annotations[column].displayCharacter,
636 (x * charWidth) + charOffset, y + iconOffset);
638 else if (row_annotations[column - 1] == null
640 || !row_annotations[column].displayCharacter
641 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
642 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
644 g.drawString(row_annotations[column].displayCharacter, x
645 * charWidth + charOffset, y + iconOffset);
652 char ss = validRes ? row_annotations[column].secondaryStructure
657 // distinguish between forward/backward base-pairing
658 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
667 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
675 // distinguish between forward/backward base-pairing
676 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
684 // distinguish between forward/backward base-pairing
685 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
693 // distinguish between forward/backward base-pairing
694 if (row_annotations[column].displayCharacter.indexOf(ss + 32) > -1)
697 ss = (char) (ss + 32);
702 if (!validRes || (ss != lastSS))
708 int nb_annot = x - temp;
709 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
712 case '(': // Stem case for RNA secondary structure
713 case ')': // and opposite direction
714 drawStemAnnot(g, row_annotations, lastSSX, x, y,
715 iconOffset, startRes, column, validRes, validEnd);
722 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
723 iconOffset, startRes, column, validRes,
731 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
732 iconOffset, startRes, column, validRes,
794 Color nonCanColor = getNotCanonicalColor(lastSS);
795 drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
796 lastSSX, x, y, iconOffset, startRes, column,
801 g.setColor(Color.gray);
802 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
818 lastSSX = (x * charWidth);
825 if (column >= row_annotations.length)
827 column = row_annotations.length - 1;
834 if ((row_annotations == null) || (row_annotations.length <= column)
835 || (row_annotations[column] == null))
854 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
855 startRes, column, validRes, validEnd);
862 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
863 startRes, column, validRes, validEnd);
868 case ')': // Stem case for RNA secondary structure
870 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
871 startRes, column, validRes, validEnd);
928 // System.out.println(lastSS);
929 Color nonCanColor = getNotCanonicalColor(lastSS);
930 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
931 x, y, iconOffset, startRes, column, validRes, validEnd);
934 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
935 startRes, column, validRes, validEnd);
940 if (row.graph > 0 && row.graphHeight > 0)
942 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
944 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
946 // TODO: JAL-1291 revise rendering model so the graphGroup map is
947 // computed efficiently for all visible labels
948 float groupmax = -999999, groupmin = 9999999;
949 for (int gg = 0; gg < aa.length; gg++)
951 if (aa[gg].graphGroup != row.graphGroup)
958 aa[gg].visible = false;
960 if (aa[gg].graphMax > groupmax)
962 groupmax = aa[gg].graphMax;
964 if (aa[gg].graphMin < groupmin)
966 groupmin = aa[gg].graphMin;
970 for (int gg = 0; gg < aa.length; gg++)
972 if (aa[gg].graphGroup == row.graphGroup)
974 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
975 endRes, y, groupmin, groupmax, row.graphHeight);
979 graphGroupDrawn.set(row.graphGroup);
983 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
984 row.graphMin, row.graphMax, row.graphHeight);
987 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
989 drawBarGraph(g, row, row_annotations, startRes, endRes,
990 row.graphMin, row.graphMax, y, renderHistogram,
991 renderProfile, normaliseProfile);
997 if (clipst && !clipend)
1001 }// end if_in_visible_region
1002 if (row.graph > 0 && row.hasText)
1018 System.err.println("Start clip at : " + yfrom + " (index " + f_i
1023 System.err.println("End clip at : " + yto + " (index " + f_to
1028 System.err.println("Annotation Rendering time:"
1029 + (System.currentTimeMillis() - stime));
1036 public static final Color GLYPHLINE_COLOR = Color.gray;
1038 public static final Color SHEET_COLOUR = Color.green;
1040 public static final Color HELIX_COLOUR = Color.red;
1042 public static final Color STEM_COLOUR = Color.blue;
1044 private Color sdNOTCANONICAL_COLOUR;
1046 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
1047 int x, int y, int iconOffset, int startRes, int column,
1048 boolean validRes, boolean validEnd)
1050 g.setColor(GLYPHLINE_COLOR);
1051 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1054 public void drawSheetAnnot(Graphics g, Annotation[] row,
1056 int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1057 boolean validRes, boolean validEnd)
1059 g.setColor(SHEET_COLOUR);
1061 if (!validEnd || !validRes || row == null || row[column] == null
1062 || row[column].secondaryStructure != 'E')
1064 g.fillRect(lastSSX, y + 4 + iconOffset,
1065 (x * charWidth) - lastSSX - 4, 7);
1066 g.fillPolygon(new int[]
1067 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1069 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1074 g.fillRect(lastSSX, y + 4 + iconOffset,
1075 (x + 1) * charWidth - lastSSX, 7);
1080 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1081 int x, int y, int iconOffset, int startRes, int column,
1082 boolean validRes, boolean validEnd)
1084 g.setColor(HELIX_COLOUR);
1086 int sCol = (lastSSX / charWidth) + startRes;
1088 int x2 = (x * charWidth);
1092 int ofs = charWidth / 2;
1093 // Off by 1 offset when drawing rects and ovals
1094 // to offscreen image on the MAC
1095 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1096 if (sCol == 0 || row[sCol - 1] == null
1097 || row[sCol - 1].secondaryStructure != 'H')
1102 // g.setColor(Color.orange);
1103 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1106 if (!validRes || row[column] == null
1107 || row[column].secondaryStructure != 'H')
1113 // g.setColor(Color.magenta);
1114 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1122 if (sCol == 0 || row[sCol - 1] == null
1123 || row[sCol - 1].secondaryStructure != 'H')
1125 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1126 x1 += charWidth / 2;
1129 if (!validRes || row[column] == null
1130 || row[column].secondaryStructure != 'H')
1132 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1134 x2 -= charWidth / 2;
1137 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1140 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1141 Annotation[] aa_annotations, int sRes, int eRes, int y,
1142 float min, float max, int graphHeight)
1144 if (sRes > aa_annotations.length)
1151 // Adjustment for fastpaint to left
1157 eRes = Math.min(eRes, aa_annotations.length);
1165 float range = max - min;
1170 y2 = y - (int) ((0 - min / range) * graphHeight);
1173 g.setColor(Color.gray);
1174 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1176 eRes = Math.min(eRes, aa_annotations.length);
1179 int aaMax = aa_annotations.length - 1;
1181 while (x < eRes - sRes)
1184 if (hasHiddenColumns)
1186 column = columnSelection.adjustForHiddenColumns(column);
1194 if (aa_annotations[column] == null
1195 || aa_annotations[column - 1] == null)
1201 if (aa_annotations[column].colour == null)
1203 g.setColor(Color.black);
1207 g.setColor(aa_annotations[column].colour);
1211 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1213 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1215 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1216 + charWidth / 2, y2);
1220 if (_aa.threshold != null)
1222 g.setColor(_aa.threshold.colour);
1223 Graphics2D g2 = (Graphics2D) g;
1224 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1225 BasicStroke.JOIN_ROUND, 3f, new float[]
1228 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1229 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1230 g2.setStroke(new BasicStroke());
1234 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1235 Annotation[] aa_annotations, int sRes, int eRes, float min,
1236 float max, int y, boolean renderHistogram, boolean renderProfile,
1237 boolean normaliseProfile)
1239 if (sRes > aa_annotations.length)
1243 Font ofont = g.getFont();
1244 eRes = Math.min(eRes, aa_annotations.length);
1246 int x = 0, y1 = y, y2 = y;
1248 float range = max - min;
1252 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1255 g.setColor(Color.gray);
1257 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1260 int aaMax = aa_annotations.length - 1;
1261 while (x < eRes - sRes)
1264 if (hasHiddenColumns)
1266 column = columnSelection.adjustForHiddenColumns(column);
1274 if (aa_annotations[column] == null)
1279 if (aa_annotations[column].colour == null)
1281 g.setColor(Color.black);
1285 g.setColor(aa_annotations[column].colour);
1289 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1291 if (renderHistogram)
1295 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1299 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1302 // draw profile if available
1306 int profl[] = getProfileFor(_aa, column);
1307 // just try to draw the logo if profl is not null
1308 if (profl != null && profl[1] != 0)
1310 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1311 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1318 * profl.length == 74 indicates that the profile of a secondary
1319 * structure conservation row was accesed. Therefore dc gets length 2,
1320 * to have space for a basepair instead of just a single nucleotide
1322 if (profl.length == 74)
1330 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1331 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1332 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1334 for (int c = 2; c < profl[0];)
1336 dc[0] = (char) profl[c++];
1338 if (_aa.label.startsWith("StrucConsensus"))
1340 dc[1] = (char) profl[c++];
1344 wdth /= fm.charsWidth(dc, 0, dc.length);
1348 scl = htn * scale * profl[c++];
1349 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1350 .getFontRenderContext());
1351 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1352 wdth, scl / lm.getAscent())));
1353 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1355 // Debug - render boxes around characters
1356 // g.setColor(Color.red);
1357 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1359 // g.setColor(profcolour.findColour(dc[0]).darker());
1360 g.setColor(profcolour.findColour(dc[0], column, null));
1362 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1363 .getBaselineIndex()]));
1365 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1373 if (_aa.threshold != null)
1375 g.setColor(_aa.threshold.colour);
1376 Graphics2D g2 = (Graphics2D) g;
1377 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1378 BasicStroke.JOIN_ROUND, 3f, new float[]
1381 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1383 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1384 g2.setStroke(new BasicStroke());
1388 // used by overview window
1389 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1390 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1392 eRes = Math.min(eRes, aa_annotations.length);
1393 g.setColor(Color.white);
1394 g.fillRect(0, 0, width, y);
1395 g.setColor(new Color(0, 0, 180));
1399 for (int j = sRes; j < eRes; j++)
1401 if (aa_annotations[j] != null)
1403 if (aa_annotations[j].colour == null)
1405 g.setColor(Color.black);
1409 g.setColor(aa_annotations[j].colour);
1412 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1418 g.fillRect(x, y - height, charWidth, height);
1424 Color getNotCanonicalColor(char lastss)
1430 return new Color(255, 125, 5);
1434 return new Color(245, 115, 10);
1438 return new Color(235, 135, 15);
1442 return new Color(225, 105, 20);
1446 return new Color(215, 145, 30);
1450 return new Color(205, 95, 35);
1454 return new Color(195, 155, 45);
1458 return new Color(185, 85, 55);
1462 return new Color(175, 165, 65);
1466 return new Color(170, 75, 75);
1470 return new Color(160, 175, 85);
1474 return new Color(150, 65, 95);
1478 return new Color(140, 185, 105);
1482 return new Color(130, 55, 110);
1486 return new Color(120, 195, 120);
1490 return new Color(110, 45, 130);
1494 return new Color(100, 205, 140);
1498 return new Color(90, 35, 150);
1502 return new Color(85, 215, 160);
1506 return new Color(75, 25, 170);
1510 return new Color(65, 225, 180);
1514 return new Color(55, 15, 185);
1518 return new Color(45, 235, 195);
1522 return new Color(35, 5, 205);
1526 return new Color(25, 245, 215);
1530 return new Color(15, 0, 225);
1534 return new Color(10, 255, 235);
1538 return new Color(5, 150, 245);
1542 return new Color(0, 80, 255);
1545 System.out.println("This is not a interaction : " + lastss);