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!=null)
\r
104 globalColourScheme.setConsensus( vconsensus );
\r
109 public void showSequenceFeatures(boolean b)
\r
111 showSequenceFeatures = b;
\r
114 public Vector vconsensus;
\r
115 AlignmentAnnotation consensus;
\r
116 AlignmentAnnotation conservation;
\r
117 AlignmentAnnotation quality;
\r
119 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
121 public void updateConservation()
\r
123 Conservation cons = new jalview.analysis.Conservation("All",
\r
124 jalview.schemes.ResidueProperties.propHash, 3,
\r
125 alignment.getSequences(), 0,
\r
126 alignment.getWidth()-1);
\r
128 cons.verdict(false, ConsPercGaps);
\r
129 cons.findQuality();
\r
130 int alWidth = alignment.getWidth();
\r
131 Annotation [] annotations = new Annotation[alWidth];
\r
132 Annotation [] qannotations = new Annotation[alWidth];
\r
133 String sequence = cons.getConsSequence().getSequence();
\r
134 float minR,minG,minB, maxR,maxG,maxB;
\r
138 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
141 float qmin = cons.qualityRange[0].floatValue();
\r
142 float qmax = cons.qualityRange[1].floatValue();
\r
144 for (int i = 0; i < alWidth; i++)
\r
149 value = Integer.parseInt(sequence.charAt(i) + "");
\r
151 catch (Exception ex)
\r
153 if (sequence.charAt(i) == '*') value = 11;
\r
154 if (sequence.charAt(i) == '+') value = 10;
\r
156 float vprop = value-min;
\r
158 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
159 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
161 value = ((Double) cons.quality.get(i)).floatValue();
\r
162 vprop = value - qmin;
\r
164 qannotations[i] = new Annotation(" ",
\r
165 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
168 if(conservation==null)
\r
170 conservation = new AlignmentAnnotation("Conservation",
\r
171 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
173 0f, // cons.qualityRange[0].floatValue(),
\r
174 11f, // cons.qualityRange[1].floatValue()
\r
176 if(showConservation)
\r
177 alignment.addAnnotation(conservation);
\r
178 quality = new AlignmentAnnotation("Quality",
\r
179 "Alignment Quality based on Blosum62 scores",
\r
181 cons.qualityRange[0].floatValue(),
\r
182 cons.qualityRange[1].floatValue(),
\r
185 alignment.addAnnotation(quality);
\r
188 conservation.annotations = annotations;
\r
189 quality.annotations = qannotations;
\r
190 quality.graphMax = cons.qualityRange[1].floatValue();
\r
196 public void updateConsensus()
\r
198 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
200 // this routine prevents vconsensus becoming a new object each time
\r
201 // consenus is calculated. Important for speed of Blosum62
\r
202 // and PID colouring of alignment
\r
203 if(vconsensus == null)
\r
204 vconsensus = alignment.getAAFrequency();
\r
207 Vector temp = alignment.getAAFrequency();
\r
208 vconsensus.clear();
\r
209 Enumeration e = temp.elements();
\r
210 while(e.hasMoreElements())
\r
212 vconsensus.add(e.nextElement());
\r
215 Hashtable hash = null;
\r
216 for (int i = 0; i<alignment.getWidth(); i++)
\r
218 hash = (Hashtable) vconsensus.elementAt(i);
\r
219 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
220 value /= Float.parseFloat(hash.get("size").toString());
\r
223 String maxRes = hash.get("maxResidue")+" ";
\r
224 String mouseOver = hash.get("maxResidue")+" ";
\r
225 if(maxRes.length()>2)
\r
227 mouseOver = "["+maxRes+"] ";
\r
231 mouseOver += (int)value+"%";
\r
232 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
236 if(consensus==null)
\r
238 consensus = new AlignmentAnnotation("% Identity",
\r
239 "PID", annotations, 0f, 100f, 1);
\r
241 alignment.addAnnotation(consensus);
\r
244 consensus.annotations = annotations;
\r
249 public SequenceGroup getSelectionGroup()
\r
251 return selectionGroup;
\r
254 public void setSelectionGroup(SequenceGroup sg)
\r
256 selectionGroup = sg;
\r
260 public boolean getConservationSelected()
\r
262 return conservationColourSelected;
\r
265 public void setConservationSelected(boolean b)
\r
267 conservationColourSelected = b;
\r
270 public boolean getAbovePIDThreshold()
\r
272 return abovePIDThreshold;
\r
275 public void setAbovePIDThreshold(boolean b)
\r
277 abovePIDThreshold = b;
\r
280 public int getStartRes() {
\r
284 public int getEndRes() {
\r
288 public int getStartSeq() {
\r
292 public void setGlobalColourScheme(ColourSchemeI cs)
\r
294 globalColourScheme = cs;
\r
297 public ColourSchemeI getGlobalColourScheme()
\r
299 return globalColourScheme;
\r
303 public void setStartRes(int res) {
\r
304 this.startRes = res;
\r
306 public void setStartSeq(int seq) {
\r
307 this.startSeq = seq;
\r
309 public void setEndRes(int res) {
\r
310 if (res > alignment.getWidth()-1) {
\r
311 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
312 res = alignment.getWidth()-1;
\r
319 public void setEndSeq(int seq) {
\r
320 if (seq > alignment.getHeight()) {
\r
321 seq = alignment.getHeight();
\r
328 public int getEndSeq() {
\r
332 public void setFont(Font f) {
\r
334 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
336 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
337 setCharHeight(fm.getHeight());
\r
338 setCharWidth(fm.charWidth('M'));
\r
341 public Font getFont() {
\r
344 public void setCharWidth(int w) {
\r
345 this.charWidth = w;
\r
347 public int getCharWidth() {
\r
350 public void setCharHeight(int h) {
\r
351 this.charHeight = h;
\r
353 public int getCharHeight() {
\r
356 public void setChunkWidth(int w) {
\r
357 this.chunkWidth = w;
\r
359 public int getChunkWidth() {
\r
362 public void setChunkHeight(int h) {
\r
363 this.chunkHeight = h;
\r
365 public int getChunkHeight() {
\r
366 return chunkHeight;
\r
368 public AlignmentI getAlignment() {
\r
371 public void setAlignment(AlignmentI align) {
\r
372 this.alignment = align;
\r
375 public void setWrapAlignment(boolean state) {
\r
376 wrapAlignment = state;
\r
378 public void setShowText(boolean state) {
\r
382 public void setRenderGaps(boolean state){
\r
383 renderGaps = state;
\r
387 public boolean getColourText()
\r
389 return showColourText;
\r
392 public void setColourText(boolean state)
\r
394 showColourText = state;
\r
397 public void setShowBoxes(boolean state) {
\r
401 public boolean getWrapAlignment() {
\r
402 return wrapAlignment;
\r
404 public boolean getShowText() {
\r
407 public boolean getShowBoxes() {
\r
411 public char getGapCharacter() {
\r
412 return getAlignment().getGapCharacter();
\r
414 public void setGapCharacter(char gap) {
\r
415 if (getAlignment() != null) {
\r
416 getAlignment().setGapCharacter(gap);
\r
419 public void setThreshold(int thresh) {
\r
420 threshold = thresh;
\r
422 public int getThreshold() {
\r
425 public void setIncrement(int inc) {
\r
428 public int getIncrement() {
\r
431 public int getIndex(int y) {
\r
433 int starty = getStartSeq();
\r
434 int endy = getEndSeq();
\r
436 for (int i = starty; i <= endy; i++) {
\r
437 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
438 int y2 = y1 + getCharHeight();
\r
440 if (y>=y1 && y <=y2) {
\r
451 public ColumnSelection getColumnSelection() {
\r
455 public void resetSeqLimits(int height) {
\r
456 setEndSeq(height/getCharHeight());
\r
458 public void setCurrentTree(NJTree tree) {
\r
459 currentTree = tree;
\r
461 public NJTree getCurrentTree() {
\r
462 return currentTree;
\r
465 public void setColourAppliesToAllGroups(boolean b)
\r
466 { colourAppliesToAllGroups = b; }
\r
468 public boolean getColourAppliesToAllGroups()
\r
469 {return colourAppliesToAllGroups; }
\r
471 public boolean getShowFullId()
\r
476 public void setShowFullId(boolean b)
\r
481 public boolean getShowAnnotation()
\r
483 return showAnnotation;
\r
486 public void setShowAnnotation(boolean b)
\r
488 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