2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.
23 import jalview.api.AlignmentColsCollectionI;
24 import jalview.api.AlignmentRowsCollectionI;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.SequenceI;
28 import jalview.renderer.seqfeatures.FeatureColourFinder;
29 import jalview.viewmodel.OverviewDimensions;
31 import java.awt.Color;
32 import java.awt.Graphics;
33 import java.awt.image.BufferedImage;
35 public class OverviewRenderer
37 private FeatureColourFinder finder;
39 private SequenceRenderer sr;
42 private BufferedImage miniMe;
44 // raw number of pixels to allocate to each column
45 private float pixelsPerCol;
47 // raw number of pixels to allocate to each row
48 private float pixelsPerSeq;
50 public OverviewRenderer(SequenceRenderer seqRenderer,
51 FeatureColourFinder colfinder, OverviewDimensions od)
56 pixelsPerCol = od.getPixelsPerCol();
57 pixelsPerSeq = od.getPixelsPerSeq();
58 miniMe = new BufferedImage(od.getWidth(), od.getHeight(),
59 BufferedImage.TYPE_INT_RGB);
63 * Draw alignment rows and columns onto an image
66 * Iterator over rows to be drawn
68 * Iterator over columns to be drawn
69 * @return image containing the drawing
71 public BufferedImage draw(AlignmentRowsCollectionI rows,
72 AlignmentColsCollectionI cols)
74 int rgbcolor = Color.white.getRGB();
77 for (int alignmentRow : rows)
79 // get details of this alignment row
80 boolean hidden = rows.isHidden(alignmentRow);
81 SequenceI seq = rows.getSequence(alignmentRow);
83 // calculate where this row extends to in pixels
84 int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1,
85 miniMe.getHeight() - 1);
89 for (int alignmentCol : cols)
91 // calculate where this column extends to in pixels
92 int endCol = Math.min(
93 Math.round((colIndex + 1) * pixelsPerCol) - 1,
94 miniMe.getWidth() - 1);
96 // determine the colour based on the sequence and column position
97 rgbcolor = getColumnColourFromSequence(seq,
98 hidden || cols.isHidden(alignmentCol), alignmentCol, finder);
100 // fill in the appropriate number of pixels
101 for (int row = pixelRow; row <= endRow; ++row)
103 for (int col = pixelCol; col <= endCol; ++col)
105 miniMe.setRGB(col, row, rgbcolor);
109 pixelCol = endCol + 1;
112 pixelRow = endRow + 1;
119 * Find the colour of a sequence at a specified column position
121 private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq,
122 boolean isHidden, int lastcol, FeatureColourFinder finder)
124 Color color = Color.white;
126 if ((seq != null) && (seq.getLength() > lastcol))
128 color = sr.getResidueColour(seq, lastcol, finder);
133 color = color.darker().darker();
136 return color.getRGB();
139 public void drawGraph(Graphics g, AlignmentAnnotation _aa, int charWidth,
140 int y, AlignmentColsCollectionI cols)
142 Annotation[] aa_annotations = _aa.annotations;
143 g.setColor(Color.white);
144 g.fillRect(0, 0, miniMe.getWidth(), y);
145 // g.setColor(new Color(0, 0, 180));
151 for (int alignmentCol : cols)
153 int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1,
154 miniMe.getWidth() - 1);
156 if (alignmentCol < aa_annotations.length
157 && aa_annotations[alignmentCol] != null)
159 if (aa_annotations[alignmentCol].colour == null)
161 g.setColor(Color.black);
165 g.setColor(aa_annotations[alignmentCol].colour);
168 height = (int) ((aa_annotations[alignmentCol].value / _aa.graphMax) * y);
174 g.fillRect(pixelCol, y - height, endCol - pixelCol + 1, height);
176 pixelCol = endCol + 1;