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 public void updateConservation()
\r
82 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
84 Conservation cons = new jalview.analysis.Conservation("All",
\r
85 jalview.schemes.ResidueProperties.propHash, 3,
\r
86 alignment.getSequences(), 0,
\r
87 alignment.getWidth());
\r
89 cons.verdict(false, 100);
\r
91 String sequence = cons.getConsSequence().getSequence();
\r
92 float minR,minG,minB, maxR,maxG,maxB;
\r
96 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring
\r
97 float min = cons.qualityRange[0].floatValue();
\r
98 float max = cons.qualityRange[1].floatValue();
\r
100 for (int i = 0; i < alignment.getWidth(); i++)
\r
105 //value = Integer.parseInt(sequence.charAt(i) + "");
\r
106 value = ((Double) cons.quality.get(i)).floatValue();
\r
108 catch (Exception ex)
\r
110 if (sequence.charAt(i) == '*') value = 10;
\r
112 float vprop = value-min;
\r
114 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
115 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minB+maxB*vprop, minB+maxB*vprop));
\r
118 if(conservation==null)
\r
120 conservation = new AlignmentAnnotation("Quality",
\r
121 "Quality of total alignment",
\r
123 cons.qualityRange[0].floatValue(),
\r
124 cons.qualityRange[1].floatValue(), 1);
\r
125 alignment.addAnnotation(conservation);
\r
128 conservation.annotations = annotations;
\r
132 public void updateConsensus()
\r
134 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
136 Vector cons = alignment.getAAFrequency();
\r
137 Hashtable hash = null;
\r
138 for (int i = 0; i < alignment.getWidth(); i++)
\r
140 hash = (Hashtable) cons.elementAt(i);
\r
141 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
142 value /= Float.parseFloat(hash.get("size").toString());
\r
145 String maxRes = hash.get("maxResidue")+" ";
\r
146 String mouseOver = hash.get("maxResidue")+" ";
\r
147 if(maxRes.length()>2)
\r
149 mouseOver = "["+maxRes+"] ";
\r
153 mouseOver += (int)value+"%";
\r
154 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
158 if(consensus==null)
\r
160 consensus = new AlignmentAnnotation("% Identity",
\r
161 "PID", annotations, 0f, 100f, 1);
\r
162 alignment.addAnnotation(consensus);
\r
165 consensus.annotations = annotations;
\r
169 public String getVisibleConsensus()
\r
171 return visibleConsensus;
\r
174 String visibleConsensus;
\r
175 Vector consensusV = new Vector();
\r
176 public Vector getConsensus(boolean recalculate)
\r
178 if(recalculate || consensusV.size()<1)
\r
180 consensusV = alignment.getAAFrequency();
\r
181 StringBuffer sb = new StringBuffer();
\r
182 Hashtable hash = null;
\r
183 for (int i = 0; i < consensusV.size(); i++)
\r
185 hash = (Hashtable) consensusV.elementAt(i);
\r
186 sb.append(hash.get("maxResidue").toString().charAt(0));
\r
188 visibleConsensus = sb.toString();
\r
196 public SequenceGroup getSelectionGroup()
\r
198 return selectionGroup;
\r
201 public void setSelectionGroup(SequenceGroup sg)
\r
203 selectionGroup = sg;
\r
207 public boolean getConservationSelected()
\r
209 return conservationColourSelected;
\r
212 public void setConservationSelected(boolean b)
\r
214 conservationColourSelected = b;
\r
217 public boolean getAbovePIDThreshold()
\r
219 return abovePIDThreshold;
\r
222 public void setAbovePIDThreshold(boolean b)
\r
224 abovePIDThreshold = b;
\r
227 public int getStartRes() {
\r
231 public int getEndRes() {
\r
235 public int getStartSeq() {
\r
239 public void setGlobalColourScheme(ColourSchemeI cs)
\r
241 globalColourScheme = cs;
\r
244 public ColourSchemeI getGlobalColourScheme()
\r
246 return globalColourScheme;
\r
250 public void setStartRes(int res) {
\r
251 this.startRes = res;
\r
253 public void setStartSeq(int seq) {
\r
254 this.startSeq = seq;
\r
256 public void setEndRes(int res) {
\r
257 if (res > alignment.getWidth()-1) {
\r
258 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
259 res = alignment.getWidth() -1;
\r
266 public void setEndSeq(int seq) {
\r
267 if (seq > alignment.getHeight()) {
\r
268 seq = alignment.getHeight();
\r
275 public int getEndSeq() {
\r
279 public void setFont(Font f) {
\r
281 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
283 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
284 setCharHeight(fm.getHeight());
\r
285 setCharWidth(fm.charWidth('M'));
\r
288 public Font getFont() {
\r
291 public void setCharWidth(int w) {
\r
292 this.charWidth = w;
\r
294 public int getCharWidth() {
\r
297 public void setCharHeight(int h) {
\r
298 this.charHeight = h;
\r
300 public int getCharHeight() {
\r
303 public void setChunkWidth(int w) {
\r
304 this.chunkWidth = w;
\r
306 public int getChunkWidth() {
\r
309 public void setChunkHeight(int h) {
\r
310 this.chunkHeight = h;
\r
312 public int getChunkHeight() {
\r
313 return chunkHeight;
\r
315 public AlignmentI getAlignment() {
\r
318 public void setAlignment(AlignmentI align) {
\r
319 this.alignment = align;
\r
322 public void setWrapAlignment(boolean state) {
\r
323 wrapAlignment = state;
\r
325 public void setShowText(boolean state) {
\r
329 public void setRenderGaps(boolean state){
\r
330 renderGaps = state;
\r
331 if(renderer instanceof SequenceRenderer)
\r
333 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
334 sr.renderGaps(state);
\r
339 public boolean getColourText()
\r
341 return showColourText;
\r
344 public void setColourText(boolean state)
\r
346 showColourText = state;
\r
349 public void setShowBoxes(boolean state) {
\r
353 public boolean getWrapAlignment() {
\r
354 return wrapAlignment;
\r
356 public boolean getShowText() {
\r
359 public boolean getShowBoxes() {
\r
363 public char getGapCharacter() {
\r
364 return getAlignment().getGapCharacter();
\r
366 public void setGapCharacter(char gap) {
\r
367 if (getAlignment() != null) {
\r
368 getAlignment().setGapCharacter(gap);
\r
371 public void setThreshold(int thresh) {
\r
372 threshold = thresh;
\r
374 public int getThreshold() {
\r
377 public void setIncrement(int inc) {
\r
380 public int getIncrement() {
\r
383 public int getIndex(int y) {
\r
385 int starty = getStartSeq();
\r
386 int endy = getEndSeq();
\r
388 for (int i = starty; i <= endy; i++) {
\r
389 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
390 int y2 = y1 + getCharHeight();
\r
392 if (y>=y1 && y <=y2) {
\r
403 public ColumnSelection getColumnSelection() {
\r
407 public void resetSeqLimits(int height) {
\r
408 setEndSeq(height/getCharHeight());
\r
410 public void setCurrentTree(NJTree tree) {
\r
411 currentTree = tree;
\r
413 public NJTree getCurrentTree() {
\r
414 return currentTree;
\r
417 public void setRenderer(RendererI rend) {
\r
418 this.renderer = rend;
\r
421 public RendererI getRenderer() {
\r
425 public void setColourAppliesToAllGroups(boolean b)
\r
426 { colourAppliesToAllGroups = b; }
\r
428 public boolean getColourAppliesToAllGroups()
\r
429 {return colourAppliesToAllGroups; }
\r
431 public boolean getShowFullId()
\r
436 public void setShowFullId(boolean b)
\r
441 public boolean getShowAnnotation()
\r
443 return showAnnotation;
\r
446 public void setShowAnnotation(boolean b)
\r
448 showAnnotation = b;
\r
451 public boolean getScaleAboveWrapped()
\r
452 { return scaleAboveWrapped;}
\r
454 public boolean getScaleLeftWrapped()
\r
455 { return scaleLeftWrapped; }
\r
457 public boolean getScaleRightWrapped()
\r
458 { return scaleRightWrapped; }
\r
460 public void setScaleAboveWrapped(boolean b)
\r
461 { scaleAboveWrapped = b; }
\r
463 public void setScaleLeftWrapped(boolean b)
\r
464 { scaleLeftWrapped = b; }
\r
466 public void setScaleRightWrapped(boolean b)
\r
467 { scaleRightWrapped = b; }
\r