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 for (int i = 0; i < alignment.getWidth(); i++)
\r
93 value = Integer.parseInt(sequence.charAt(i) + "");
\r
95 catch (Exception ex)
\r
97 if (sequence.charAt(i) == '*') value = 10;
\r
100 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
101 "Conservation graph", ' ', value);
\r
104 if(conservation==null)
\r
106 conservation = new AlignmentAnnotation("Conservation",
\r
107 "Conservation of total alignment",
\r
108 annotations, 0, 10, 1);
\r
109 alignment.addAnnotation(conservation);
\r
112 conservation.annotations = annotations;
\r
116 public void updateConsensus()
\r
118 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
120 Vector cons = alignment.getAAFrequency();
\r
121 Hashtable hash = null;
\r
122 for (int i = 0; i < alignment.getWidth(); i++)
\r
124 hash = (Hashtable) cons.elementAt(i);
\r
125 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
126 value /= Float.parseFloat(hash.get("size").toString());
\r
129 String maxRes = hash.get("maxResidue")+" ";
\r
130 String mouseOver = hash.get("maxResidue")+" ";
\r
131 if(maxRes.length()>2)
\r
133 mouseOver = "["+maxRes+"] ";
\r
137 mouseOver += (int)value+"%";
\r
138 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
142 if(consensus==null)
\r
144 consensus = new AlignmentAnnotation("% Identity",
\r
145 "PID", annotations, 0f, 100f, 1);
\r
146 alignment.addAnnotation(consensus);
\r
149 consensus.annotations = annotations;
\r
153 public String getVisibleConsensus()
\r
155 return visibleConsensus;
\r
158 String visibleConsensus;
\r
159 Vector consensusV = new Vector();
\r
160 public Vector getConsensus(boolean recalculate)
\r
162 if(recalculate || consensusV.size()<1)
\r
164 consensusV = alignment.getAAFrequency();
\r
165 StringBuffer sb = new StringBuffer();
\r
166 Hashtable hash = null;
\r
167 for (int i = 0; i < consensusV.size(); i++)
\r
169 hash = (Hashtable) consensusV.elementAt(i);
\r
170 sb.append(hash.get("maxResidue").toString().charAt(0));
\r
172 visibleConsensus = sb.toString();
\r
180 public SequenceGroup getSelectionGroup()
\r
182 return selectionGroup;
\r
185 public void setSelectionGroup(SequenceGroup sg)
\r
187 selectionGroup = sg;
\r
191 public boolean getConservationSelected()
\r
193 return conservationColourSelected;
\r
196 public void setConservationSelected(boolean b)
\r
198 conservationColourSelected = b;
\r
201 public boolean getAbovePIDThreshold()
\r
203 return abovePIDThreshold;
\r
206 public void setAbovePIDThreshold(boolean b)
\r
208 abovePIDThreshold = b;
\r
211 public int getStartRes() {
\r
215 public int getEndRes() {
\r
219 public int getStartSeq() {
\r
223 public void setGlobalColourScheme(ColourSchemeI cs)
\r
225 globalColourScheme = cs;
\r
228 public ColourSchemeI getGlobalColourScheme()
\r
230 return globalColourScheme;
\r
234 public void setStartRes(int res) {
\r
235 this.startRes = res;
\r
237 public void setStartSeq(int seq) {
\r
238 this.startSeq = seq;
\r
240 public void setEndRes(int res) {
\r
241 if (res > alignment.getWidth()-1) {
\r
242 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
243 res = alignment.getWidth() -1;
\r
250 public void setEndSeq(int seq) {
\r
251 if (seq > alignment.getHeight()) {
\r
252 seq = alignment.getHeight();
\r
259 public int getEndSeq() {
\r
263 public void setFont(Font f) {
\r
265 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
267 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
268 setCharHeight(fm.getHeight());
\r
269 setCharWidth(fm.charWidth('M'));
\r
272 public Font getFont() {
\r
275 public void setCharWidth(int w) {
\r
276 this.charWidth = w;
\r
278 public int getCharWidth() {
\r
281 public void setCharHeight(int h) {
\r
282 this.charHeight = h;
\r
284 public int getCharHeight() {
\r
287 public void setChunkWidth(int w) {
\r
288 this.chunkWidth = w;
\r
290 public int getChunkWidth() {
\r
293 public void setChunkHeight(int h) {
\r
294 this.chunkHeight = h;
\r
296 public int getChunkHeight() {
\r
297 return chunkHeight;
\r
299 public AlignmentI getAlignment() {
\r
302 public void setAlignment(AlignmentI align) {
\r
303 this.alignment = align;
\r
306 public void setWrapAlignment(boolean state) {
\r
307 wrapAlignment = state;
\r
309 public void setShowText(boolean state) {
\r
313 public void setRenderGaps(boolean state){
\r
314 renderGaps = state;
\r
315 if(renderer instanceof SequenceRenderer)
\r
317 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
318 sr.renderGaps(state);
\r
323 public boolean getColourText()
\r
325 return showColourText;
\r
328 public void setColourText(boolean state)
\r
330 showColourText = state;
\r
333 public void setShowBoxes(boolean state) {
\r
337 public boolean getWrapAlignment() {
\r
338 return wrapAlignment;
\r
340 public boolean getShowText() {
\r
343 public boolean getShowBoxes() {
\r
347 public char getGapCharacter() {
\r
348 return getAlignment().getGapCharacter();
\r
350 public void setGapCharacter(char gap) {
\r
351 if (getAlignment() != null) {
\r
352 getAlignment().setGapCharacter(gap);
\r
355 public void setThreshold(int thresh) {
\r
356 threshold = thresh;
\r
358 public int getThreshold() {
\r
361 public void setIncrement(int inc) {
\r
364 public int getIncrement() {
\r
367 public int getIndex(int y) {
\r
369 int starty = getStartSeq();
\r
370 int endy = getEndSeq();
\r
372 for (int i = starty; i <= endy; i++) {
\r
373 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
374 int y2 = y1 + getCharHeight();
\r
376 if (y>=y1 && y <=y2) {
\r
387 public ColumnSelection getColumnSelection() {
\r
391 public void resetSeqLimits(int height) {
\r
392 setEndSeq(height/getCharHeight());
\r
394 public void setCurrentTree(NJTree tree) {
\r
395 currentTree = tree;
\r
397 public NJTree getCurrentTree() {
\r
398 return currentTree;
\r
401 public void setRenderer(RendererI rend) {
\r
402 this.renderer = rend;
\r
405 public RendererI getRenderer() {
\r
409 public void setColourAppliesToAllGroups(boolean b)
\r
410 { colourAppliesToAllGroups = b; }
\r
412 public boolean getColourAppliesToAllGroups()
\r
413 {return colourAppliesToAllGroups; }
\r
415 public boolean getShowFullId()
\r
420 public void setShowFullId(boolean b)
\r
425 public boolean getShowAnnotation()
\r
427 return showAnnotation;
\r
430 public void setShowAnnotation(boolean b)
\r
432 showAnnotation = b;
\r