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 public Vector vconsensus;
\r
79 AlignmentAnnotation consensus;
\r
80 AlignmentAnnotation conservation;
\r
81 AlignmentAnnotation quality;
\r
83 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
85 public void updateConservation()
\r
87 Conservation cons = new jalview.analysis.Conservation("All",
\r
88 jalview.schemes.ResidueProperties.propHash, 3,
\r
89 alignment.getSequences(), 0,
\r
90 alignment.getWidth()-1);
\r
92 cons.verdict(false, ConsPercGaps);
\r
94 int alWidth = alignment.getWidth();
\r
95 Annotation [] annotations = new Annotation[alWidth];
\r
96 Annotation [] qannotations = new Annotation[alWidth];
\r
97 String sequence = cons.getConsSequence().getSequence();
\r
98 float minR,minG,minB, maxR,maxG,maxB;
\r
102 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
105 float qmin = cons.qualityRange[0].floatValue();
\r
106 float qmax = cons.qualityRange[1].floatValue();
\r
108 for (int i = 0; i < alWidth; i++)
\r
113 value = Integer.parseInt(sequence.charAt(i) + "");
\r
115 catch (Exception ex)
\r
117 if (sequence.charAt(i) == '*') value = 11;
\r
118 if (sequence.charAt(i) == '+') value = 10;
\r
120 float vprop = value-min;
\r
122 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
123 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
125 value = ((Double) cons.quality.get(i)).floatValue();
\r
126 vprop = value - qmin;
\r
128 qannotations[i] = new Annotation(" ",
\r
129 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
132 if(conservation==null)
\r
134 conservation = new AlignmentAnnotation("Conservation",
\r
135 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
137 0f, // cons.qualityRange[0].floatValue(),
\r
138 11f, // cons.qualityRange[1].floatValue()
\r
140 alignment.addAnnotation(conservation);
\r
141 quality = new AlignmentAnnotation("Quality",
\r
142 "Alignment Quality based on Blosum62 scores",
\r
144 cons.qualityRange[0].floatValue(),
\r
145 cons.qualityRange[1].floatValue(),
\r
147 alignment.addAnnotation(quality);
\r
150 conservation.annotations = annotations;
\r
151 quality.annotations = qannotations;
\r
157 public void updateConsensus()
\r
159 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
161 // this routine prevents vconsensus becoming a new object each time
\r
162 // consenus is calculated. Important for speed of Blosum62
\r
163 // and PID colouring of alignment
\r
164 if(vconsensus == null)
\r
165 vconsensus = alignment.getAAFrequency();
\r
168 Vector temp = alignment.getAAFrequency();
\r
169 vconsensus.clear();
\r
170 Enumeration e = temp.elements();
\r
171 while(e.hasMoreElements())
\r
173 vconsensus.add(e.nextElement());
\r
176 Hashtable hash = null;
\r
177 for (int i = 0; i<alignment.getWidth(); i++)
\r
179 hash = (Hashtable) vconsensus.elementAt(i);
\r
180 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
181 value /= Float.parseFloat(hash.get("size").toString());
\r
184 String maxRes = hash.get("maxResidue")+" ";
\r
185 String mouseOver = hash.get("maxResidue")+" ";
\r
186 if(maxRes.length()>2)
\r
188 mouseOver = "["+maxRes+"] ";
\r
192 mouseOver += (int)value+"%";
\r
193 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
197 if(consensus==null)
\r
199 consensus = new AlignmentAnnotation("% Identity",
\r
200 "PID", annotations, 0f, 100f, 1);
\r
201 alignment.addAnnotation(consensus);
\r
204 consensus.annotations = annotations;
\r
209 public SequenceGroup getSelectionGroup()
\r
211 return selectionGroup;
\r
214 public void setSelectionGroup(SequenceGroup sg)
\r
216 selectionGroup = sg;
\r
220 public boolean getConservationSelected()
\r
222 return conservationColourSelected;
\r
225 public void setConservationSelected(boolean b)
\r
227 conservationColourSelected = b;
\r
230 public boolean getAbovePIDThreshold()
\r
232 return abovePIDThreshold;
\r
235 public void setAbovePIDThreshold(boolean b)
\r
237 abovePIDThreshold = b;
\r
240 public int getStartRes() {
\r
244 public int getEndRes() {
\r
248 public int getStartSeq() {
\r
252 public void setGlobalColourScheme(ColourSchemeI cs)
\r
254 globalColourScheme = cs;
\r
257 public ColourSchemeI getGlobalColourScheme()
\r
259 return globalColourScheme;
\r
263 public void setStartRes(int res) {
\r
264 this.startRes = res;
\r
266 public void setStartSeq(int seq) {
\r
267 this.startSeq = seq;
\r
269 public void setEndRes(int res) {
\r
270 if (res > alignment.getWidth()-1) {
\r
271 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
272 res = alignment.getWidth()-1;
\r
279 public void setEndSeq(int seq) {
\r
280 if (seq > alignment.getHeight()) {
\r
281 seq = alignment.getHeight();
\r
288 public int getEndSeq() {
\r
292 public void setFont(Font f) {
\r
294 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
296 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
297 setCharHeight(fm.getHeight());
\r
298 setCharWidth(fm.charWidth('M'));
\r
301 public Font getFont() {
\r
304 public void setCharWidth(int w) {
\r
305 this.charWidth = w;
\r
307 public int getCharWidth() {
\r
310 public void setCharHeight(int h) {
\r
311 this.charHeight = h;
\r
313 public int getCharHeight() {
\r
316 public void setChunkWidth(int w) {
\r
317 this.chunkWidth = w;
\r
319 public int getChunkWidth() {
\r
322 public void setChunkHeight(int h) {
\r
323 this.chunkHeight = h;
\r
325 public int getChunkHeight() {
\r
326 return chunkHeight;
\r
328 public AlignmentI getAlignment() {
\r
331 public void setAlignment(AlignmentI align) {
\r
332 this.alignment = align;
\r
335 public void setWrapAlignment(boolean state) {
\r
336 wrapAlignment = state;
\r
338 public void setShowText(boolean state) {
\r
342 public void setRenderGaps(boolean state){
\r
343 renderGaps = state;
\r
344 if(renderer instanceof SequenceRenderer)
\r
346 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
347 sr.renderGaps(state);
\r
352 public boolean getColourText()
\r
354 return showColourText;
\r
357 public void setColourText(boolean state)
\r
359 showColourText = state;
\r
362 public void setShowBoxes(boolean state) {
\r
366 public boolean getWrapAlignment() {
\r
367 return wrapAlignment;
\r
369 public boolean getShowText() {
\r
372 public boolean getShowBoxes() {
\r
376 public char getGapCharacter() {
\r
377 return getAlignment().getGapCharacter();
\r
379 public void setGapCharacter(char gap) {
\r
380 if (getAlignment() != null) {
\r
381 getAlignment().setGapCharacter(gap);
\r
384 public void setThreshold(int thresh) {
\r
385 threshold = thresh;
\r
387 public int getThreshold() {
\r
390 public void setIncrement(int inc) {
\r
393 public int getIncrement() {
\r
396 public int getIndex(int y) {
\r
398 int starty = getStartSeq();
\r
399 int endy = getEndSeq();
\r
401 for (int i = starty; i <= endy; i++) {
\r
402 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
403 int y2 = y1 + getCharHeight();
\r
405 if (y>=y1 && y <=y2) {
\r
416 public ColumnSelection getColumnSelection() {
\r
420 public void resetSeqLimits(int height) {
\r
421 setEndSeq(height/getCharHeight());
\r
423 public void setCurrentTree(NJTree tree) {
\r
424 currentTree = tree;
\r
426 public NJTree getCurrentTree() {
\r
427 return currentTree;
\r
430 public void setRenderer(RendererI rend) {
\r
431 this.renderer = rend;
\r
434 public RendererI getRenderer() {
\r
438 public void setColourAppliesToAllGroups(boolean b)
\r
439 { colourAppliesToAllGroups = b; }
\r
441 public boolean getColourAppliesToAllGroups()
\r
442 {return colourAppliesToAllGroups; }
\r
444 public boolean getShowFullId()
\r
449 public void setShowFullId(boolean b)
\r
454 public boolean getShowAnnotation()
\r
456 return showAnnotation;
\r
459 public void setShowAnnotation(boolean b)
\r
461 showAnnotation = b;
\r
464 public boolean getScaleAboveWrapped()
\r
465 { return scaleAboveWrapped;}
\r
467 public boolean getScaleLeftWrapped()
\r
468 { return scaleLeftWrapped; }
\r
470 public boolean getScaleRightWrapped()
\r
471 { return scaleRightWrapped; }
\r
473 public void setScaleAboveWrapped(boolean b)
\r
474 { scaleAboveWrapped = b; }
\r
476 public void setScaleLeftWrapped(boolean b)
\r
477 { scaleLeftWrapped = b; }
\r
479 public void setScaleRightWrapped(boolean b)
\r
480 { scaleRightWrapped = b; }
\r