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
32 * @version $Revision$
\r
34 public class FeatureRenderer
\r
37 SequenceGroup currentSequenceGroup = null;
\r
38 SequenceGroup[] allGroups = null;
\r
41 float transparency = 1.0f;
\r
43 // The following vector holds the features which are
\r
44 // to be added, in the correct order or rendering
\r
45 Vector featuresDisplayed;
\r
48 * Creates a new FeatureRenderer object.
\r
50 * @param av DOCUMENT ME!
\r
52 public FeatureRenderer(AlignViewport av)
\r
61 * @param g DOCUMENT ME!
\r
62 * @param seq DOCUMENT ME!
\r
63 * @param sg DOCUMENT ME!
\r
64 * @param start DOCUMENT ME!
\r
65 * @param end DOCUMENT ME!
\r
66 * @param x1 DOCUMENT ME!
\r
67 * @param y1 DOCUMENT ME!
\r
68 * @param width DOCUMENT ME!
\r
69 * @param height DOCUMENT ME!
\r
71 public void drawSequence(Graphics g1, SequenceI seq, SequenceGroup[] sg,
\r
72 int start, int end, int x1, int y1, int width, int height)
\r
75 if(seq.getSequenceFeatures()==null)
\r
78 Enumeration e = null, e2;
\r
80 if(featuresDisplayed!=null)
\r
81 e = featuresDisplayed.elements();
\r
83 e = seq.getSequenceFeatures().elements();
\r
85 Graphics2D g = (Graphics2D)g1;
\r
87 AlphaComposite.getInstance(
\r
88 AlphaComposite.SRC_OVER,transparency));
\r
90 while (e.hasMoreElements())
\r
92 SequenceFeature sf=null;
\r
93 if(featuresDisplayed!=null)
\r
95 e2 = seq.getSequenceFeatures().elements();
\r
96 type = e.nextElement().toString();
\r
97 while(e2.hasMoreElements())
\r
99 sf = (SequenceFeature) e2.nextElement();
\r
100 if(sf.getType().equals(type))
\r
108 sf = (SequenceFeature) e.nextElement();
\r
109 type = sf.getType();
\r
116 if (sf.getBegin() > seq.getEnd())
\r
121 int fstart = seq.findIndex(sf.getBegin()) - 1;
\r
122 int fend = seq.findIndex(sf.getEnd()) - 1;
\r
124 if (((fstart <= end) && (fend >= start)))
\r
126 if (fstart < start)
\r
127 { // fix for if the feature we have starts before the sequence start,
\r
128 fstart = start; // but the feature end is still valid!!
\r
136 if (fstart == fend)
\r
138 g.setColor(getColour(type));
\r
139 g.fillRoundRect((fstart - start) * width, y1, width,
\r
141 g.setColor(Color.white);
\r
143 char s = seq.getSequence().charAt(fstart);
\r
144 FontMetrics fm = g.getFontMetrics();
\r
145 int charOffset = (width - fm.charWidth(s)) / 2;
\r
146 int pady = height / 5;
\r
147 g.drawString(String.valueOf(s),
\r
148 charOffset + x1 + (width * (fstart - start)),
\r
149 (y1 + height) - pady);
\r
153 for (int i = fstart; i <= fend; i++)
\r
155 char s = seq.getSequence().charAt(i);
\r
157 if (jalview.util.Comparison.isGap(s))
\r
162 g.setColor(getColour(type));
\r
163 g.fillRect((i - start) * width, y1, width, height);
\r
165 g.setColor(Color.white);
\r
167 FontMetrics fm = g.getFontMetrics();
\r
168 int charOffset = (width - fm.charWidth(s)) / 2;
\r
169 int pady = height / 5;
\r
170 g.drawString(String.valueOf(s),
\r
171 charOffset + x1 + (width * (i - start)),
\r
172 (y1 + height) - pady);
\r
178 AlphaComposite.getInstance(
\r
179 AlphaComposite.SRC_OVER,1.0f));
\r
183 public Color getColour(String featureType)
\r
185 return (Color)featureColours.get(featureType);
\r
188 public void setColour(String featureType, Color col)
\r
190 featureColours.put(featureType, col);
\r
193 public void setTransparency(float value)
\r
195 transparency = value;
\r
198 public float getTransparency()
\r
200 return transparency;
\r
203 public void setFeaturePriority(Object [][] data)
\r
205 // The feature table will display high priority
\r
206 // features at the top, but theses are the ones
\r
207 // we need to render last, so invert the data
\r
208 featuresDisplayed = new Vector();
\r
209 for(int i=data.length-1; i>-1; i--)
\r
211 String type = data[i][0].toString();
\r
212 setColour(type, (Color)data[i][1]);
\r
213 if( ((Boolean)data[i][2]).booleanValue() )
\r
214 featuresDisplayed.addElement(type);
\r
218 Hashtable featureColours = new Hashtable();
\r
221 featureColours.put("active site", new Color(255, 75, 0));
\r
222 featureColours.put("binding site", new Color(245, 85, 0));
\r
223 featureColours.put("calcium-binding region", new Color(235, 95, 0));
\r
224 featureColours.put("chain", new Color(225, 105, 0));
\r
225 featureColours.put("coiled-coil region", new Color(215, 115, 0));
\r
226 featureColours.put("compositionally biased region", new Color(205, 125, 0));
\r
227 featureColours.put("cross-link", new Color(195, 135, 0));
\r
228 featureColours.put("disulfide bond", new Color(185, 145, 0));
\r
229 featureColours.put("DNA-binding region", new Color(175, 155, 0));
\r
230 featureColours.put("domain", new Color(165, 165, 0));
\r
231 featureColours.put("glycosylation site", new Color(155, 175, 0));
\r
232 featureColours.put("helix", new Color(145, 185, 0));
\r
233 featureColours.put("initiator methionine", new Color(135, 195, 5));
\r
234 featureColours.put("lipid moiety-binding region", new Color(125, 205, 15));
\r
235 featureColours.put("metal ion-binding site", new Color(115, 215, 25));
\r
236 featureColours.put("modified residue", new Color(105, 225, 35));
\r
237 featureColours.put("mutagenesis site", new Color(95, 235, 45));
\r
238 featureColours.put("non-consecutive residues", new Color(85, 245, 55));
\r
239 featureColours.put("non-terminal residue", new Color(75, 255, 65));
\r
240 featureColours.put("nucleotide phosphate-binding region",
\r
241 new Color(65, 245, 75));
\r
242 featureColours.put("peptide", new Color(55, 235, 85));
\r
243 featureColours.put("propeptide", new Color(45, 225, 95));
\r
244 featureColours.put("region of interest", new Color(35, 215, 105));
\r
245 featureColours.put("repeat", new Color(25, 205, 115));
\r
246 featureColours.put("selenocysteine", new Color(15, 195, 125));
\r
247 featureColours.put("sequence conflict", new Color(5, 185, 135));
\r
248 featureColours.put("sequence variant", new Color(0, 175, 145));
\r
249 featureColours.put("short sequence motif", new Color(0, 165, 155));
\r
250 featureColours.put("signal peptide", new Color(0, 155, 165));
\r
251 featureColours.put("site", new Color(0, 145, 175));
\r
252 featureColours.put("splice variant", new Color(0, 135, 185));
\r
253 featureColours.put("strand", new Color(0, 125, 195));
\r
254 featureColours.put("topological domain", new Color(0, 115, 205));
\r
255 featureColours.put("transit peptide", new Color(0, 105, 215));
\r
256 featureColours.put("transmembrane region", new Color(0, 95, 225));
\r
257 featureColours.put("turn", new Color(0, 85, 235));
\r
258 featureColours.put("unsure residue", new Color(0, 75, 245));
\r
259 featureColours.put("zinc finger region", new Color(0, 65, 255));
\r