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
20 package jalview.gui;
\r
23 import jalview.analysis.*;
\r
24 import jalview.analysis.NJTree;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.schemes.*;
\r
28 import jalview.bin.Cache;
\r
30 public class AlignViewport
\r
38 boolean showFullId = false;
\r
39 boolean showText=true;
\r
40 boolean showColourText=false;
\r
41 boolean showBoxes=true;
\r
42 boolean wrapAlignment=false;
\r
43 boolean renderGaps = true;
\r
44 boolean showSequenceFeatures = false;
\r
45 boolean showAnnotation = true;
\r
46 boolean showConservation = true;
\r
47 boolean showQuality = true;
\r
48 boolean showIdentity = true;
\r
50 boolean colourAppliesToAllGroups = true;
\r
51 ColourSchemeI globalColourScheme = null;
\r
52 boolean conservationColourSelected = false;
\r
53 boolean abovePIDThreshold = false;
\r
55 SequenceGroup selectionGroup = new SequenceGroup();
\r
63 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
64 AlignmentI alignment;
\r
66 ColumnSelection colSel = new ColumnSelection();
\r
71 NJTree currentTree = null;
\r
73 boolean scaleAboveWrapped = false;
\r
74 boolean scaleLeftWrapped = true;
\r
75 boolean scaleRightWrapped = true;
\r
78 public AlignViewport(AlignmentI al)
\r
82 this.endRes = al.getWidth()-1;
\r
84 this.endSeq = al.getHeight()-1;
\r
86 updateFromPreferences();
\r
90 public void updateFromPreferences()
\r
92 showFullId = Preferences.showFullId;
\r
93 showAnnotation = Preferences.showAnnotation;
\r
94 showConservation = Preferences.showConservation;
\r
95 showQuality = Preferences.showQuality;
\r
96 showIdentity = Preferences.showIdentity;
\r
97 showFullId = Preferences.showFullId;
\r
98 String fontName = Preferences.fontName;
\r
99 String fontStyle = Preferences.fontStyle;
\r
100 String fontSize = Cache.getProperty("FONT_SIZE");
\r
101 if (fontName != null && fontStyle != null && fontSize != null)
\r
104 if(fontStyle.equals("bold"))
\r
106 else if(fontStyle.equals("italic"))
\r
108 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
\r
113 alignment.setGapCharacter(Preferences.gapSymbol);
\r
115 // We must set conservation and consensus before setting colour,
\r
116 // as Blosum and Clustal require this to be done
\r
117 updateConservation();
\r
119 if(Preferences.defaultColour!=null)
\r
121 globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour);
\r
122 if(globalColourScheme instanceof UserColourScheme)
\r
124 globalColourScheme = UserDefinedColours.loadDefaultColours();
\r
126 if(globalColourScheme!=null)
\r
127 globalColourScheme.setConsensus( vconsensus );
\r
132 public void showSequenceFeatures(boolean b)
\r
134 showSequenceFeatures = b;
\r
137 public Vector vconsensus;
\r
138 AlignmentAnnotation consensus;
\r
139 AlignmentAnnotation conservation;
\r
140 AlignmentAnnotation quality;
\r
142 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
144 public void updateConservation()
\r
146 Conservation cons = new jalview.analysis.Conservation("All",
\r
147 jalview.schemes.ResidueProperties.propHash, 3,
\r
148 alignment.getSequences(), 0,
\r
149 alignment.getWidth()-1);
\r
151 cons.verdict(false, ConsPercGaps);
\r
152 cons.findQuality();
\r
153 int alWidth = alignment.getWidth();
\r
154 Annotation [] annotations = new Annotation[alWidth];
\r
155 Annotation [] qannotations = new Annotation[alWidth];
\r
156 String sequence = cons.getConsSequence().getSequence();
\r
157 float minR,minG,minB, maxR,maxG,maxB;
\r
161 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
164 float qmin = cons.qualityRange[0].floatValue();
\r
165 float qmax = cons.qualityRange[1].floatValue();
\r
167 for (int i = 0; i < alWidth; i++)
\r
172 value = Integer.parseInt(sequence.charAt(i) + "");
\r
174 catch (Exception ex)
\r
176 if (sequence.charAt(i) == '*') value = 11;
\r
177 if (sequence.charAt(i) == '+') value = 10;
\r
179 float vprop = value-min;
\r
181 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
182 "", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
184 value = ((Double) cons.quality.get(i)).floatValue();
\r
185 vprop = value - qmin;
\r
187 qannotations[i] = new Annotation(" ",
\r
188 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
191 if(conservation==null)
\r
193 conservation = new AlignmentAnnotation("Conservation",
\r
194 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
196 0f, // cons.qualityRange[0].floatValue(),
\r
197 11f, // cons.qualityRange[1].floatValue()
\r
199 if(showConservation)
\r
200 alignment.addAnnotation(conservation);
\r
201 quality = new AlignmentAnnotation("Quality",
\r
202 "Alignment Quality based on Blosum62 scores",
\r
204 cons.qualityRange[0].floatValue(),
\r
205 cons.qualityRange[1].floatValue(),
\r
208 alignment.addAnnotation(quality);
\r
211 conservation.annotations = annotations;
\r
212 quality.annotations = qannotations;
\r
213 quality.graphMax = cons.qualityRange[1].floatValue();
\r
219 public void updateConsensus()
\r
221 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
223 // this routine prevents vconsensus becoming a new object each time
\r
224 // consenus is calculated. Important for speed of Blosum62
\r
225 // and PID colouring of alignment
\r
226 if(vconsensus == null)
\r
227 vconsensus = alignment.getAAFrequency();
\r
230 Vector temp = alignment.getAAFrequency();
\r
231 vconsensus.clear();
\r
232 Enumeration e = temp.elements();
\r
233 while(e.hasMoreElements())
\r
235 vconsensus.add(e.nextElement());
\r
238 Hashtable hash = null;
\r
239 for (int i = 0; i<alignment.getWidth(); i++)
\r
241 hash = (Hashtable) vconsensus.elementAt(i);
\r
242 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
243 value /= Float.parseFloat(hash.get("size").toString());
\r
246 String maxRes = hash.get("maxResidue")+" ";
\r
247 String mouseOver = hash.get("maxResidue")+" ";
\r
248 if(maxRes.length()>2)
\r
250 mouseOver = "["+maxRes+"] ";
\r
254 mouseOver += (int)value+"%";
\r
255 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
259 if(consensus==null)
\r
261 consensus = new AlignmentAnnotation("Consensus",
\r
262 "PID", annotations, 0f, 100f, 1);
\r
264 alignment.addAnnotation(consensus);
\r
267 consensus.annotations = annotations;
\r
272 public SequenceGroup getSelectionGroup()
\r
274 return selectionGroup;
\r
277 public void setSelectionGroup(SequenceGroup sg)
\r
279 selectionGroup = sg;
\r
283 public boolean getConservationSelected()
\r
285 return conservationColourSelected;
\r
288 public void setConservationSelected(boolean b)
\r
290 conservationColourSelected = b;
\r
293 public boolean getAbovePIDThreshold()
\r
295 return abovePIDThreshold;
\r
298 public void setAbovePIDThreshold(boolean b)
\r
300 abovePIDThreshold = b;
\r
303 public int getStartRes() {
\r
307 public int getEndRes() {
\r
311 public int getStartSeq() {
\r
315 public void setGlobalColourScheme(ColourSchemeI cs)
\r
317 globalColourScheme = cs;
\r
320 public ColourSchemeI getGlobalColourScheme()
\r
322 return globalColourScheme;
\r
326 public void setStartRes(int res) {
\r
327 this.startRes = res;
\r
329 public void setStartSeq(int seq) {
\r
330 this.startSeq = seq;
\r
332 public void setEndRes(int res) {
\r
333 if (res > alignment.getWidth()-1) {
\r
334 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
335 res = alignment.getWidth()-1;
\r
342 public void setEndSeq(int seq) {
\r
343 if (seq > alignment.getHeight()) {
\r
344 seq = alignment.getHeight();
\r
351 public int getEndSeq() {
\r
355 public void setFont(Font f) {
\r
357 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
359 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
360 setCharHeight(fm.getHeight());
\r
361 setCharWidth(fm.charWidth('M'));
\r
364 public Font getFont() {
\r
367 public void setCharWidth(int w) {
\r
368 this.charWidth = w;
\r
370 public int getCharWidth() {
\r
373 public void setCharHeight(int h) {
\r
374 this.charHeight = h;
\r
376 public int getCharHeight() {
\r
379 public void setChunkWidth(int w) {
\r
380 this.chunkWidth = w;
\r
382 public int getChunkWidth() {
\r
385 public void setChunkHeight(int h) {
\r
386 this.chunkHeight = h;
\r
388 public int getChunkHeight() {
\r
389 return chunkHeight;
\r
391 public AlignmentI getAlignment() {
\r
394 public void setAlignment(AlignmentI align) {
\r
395 this.alignment = align;
\r
398 public void setWrapAlignment(boolean state) {
\r
399 wrapAlignment = state;
\r
401 public void setShowText(boolean state) {
\r
405 public void setRenderGaps(boolean state){
\r
406 renderGaps = state;
\r
410 public boolean getColourText()
\r
412 return showColourText;
\r
415 public void setColourText(boolean state)
\r
417 showColourText = state;
\r
420 public void setShowBoxes(boolean state) {
\r
424 public boolean getWrapAlignment() {
\r
425 return wrapAlignment;
\r
427 public boolean getShowText() {
\r
430 public boolean getShowBoxes() {
\r
434 public char getGapCharacter() {
\r
435 return getAlignment().getGapCharacter();
\r
437 public void setGapCharacter(char gap) {
\r
438 if (getAlignment() != null) {
\r
439 getAlignment().setGapCharacter(gap);
\r
442 public void setThreshold(int thresh) {
\r
443 threshold = thresh;
\r
445 public int getThreshold() {
\r
448 public void setIncrement(int inc) {
\r
451 public int getIncrement() {
\r
454 public int getIndex(int y) {
\r
456 int starty = getStartSeq();
\r
457 int endy = getEndSeq();
\r
459 for (int i = starty; i <= endy; i++) {
\r
460 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
461 int y2 = y1 + getCharHeight();
\r
463 if (y>=y1 && y <=y2) {
\r
474 public ColumnSelection getColumnSelection() {
\r
478 public void resetSeqLimits(int height) {
\r
479 setEndSeq(height/getCharHeight());
\r
481 public void setCurrentTree(NJTree tree) {
\r
482 currentTree = tree;
\r
484 public NJTree getCurrentTree() {
\r
485 return currentTree;
\r
488 public void setColourAppliesToAllGroups(boolean b)
\r
489 { colourAppliesToAllGroups = b; }
\r
491 public boolean getColourAppliesToAllGroups()
\r
492 {return colourAppliesToAllGroups; }
\r
494 public boolean getShowFullId()
\r
499 public void setShowFullId(boolean b)
\r
504 public boolean getShowAnnotation()
\r
505 { return showAnnotation; }
\r
507 public void setShowAnnotation(boolean b)
\r
508 { showAnnotation = b; }
\r
510 public boolean getScaleAboveWrapped()
\r
511 { return scaleAboveWrapped;}
\r
513 public boolean getScaleLeftWrapped()
\r
514 { return scaleLeftWrapped; }
\r
516 public boolean getScaleRightWrapped()
\r
517 { return scaleRightWrapped; }
\r
519 public void setScaleAboveWrapped(boolean b)
\r
520 { scaleAboveWrapped = b; }
\r
522 public void setScaleLeftWrapped(boolean b)
\r
523 { scaleLeftWrapped = b; }
\r
525 public void setScaleRightWrapped(boolean b)
\r
526 { scaleRightWrapped = b; }
\r
527 // JBPNote Prolly only need this in the applet version.
\r
528 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
529 public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
530 changeSupport.addPropertyChangeListener(listener);
\r
533 public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
534 changeSupport.removePropertyChangeListener(listener);
\r
536 public void firePropertyChange(String prop, Object oldvalue, Object newvalue) {
\r
537 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r