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
38 RendererI renderer = new SequenceRenderer(this);
\r
45 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
46 AlignmentI alignment;
\r
48 ColumnSelection colSel = new ColumnSelection();
\r
53 NJTree currentTree = null;
\r
55 boolean scaleAboveWrapped = false;
\r
56 boolean scaleLeftWrapped = true;
\r
57 boolean scaleRightWrapped = true;
\r
60 public AlignViewport(AlignmentI al)
\r
64 this.endRes = al.getWidth()-1;
\r
66 this.endSeq = al.getHeight()-1;
\r
68 updateFromPreferences();
\r
72 public void updateFromPreferences()
\r
74 showFullId = Preferences.showFullId;
\r
75 showAnnotation = Preferences.showAnnotation;
\r
76 showConservation = Preferences.showConservation;
\r
77 showQuality = Preferences.showQuality;
\r
78 showIdentity = Preferences.showIdentity;
\r
79 showFullId = Preferences.showFullId;
\r
80 String fontName = Preferences.fontName;
\r
81 String fontStyle = Preferences.fontStyle;
\r
82 String fontSize = Cache.getProperty("FONT_SIZE");
\r
83 if (fontName != null && fontStyle != null && fontSize != null)
\r
86 if(fontStyle.equals("bold"))
\r
88 else if(fontStyle.equals("italic"))
\r
90 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
\r
95 alignment.setGapCharacter(Preferences.gapSymbol);
\r
97 // We must set conservation and consensus before setting colour,
\r
98 // as Blosum and Clustal require this to be done
\r
99 updateConservation();
\r
101 if(Preferences.defaultColour!=null)
\r
103 globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour);
\r
104 if(globalColourScheme!=null)
\r
105 globalColourScheme.setConsensus( vconsensus );
\r
110 public void showSequenceFeatures(boolean b)
\r
112 showSequenceFeatures = b;
\r
115 public Vector vconsensus;
\r
116 AlignmentAnnotation consensus;
\r
117 AlignmentAnnotation conservation;
\r
118 AlignmentAnnotation quality;
\r
120 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
122 public void updateConservation()
\r
124 Conservation cons = new jalview.analysis.Conservation("All",
\r
125 jalview.schemes.ResidueProperties.propHash, 3,
\r
126 alignment.getSequences(), 0,
\r
127 alignment.getWidth()-1);
\r
129 cons.verdict(false, ConsPercGaps);
\r
130 cons.findQuality();
\r
131 int alWidth = alignment.getWidth();
\r
132 Annotation [] annotations = new Annotation[alWidth];
\r
133 Annotation [] qannotations = new Annotation[alWidth];
\r
134 String sequence = cons.getConsSequence().getSequence();
\r
135 float minR,minG,minB, maxR,maxG,maxB;
\r
139 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
142 float qmin = cons.qualityRange[0].floatValue();
\r
143 float qmax = cons.qualityRange[1].floatValue();
\r
145 for (int i = 0; i < alWidth; i++)
\r
150 value = Integer.parseInt(sequence.charAt(i) + "");
\r
152 catch (Exception ex)
\r
154 if (sequence.charAt(i) == '*') value = 11;
\r
155 if (sequence.charAt(i) == '+') value = 10;
\r
157 float vprop = value-min;
\r
159 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
160 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
162 value = ((Double) cons.quality.get(i)).floatValue();
\r
163 vprop = value - qmin;
\r
165 qannotations[i] = new Annotation(" ",
\r
166 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
169 if(conservation==null)
\r
171 conservation = new AlignmentAnnotation("Conservation",
\r
172 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
174 0f, // cons.qualityRange[0].floatValue(),
\r
175 11f, // cons.qualityRange[1].floatValue()
\r
177 if(showConservation)
\r
178 alignment.addAnnotation(conservation);
\r
179 quality = new AlignmentAnnotation("Quality",
\r
180 "Alignment Quality based on Blosum62 scores",
\r
182 cons.qualityRange[0].floatValue(),
\r
183 cons.qualityRange[1].floatValue(),
\r
186 alignment.addAnnotation(quality);
\r
189 conservation.annotations = annotations;
\r
190 quality.annotations = qannotations;
\r
191 quality.graphMax = cons.qualityRange[1].floatValue();
\r
197 public void updateConsensus()
\r
199 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
201 // this routine prevents vconsensus becoming a new object each time
\r
202 // consenus is calculated. Important for speed of Blosum62
\r
203 // and PID colouring of alignment
\r
204 if(vconsensus == null)
\r
205 vconsensus = alignment.getAAFrequency();
\r
208 Vector temp = alignment.getAAFrequency();
\r
209 vconsensus.clear();
\r
210 Enumeration e = temp.elements();
\r
211 while(e.hasMoreElements())
\r
213 vconsensus.add(e.nextElement());
\r
216 Hashtable hash = null;
\r
217 for (int i = 0; i<alignment.getWidth(); i++)
\r
219 hash = (Hashtable) vconsensus.elementAt(i);
\r
220 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
221 value /= Float.parseFloat(hash.get("size").toString());
\r
224 String maxRes = hash.get("maxResidue")+" ";
\r
225 String mouseOver = hash.get("maxResidue")+" ";
\r
226 if(maxRes.length()>2)
\r
228 mouseOver = "["+maxRes+"] ";
\r
232 mouseOver += (int)value+"%";
\r
233 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
237 if(consensus==null)
\r
239 consensus = new AlignmentAnnotation("% Identity",
\r
240 "PID", annotations, 0f, 100f, 1);
\r
242 alignment.addAnnotation(consensus);
\r
245 consensus.annotations = annotations;
\r
250 public SequenceGroup getSelectionGroup()
\r
252 return selectionGroup;
\r
255 public void setSelectionGroup(SequenceGroup sg)
\r
257 selectionGroup = sg;
\r
261 public boolean getConservationSelected()
\r
263 return conservationColourSelected;
\r
266 public void setConservationSelected(boolean b)
\r
268 conservationColourSelected = b;
\r
271 public boolean getAbovePIDThreshold()
\r
273 return abovePIDThreshold;
\r
276 public void setAbovePIDThreshold(boolean b)
\r
278 abovePIDThreshold = b;
\r
281 public int getStartRes() {
\r
285 public int getEndRes() {
\r
289 public int getStartSeq() {
\r
293 public void setGlobalColourScheme(ColourSchemeI cs)
\r
295 globalColourScheme = cs;
\r
298 public ColourSchemeI getGlobalColourScheme()
\r
300 return globalColourScheme;
\r
304 public void setStartRes(int res) {
\r
305 this.startRes = res;
\r
307 public void setStartSeq(int seq) {
\r
308 this.startSeq = seq;
\r
310 public void setEndRes(int res) {
\r
311 if (res > alignment.getWidth()-1) {
\r
312 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
313 res = alignment.getWidth()-1;
\r
320 public void setEndSeq(int seq) {
\r
321 if (seq > alignment.getHeight()) {
\r
322 seq = alignment.getHeight();
\r
329 public int getEndSeq() {
\r
333 public void setFont(Font f) {
\r
335 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
337 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
338 setCharHeight(fm.getHeight());
\r
339 setCharWidth(fm.charWidth('M'));
\r
342 public Font getFont() {
\r
345 public void setCharWidth(int w) {
\r
346 this.charWidth = w;
\r
348 public int getCharWidth() {
\r
351 public void setCharHeight(int h) {
\r
352 this.charHeight = h;
\r
354 public int getCharHeight() {
\r
357 public void setChunkWidth(int w) {
\r
358 this.chunkWidth = w;
\r
360 public int getChunkWidth() {
\r
363 public void setChunkHeight(int h) {
\r
364 this.chunkHeight = h;
\r
366 public int getChunkHeight() {
\r
367 return chunkHeight;
\r
369 public AlignmentI getAlignment() {
\r
372 public void setAlignment(AlignmentI align) {
\r
373 this.alignment = align;
\r
376 public void setWrapAlignment(boolean state) {
\r
377 wrapAlignment = state;
\r
379 public void setShowText(boolean state) {
\r
383 public void setRenderGaps(boolean state){
\r
384 renderGaps = state;
\r
385 if(renderer instanceof SequenceRenderer)
\r
387 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
388 sr.renderGaps(state);
\r
393 public boolean getColourText()
\r
395 return showColourText;
\r
398 public void setColourText(boolean state)
\r
400 showColourText = state;
\r
403 public void setShowBoxes(boolean state) {
\r
407 public boolean getWrapAlignment() {
\r
408 return wrapAlignment;
\r
410 public boolean getShowText() {
\r
413 public boolean getShowBoxes() {
\r
417 public char getGapCharacter() {
\r
418 return getAlignment().getGapCharacter();
\r
420 public void setGapCharacter(char gap) {
\r
421 if (getAlignment() != null) {
\r
422 getAlignment().setGapCharacter(gap);
\r
425 public void setThreshold(int thresh) {
\r
426 threshold = thresh;
\r
428 public int getThreshold() {
\r
431 public void setIncrement(int inc) {
\r
434 public int getIncrement() {
\r
437 public int getIndex(int y) {
\r
439 int starty = getStartSeq();
\r
440 int endy = getEndSeq();
\r
442 for (int i = starty; i <= endy; i++) {
\r
443 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
444 int y2 = y1 + getCharHeight();
\r
446 if (y>=y1 && y <=y2) {
\r
457 public ColumnSelection getColumnSelection() {
\r
461 public void resetSeqLimits(int height) {
\r
462 setEndSeq(height/getCharHeight());
\r
464 public void setCurrentTree(NJTree tree) {
\r
465 currentTree = tree;
\r
467 public NJTree getCurrentTree() {
\r
468 return currentTree;
\r
471 public void setRenderer(RendererI rend) {
\r
472 this.renderer = rend;
\r
475 public RendererI getRenderer() {
\r
479 public void setColourAppliesToAllGroups(boolean b)
\r
480 { colourAppliesToAllGroups = b; }
\r
482 public boolean getColourAppliesToAllGroups()
\r
483 {return colourAppliesToAllGroups; }
\r
485 public boolean getShowFullId()
\r
490 public void setShowFullId(boolean b)
\r
495 public boolean getShowAnnotation()
\r
497 return showAnnotation;
\r
500 public void setShowAnnotation(boolean b)
\r
502 showAnnotation = b;
\r
505 public boolean getScaleAboveWrapped()
\r
506 { return scaleAboveWrapped;}
\r
508 public boolean getScaleLeftWrapped()
\r
509 { return scaleLeftWrapped; }
\r
511 public boolean getScaleRightWrapped()
\r
512 { return scaleRightWrapped; }
\r
514 public void setScaleAboveWrapped(boolean b)
\r
515 { scaleAboveWrapped = b; }
\r
517 public void setScaleLeftWrapped(boolean b)
\r
518 { scaleLeftWrapped = b; }
\r
520 public void setScaleRightWrapped(boolean b)
\r
521 { scaleRightWrapped = b; }
\r