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
52 public AlignViewport(AlignmentI al,
\r
55 boolean wrapAlignment) {
\r
58 this.endRes = al.getWidth()-1;
\r
60 this.endSeq = al.getHeight()-1;
\r
61 this.showText = showText;
\r
62 this.showBoxes = showBoxes;
\r
63 this.wrapAlignment = wrapAlignment;
\r
69 public void showSequenceFeatures(boolean b)
\r
71 showSequenceFeatures = b;
\r
74 AlignmentAnnotation consensus;
\r
75 AlignmentAnnotation conservation;
\r
76 public void updateConservation()
\r
78 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
80 Conservation cons = new jalview.analysis.Conservation("All",
\r
81 jalview.schemes.ResidueProperties.propHash, 3,
\r
82 alignment.getSequences(), 0,
\r
83 alignment.getWidth());
\r
85 cons.verdict(false, 100);
\r
87 String sequence = cons.getConsSequence().getSequence();
\r
88 float minR,minG,minB, maxR,maxG,maxB;
\r
92 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring
\r
93 float min = cons.qualityRange[0].floatValue();
\r
94 float max = cons.qualityRange[1].floatValue();
\r
96 for (int i = 0; i < alignment.getWidth(); i++)
\r
101 //value = Integer.parseInt(sequence.charAt(i) + "");
\r
102 value = ((Double) cons.quality.get(i)).floatValue();
\r
104 catch (Exception ex)
\r
106 if (sequence.charAt(i) == '*') value = 10;
\r
108 float vprop = value-min;
\r
110 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
111 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minB+maxB*vprop, minB+maxB*vprop));
\r
114 if(conservation==null)
\r
116 conservation = new AlignmentAnnotation("Conservation",
\r
117 "Conservation of total alignment",
\r
119 cons.qualityRange[0].floatValue(),
\r
120 cons.qualityRange[1].floatValue(), 1);
\r
121 alignment.addAnnotation(conservation);
\r
124 conservation.annotations = annotations;
\r
128 public void updateConsensus()
\r
130 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
132 Vector cons = alignment.getAAFrequency();
\r
133 Hashtable hash = null;
\r
134 for (int i = 0; i < alignment.getWidth(); i++)
\r
136 hash = (Hashtable) cons.elementAt(i);
\r
137 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
138 value /= Float.parseFloat(hash.get("size").toString());
\r
141 String maxRes = hash.get("maxResidue")+" ";
\r
142 String mouseOver = hash.get("maxResidue")+" ";
\r
143 if(maxRes.length()>2)
\r
145 mouseOver = "["+maxRes+"] ";
\r
149 mouseOver += (int)value+"%";
\r
150 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
154 if(consensus==null)
\r
156 consensus = new AlignmentAnnotation("% Identity",
\r
157 "PID", annotations, 0f, 100f, 1);
\r
158 alignment.addAnnotation(consensus);
\r
161 consensus.annotations = annotations;
\r
165 public String getVisibleConsensus()
\r
167 return visibleConsensus;
\r
170 String visibleConsensus;
\r
171 Vector consensusV = new Vector();
\r
172 public Vector getConsensus(boolean recalculate)
\r
174 if(recalculate || consensusV.size()<1)
\r
176 consensusV = alignment.getAAFrequency();
\r
177 StringBuffer sb = new StringBuffer();
\r
178 Hashtable hash = null;
\r
179 for (int i = 0; i < consensusV.size(); i++)
\r
181 hash = (Hashtable) consensusV.elementAt(i);
\r
182 sb.append(hash.get("maxResidue").toString().charAt(0));
\r
184 visibleConsensus = sb.toString();
\r
192 public SequenceGroup getSelectionGroup()
\r
194 return selectionGroup;
\r
197 public void setSelectionGroup(SequenceGroup sg)
\r
199 selectionGroup = sg;
\r
203 public boolean getConservationSelected()
\r
205 return conservationColourSelected;
\r
208 public void setConservationSelected(boolean b)
\r
210 conservationColourSelected = b;
\r
213 public boolean getAbovePIDThreshold()
\r
215 return abovePIDThreshold;
\r
218 public void setAbovePIDThreshold(boolean b)
\r
220 abovePIDThreshold = b;
\r
223 public int getStartRes() {
\r
227 public int getEndRes() {
\r
231 public int getStartSeq() {
\r
235 public void setGlobalColourScheme(ColourSchemeI cs)
\r
237 globalColourScheme = cs;
\r
240 public ColourSchemeI getGlobalColourScheme()
\r
242 return globalColourScheme;
\r
246 public void setStartRes(int res) {
\r
247 this.startRes = res;
\r
249 public void setStartSeq(int seq) {
\r
250 this.startSeq = seq;
\r
252 public void setEndRes(int res) {
\r
253 if (res > alignment.getWidth()-1) {
\r
254 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
255 res = alignment.getWidth() -1;
\r
262 public void setEndSeq(int seq) {
\r
263 if (seq > alignment.getHeight()) {
\r
264 seq = alignment.getHeight();
\r
271 public int getEndSeq() {
\r
275 public void setFont(Font f) {
\r
277 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
279 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
280 setCharHeight(fm.getHeight());
\r
281 setCharWidth(fm.charWidth('M'));
\r
284 public Font getFont() {
\r
287 public void setCharWidth(int w) {
\r
288 this.charWidth = w;
\r
290 public int getCharWidth() {
\r
293 public void setCharHeight(int h) {
\r
294 this.charHeight = h;
\r
296 public int getCharHeight() {
\r
299 public void setChunkWidth(int w) {
\r
300 this.chunkWidth = w;
\r
302 public int getChunkWidth() {
\r
305 public void setChunkHeight(int h) {
\r
306 this.chunkHeight = h;
\r
308 public int getChunkHeight() {
\r
309 return chunkHeight;
\r
311 public AlignmentI getAlignment() {
\r
314 public void setAlignment(AlignmentI align) {
\r
315 this.alignment = align;
\r
318 public void setWrapAlignment(boolean state) {
\r
319 wrapAlignment = state;
\r
321 public void setShowText(boolean state) {
\r
325 public void setRenderGaps(boolean state){
\r
326 renderGaps = state;
\r
327 if(renderer instanceof SequenceRenderer)
\r
329 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
330 sr.renderGaps(state);
\r
335 public boolean getColourText()
\r
337 return showColourText;
\r
340 public void setColourText(boolean state)
\r
342 showColourText = state;
\r
345 public void setShowBoxes(boolean state) {
\r
349 public boolean getWrapAlignment() {
\r
350 return wrapAlignment;
\r
352 public boolean getShowText() {
\r
355 public boolean getShowBoxes() {
\r
359 public char getGapCharacter() {
\r
360 return getAlignment().getGapCharacter();
\r
362 public void setGapCharacter(char gap) {
\r
363 if (getAlignment() != null) {
\r
364 getAlignment().setGapCharacter(gap);
\r
367 public void setThreshold(int thresh) {
\r
368 threshold = thresh;
\r
370 public int getThreshold() {
\r
373 public void setIncrement(int inc) {
\r
376 public int getIncrement() {
\r
379 public int getIndex(int y) {
\r
381 int starty = getStartSeq();
\r
382 int endy = getEndSeq();
\r
384 for (int i = starty; i <= endy; i++) {
\r
385 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
386 int y2 = y1 + getCharHeight();
\r
388 if (y>=y1 && y <=y2) {
\r
399 public ColumnSelection getColumnSelection() {
\r
403 public void resetSeqLimits(int height) {
\r
404 setEndSeq(height/getCharHeight());
\r
406 public void setCurrentTree(NJTree tree) {
\r
407 currentTree = tree;
\r
409 public NJTree getCurrentTree() {
\r
410 return currentTree;
\r
413 public void setRenderer(RendererI rend) {
\r
414 this.renderer = rend;
\r
417 public RendererI getRenderer() {
\r
421 public void setColourAppliesToAllGroups(boolean b)
\r
422 { colourAppliesToAllGroups = b; }
\r
424 public boolean getColourAppliesToAllGroups()
\r
425 {return colourAppliesToAllGroups; }
\r
427 public boolean getShowFullId()
\r
432 public void setShowFullId(boolean b)
\r
437 public boolean getShowAnnotation()
\r
439 return showAnnotation;
\r
442 public void setShowAnnotation(boolean b)
\r
444 showAnnotation = b;
\r