4 import jalview.analysis.*;
\r
5 import jalview.analysis.NJTree;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.schemes.*;
\r
10 public class AlignViewport
\r
18 boolean showFullId = false;
\r
19 boolean showText=true;
\r
20 boolean showColourText=false;
\r
21 boolean showBoxes=true;
\r
22 boolean wrapAlignment=false;
\r
23 boolean renderGaps = true;
\r
24 boolean showSequenceFeatures = false;
\r
25 boolean showAnnotation = true;
\r
27 boolean colourAppliesToAllGroups = true;
\r
28 ColourSchemeI globalColourScheme = null;
\r
29 boolean conservationColourSelected = false;
\r
30 boolean abovePIDThreshold = false;
\r
32 SequenceGroup selectionGroup = new SequenceGroup();
\r
34 RendererI renderer = new SequenceRenderer(this);
\r
41 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
42 AlignmentI alignment;
\r
44 ColumnSelection colSel = new ColumnSelection();
\r
49 NJTree currentTree = null;
\r
51 boolean scaleAboveWrapped = false;
\r
52 boolean scaleLeftWrapped = true;
\r
53 boolean scaleRightWrapped = true;
\r
56 public AlignViewport(AlignmentI al,
\r
59 boolean wrapAlignment) {
\r
62 this.endRes = al.getWidth()-1;
\r
64 this.endSeq = al.getHeight()-1;
\r
65 this.showText = showText;
\r
66 this.showBoxes = showBoxes;
\r
67 this.wrapAlignment = wrapAlignment;
\r
73 public void showSequenceFeatures(boolean b)
\r
75 showSequenceFeatures = b;
\r
78 AlignmentAnnotation consensus;
\r
79 AlignmentAnnotation conservation;
\r
80 AlignmentAnnotation quality;
\r
82 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
84 public void updateConservation()
\r
86 Conservation cons = new jalview.analysis.Conservation("All",
\r
87 jalview.schemes.ResidueProperties.propHash, 3,
\r
88 alignment.getSequences(), 0,
\r
89 alignment.getWidth()-1);
\r
91 cons.verdict(false, ConsPercGaps);
\r
93 int alWidth = alignment.getWidth();
\r
94 Annotation [] annotations = new Annotation[alWidth];
\r
95 Annotation [] qannotations = new Annotation[alWidth];
\r
96 String sequence = cons.getConsSequence().getSequence();
\r
97 float minR,minG,minB, maxR,maxG,maxB;
\r
101 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
104 float qmin = cons.qualityRange[0].floatValue();
\r
105 float qmax = cons.qualityRange[1].floatValue();
\r
107 for (int i = 0; i < alWidth; i++)
\r
112 value = Integer.parseInt(sequence.charAt(i) + "");
\r
114 catch (Exception ex)
\r
116 if (sequence.charAt(i) == '*') value = 11;
\r
117 if (sequence.charAt(i) == '+') value = 10;
\r
119 float vprop = value-min;
\r
121 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
122 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
124 value = ((Double) cons.quality.get(i)).floatValue();
\r
125 vprop = value - qmin;
\r
127 qannotations[i] = new Annotation(" ",
\r
128 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
131 if(conservation==null)
\r
133 conservation = new AlignmentAnnotation("Conservation",
\r
134 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
136 0f, // cons.qualityRange[0].floatValue(),
\r
137 11f, // cons.qualityRange[1].floatValue()
\r
139 alignment.addAnnotation(conservation);
\r
140 quality = new AlignmentAnnotation("Quality",
\r
141 "Alignment Quality based on Blosum62 scores",
\r
143 cons.qualityRange[0].floatValue(),
\r
144 cons.qualityRange[1].floatValue(),
\r
146 alignment.addAnnotation(quality);
\r
149 conservation.annotations = annotations;
\r
150 quality.annotations = qannotations;
\r
156 public void updateConsensus()
\r
158 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
160 Vector cons = alignment.getAAFrequency();
\r
161 Hashtable hash = null;
\r
162 for (int i = 0; i<alignment.getWidth(); i++)
\r
164 hash = (Hashtable) cons.elementAt(i);
\r
165 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
166 value /= Float.parseFloat(hash.get("size").toString());
\r
169 String maxRes = hash.get("maxResidue")+" ";
\r
170 String mouseOver = hash.get("maxResidue")+" ";
\r
171 if(maxRes.length()>2)
\r
173 mouseOver = "["+maxRes+"] ";
\r
177 mouseOver += (int)value+"%";
\r
178 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
182 if(consensus==null)
\r
184 consensus = new AlignmentAnnotation("% Identity",
\r
185 "PID", annotations, 0f, 100f, 1);
\r
186 alignment.addAnnotation(consensus);
\r
189 consensus.annotations = annotations;
\r
193 public String getVisibleConsensus()
\r
195 return visibleConsensus;
\r
198 String visibleConsensus;
\r
199 Vector consensusV = new Vector();
\r
200 public Vector getConsensus(boolean recalculate)
\r
202 if(recalculate || consensusV.size()<1)
\r
204 consensusV = alignment.getAAFrequency();
\r
205 StringBuffer sb = new StringBuffer();
\r
206 Hashtable hash = null;
\r
207 for (int i = 0, sz=consensusV.size(); i < sz; i++)
\r
209 hash = (Hashtable) consensusV.elementAt(i);
\r
210 sb.append(hash.get("maxResidue").toString().charAt(0));
\r
212 visibleConsensus = sb.toString();
\r
220 public SequenceGroup getSelectionGroup()
\r
222 return selectionGroup;
\r
225 public void setSelectionGroup(SequenceGroup sg)
\r
227 selectionGroup = sg;
\r
231 public boolean getConservationSelected()
\r
233 return conservationColourSelected;
\r
236 public void setConservationSelected(boolean b)
\r
238 conservationColourSelected = b;
\r
241 public boolean getAbovePIDThreshold()
\r
243 return abovePIDThreshold;
\r
246 public void setAbovePIDThreshold(boolean b)
\r
248 abovePIDThreshold = b;
\r
251 public int getStartRes() {
\r
255 public int getEndRes() {
\r
259 public int getStartSeq() {
\r
263 public void setGlobalColourScheme(ColourSchemeI cs)
\r
265 globalColourScheme = cs;
\r
268 public ColourSchemeI getGlobalColourScheme()
\r
270 return globalColourScheme;
\r
274 public void setStartRes(int res) {
\r
275 this.startRes = res;
\r
277 public void setStartSeq(int seq) {
\r
278 this.startSeq = seq;
\r
280 public void setEndRes(int res) {
\r
281 if (res > alignment.getWidth()-1) {
\r
282 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
283 res = alignment.getWidth()-1;
\r
290 public void setEndSeq(int seq) {
\r
291 if (seq > alignment.getHeight()) {
\r
292 seq = alignment.getHeight();
\r
299 public int getEndSeq() {
\r
303 public void setFont(Font f) {
\r
305 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
307 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
308 setCharHeight(fm.getHeight());
\r
309 setCharWidth(fm.charWidth('M'));
\r
312 public Font getFont() {
\r
315 public void setCharWidth(int w) {
\r
316 this.charWidth = w;
\r
318 public int getCharWidth() {
\r
321 public void setCharHeight(int h) {
\r
322 this.charHeight = h;
\r
324 public int getCharHeight() {
\r
327 public void setChunkWidth(int w) {
\r
328 this.chunkWidth = w;
\r
330 public int getChunkWidth() {
\r
333 public void setChunkHeight(int h) {
\r
334 this.chunkHeight = h;
\r
336 public int getChunkHeight() {
\r
337 return chunkHeight;
\r
339 public AlignmentI getAlignment() {
\r
342 public void setAlignment(AlignmentI align) {
\r
343 this.alignment = align;
\r
346 public void setWrapAlignment(boolean state) {
\r
347 wrapAlignment = state;
\r
349 public void setShowText(boolean state) {
\r
353 public void setRenderGaps(boolean state){
\r
354 renderGaps = state;
\r
355 if(renderer instanceof SequenceRenderer)
\r
357 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
358 sr.renderGaps(state);
\r
363 public boolean getColourText()
\r
365 return showColourText;
\r
368 public void setColourText(boolean state)
\r
370 showColourText = state;
\r
373 public void setShowBoxes(boolean state) {
\r
377 public boolean getWrapAlignment() {
\r
378 return wrapAlignment;
\r
380 public boolean getShowText() {
\r
383 public boolean getShowBoxes() {
\r
387 public char getGapCharacter() {
\r
388 return getAlignment().getGapCharacter();
\r
390 public void setGapCharacter(char gap) {
\r
391 if (getAlignment() != null) {
\r
392 getAlignment().setGapCharacter(gap);
\r
395 public void setThreshold(int thresh) {
\r
396 threshold = thresh;
\r
398 public int getThreshold() {
\r
401 public void setIncrement(int inc) {
\r
404 public int getIncrement() {
\r
407 public int getIndex(int y) {
\r
409 int starty = getStartSeq();
\r
410 int endy = getEndSeq();
\r
412 for (int i = starty; i <= endy; i++) {
\r
413 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
414 int y2 = y1 + getCharHeight();
\r
416 if (y>=y1 && y <=y2) {
\r
427 public ColumnSelection getColumnSelection() {
\r
431 public void resetSeqLimits(int height) {
\r
432 setEndSeq(height/getCharHeight());
\r
434 public void setCurrentTree(NJTree tree) {
\r
435 currentTree = tree;
\r
437 public NJTree getCurrentTree() {
\r
438 return currentTree;
\r
441 public void setRenderer(RendererI rend) {
\r
442 this.renderer = rend;
\r
445 public RendererI getRenderer() {
\r
449 public void setColourAppliesToAllGroups(boolean b)
\r
450 { colourAppliesToAllGroups = b; }
\r
452 public boolean getColourAppliesToAllGroups()
\r
453 {return colourAppliesToAllGroups; }
\r
455 public boolean getShowFullId()
\r
460 public void setShowFullId(boolean b)
\r
465 public boolean getShowAnnotation()
\r
467 return showAnnotation;
\r
470 public void setShowAnnotation(boolean b)
\r
472 showAnnotation = b;
\r
475 public boolean getScaleAboveWrapped()
\r
476 { return scaleAboveWrapped;}
\r
478 public boolean getScaleLeftWrapped()
\r
479 { return scaleLeftWrapped; }
\r
481 public boolean getScaleRightWrapped()
\r
482 { return scaleRightWrapped; }
\r
484 public void setScaleAboveWrapped(boolean b)
\r
485 { scaleAboveWrapped = b; }
\r
487 public void setScaleLeftWrapped(boolean b)
\r
488 { scaleLeftWrapped = b; }
\r
490 public void setScaleRightWrapped(boolean b)
\r
491 { scaleRightWrapped = b; }
\r