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
153 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
154 "", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
156 value = ((Double) cons.quality.elementAt(i)).floatValue();
\r
157 vprop = value - qmin;
\r
159 qannotations[i] = new Annotation(" ",
\r
160 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
163 if(conservation==null)
\r
165 conservation = new AlignmentAnnotation("Conservation",
\r
166 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
168 0f, // cons.qualityRange[0].floatValue(),
\r
169 11f, // cons.qualityRange[1].floatValue()
\r
171 if(showConservation)
\r
172 alignment.addAnnotation(conservation);
\r
173 quality = new AlignmentAnnotation("Quality",
\r
174 "Alignment Quality based on Blosum62 scores",
\r
176 cons.qualityRange[0].floatValue(),
\r
177 cons.qualityRange[1].floatValue(),
\r
180 alignment.addAnnotation(quality);
\r
183 conservation.annotations = annotations;
\r
184 quality.annotations = qannotations;
\r
185 quality.graphMax = cons.qualityRange[1].floatValue();
\r
191 public void updateConsensus()
\r
193 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
195 // this routine prevents vconsensus becoming a new object each time
\r
196 // consenus is calculated. Important for speed of Blosum62
\r
197 // and PID colouring of alignment
\r
198 if(vconsensus == null)
\r
199 vconsensus = alignment.getAAFrequency();
\r
202 Vector temp = alignment.getAAFrequency();
\r
203 vconsensus.removeAllElements();
\r
204 Enumeration e = temp.elements();
\r
205 while(e.hasMoreElements())
\r
207 vconsensus.addElement(e.nextElement());
\r
210 Hashtable hash = null;
\r
211 for (int i = 0; i<alignment.getWidth(); i++)
\r
213 hash = (Hashtable) vconsensus.elementAt(i);
\r
214 float value = new Float(hash.get("maxCount").toString()).floatValue();
\r
215 value /= new Float(hash.get("size").toString()).floatValue();
\r
218 String maxRes = hash.get("maxResidue")+" ";
\r
219 String mouseOver = hash.get("maxResidue")+" ";
\r
220 if(maxRes.length()>2)
\r
222 mouseOver = "["+maxRes+"] ";
\r
226 mouseOver += (int)value+"%";
\r
227 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
231 if(consensus==null)
\r
233 consensus = new AlignmentAnnotation("Consensus",
\r
234 "PID", annotations, 0f, 100f, 1);
\r
236 alignment.addAnnotation(consensus);
\r
239 consensus.annotations = annotations;
\r
244 public SequenceGroup getSelectionGroup()
\r
246 return selectionGroup;
\r
249 public void setSelectionGroup(SequenceGroup sg)
\r
251 selectionGroup = sg;
\r
255 public boolean getConservationSelected()
\r
257 return conservationColourSelected;
\r
260 public void setConservationSelected(boolean b)
\r
262 conservationColourSelected = b;
\r
265 public boolean getAbovePIDThreshold()
\r
267 return abovePIDThreshold;
\r
270 public void setAbovePIDThreshold(boolean b)
\r
272 abovePIDThreshold = b;
\r
275 public int getStartRes() {
\r
279 public int getEndRes() {
\r
283 public int getStartSeq() {
\r
287 public void setGlobalColourScheme(ColourSchemeI cs)
\r
289 globalColourScheme = cs;
\r
292 public ColourSchemeI getGlobalColourScheme()
\r
294 return globalColourScheme;
\r
298 public void setStartRes(int res) {
\r
299 this.startRes = res;
\r
301 public void setStartSeq(int seq) {
\r
302 this.startSeq = seq;
\r
304 public void setEndRes(int res) {
\r
305 if (res > alignment.getWidth()-1) {
\r
306 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
307 res = alignment.getWidth()-1;
\r
314 public void setEndSeq(int seq) {
\r
315 if (seq > alignment.getHeight()) {
\r
316 seq = alignment.getHeight();
\r
323 public int getEndSeq() {
\r
327 public void setFont(Font f) {
\r
329 java.awt.Frame temp = new java.awt.Frame();
\r
331 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
332 setCharHeight(fm.getHeight());
\r
333 setCharWidth(fm.charWidth('M'));
\r
336 public Font getFont() {
\r
339 public void setCharWidth(int w) {
\r
340 this.charWidth = w;
\r
342 public int getCharWidth() {
\r
345 public void setCharHeight(int h) {
\r
346 this.charHeight = h;
\r
348 public int getCharHeight() {
\r
351 public void setChunkWidth(int w) {
\r
352 this.chunkWidth = w;
\r
354 public int getChunkWidth() {
\r
357 public void setChunkHeight(int h) {
\r
358 this.chunkHeight = h;
\r
360 public int getChunkHeight() {
\r
361 return chunkHeight;
\r
363 public AlignmentI getAlignment() {
\r
366 public void setAlignment(AlignmentI align) {
\r
367 this.alignment = align;
\r
370 public void setWrapAlignment(boolean state) {
\r
371 wrapAlignment = state;
\r
373 public void setShowText(boolean state) {
\r
377 public void setRenderGaps(boolean state){
\r
378 renderGaps = state;
\r
382 public boolean getColourText()
\r
384 return showColourText;
\r
387 public void setColourText(boolean state)
\r
389 showColourText = state;
\r
392 public void setShowBoxes(boolean state) {
\r
396 public boolean getWrapAlignment() {
\r
397 return wrapAlignment;
\r
399 public boolean getShowText() {
\r
402 public boolean getShowBoxes() {
\r
406 public char getGapCharacter() {
\r
407 return getAlignment().getGapCharacter();
\r
409 public void setGapCharacter(char gap) {
\r
410 if (getAlignment() != null) {
\r
411 getAlignment().setGapCharacter(gap);
\r
414 public void setThreshold(int thresh) {
\r
415 threshold = thresh;
\r
417 public int getThreshold() {
\r
420 public void setIncrement(int inc) {
\r
423 public int getIncrement() {
\r
426 public int getIndex(int y) {
\r
428 int starty = getStartSeq();
\r
429 int endy = getEndSeq();
\r
431 for (int i = starty; i <= endy; i++) {
\r
432 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
433 int y2 = y1 + getCharHeight();
\r
435 if (y>=y1 && y <=y2) {
\r
446 public ColumnSelection getColumnSelection() {
\r
450 public void resetSeqLimits(int height) {
\r
451 setEndSeq(height/getCharHeight());
\r
453 public void setCurrentTree(NJTree tree) {
\r
454 currentTree = tree;
\r
456 public NJTree getCurrentTree() {
\r
457 return currentTree;
\r
461 public void setColourAppliesToAllGroups(boolean b)
\r
462 { colourAppliesToAllGroups = b; }
\r
464 public boolean getColourAppliesToAllGroups()
\r
465 {return colourAppliesToAllGroups; }
\r
467 public boolean getShowFullId()
\r
472 public void setShowFullId(boolean b)
\r
477 public boolean getShowAnnotation()
\r
479 return showAnnotation;
\r
482 public void setShowAnnotation(boolean b)
\r
484 showAnnotation = b;
\r
487 public boolean getScaleAboveWrapped()
\r
488 { return scaleAboveWrapped;}
\r
490 public boolean getScaleLeftWrapped()
\r
491 { return scaleLeftWrapped; }
\r
493 public boolean getScaleRightWrapped()
\r
494 { return scaleRightWrapped; }
\r
496 public void setScaleAboveWrapped(boolean b)
\r
497 { scaleAboveWrapped = b; }
\r
499 public void setScaleLeftWrapped(boolean b)
\r
500 { scaleLeftWrapped = b; }
\r
502 public void setScaleRightWrapped(boolean b)
\r
503 { scaleRightWrapped = b; }
\r