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 void updateConservation()
\r
84 int percGaps = 100; // JBPNote : This should be a scalable property!
\r
85 Conservation cons = new jalview.analysis.Conservation("All",
\r
86 jalview.schemes.ResidueProperties.propHash, 1,
\r
87 alignment.getSequences(), 0,
\r
88 alignment.getWidth());
\r
90 cons.verdict(false, percGaps);
\r
92 int alWidth = alignment.getWidth();
\r
93 Annotation [] annotations = new Annotation[alWidth];
\r
94 Annotation [] qannotations = new Annotation[alWidth];
\r
95 String sequence = cons.getConsSequence().getSequence();
\r
96 float minR,minG,minB, maxR,maxG,maxB;
\r
100 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
103 float qmin = cons.qualityRange[0].floatValue();
\r
104 float qmax = cons.qualityRange[1].floatValue();
\r
106 for (int i = 0; i < alWidth; i++)
\r
111 value = Integer.parseInt(sequence.charAt(i) + "");
\r
113 catch (Exception ex)
\r
115 if (sequence.charAt(i) == '*') value = 11;
\r
116 if (sequence.charAt(i) == '+') value = 10;
\r
118 float vprop = value-min;
\r
120 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
121 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
123 value = ((Double) cons.quality.get(i)).floatValue();
\r
124 vprop = value - qmin;
\r
126 qannotations[i] = new Annotation(sequence.charAt(i) + "",
\r
127 new String().valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
130 if(conservation==null)
\r
132 conservation = new AlignmentAnnotation("Conservation",
\r
133 "Conservation of total alignment less than "+percGaps+"% gaps",
\r
135 0f, // cons.qualityRange[0].floatValue(),
\r
136 11f, // cons.qualityRange[1].floatValue()
\r
138 alignment.addAnnotation(conservation);
\r
139 quality = new AlignmentAnnotation("Quality",
\r
140 "Alignment Quality based on Blosum62 scores",
\r
142 cons.qualityRange[0].floatValue(),
\r
143 cons.qualityRange[1].floatValue(),
\r
145 alignment.addAnnotation(quality);
\r
148 conservation.annotations = annotations;
\r
149 quality.annotations = qannotations;
\r
155 public void updateConsensus()
\r
157 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
159 Vector cons = alignment.getAAFrequency();
\r
160 Hashtable hash = null;
\r
161 for (int i = 0, alWidth=alignment.getWidth(); i<alWidth; i++)
\r
163 hash = (Hashtable) cons.elementAt(i);
\r
164 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
165 value /= Float.parseFloat(hash.get("size").toString());
\r
168 String maxRes = hash.get("maxResidue")+" ";
\r
169 String mouseOver = hash.get("maxResidue")+" ";
\r
170 if(maxRes.length()>2)
\r
172 mouseOver = "["+maxRes+"] ";
\r
176 mouseOver += (int)value+"%";
\r
177 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
181 if(consensus==null)
\r
183 consensus = new AlignmentAnnotation("% Identity",
\r
184 "PID", annotations, 0f, 100f, 1);
\r
185 alignment.addAnnotation(consensus);
\r
188 consensus.annotations = annotations;
\r
192 public String getVisibleConsensus()
\r
194 return visibleConsensus;
\r
197 String visibleConsensus;
\r
198 Vector consensusV = new Vector();
\r
199 public Vector getConsensus(boolean recalculate)
\r
201 if(recalculate || consensusV.size()<1)
\r
203 consensusV = alignment.getAAFrequency();
\r
204 StringBuffer sb = new StringBuffer();
\r
205 Hashtable hash = null;
\r
206 for (int i = 0, sz=consensusV.size(); i < sz; i++)
\r
208 hash = (Hashtable) consensusV.elementAt(i);
\r
209 sb.append(hash.get("maxResidue").toString().charAt(0));
\r
211 visibleConsensus = sb.toString();
\r
219 public SequenceGroup getSelectionGroup()
\r
221 return selectionGroup;
\r
224 public void setSelectionGroup(SequenceGroup sg)
\r
226 selectionGroup = sg;
\r
230 public boolean getConservationSelected()
\r
232 return conservationColourSelected;
\r
235 public void setConservationSelected(boolean b)
\r
237 conservationColourSelected = b;
\r
240 public boolean getAbovePIDThreshold()
\r
242 return abovePIDThreshold;
\r
245 public void setAbovePIDThreshold(boolean b)
\r
247 abovePIDThreshold = b;
\r
250 public int getStartRes() {
\r
254 public int getEndRes() {
\r
258 public int getStartSeq() {
\r
262 public void setGlobalColourScheme(ColourSchemeI cs)
\r
264 globalColourScheme = cs;
\r
267 public ColourSchemeI getGlobalColourScheme()
\r
269 return globalColourScheme;
\r
273 public void setStartRes(int res) {
\r
274 this.startRes = res;
\r
276 public void setStartSeq(int seq) {
\r
277 this.startSeq = seq;
\r
279 public void setEndRes(int res) {
\r
280 if (res > alignment.getWidth()-1) {
\r
281 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
282 res = alignment.getWidth()-1;
\r
289 public void setEndSeq(int seq) {
\r
290 if (seq > alignment.getHeight()) {
\r
291 seq = alignment.getHeight();
\r
298 public int getEndSeq() {
\r
302 public void setFont(Font f) {
\r
304 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
306 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
307 setCharHeight(fm.getHeight());
\r
308 setCharWidth(fm.charWidth('M'));
\r
311 public Font getFont() {
\r
314 public void setCharWidth(int w) {
\r
315 this.charWidth = w;
\r
317 public int getCharWidth() {
\r
320 public void setCharHeight(int h) {
\r
321 this.charHeight = h;
\r
323 public int getCharHeight() {
\r
326 public void setChunkWidth(int w) {
\r
327 this.chunkWidth = w;
\r
329 public int getChunkWidth() {
\r
332 public void setChunkHeight(int h) {
\r
333 this.chunkHeight = h;
\r
335 public int getChunkHeight() {
\r
336 return chunkHeight;
\r
338 public AlignmentI getAlignment() {
\r
341 public void setAlignment(AlignmentI align) {
\r
342 this.alignment = align;
\r
345 public void setWrapAlignment(boolean state) {
\r
346 wrapAlignment = state;
\r
348 public void setShowText(boolean state) {
\r
352 public void setRenderGaps(boolean state){
\r
353 renderGaps = state;
\r
354 if(renderer instanceof SequenceRenderer)
\r
356 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
357 sr.renderGaps(state);
\r
362 public boolean getColourText()
\r
364 return showColourText;
\r
367 public void setColourText(boolean state)
\r
369 showColourText = state;
\r
372 public void setShowBoxes(boolean state) {
\r
376 public boolean getWrapAlignment() {
\r
377 return wrapAlignment;
\r
379 public boolean getShowText() {
\r
382 public boolean getShowBoxes() {
\r
386 public char getGapCharacter() {
\r
387 return getAlignment().getGapCharacter();
\r
389 public void setGapCharacter(char gap) {
\r
390 if (getAlignment() != null) {
\r
391 getAlignment().setGapCharacter(gap);
\r
394 public void setThreshold(int thresh) {
\r
395 threshold = thresh;
\r
397 public int getThreshold() {
\r
400 public void setIncrement(int inc) {
\r
403 public int getIncrement() {
\r
406 public int getIndex(int y) {
\r
408 int starty = getStartSeq();
\r
409 int endy = getEndSeq();
\r
411 for (int i = starty; i <= endy; i++) {
\r
412 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
413 int y2 = y1 + getCharHeight();
\r
415 if (y>=y1 && y <=y2) {
\r
426 public ColumnSelection getColumnSelection() {
\r
430 public void resetSeqLimits(int height) {
\r
431 setEndSeq(height/getCharHeight());
\r
433 public void setCurrentTree(NJTree tree) {
\r
434 currentTree = tree;
\r
436 public NJTree getCurrentTree() {
\r
437 return currentTree;
\r
440 public void setRenderer(RendererI rend) {
\r
441 this.renderer = rend;
\r
444 public RendererI getRenderer() {
\r
448 public void setColourAppliesToAllGroups(boolean b)
\r
449 { colourAppliesToAllGroups = b; }
\r
451 public boolean getColourAppliesToAllGroups()
\r
452 {return colourAppliesToAllGroups; }
\r
454 public boolean getShowFullId()
\r
459 public void setShowFullId(boolean b)
\r
464 public boolean getShowAnnotation()
\r
466 return showAnnotation;
\r
469 public void setShowAnnotation(boolean b)
\r
471 showAnnotation = b;
\r
474 public boolean getScaleAboveWrapped()
\r
475 { return scaleAboveWrapped;}
\r
477 public boolean getScaleLeftWrapped()
\r
478 { return scaleLeftWrapped; }
\r
480 public boolean getScaleRightWrapped()
\r
481 { return scaleRightWrapped; }
\r
483 public void setScaleAboveWrapped(boolean b)
\r
484 { scaleAboveWrapped = b; }
\r
486 public void setScaleLeftWrapped(boolean b)
\r
487 { scaleLeftWrapped = b; }
\r
489 public void setScaleRightWrapped(boolean b)
\r
490 { scaleRightWrapped = b; }
\r