2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.renderer;
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.StructureFrequency;
22 import jalview.api.AlignViewportI;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.schemes.ColourSchemeI;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.Image;
35 import java.awt.font.LineMetrics;
36 import java.awt.geom.AffineTransform;
37 import java.awt.image.ImageObserver;
38 import java.util.BitSet;
39 import java.util.Hashtable;
41 import com.stevesoft.pat.Regex;
43 public class AnnotationRenderer
46 * flag indicating if timing and redraw parameter info should be output
48 private final boolean debugRedraw;
50 public AnnotationRenderer()
55 * Create a new annotation Renderer
56 * @param debugRedraw flag indicating if timing and redraw parameter info should be output
58 public AnnotationRenderer(boolean debugRedraw)
60 this.debugRedraw=debugRedraw;
63 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
64 int lastSSX, int x, int y, int iconOffset, int startRes,
65 int column, boolean validRes, boolean validEnd)
67 g.setColor(STEM_COLOUR);
68 int sCol = (lastSSX / charWidth) + startRes;
70 int x2 = (x * charWidth);
71 Regex closeparen = new Regex("(\\))");
73 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
74 : row_annotations[column - 1].displayCharacter;
76 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
77 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
78 boolean diffdownstream = !validRes || !validEnd
79 || row_annotations[column] == null
80 || !dc.equals(row_annotations[column].displayCharacter);
81 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
82 // If a closing base pair half of the stem, display a backward arrow
83 if (column > 0 && closeparen.search(dc))
87 // if (validRes && column>1 && row_annotations[column-2]!=null &&
88 // dc.equals(row_annotations[column-2].displayCharacter))
90 g.fillPolygon(new int[]
91 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
92 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
103 // display a forward arrow
106 g.fillPolygon(new int[]
107 { x2 - 5, x2 - 5, x2 }, new int[]
108 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
117 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
120 private int charWidth, endRes, charHeight;
122 private boolean validCharWidth, hasHiddenColumns;
124 private FontMetrics fm;
126 private final boolean MAC = new jalview.util.Platform().isAMac();
128 boolean av_renderHistogram = true, av_renderProfile = true,
129 av_normaliseProfile = false;
131 ColourSchemeI profcolour = null;
133 private ColumnSelection columnSelection;
135 private Hashtable[] hconsensus;
137 private Hashtable[] hStrucConsensus;
139 private boolean av_ignoreGapsConsensus;
142 * attributes set from AwtRenderPanelI
145 * old image used when data is currently being calculated and cannot be
148 private Image fadedImage;
151 * panel being rendered into
153 private ImageObserver annotationPanel;
156 * width of image to render in panel
158 private int imgWidth;
160 * offset to beginning of visible area
164 * offset to end of visible area
166 private int visHeight;
168 * indicate if the renderer should only render the visible portion of the annotation given the current view settings
170 private boolean useClip=true;
172 * master flag indicating if renderer should ever try to clip. not enabled for jalview 2.8.1
174 private boolean canClip=false;
177 public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations,
178 int lastSSX, int x, int y, int iconOffset, int startRes,
179 int column, boolean validRes, boolean validEnd)
181 //System.out.println(nonCanColor);
183 g.setColor(nonCanColor);
184 int sCol = (lastSSX / charWidth) + startRes;
186 int x2 = (x * charWidth);
187 Regex closeparen = new Regex("}|]|<|[a-z]");
189 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
190 : row_annotations[column - 1].displayCharacter;
192 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
193 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
194 boolean diffdownstream = !validRes || !validEnd
195 || row_annotations[column] == null
196 || !dc.equals(row_annotations[column].displayCharacter);
197 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
198 // If a closing base pair half of the stem, display a backward arrow
199 if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
203 // if (validRes && column>1 && row_annotations[column-2]!=null &&
204 // dc.equals(row_annotations[column-2].displayCharacter))
206 g.fillPolygon(new int[]
207 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
208 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
219 // display a forward arrow
222 g.fillPolygon(new int[]
223 { x2 - 5, x2 - 5, x2 }, new int[]
224 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
233 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
235 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
237 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
240 fm = annotPanel.getFontMetrics();
241 annotationPanel = annotPanel;
242 fadedImage = annotPanel.getFadedImage();
243 imgWidth = annotPanel.getFadedImageWidth();
244 // visible area for rendering
245 int[] bounds=annotPanel.getVisibleVRange();
249 visHeight = bounds[1];
260 updateFromAlignViewport(av);
263 public void updateFromAlignViewport(AlignViewportI av)
265 charWidth = av.getCharWidth();
266 endRes = av.getEndRes();
267 charHeight = av.getCharHeight();
268 hasHiddenColumns = av.hasHiddenColumns();
269 validCharWidth = av.isValidCharWidth();
270 av_renderHistogram = av.isShowConsensusHistogram();
271 av_renderProfile = av.isShowSequenceLogo();
272 av_normaliseProfile = av.isNormaliseSequenceLogo();
273 profcolour = av.getGlobalColourScheme();
274 if (profcolour == null)
276 // Set the default colour for sequence logo if the alignnent has no
278 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
279 : new jalview.schemes.ZappoColourScheme();
281 columnSelection = av.getColumnSelection();
282 hconsensus = av.getSequenceConsensusHash();// hconsensus;
283 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
284 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
287 public int[] getProfileFor(AlignmentAnnotation aa, int column)
289 // TODO : consider refactoring the global alignment calculation
290 // properties/rendering attributes as a global 'alignment group' which holds
291 // all vis settings for the alignment as a whole rather than a subset
293 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
295 if (aa.groupRef != null && aa.groupRef.consensusData != null
296 && aa.groupRef.isShowSequenceLogo())
298 return AAFrequency.extractProfile(
299 aa.groupRef.consensusData[column],
300 aa.groupRef.getIgnoreGapsConsensus());
302 // TODO extend annotation row to enable dynamic and static profile data to
304 if (aa.groupRef == null && aa.sequenceRef == null)
306 return AAFrequency.extractProfile(hconsensus[column],
307 av_ignoreGapsConsensus);
312 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
314 // TODO implement group structure consensus
316 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
317 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
318 * group selections return StructureFrequency.extractProfile(
319 * aa.groupRef.consensusData[column], aa.groupRef
320 * .getIgnoreGapsConsensus()); }
322 // TODO extend annotation row to enable dynamic and static profile data
325 if (aa.groupRef == null && aa.sequenceRef == null
326 && hStrucConsensus != null
327 && hStrucConsensus.length > column)
329 return StructureFrequency.extractProfile(hStrucConsensus[column],
330 av_ignoreGapsConsensus);
338 * Render the annotation rows associated with an alignment.
343 * data and view settings to render
345 * destination for graphics
347 * row where a mouse event occured (or -1)
349 * first column that will be drawn
351 * last column that will be drawn
352 * @return true if the fadedImage was used for any alignment annotation rows
353 * currently being calculated
355 public boolean drawComponent(AwtRenderPanelI annotPanel,
356 AlignViewportI av, Graphics g, int activeRow, int startRes,
359 long stime=System.currentTimeMillis();
360 boolean usedFaded = false;
362 // AnnotationPanel needs to implement: ImageObserver, access to
364 updateFromAwtRenderPanel(annotPanel, av);
365 fm = g.getFontMetrics();
366 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
377 boolean validRes = false;
378 boolean validEnd = false;
379 boolean labelAllCols = false;
380 boolean centreColLabels, centreColLabelsDef = av
381 .getCentreColumnLabels();
382 boolean scaleColLabel = false;
383 AlignmentAnnotation consensusAnnot=av.getAlignmentConsensusAnnotation(),structConsensusAnnot=av.getAlignmentStrucConsensusAnnotation();
384 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
386 BitSet graphGroupDrawn = new BitSet();
387 int charOffset = 0; // offset for a label
388 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
390 Font ofont = g.getFont();
393 int yfrom=0,f_i=0,yto=0,f_to=0;
394 boolean clipst=false,clipend=false;
395 for (int i = 0; i < aa.length; i++)
397 AlignmentAnnotation row = aa[i];
399 // check if this is a consensus annotation row and set the display settings appropriately
400 // TODO: generalise this to have render styles for consensus/profile
402 if (row.groupRef != null && row == row.groupRef.getConsensus())
404 renderHistogram = row.groupRef.isShowConsensusHistogram();
405 renderProfile = row.groupRef.isShowSequenceLogo();
406 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
408 else if (row == consensusAnnot || row == structConsensusAnnot)
410 renderHistogram = av_renderHistogram;
411 renderProfile = av_renderProfile;
412 normaliseProfile = av_normaliseProfile;
414 renderHistogram = true;
415 // don't need to set render/normaliseProfile since they are not currently used in any other annotation track renderer
418 Annotation[] row_annotations = row.annotations;
423 centreColLabels = row.centreColLabels || centreColLabelsDef;
424 labelAllCols = row.showAllColLabels;
425 scaleColLabel = row.scaleColLabel;
429 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
430 {// if_in_visible_region
441 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
445 // this is so that we draw the characters below the graph
450 iconOffset = charHeight - fm.getDescent();
454 else if (row.hasText)
456 iconOffset = charHeight - fm.getDescent();
464 if (row.autoCalculated && av.isCalculationInProgress(row))
468 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
469 - row.height, imgWidth, y, annotationPanel);
470 g.setColor(Color.black);
471 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
477 * else if (annotationPanel.av.updatingConservation &&
478 * aa[i].label.equals("Conservation")) {
480 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
481 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
482 * annotationPanel.imgWidth, y, annotationPanel);
484 * g.setColor(Color.black); //
485 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
487 * continue; } else if (annotationPanel.av.updatingConservation &&
488 * aa[i].label.equals("Quality")) {
490 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
491 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
492 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
493 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
497 // first pass sets up state for drawing continuation from left-hand column
499 x = (startRes == 0) ? 0 : -1;
500 while (x < endRes - startRes)
502 if (hasHiddenColumns)
504 column = columnSelection.adjustForHiddenColumns(startRes + x);
505 if (column > row_annotations.length - 1)
512 column = startRes + x;
515 if ((row_annotations == null) || (row_annotations.length <= column)
516 || (row_annotations[column] == null))
528 g.setColor(Color.red);
530 if (columnSelection != null)
532 for (int n = 0; n < columnSelection.size(); n++)
534 int v = columnSelection.columnAt(n);
538 g.fillRect(x * charWidth, y, charWidth, charHeight);
543 if (!row.isValidStruc())
545 g.setColor(Color.orange);
546 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
547 charWidth, charHeight);
551 && row_annotations[column].displayCharacter != null
552 && (row_annotations[column].displayCharacter.length() > 0))
555 if (centreColLabels || scaleColLabel)
557 fmWidth = fm.charsWidth(
558 row_annotations[column].displayCharacter
560 row_annotations[column].displayCharacter.length());
564 // justify the label and scale to fit in column
565 if (fmWidth > charWidth)
567 // scale only if the current font isn't already small enough
568 fmScaling = charWidth;
569 fmScaling /= fmWidth;
570 g.setFont(ofont.deriveFont(AffineTransform
571 .getScaleInstance(fmScaling, 1.0)));
572 // and update the label's width to reflect the scaling.
580 .charWidth(row_annotations[column].displayCharacter
583 charOffset = (int) ((charWidth - fmWidth) / 2f);
585 if (row_annotations[column].colour == null)
586 g.setColor(Color.black);
588 g.setColor(row_annotations[column].colour);
590 if (column == 0 || row.graph > 0)
592 g.drawString(row_annotations[column].displayCharacter,
593 (x * charWidth) + charOffset, y + iconOffset);
595 else if (row_annotations[column - 1] == null
597 || !row_annotations[column].displayCharacter
598 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
599 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
601 g.drawString(row_annotations[column].displayCharacter
603 * charWidth + charOffset, y + iconOffset);
610 char ss = validRes ? row_annotations[column].secondaryStructure
615 // distinguish between forward/backward base-pairing
616 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
625 if ((row_annotations[column].displayCharacter.indexOf(']') > -1))
634 // distinguish between forward/backward base-pairing
635 if (row_annotations[column].displayCharacter.indexOf('}') > -1)
644 // distinguish between forward/backward base-pairing
645 if (row_annotations[column].displayCharacter.indexOf('<') > -1)
654 // distinguish between forward/backward base-pairing
655 if (row_annotations[column].displayCharacter.indexOf(ss+32) > -1)
665 if (!validRes || (ss != lastSS))
674 //System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
679 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
680 column, validRes, validEnd);
684 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
685 column, validRes, validEnd);
688 case '(': // Stem case for RNA secondary structure
689 case ')': // and opposite direction
690 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
691 column, validRes, validEnd);
753 Color nonCanColor= getNotCanonicalColor(lastSS);
754 drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
755 column, validRes, validEnd);
759 g.setColor(Color.gray);
760 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
776 lastSSX = (x * charWidth);
783 if (column >= row_annotations.length)
785 column = row_annotations.length - 1;
792 if ((row_annotations == null) || (row_annotations.length <= column)
793 || (row_annotations[column] == null))
809 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
810 column, validRes, validEnd);
814 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
815 column, validRes, validEnd);
818 case 'S': // Stem case for RNA secondary structure
820 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
821 column, validRes, validEnd);
880 //System.out.println(lastSS);
881 Color nonCanColor = getNotCanonicalColor(lastSS);
882 drawNotCanonicalAnnot(g,nonCanColor, row_annotations, lastSSX, x, y, iconOffset, startRes,
883 column, validRes, validEnd);
886 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
887 column, validRes, validEnd);
892 if (row.graph > 0 && row.graphHeight > 0)
894 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
896 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
898 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
899 float groupmax = -999999, groupmin = 9999999;
900 for (int gg = 0; gg < aa.length; gg++)
902 if (aa[gg].graphGroup != row.graphGroup)
909 aa[gg].visible = false;
911 if (aa[gg].graphMax > groupmax)
913 groupmax = aa[gg].graphMax;
915 if (aa[gg].graphMin < groupmin)
917 groupmin = aa[gg].graphMin;
921 for (int gg = 0; gg < aa.length; gg++)
923 if (aa[gg].graphGroup == row.graphGroup)
925 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes, endRes, y, groupmin,
926 groupmax, row.graphHeight);
930 graphGroupDrawn.set(row.graphGroup);
934 drawLineGraph(g, row, row_annotations, startRes, endRes, y, row.graphMin,
935 row.graphMax, row.graphHeight);
938 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
940 drawBarGraph(g, row, row_annotations, startRes, endRes,
941 row.graphMin, row.graphMax, y, renderHistogram,renderProfile,normaliseProfile);
945 if (clipst && !clipend)
949 }// end if_in_visible_region
950 if (row.graph > 0 && row.hasText)
966 System.err.println("Start clip at : " + yfrom + " (index " + f_i
971 System.err.println("End clip at : " + yto + " (index " + f_to
976 System.err.println("Annotation Rendering time:"
977 + (System.currentTimeMillis() - stime));
984 private final Color GLYPHLINE_COLOR = Color.gray;
986 private final Color SHEET_COLOUR = Color.green;
988 private final Color HELIX_COLOUR = Color.red;
990 private final Color STEM_COLOUR = Color.blue;
992 private Color sdNOTCANONICAL_COLOUR;
994 public void drawGlyphLine(Graphics g, Annotation[] row,
995 int lastSSX, int x, int y, int iconOffset, int startRes,
996 int column, boolean validRes, boolean validEnd)
998 g.setColor(GLYPHLINE_COLOR);
999 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1002 public void drawSheetAnnot(Graphics g, Annotation[] row,
1004 int lastSSX, int x, int y, int iconOffset, int startRes,
1005 int column, boolean validRes, boolean validEnd)
1007 g.setColor(SHEET_COLOUR);
1009 if (!validEnd || !validRes || row == null || row[column] == null
1010 || row[column].secondaryStructure != 'E')
1012 g.fillRect(lastSSX, y + 4 + iconOffset,
1013 (x * charWidth) - lastSSX - 4, 7);
1014 g.fillPolygon(new int[]
1015 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1017 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1022 g.fillRect(lastSSX, y + 4 + iconOffset,
1023 (x + 1) * charWidth - lastSSX, 7);
1028 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
1029 int x, int y, int iconOffset, int startRes, int column,
1030 boolean validRes, boolean validEnd)
1032 g.setColor(HELIX_COLOUR);
1034 int sCol = (lastSSX / charWidth) + startRes;
1036 int x2 = (x * charWidth);
1040 int ofs = charWidth / 2;
1041 // Off by 1 offset when drawing rects and ovals
1042 // to offscreen image on the MAC
1043 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1044 if (sCol == 0 || row[sCol - 1] == null
1045 || row[sCol - 1].secondaryStructure != 'H')
1050 // g.setColor(Color.orange);
1051 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1054 if (!validRes || row[column] == null
1055 || row[column].secondaryStructure != 'H')
1061 // g.setColor(Color.magenta);
1062 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1070 if (sCol == 0 || row[sCol - 1] == null
1071 || row[sCol - 1].secondaryStructure != 'H')
1073 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1074 x1 += charWidth / 2;
1077 if (!validRes || row[column] == null
1078 || row[column].secondaryStructure != 'H')
1080 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1082 x2 -= charWidth / 2;
1085 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1088 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1089 Annotation[] aa_annotations, int sRes, int eRes, int y,
1090 float min, float max, int graphHeight)
1092 if (sRes > aa_annotations.length)
1099 // Adjustment for fastpaint to left
1105 eRes = Math.min(eRes, aa_annotations.length);
1113 float range = max - min;
1118 y2 = y - (int) ((0 - min / range) * graphHeight);
1121 g.setColor(Color.gray);
1122 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1124 eRes = Math.min(eRes, aa_annotations.length);
1127 int aaMax = aa_annotations.length - 1;
1129 while (x < eRes - sRes)
1132 if (hasHiddenColumns)
1134 column = columnSelection.adjustForHiddenColumns(column);
1142 if (aa_annotations[column] == null
1143 || aa_annotations[column - 1] == null)
1149 if (aa_annotations[column].colour == null)
1150 g.setColor(Color.black);
1152 g.setColor(aa_annotations[column].colour);
1155 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1157 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1159 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1160 + charWidth / 2, y2);
1164 if (_aa.threshold != null)
1166 g.setColor(_aa.threshold.colour);
1167 Graphics2D g2 = (Graphics2D) g;
1168 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1169 BasicStroke.JOIN_ROUND, 3f, new float[]
1172 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1173 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1174 g2.setStroke(new BasicStroke());
1178 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1179 Annotation[] aa_annotations, int sRes, int eRes, float min,
1180 float max, int y, boolean renderHistogram,boolean renderProfile,boolean normaliseProfile)
1182 if (sRes > aa_annotations.length)
1186 Font ofont = g.getFont();
1187 eRes = Math.min(eRes, aa_annotations.length);
1189 int x = 0, y1 = y, y2 = y;
1191 float range = max - min;
1195 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1198 g.setColor(Color.gray);
1200 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1203 int aaMax = aa_annotations.length - 1;
1204 while (x < eRes - sRes)
1207 if (hasHiddenColumns)
1209 column = columnSelection.adjustForHiddenColumns(column);
1217 if (aa_annotations[column] == null)
1222 if (aa_annotations[column].colour == null)
1223 g.setColor(Color.black);
1225 g.setColor(aa_annotations[column].colour);
1228 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1230 if (renderHistogram)
1234 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1238 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1241 // draw profile if available
1245 int profl[] = getProfileFor(_aa, column);
1246 // just try to draw the logo if profl is not null
1247 if (profl != null && profl[1] != 0)
1249 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1250 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1257 * profl.length == 74 indicates that the profile of a secondary
1258 * structure conservation row was accesed. Therefore dc gets length 2,
1259 * to have space for a basepair instead of just a single nucleotide
1261 if (profl.length == 74)
1269 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1270 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1271 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1273 for (int c = 2; c < profl[0];)
1275 dc[0] = (char) profl[c++];
1277 if (_aa.label.startsWith("StrucConsensus"))
1279 dc[1] = (char) profl[c++];
1283 wdth /= fm.charsWidth(dc, 0, dc.length);
1287 scl = htn * scale * profl[c++];
1288 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1289 .getFontRenderContext());
1290 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1291 wdth, scl / lm.getAscent())));
1292 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1294 // Debug - render boxes around characters
1295 // g.setColor(Color.red);
1296 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1298 // g.setColor(profcolour.findColour(dc[0]).darker());
1299 g.setColor(profcolour.findColour(dc[0], column, null));
1301 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1302 .getBaselineIndex()]));
1304 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1312 if (_aa.threshold != null)
1314 g.setColor(_aa.threshold.colour);
1315 Graphics2D g2 = (Graphics2D) g;
1316 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1317 BasicStroke.JOIN_ROUND, 3f, new float[]
1320 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1322 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1323 g2.setStroke(new BasicStroke());
1327 // used by overview window
1328 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1329 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1331 eRes = Math.min(eRes, aa_annotations.length);
1332 g.setColor(Color.white);
1333 g.fillRect(0, 0, width, y);
1334 g.setColor(new Color(0, 0, 180));
1338 for (int j = sRes; j < eRes; j++)
1340 if (aa_annotations[j] != null)
1342 if (aa_annotations[j].colour == null)
1343 g.setColor(Color.black);
1345 g.setColor(aa_annotations[j].colour);
1347 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1353 g.fillRect(x, y - height, charWidth, height);
1360 Color getNotCanonicalColor(char lastss)
1366 return new Color(255,125,5);
1370 return new Color(245,115,10);
1374 return new Color(235,135,15);
1378 return new Color(225,105,20);
1382 return new Color(215,145,30);
1386 return new Color(205,95,35);
1390 return new Color(195,155,45);
1394 return new Color(185,85,55);
1398 return new Color(175,165,65);
1402 return new Color(170,75,75);
1406 return new Color(160,175,85);
1410 return new Color(150,65,95);
1414 return new Color(140,185,105);
1418 return new Color(130,55,110);
1422 return new Color(120,195,120);
1426 return new Color(110,45,130);
1430 return new Color(100,205,140);
1434 return new Color(90,35,150);
1438 return new Color(85,215,160);
1442 return new Color(75,25,170);
1446 return new Color(65,225,180);
1450 return new Color(55,15,185);
1454 return new Color(45,235,195);
1458 return new Color(35,5,205);
1462 return new Color(25,245,215);
1466 return new Color(15,0,225);
1470 return new Color(10,255,235);
1474 return new Color(5,150,245);
1478 return new Color(0,80,255);
1481 System.out.println("This is not a interaction : "+lastss);