2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
27 import java.awt.image.*;
\r
34 * @version $Revision$
\r
36 public class FeatureRenderer
\r
39 SequenceGroup currentSequenceGroup = null;
\r
40 SequenceGroup[] allGroups = null;
\r
43 float transparency = 1.0f;
\r
46 boolean drawText = true;
\r
48 // The following vector holds the features which are
\r
49 // to be added, in the correct order or rendering
\r
50 Vector featuresDisplayed;
\r
53 * Creates a new FeatureRenderer object.
\r
55 * @param av DOCUMENT ME!
\r
57 public FeatureRenderer(AlignViewport av)
\r
64 * This is used by the Molecule Viewer to get the accurate colour
\r
65 * of the rendered sequence
\r
68 public Color findFeatureColour(Color initialCol, SequenceI seq, int i)
\r
70 if(!av.showSequenceFeatures)
\r
74 bi = new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB);
\r
77 bi.getGraphics().setColor(initialCol);
\r
78 bi.getGraphics().fillRect(0, 0, 1, 1);
\r
79 drawSequence(bi.getGraphics(), seq, i, i, 0, 0, 1, 1);
\r
82 return new Color(bi.getRGB(0, 0));
\r
89 * @param g DOCUMENT ME!
\r
90 * @param seq DOCUMENT ME!
\r
91 * @param sg DOCUMENT ME!
\r
92 * @param start DOCUMENT ME!
\r
93 * @param end DOCUMENT ME!
\r
94 * @param x1 DOCUMENT ME!
\r
95 * @param y1 DOCUMENT ME!
\r
96 * @param width DOCUMENT ME!
\r
97 * @param height DOCUMENT ME!
\r
99 public void drawSequence(Graphics g, SequenceI seq,
\r
100 int start, int end, int x1, int y1, int width, int height)
\r
103 if (seq.getDatasetSequence().getSequenceFeatures() == null
\r
104 || seq.getDatasetSequence().getSequenceFeatures().size()==0)
\r
107 fm = g.getFontMetrics();
\r
109 if (transparency != 1)
\r
111 Graphics2D g2 = (Graphics2D) g;
\r
113 AlphaComposite.getInstance(
\r
114 AlphaComposite.SRC_OVER, transparency));
\r
118 SequenceFeature sf;
\r
119 if (featuresDisplayed == null)
\r
122 Enumeration e = featuresDisplayed.elements(), e2;
\r
124 // Loop through each visible feature
\r
125 while (e.hasMoreElements())
\r
128 type = e.nextElement().toString();
\r
129 e2 = seq.getDatasetSequence().getSequenceFeatures().elements();
\r
130 // loop through all features in sequence to find
\r
131 // current feature to render
\r
132 while (e2.hasMoreElements())
\r
135 sf = (SequenceFeature) e2.nextElement();
\r
136 if (!type.equals(sf.getType()))
\r
139 if (sf.getBegin() > seq.getEnd())
\r
142 if (type.equals("disulfide bond"))
\r
145 renderFeature(g, seq,
\r
146 seq.findIndex(sf.getBegin()) - 1,
\r
147 seq.findIndex(sf.getBegin()) - 1,
\r
148 type, start, end, x1, y1, width, height);
\r
149 renderFeature(g, seq,
\r
150 seq.findIndex(sf.getEnd()) - 1,
\r
151 seq.findIndex(sf.getEnd()) - 1,
\r
152 type, start, end, x1, y1, width, height);
\r
156 renderFeature(g, seq,
\r
157 seq.findIndex(sf.getBegin()) - 1,
\r
158 seq.findIndex(sf.getEnd()) - 1,
\r
159 type, start, end, x1, y1, width, height);
\r
163 if(transparency!=1.0f)
\r
165 Graphics2D g2 = (Graphics2D) g;
\r
167 AlphaComposite.getInstance(
\r
168 AlphaComposite.SRC_OVER, 1.0f));
\r
173 void renderFeature(Graphics g, SequenceI seq,
\r
174 int fstart, int fend, String type, int start, int end, int x1, int y1, int width, int height)
\r
177 if (((fstart <= end) && (fend >= start)))
\r
179 if (fstart < start)
\r
180 { // fix for if the feature we have starts before the sequence start,
\r
181 fstart = start; // but the feature end is still valid!!
\r
188 for (int i = fstart; i <= fend; i++)
\r
190 char s = seq.getSequence().charAt(i);
\r
192 if (jalview.util.Comparison.isGap(s))
\r
197 g.setColor(getColour(type));
\r
199 g.fillRect( (i - start) * width, y1, width, height);
\r
203 g.setColor(Color.white);
\r
204 charOffset = (width - fm.charWidth(s)) / 2;
\r
205 g.drawString(String.valueOf(s),
\r
206 charOffset + x1 + (width * (i - start)),
\r
207 (y1 + height) - height / 5); //pady = height / 5;
\r
213 void findAllFeatures()
\r
215 Vector features = new Vector();
\r
216 SequenceFeature sf;
\r
217 featuresDisplayed = new Vector();
\r
219 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
221 features = av.alignment.getSequenceAt(i).getDatasetSequence().
\r
222 getSequenceFeatures();
\r
223 if (features == null)
\r
226 e = features.elements();
\r
227 while (e.hasMoreElements())
\r
229 sf = (SequenceFeature) e.nextElement();
\r
230 if (!featuresDisplayed.contains(sf.getType()))
\r
232 featuresDisplayed.addElement(sf.getType());
\r
238 public Color getColour(String featureType)
\r
240 return (Color)featureColours.get(featureType);
\r
243 public void setColour(String featureType, Color col)
\r
245 featureColours.put(featureType, col);
\r
248 public void setTransparency(float value)
\r
250 transparency = value;
\r
253 public float getTransparency()
\r
255 return transparency;
\r
258 public void setFeaturePriority(Object [][] data)
\r
260 // The feature table will display high priority
\r
261 // features at the top, but theses are the ones
\r
262 // we need to render last, so invert the data
\r
263 featuresDisplayed = new Vector();
\r
264 for(int i=data.length-1; i>-1; i--)
\r
266 String type = data[i][0].toString();
\r
267 setColour(type, (Color)data[i][1]);
\r
268 if( ((Boolean)data[i][2]).booleanValue() )
\r
269 featuresDisplayed.addElement(type);
\r
273 Hashtable featureColours = new Hashtable();
\r
276 featureColours.put("active site", new Color(255, 75, 0));
\r
277 featureColours.put("binding site", new Color(245, 85, 0));
\r
278 featureColours.put("calcium-binding region", new Color(235, 95, 0));
\r
279 featureColours.put("chain", new Color(225, 105, 0));
\r
280 featureColours.put("coiled-coil region", new Color(215, 115, 0));
\r
281 featureColours.put("compositionally biased region", new Color(205, 125, 0));
\r
282 featureColours.put("cross-link", new Color(195, 135, 0));
\r
283 featureColours.put("disulfide bond", new Color(230,230,0));
\r
284 featureColours.put("DNA-binding region", new Color(175, 155, 0));
\r
285 featureColours.put("domain", new Color(165, 165, 0));
\r
286 featureColours.put("glycosylation site", new Color(155, 175, 0));
\r
287 featureColours.put("helix", new Color(145, 185, 0));
\r
288 featureColours.put("initiator methionine", new Color(135, 195, 5));
\r
289 featureColours.put("lipid moiety-binding region", new Color(125, 205, 15));
\r
290 featureColours.put("metal ion-binding site", new Color(115, 215, 25));
\r
291 featureColours.put("modified residue", new Color(105, 225, 35));
\r
292 featureColours.put("mutagenesis site", new Color(95, 235, 45));
\r
293 featureColours.put("non-consecutive residues", new Color(85, 245, 55));
\r
294 featureColours.put("non-terminal residue", new Color(75, 255, 65));
\r
295 featureColours.put("nucleotide phosphate-binding region",new Color(65, 245, 75));
\r
296 featureColours.put("peptide", new Color(55, 235, 85));
\r
297 featureColours.put("propeptide", new Color(45, 225, 95));
\r
298 featureColours.put("region of interest", new Color(35, 215, 105));
\r
299 featureColours.put("repeat", new Color(25, 205, 115));
\r
300 featureColours.put("selenocysteine", new Color(15, 195, 125));
\r
301 featureColours.put("sequence conflict", new Color(5, 185, 135));
\r
302 featureColours.put("sequence variant", new Color(0, 175, 145));
\r
303 featureColours.put("short sequence motif", new Color(0, 165, 155));
\r
304 featureColours.put("signal peptide", new Color(0, 155, 165));
\r
305 featureColours.put("site", new Color(0, 145, 175));
\r
306 featureColours.put("splice variant", new Color(0, 135, 185));
\r
307 featureColours.put("strand", new Color(0, 125, 195));
\r
308 featureColours.put("topological domain", new Color(0, 115, 205));
\r
309 featureColours.put("transit peptide", new Color(0, 105, 215));
\r
310 featureColours.put("transmembrane region", new Color(0, 95, 225));
\r
311 featureColours.put("turn", new Color(0, 85, 235));
\r
312 featureColours.put("unsure residue", new Color(0, 75, 245));
\r
313 featureColours.put("zinc finger region", new Color(0, 65, 255));
\r