4 import jalview.analysis.*;
\r
5 import jalview.analysis.NJTree;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.schemes.*;
\r
9 import jalview.bin.Cache;
\r
11 public class AlignViewport
\r
19 boolean showFullId = false;
\r
20 boolean showText=true;
\r
21 boolean showColourText=false;
\r
22 boolean showBoxes=true;
\r
23 boolean wrapAlignment=false;
\r
24 boolean renderGaps = true;
\r
25 boolean showSequenceFeatures = false;
\r
26 boolean showAnnotation = true;
\r
27 boolean showConservation = true;
\r
28 boolean showQuality = true;
\r
29 boolean showIdentity = true;
\r
31 boolean colourAppliesToAllGroups = true;
\r
32 ColourSchemeI globalColourScheme = null;
\r
33 boolean conservationColourSelected = false;
\r
34 boolean abovePIDThreshold = false;
\r
36 SequenceGroup selectionGroup = new SequenceGroup();
\r
44 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
45 AlignmentI alignment;
\r
47 ColumnSelection colSel = new ColumnSelection();
\r
52 NJTree currentTree = null;
\r
54 boolean scaleAboveWrapped = false;
\r
55 boolean scaleLeftWrapped = true;
\r
56 boolean scaleRightWrapped = true;
\r
59 public AlignViewport(AlignmentI al)
\r
63 this.endRes = al.getWidth()-1;
\r
65 this.endSeq = al.getHeight()-1;
\r
67 updateFromPreferences();
\r
71 public void updateFromPreferences()
\r
73 showFullId = Preferences.showFullId;
\r
74 showAnnotation = Preferences.showAnnotation;
\r
75 showConservation = Preferences.showConservation;
\r
76 showQuality = Preferences.showQuality;
\r
77 showIdentity = Preferences.showIdentity;
\r
78 showFullId = Preferences.showFullId;
\r
79 String fontName = Preferences.fontName;
\r
80 String fontStyle = Preferences.fontStyle;
\r
81 String fontSize = Cache.getProperty("FONT_SIZE");
\r
82 if (fontName != null && fontStyle != null && fontSize != null)
\r
85 if(fontStyle.equals("bold"))
\r
87 else if(fontStyle.equals("italic"))
\r
89 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
\r
94 alignment.setGapCharacter(Preferences.gapSymbol);
\r
96 // We must set conservation and consensus before setting colour,
\r
97 // as Blosum and Clustal require this to be done
\r
98 updateConservation();
\r
100 if(Preferences.defaultColour!=null)
\r
102 globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour);
\r
103 if(globalColourScheme instanceof UserColourScheme)
\r
105 globalColourScheme = UserDefinedColours.loadDefaultColours();
\r
107 if(globalColourScheme!=null)
\r
108 globalColourScheme.setConsensus( vconsensus );
\r
113 public void showSequenceFeatures(boolean b)
\r
115 showSequenceFeatures = b;
\r
118 public Vector vconsensus;
\r
119 AlignmentAnnotation consensus;
\r
120 AlignmentAnnotation conservation;
\r
121 AlignmentAnnotation quality;
\r
123 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
125 public void updateConservation()
\r
127 Conservation cons = new jalview.analysis.Conservation("All",
\r
128 jalview.schemes.ResidueProperties.propHash, 3,
\r
129 alignment.getSequences(), 0,
\r
130 alignment.getWidth()-1);
\r
132 cons.verdict(false, ConsPercGaps);
\r
133 cons.findQuality();
\r
134 int alWidth = alignment.getWidth();
\r
135 Annotation [] annotations = new Annotation[alWidth];
\r
136 Annotation [] qannotations = new Annotation[alWidth];
\r
137 String sequence = cons.getConsSequence().getSequence();
\r
138 float minR,minG,minB, maxR,maxG,maxB;
\r
142 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
145 float qmin = cons.qualityRange[0].floatValue();
\r
146 float qmax = cons.qualityRange[1].floatValue();
\r
148 for (int i = 0; i < alWidth; i++)
\r
153 value = Integer.parseInt(sequence.charAt(i) + "");
\r
155 catch (Exception ex)
\r
157 if (sequence.charAt(i) == '*') value = 11;
\r
158 if (sequence.charAt(i) == '+') value = 10;
\r
160 float vprop = value-min;
\r
162 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
163 "", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
165 value = ((Double) cons.quality.get(i)).floatValue();
\r
166 vprop = value - qmin;
\r
168 qannotations[i] = new Annotation(" ",
\r
169 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
172 if(conservation==null)
\r
174 conservation = new AlignmentAnnotation("Conservation",
\r
175 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
177 0f, // cons.qualityRange[0].floatValue(),
\r
178 11f, // cons.qualityRange[1].floatValue()
\r
180 if(showConservation)
\r
181 alignment.addAnnotation(conservation);
\r
182 quality = new AlignmentAnnotation("Quality",
\r
183 "Alignment Quality based on Blosum62 scores",
\r
185 cons.qualityRange[0].floatValue(),
\r
186 cons.qualityRange[1].floatValue(),
\r
189 alignment.addAnnotation(quality);
\r
192 conservation.annotations = annotations;
\r
193 quality.annotations = qannotations;
\r
194 quality.graphMax = cons.qualityRange[1].floatValue();
\r
200 public void updateConsensus()
\r
202 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
204 // this routine prevents vconsensus becoming a new object each time
\r
205 // consenus is calculated. Important for speed of Blosum62
\r
206 // and PID colouring of alignment
\r
207 if(vconsensus == null)
\r
208 vconsensus = alignment.getAAFrequency();
\r
211 Vector temp = alignment.getAAFrequency();
\r
212 vconsensus.clear();
\r
213 Enumeration e = temp.elements();
\r
214 while(e.hasMoreElements())
\r
216 vconsensus.add(e.nextElement());
\r
219 Hashtable hash = null;
\r
220 for (int i = 0; i<alignment.getWidth(); i++)
\r
222 hash = (Hashtable) vconsensus.elementAt(i);
\r
223 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
224 value /= Float.parseFloat(hash.get("size").toString());
\r
227 String maxRes = hash.get("maxResidue")+" ";
\r
228 String mouseOver = hash.get("maxResidue")+" ";
\r
229 if(maxRes.length()>2)
\r
231 mouseOver = "["+maxRes+"] ";
\r
235 mouseOver += (int)value+"%";
\r
236 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
240 if(consensus==null)
\r
242 consensus = new AlignmentAnnotation("Consensus",
\r
243 "PID", annotations, 0f, 100f, 1);
\r
245 alignment.addAnnotation(consensus);
\r
248 consensus.annotations = annotations;
\r
253 public SequenceGroup getSelectionGroup()
\r
255 return selectionGroup;
\r
258 public void setSelectionGroup(SequenceGroup sg)
\r
260 selectionGroup = sg;
\r
264 public boolean getConservationSelected()
\r
266 return conservationColourSelected;
\r
269 public void setConservationSelected(boolean b)
\r
271 conservationColourSelected = b;
\r
274 public boolean getAbovePIDThreshold()
\r
276 return abovePIDThreshold;
\r
279 public void setAbovePIDThreshold(boolean b)
\r
281 abovePIDThreshold = b;
\r
284 public int getStartRes() {
\r
288 public int getEndRes() {
\r
292 public int getStartSeq() {
\r
296 public void setGlobalColourScheme(ColourSchemeI cs)
\r
298 globalColourScheme = cs;
\r
301 public ColourSchemeI getGlobalColourScheme()
\r
303 return globalColourScheme;
\r
307 public void setStartRes(int res) {
\r
308 this.startRes = res;
\r
310 public void setStartSeq(int seq) {
\r
311 this.startSeq = seq;
\r
313 public void setEndRes(int res) {
\r
314 if (res > alignment.getWidth()-1) {
\r
315 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
316 res = alignment.getWidth()-1;
\r
323 public void setEndSeq(int seq) {
\r
324 if (seq > alignment.getHeight()) {
\r
325 seq = alignment.getHeight();
\r
332 public int getEndSeq() {
\r
336 public void setFont(Font f) {
\r
338 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
340 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
341 setCharHeight(fm.getHeight());
\r
342 setCharWidth(fm.charWidth('M'));
\r
345 public Font getFont() {
\r
348 public void setCharWidth(int w) {
\r
349 this.charWidth = w;
\r
351 public int getCharWidth() {
\r
354 public void setCharHeight(int h) {
\r
355 this.charHeight = h;
\r
357 public int getCharHeight() {
\r
360 public void setChunkWidth(int w) {
\r
361 this.chunkWidth = w;
\r
363 public int getChunkWidth() {
\r
366 public void setChunkHeight(int h) {
\r
367 this.chunkHeight = h;
\r
369 public int getChunkHeight() {
\r
370 return chunkHeight;
\r
372 public AlignmentI getAlignment() {
\r
375 public void setAlignment(AlignmentI align) {
\r
376 this.alignment = align;
\r
379 public void setWrapAlignment(boolean state) {
\r
380 wrapAlignment = state;
\r
382 public void setShowText(boolean state) {
\r
386 public void setRenderGaps(boolean state){
\r
387 renderGaps = state;
\r
391 public boolean getColourText()
\r
393 return showColourText;
\r
396 public void setColourText(boolean state)
\r
398 showColourText = state;
\r
401 public void setShowBoxes(boolean state) {
\r
405 public boolean getWrapAlignment() {
\r
406 return wrapAlignment;
\r
408 public boolean getShowText() {
\r
411 public boolean getShowBoxes() {
\r
415 public char getGapCharacter() {
\r
416 return getAlignment().getGapCharacter();
\r
418 public void setGapCharacter(char gap) {
\r
419 if (getAlignment() != null) {
\r
420 getAlignment().setGapCharacter(gap);
\r
423 public void setThreshold(int thresh) {
\r
424 threshold = thresh;
\r
426 public int getThreshold() {
\r
429 public void setIncrement(int inc) {
\r
432 public int getIncrement() {
\r
435 public int getIndex(int y) {
\r
437 int starty = getStartSeq();
\r
438 int endy = getEndSeq();
\r
440 for (int i = starty; i <= endy; i++) {
\r
441 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
442 int y2 = y1 + getCharHeight();
\r
444 if (y>=y1 && y <=y2) {
\r
455 public ColumnSelection getColumnSelection() {
\r
459 public void resetSeqLimits(int height) {
\r
460 setEndSeq(height/getCharHeight());
\r
462 public void setCurrentTree(NJTree tree) {
\r
463 currentTree = tree;
\r
465 public NJTree getCurrentTree() {
\r
466 return currentTree;
\r
469 public void setColourAppliesToAllGroups(boolean b)
\r
470 { colourAppliesToAllGroups = b; }
\r
472 public boolean getColourAppliesToAllGroups()
\r
473 {return colourAppliesToAllGroups; }
\r
475 public boolean getShowFullId()
\r
480 public void setShowFullId(boolean b)
\r
485 public boolean getShowAnnotation()
\r
486 { return showAnnotation; }
\r
488 public void setShowAnnotation(boolean b)
\r
489 { showAnnotation = b; }
\r
491 public boolean getScaleAboveWrapped()
\r
492 { return scaleAboveWrapped;}
\r
494 public boolean getScaleLeftWrapped()
\r
495 { return scaleLeftWrapped; }
\r
497 public boolean getScaleRightWrapped()
\r
498 { return scaleRightWrapped; }
\r
500 public void setScaleAboveWrapped(boolean b)
\r
501 { scaleAboveWrapped = b; }
\r
503 public void setScaleLeftWrapped(boolean b)
\r
504 { scaleLeftWrapped = b; }
\r
506 public void setScaleRightWrapped(boolean b)
\r
507 { scaleRightWrapped = b; }
\r
508 // JBPNote Prolly only need this in the applet version.
\r
509 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
510 public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
511 changeSupport.addPropertyChangeListener(listener);
\r
514 public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
515 changeSupport.removePropertyChangeListener(listener);
\r
517 public void firePropertyChange(String prop, Object oldvalue, Object newvalue) {
\r
518 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r