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
104 globalColourScheme = UserDefinedColours.loadDefaultColours();
\r
105 if(globalColourScheme!=null)
\r
106 globalColourScheme.setConsensus( vconsensus );
\r
111 public void showSequenceFeatures(boolean b)
\r
113 showSequenceFeatures = b;
\r
116 public Vector vconsensus;
\r
117 AlignmentAnnotation consensus;
\r
118 AlignmentAnnotation conservation;
\r
119 AlignmentAnnotation quality;
\r
121 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
123 public void updateConservation()
\r
125 Conservation cons = new jalview.analysis.Conservation("All",
\r
126 jalview.schemes.ResidueProperties.propHash, 3,
\r
127 alignment.getSequences(), 0,
\r
128 alignment.getWidth()-1);
\r
130 cons.verdict(false, ConsPercGaps);
\r
131 cons.findQuality();
\r
132 int alWidth = alignment.getWidth();
\r
133 Annotation [] annotations = new Annotation[alWidth];
\r
134 Annotation [] qannotations = new Annotation[alWidth];
\r
135 String sequence = cons.getConsSequence().getSequence();
\r
136 float minR,minG,minB, maxR,maxG,maxB;
\r
140 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
143 float qmin = cons.qualityRange[0].floatValue();
\r
144 float qmax = cons.qualityRange[1].floatValue();
\r
146 for (int i = 0; i < alWidth; i++)
\r
151 value = Integer.parseInt(sequence.charAt(i) + "");
\r
153 catch (Exception ex)
\r
155 if (sequence.charAt(i) == '*') value = 11;
\r
156 if (sequence.charAt(i) == '+') value = 10;
\r
158 float vprop = value-min;
\r
160 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
161 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
163 value = ((Double) cons.quality.get(i)).floatValue();
\r
164 vprop = value - qmin;
\r
166 qannotations[i] = new Annotation(" ",
\r
167 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
170 if(conservation==null)
\r
172 conservation = new AlignmentAnnotation("Conservation",
\r
173 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
175 0f, // cons.qualityRange[0].floatValue(),
\r
176 11f, // cons.qualityRange[1].floatValue()
\r
178 if(showConservation)
\r
179 alignment.addAnnotation(conservation);
\r
180 quality = new AlignmentAnnotation("Quality",
\r
181 "Alignment Quality based on Blosum62 scores",
\r
183 cons.qualityRange[0].floatValue(),
\r
184 cons.qualityRange[1].floatValue(),
\r
187 alignment.addAnnotation(quality);
\r
190 conservation.annotations = annotations;
\r
191 quality.annotations = qannotations;
\r
192 quality.graphMax = cons.qualityRange[1].floatValue();
\r
198 public void updateConsensus()
\r
200 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
202 // this routine prevents vconsensus becoming a new object each time
\r
203 // consenus is calculated. Important for speed of Blosum62
\r
204 // and PID colouring of alignment
\r
205 if(vconsensus == null)
\r
206 vconsensus = alignment.getAAFrequency();
\r
209 Vector temp = alignment.getAAFrequency();
\r
210 vconsensus.clear();
\r
211 Enumeration e = temp.elements();
\r
212 while(e.hasMoreElements())
\r
214 vconsensus.add(e.nextElement());
\r
217 Hashtable hash = null;
\r
218 for (int i = 0; i<alignment.getWidth(); i++)
\r
220 hash = (Hashtable) vconsensus.elementAt(i);
\r
221 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
222 value /= Float.parseFloat(hash.get("size").toString());
\r
225 String maxRes = hash.get("maxResidue")+" ";
\r
226 String mouseOver = hash.get("maxResidue")+" ";
\r
227 if(maxRes.length()>2)
\r
229 mouseOver = "["+maxRes+"] ";
\r
233 mouseOver += (int)value+"%";
\r
234 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
238 if(consensus==null)
\r
240 consensus = new AlignmentAnnotation("Consensus",
\r
241 "PID", annotations, 0f, 100f, 1);
\r
243 alignment.addAnnotation(consensus);
\r
246 consensus.annotations = annotations;
\r
251 public SequenceGroup getSelectionGroup()
\r
253 return selectionGroup;
\r
256 public void setSelectionGroup(SequenceGroup sg)
\r
258 selectionGroup = sg;
\r
262 public boolean getConservationSelected()
\r
264 return conservationColourSelected;
\r
267 public void setConservationSelected(boolean b)
\r
269 conservationColourSelected = b;
\r
272 public boolean getAbovePIDThreshold()
\r
274 return abovePIDThreshold;
\r
277 public void setAbovePIDThreshold(boolean b)
\r
279 abovePIDThreshold = b;
\r
282 public int getStartRes() {
\r
286 public int getEndRes() {
\r
290 public int getStartSeq() {
\r
294 public void setGlobalColourScheme(ColourSchemeI cs)
\r
296 globalColourScheme = cs;
\r
299 public ColourSchemeI getGlobalColourScheme()
\r
301 return globalColourScheme;
\r
305 public void setStartRes(int res) {
\r
306 this.startRes = res;
\r
308 public void setStartSeq(int seq) {
\r
309 this.startSeq = seq;
\r
311 public void setEndRes(int res) {
\r
312 if (res > alignment.getWidth()-1) {
\r
313 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
314 res = alignment.getWidth()-1;
\r
321 public void setEndSeq(int seq) {
\r
322 if (seq > alignment.getHeight()) {
\r
323 seq = alignment.getHeight();
\r
330 public int getEndSeq() {
\r
334 public void setFont(Font f) {
\r
336 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
338 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
339 setCharHeight(fm.getHeight());
\r
340 setCharWidth(fm.charWidth('M'));
\r
343 public Font getFont() {
\r
346 public void setCharWidth(int w) {
\r
347 this.charWidth = w;
\r
349 public int getCharWidth() {
\r
352 public void setCharHeight(int h) {
\r
353 this.charHeight = h;
\r
355 public int getCharHeight() {
\r
358 public void setChunkWidth(int w) {
\r
359 this.chunkWidth = w;
\r
361 public int getChunkWidth() {
\r
364 public void setChunkHeight(int h) {
\r
365 this.chunkHeight = h;
\r
367 public int getChunkHeight() {
\r
368 return chunkHeight;
\r
370 public AlignmentI getAlignment() {
\r
373 public void setAlignment(AlignmentI align) {
\r
374 this.alignment = align;
\r
377 public void setWrapAlignment(boolean state) {
\r
378 wrapAlignment = state;
\r
380 public void setShowText(boolean state) {
\r
384 public void setRenderGaps(boolean state){
\r
385 renderGaps = state;
\r
389 public boolean getColourText()
\r
391 return showColourText;
\r
394 public void setColourText(boolean state)
\r
396 showColourText = state;
\r
399 public void setShowBoxes(boolean state) {
\r
403 public boolean getWrapAlignment() {
\r
404 return wrapAlignment;
\r
406 public boolean getShowText() {
\r
409 public boolean getShowBoxes() {
\r
413 public char getGapCharacter() {
\r
414 return getAlignment().getGapCharacter();
\r
416 public void setGapCharacter(char gap) {
\r
417 if (getAlignment() != null) {
\r
418 getAlignment().setGapCharacter(gap);
\r
421 public void setThreshold(int thresh) {
\r
422 threshold = thresh;
\r
424 public int getThreshold() {
\r
427 public void setIncrement(int inc) {
\r
430 public int getIncrement() {
\r
433 public int getIndex(int y) {
\r
435 int starty = getStartSeq();
\r
436 int endy = getEndSeq();
\r
438 for (int i = starty; i <= endy; i++) {
\r
439 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
440 int y2 = y1 + getCharHeight();
\r
442 if (y>=y1 && y <=y2) {
\r
453 public ColumnSelection getColumnSelection() {
\r
457 public void resetSeqLimits(int height) {
\r
458 setEndSeq(height/getCharHeight());
\r
460 public void setCurrentTree(NJTree tree) {
\r
461 currentTree = tree;
\r
463 public NJTree getCurrentTree() {
\r
464 return currentTree;
\r
467 public void setColourAppliesToAllGroups(boolean b)
\r
468 { colourAppliesToAllGroups = b; }
\r
470 public boolean getColourAppliesToAllGroups()
\r
471 {return colourAppliesToAllGroups; }
\r
473 public boolean getShowFullId()
\r
478 public void setShowFullId(boolean b)
\r
483 public boolean getShowAnnotation()
\r
484 { return showAnnotation; }
\r
486 public void setShowAnnotation(boolean b)
\r
487 { showAnnotation = b; }
\r
489 public boolean getScaleAboveWrapped()
\r
490 { return scaleAboveWrapped;}
\r
492 public boolean getScaleLeftWrapped()
\r
493 { return scaleLeftWrapped; }
\r
495 public boolean getScaleRightWrapped()
\r
496 { return scaleRightWrapped; }
\r
498 public void setScaleAboveWrapped(boolean b)
\r
499 { scaleAboveWrapped = b; }
\r
501 public void setScaleLeftWrapped(boolean b)
\r
502 { scaleLeftWrapped = b; }
\r
504 public void setScaleRightWrapped(boolean b)
\r
505 { scaleRightWrapped = b; }
\r
506 // JBPNote Prolly only need this in the applet version.
\r
507 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
508 public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
509 changeSupport.addPropertyChangeListener(listener);
\r
512 public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) {
\r
513 changeSupport.removePropertyChangeListener(listener);
\r
515 public void firePropertyChange(String prop, Object oldvalue, Object newvalue) {
\r
516 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r