1 package jalview.appletgui;
\r
4 import jalview.bin.*;
\r
5 import jalview.analysis.*;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.schemes.*;
\r
10 public class AlignViewport
\r
18 boolean showFullId = true;
\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
26 boolean showConservation = true;
\r
27 boolean showQuality = true;
\r
28 boolean showConsensus = true;
\r
30 boolean colourAppliesToAllGroups = true;
\r
31 ColourSchemeI globalColourScheme = null;
\r
32 boolean conservationColourSelected = false;
\r
33 boolean abovePIDThreshold = false;
\r
35 SequenceGroup selectionGroup = new SequenceGroup();
\r
42 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
43 AlignmentI alignment;
\r
45 ColumnSelection colSel = new ColumnSelection();
\r
50 NJTree currentTree = null;
\r
52 boolean scaleAboveWrapped = true;
\r
53 boolean scaleLeftWrapped = true;
\r
54 boolean scaleRightWrapped = true;
\r
56 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
60 this.endRes = al.getWidth()-1;
\r
62 this.endSeq = al.getHeight()-1;
\r
68 String param = applet.getParameter("showFullId");
\r
70 showFullId = Boolean.valueOf(param).booleanValue();
\r
72 param = applet.getParameter("showAnnotation");
\r
74 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
76 param = applet.getParameter("showConservation");
\r
78 showConservation = Boolean.valueOf(param).booleanValue();
\r
80 param = applet.getParameter("showQuality");
\r
82 showQuality = Boolean.valueOf(param).booleanValue();
\r
84 param = applet.getParameter("showConsensus");
\r
86 showConsensus = Boolean.valueOf(param).booleanValue();
\r
88 // We must set conservation and consensus before setting colour,
\r
89 // as Blosum and Clustal require this to be done
\r
90 updateConservation();
\r
93 if(applet!=null && applet.getParameter("defaultColour")!=null)
\r
95 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
96 applet.getParameter("defaultColour"));
\r
97 if(globalColourScheme!=null)
\r
98 globalColourScheme.setConsensus( vconsensus );
\r
103 public void showSequenceFeatures(boolean b)
\r
105 showSequenceFeatures = b;
\r
108 public Vector vconsensus;
\r
109 AlignmentAnnotation consensus;
\r
110 AlignmentAnnotation conservation;
\r
111 AlignmentAnnotation quality;
\r
113 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
115 public void updateConservation()
\r
117 Conservation cons = new jalview.analysis.Conservation("All",
\r
118 jalview.schemes.ResidueProperties.propHash, 3,
\r
119 alignment.getSequences(), 0,
\r
120 alignment.getWidth()-1);
\r
122 cons.verdict(false, ConsPercGaps);
\r
123 cons.findQuality();
\r
124 int alWidth = alignment.getWidth();
\r
125 Annotation [] annotations = new Annotation[alWidth];
\r
126 Annotation [] qannotations = new Annotation[alWidth];
\r
127 String sequence = cons.getConsSequence().getSequence();
\r
128 float minR,minG,minB, maxR,maxG,maxB;
\r
132 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
135 float qmin = cons.qualityRange[0].floatValue();
\r
136 float qmax = cons.qualityRange[1].floatValue();
\r
138 for (int i = 0; i < alWidth; i++)
\r
143 value = Integer.parseInt(sequence.charAt(i) + "");
\r
145 catch (Exception ex)
\r
147 if (sequence.charAt(i) == '*') value = 11;
\r
148 if (sequence.charAt(i) == '+') value = 10;
\r
150 float vprop = value-min;
\r
152 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
153 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
155 value = ((Double) cons.quality.elementAt(i)).floatValue();
\r
156 vprop = value - qmin;
\r
158 qannotations[i] = new Annotation(" ",
\r
159 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
162 if(conservation==null)
\r
164 conservation = new AlignmentAnnotation("Conservation",
\r
165 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
167 0f, // cons.qualityRange[0].floatValue(),
\r
168 11f, // cons.qualityRange[1].floatValue()
\r
170 if(showConservation)
\r
171 alignment.addAnnotation(conservation);
\r
172 quality = new AlignmentAnnotation("Quality",
\r
173 "Alignment Quality based on Blosum62 scores",
\r
175 cons.qualityRange[0].floatValue(),
\r
176 cons.qualityRange[1].floatValue(),
\r
179 alignment.addAnnotation(quality);
\r
182 conservation.annotations = annotations;
\r
183 quality.annotations = qannotations;
\r
184 quality.graphMax = cons.qualityRange[1].floatValue();
\r
190 public void updateConsensus()
\r
192 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
194 // this routine prevents vconsensus becoming a new object each time
\r
195 // consenus is calculated. Important for speed of Blosum62
\r
196 // and PID colouring of alignment
\r
197 if(vconsensus == null)
\r
198 vconsensus = alignment.getAAFrequency();
\r
201 Vector temp = alignment.getAAFrequency();
\r
202 vconsensus.removeAllElements();
\r
203 Enumeration e = temp.elements();
\r
204 while(e.hasMoreElements())
\r
206 vconsensus.addElement(e.nextElement());
\r
209 Hashtable hash = null;
\r
210 for (int i = 0; i<alignment.getWidth(); i++)
\r
212 hash = (Hashtable) vconsensus.elementAt(i);
\r
213 float value = new Float(hash.get("maxCount").toString()).floatValue();
\r
214 value /= new Float(hash.get("size").toString()).floatValue();
\r
217 String maxRes = hash.get("maxResidue")+" ";
\r
218 String mouseOver = hash.get("maxResidue")+" ";
\r
219 if(maxRes.length()>2)
\r
221 mouseOver = "["+maxRes+"] ";
\r
225 mouseOver += (int)value+"%";
\r
226 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
230 if(consensus==null)
\r
232 consensus = new AlignmentAnnotation("Consensus",
\r
233 "PID", annotations, 0f, 100f, 1);
\r
235 alignment.addAnnotation(consensus);
\r
238 consensus.annotations = annotations;
\r
243 public SequenceGroup getSelectionGroup()
\r
245 return selectionGroup;
\r
248 public void setSelectionGroup(SequenceGroup sg)
\r
250 selectionGroup = sg;
\r
254 public boolean getConservationSelected()
\r
256 return conservationColourSelected;
\r
259 public void setConservationSelected(boolean b)
\r
261 conservationColourSelected = b;
\r
264 public boolean getAbovePIDThreshold()
\r
266 return abovePIDThreshold;
\r
269 public void setAbovePIDThreshold(boolean b)
\r
271 abovePIDThreshold = b;
\r
274 public int getStartRes() {
\r
278 public int getEndRes() {
\r
282 public int getStartSeq() {
\r
286 public void setGlobalColourScheme(ColourSchemeI cs)
\r
288 globalColourScheme = cs;
\r
291 public ColourSchemeI getGlobalColourScheme()
\r
293 return globalColourScheme;
\r
297 public void setStartRes(int res) {
\r
298 this.startRes = res;
\r
300 public void setStartSeq(int seq) {
\r
301 this.startSeq = seq;
\r
303 public void setEndRes(int res) {
\r
304 if (res > alignment.getWidth()-1) {
\r
305 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
306 res = alignment.getWidth()-1;
\r
313 public void setEndSeq(int seq) {
\r
314 if (seq > alignment.getHeight()) {
\r
315 seq = alignment.getHeight();
\r
322 public int getEndSeq() {
\r
326 public void setFont(Font f) {
\r
328 java.awt.Frame temp = new java.awt.Frame();
\r
330 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
331 setCharHeight(fm.getHeight());
\r
332 setCharWidth(fm.charWidth('M'));
\r
335 public Font getFont() {
\r
338 public void setCharWidth(int w) {
\r
339 this.charWidth = w;
\r
341 public int getCharWidth() {
\r
344 public void setCharHeight(int h) {
\r
345 this.charHeight = h;
\r
347 public int getCharHeight() {
\r
350 public void setChunkWidth(int w) {
\r
351 this.chunkWidth = w;
\r
353 public int getChunkWidth() {
\r
356 public void setChunkHeight(int h) {
\r
357 this.chunkHeight = h;
\r
359 public int getChunkHeight() {
\r
360 return chunkHeight;
\r
362 public AlignmentI getAlignment() {
\r
365 public void setAlignment(AlignmentI align) {
\r
366 this.alignment = align;
\r
369 public void setWrapAlignment(boolean state) {
\r
370 wrapAlignment = state;
\r
372 public void setShowText(boolean state) {
\r
376 public void setRenderGaps(boolean state){
\r
377 renderGaps = state;
\r
381 public boolean getColourText()
\r
383 return showColourText;
\r
386 public void setColourText(boolean state)
\r
388 showColourText = state;
\r
391 public void setShowBoxes(boolean state) {
\r
395 public boolean getWrapAlignment() {
\r
396 return wrapAlignment;
\r
398 public boolean getShowText() {
\r
401 public boolean getShowBoxes() {
\r
405 public char getGapCharacter() {
\r
406 return getAlignment().getGapCharacter();
\r
408 public void setGapCharacter(char gap) {
\r
409 if (getAlignment() != null) {
\r
410 getAlignment().setGapCharacter(gap);
\r
413 public void setThreshold(int thresh) {
\r
414 threshold = thresh;
\r
416 public int getThreshold() {
\r
419 public void setIncrement(int inc) {
\r
422 public int getIncrement() {
\r
425 public int getIndex(int y) {
\r
427 int starty = getStartSeq();
\r
428 int endy = getEndSeq();
\r
430 for (int i = starty; i <= endy; i++) {
\r
431 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
432 int y2 = y1 + getCharHeight();
\r
434 if (y>=y1 && y <=y2) {
\r
445 public ColumnSelection getColumnSelection() {
\r
449 public void resetSeqLimits(int height) {
\r
450 setEndSeq(height/getCharHeight());
\r
452 public void setCurrentTree(NJTree tree) {
\r
453 currentTree = tree;
\r
455 public NJTree getCurrentTree() {
\r
456 return currentTree;
\r
460 public void setColourAppliesToAllGroups(boolean b)
\r
461 { colourAppliesToAllGroups = b; }
\r
463 public boolean getColourAppliesToAllGroups()
\r
464 {return colourAppliesToAllGroups; }
\r
466 public boolean getShowFullId()
\r
471 public void setShowFullId(boolean b)
\r
476 public boolean getShowAnnotation()
\r
478 return showAnnotation;
\r
481 public void setShowAnnotation(boolean b)
\r
483 showAnnotation = b;
\r
486 public boolean getScaleAboveWrapped()
\r
487 { return scaleAboveWrapped;}
\r
489 public boolean getScaleLeftWrapped()
\r
490 { return scaleLeftWrapped; }
\r
492 public boolean getScaleRightWrapped()
\r
493 { return scaleRightWrapped; }
\r
495 public void setScaleAboveWrapped(boolean b)
\r
496 { scaleAboveWrapped = b; }
\r
498 public void setScaleLeftWrapped(boolean b)
\r
499 { scaleLeftWrapped = b; }
\r
501 public void setScaleRightWrapped(boolean b)
\r
502 { scaleRightWrapped = b; }
\r