4 import jalview.analysis.*;
\r
5 import jalview.analysis.NJTree;
\r
6 import jalview.datamodel.*;
\r
7 import jalview.schemes.*;
\r
9 import jalview.bin.Cache;
\r
11 public class AlignViewport
\r
19 boolean showFullId = false;
\r
20 boolean showText=true;
\r
21 boolean showColourText=false;
\r
22 boolean showBoxes=true;
\r
23 boolean wrapAlignment=false;
\r
24 boolean renderGaps = true;
\r
25 boolean showSequenceFeatures = false;
\r
26 boolean showAnnotation = true;
\r
27 boolean showConservation = true;
\r
28 boolean showQuality = true;
\r
29 boolean showIdentity = true;
\r
31 boolean colourAppliesToAllGroups = true;
\r
32 ColourSchemeI globalColourScheme = null;
\r
33 boolean conservationColourSelected = false;
\r
34 boolean abovePIDThreshold = false;
\r
36 SequenceGroup selectionGroup = new SequenceGroup();
\r
38 RendererI renderer = new SequenceRenderer(this);
\r
45 Font font = new Font("SansSerif",Font.PLAIN,10);
\r
46 AlignmentI alignment;
\r
48 ColumnSelection colSel = new ColumnSelection();
\r
53 NJTree currentTree = null;
\r
55 boolean scaleAboveWrapped = false;
\r
56 boolean scaleLeftWrapped = true;
\r
57 boolean scaleRightWrapped = true;
\r
60 public AlignViewport(AlignmentI al)
\r
64 this.endRes = al.getWidth()-1;
\r
66 this.endSeq = al.getHeight()-1;
\r
68 updateFromPreferences();
\r
72 public void updateFromPreferences()
\r
74 String string = Cache.getProperty("SHOW_FULL_ID");
\r
76 showFullId = Boolean.valueOf(string).booleanValue();
\r
78 string = Cache.getProperty("SHOW_ANNOTATIONS");
\r
80 showAnnotation = Boolean.valueOf(string).booleanValue();
\r
82 string = Cache.getProperty("SHOW_CONSERVATION");
\r
84 showConservation = Boolean.valueOf(string).booleanValue();
\r
85 string = Cache.getProperty("SHOW_QUALITY");
\r
87 showQuality = Boolean.valueOf(string).booleanValue();
\r
88 string = Cache.getProperty("SHOW_IDENTITY");
\r
90 showIdentity = Boolean.valueOf(string).booleanValue();
\r
92 string = Cache.getProperty("SHOW_FULL_ID");
\r
94 showFullId = Boolean.valueOf(string).booleanValue();
\r
96 String fontName = Cache.getProperty("FONT_NAME");
\r
97 String fontStyle= Cache.getProperty("FONT_STYLE");
\r
98 String fontSize = Cache.getProperty("FONT_SIZE");
\r
99 if(fontName!=null && fontStyle!=null && fontSize!=null)
\r
100 setFont( new Font(fontName,Integer.parseInt(fontStyle),Integer.parseInt(fontSize)) );
\r
104 string = Cache.getProperty("GAP_SYMBOL");
\r
106 alignment.setGapCharacter( string.charAt(0) );
\r
109 // We must set conservation and consensus before setting colour,
\r
110 // as Blosum and Clustal require this to be done
\r
111 updateConservation();
\r
113 string = Cache.getProperty("DEFAULT_COLOUR");
\r
116 globalColourScheme = ColourSchemeProperty.getColour(alignment, string);
\r
117 if(globalColourScheme!=null)
\r
118 globalColourScheme.setConsensus( vconsensus );
\r
123 public void showSequenceFeatures(boolean b)
\r
125 showSequenceFeatures = b;
\r
128 public Vector vconsensus;
\r
129 AlignmentAnnotation consensus;
\r
130 AlignmentAnnotation conservation;
\r
131 AlignmentAnnotation quality;
\r
133 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
135 public void updateConservation()
\r
137 Conservation cons = new jalview.analysis.Conservation("All",
\r
138 jalview.schemes.ResidueProperties.propHash, 3,
\r
139 alignment.getSequences(), 0,
\r
140 alignment.getWidth()-1);
\r
142 cons.verdict(false, ConsPercGaps);
\r
143 cons.findQuality();
\r
144 int alWidth = alignment.getWidth();
\r
145 Annotation [] annotations = new Annotation[alWidth];
\r
146 Annotation [] qannotations = new Annotation[alWidth];
\r
147 String sequence = cons.getConsSequence().getSequence();
\r
148 float minR,minG,minB, maxR,maxG,maxB;
\r
152 maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring both Conservation and Quality
\r
155 float qmin = cons.qualityRange[0].floatValue();
\r
156 float qmax = cons.qualityRange[1].floatValue();
\r
158 for (int i = 0; i < alWidth; i++)
\r
163 value = Integer.parseInt(sequence.charAt(i) + "");
\r
165 catch (Exception ex)
\r
167 if (sequence.charAt(i) == '*') value = 11;
\r
168 if (sequence.charAt(i) == '+') value = 10;
\r
170 float vprop = value-min;
\r
172 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
173 "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
175 value = ((Double) cons.quality.get(i)).floatValue();
\r
176 vprop = value - qmin;
\r
178 qannotations[i] = new Annotation(" ",
\r
179 String.valueOf(value), ' ', value, new Color(minR+maxR*vprop, minG+maxG*vprop, minB+maxB*vprop));
\r
182 if(conservation==null)
\r
184 conservation = new AlignmentAnnotation("Conservation",
\r
185 "Conservation of total alignment less than "+ConsPercGaps+"% gaps",
\r
187 0f, // cons.qualityRange[0].floatValue(),
\r
188 11f, // cons.qualityRange[1].floatValue()
\r
190 if(showConservation)
\r
191 alignment.addAnnotation(conservation);
\r
192 quality = new AlignmentAnnotation("Quality",
\r
193 "Alignment Quality based on Blosum62 scores",
\r
195 cons.qualityRange[0].floatValue(),
\r
196 cons.qualityRange[1].floatValue(),
\r
199 alignment.addAnnotation(quality);
\r
202 conservation.annotations = annotations;
\r
203 quality.annotations = qannotations;
\r
204 quality.graphMax = cons.qualityRange[1].floatValue();
\r
210 public void updateConsensus()
\r
212 Annotation [] annotations = new Annotation[alignment.getWidth()];
\r
214 // this routine prevents vconsensus becoming a new object each time
\r
215 // consenus is calculated. Important for speed of Blosum62
\r
216 // and PID colouring of alignment
\r
217 if(vconsensus == null)
\r
218 vconsensus = alignment.getAAFrequency();
\r
221 Vector temp = alignment.getAAFrequency();
\r
222 vconsensus.clear();
\r
223 Enumeration e = temp.elements();
\r
224 while(e.hasMoreElements())
\r
226 vconsensus.add(e.nextElement());
\r
229 Hashtable hash = null;
\r
230 for (int i = 0; i<alignment.getWidth(); i++)
\r
232 hash = (Hashtable) vconsensus.elementAt(i);
\r
233 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
234 value /= Float.parseFloat(hash.get("size").toString());
\r
237 String maxRes = hash.get("maxResidue")+" ";
\r
238 String mouseOver = hash.get("maxResidue")+" ";
\r
239 if(maxRes.length()>2)
\r
241 mouseOver = "["+maxRes+"] ";
\r
245 mouseOver += (int)value+"%";
\r
246 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
250 if(consensus==null)
\r
252 consensus = new AlignmentAnnotation("% Identity",
\r
253 "PID", annotations, 0f, 100f, 1);
\r
255 alignment.addAnnotation(consensus);
\r
258 consensus.annotations = annotations;
\r
263 public SequenceGroup getSelectionGroup()
\r
265 return selectionGroup;
\r
268 public void setSelectionGroup(SequenceGroup sg)
\r
270 selectionGroup = sg;
\r
274 public boolean getConservationSelected()
\r
276 return conservationColourSelected;
\r
279 public void setConservationSelected(boolean b)
\r
281 conservationColourSelected = b;
\r
284 public boolean getAbovePIDThreshold()
\r
286 return abovePIDThreshold;
\r
289 public void setAbovePIDThreshold(boolean b)
\r
291 abovePIDThreshold = b;
\r
294 public int getStartRes() {
\r
298 public int getEndRes() {
\r
302 public int getStartSeq() {
\r
306 public void setGlobalColourScheme(ColourSchemeI cs)
\r
308 globalColourScheme = cs;
\r
311 public ColourSchemeI getGlobalColourScheme()
\r
313 return globalColourScheme;
\r
317 public void setStartRes(int res) {
\r
318 this.startRes = res;
\r
320 public void setStartSeq(int seq) {
\r
321 this.startSeq = seq;
\r
323 public void setEndRes(int res) {
\r
324 if (res > alignment.getWidth()-1) {
\r
325 System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
326 res = alignment.getWidth()-1;
\r
333 public void setEndSeq(int seq) {
\r
334 if (seq > alignment.getHeight()) {
\r
335 seq = alignment.getHeight();
\r
342 public int getEndSeq() {
\r
346 public void setFont(Font f) {
\r
348 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
350 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
351 setCharHeight(fm.getHeight());
\r
352 setCharWidth(fm.charWidth('M'));
\r
355 public Font getFont() {
\r
358 public void setCharWidth(int w) {
\r
359 this.charWidth = w;
\r
361 public int getCharWidth() {
\r
364 public void setCharHeight(int h) {
\r
365 this.charHeight = h;
\r
367 public int getCharHeight() {
\r
370 public void setChunkWidth(int w) {
\r
371 this.chunkWidth = w;
\r
373 public int getChunkWidth() {
\r
376 public void setChunkHeight(int h) {
\r
377 this.chunkHeight = h;
\r
379 public int getChunkHeight() {
\r
380 return chunkHeight;
\r
382 public AlignmentI getAlignment() {
\r
385 public void setAlignment(AlignmentI align) {
\r
386 this.alignment = align;
\r
389 public void setWrapAlignment(boolean state) {
\r
390 wrapAlignment = state;
\r
392 public void setShowText(boolean state) {
\r
396 public void setRenderGaps(boolean state){
\r
397 renderGaps = state;
\r
398 if(renderer instanceof SequenceRenderer)
\r
400 SequenceRenderer sr = (SequenceRenderer)renderer;
\r
401 sr.renderGaps(state);
\r
406 public boolean getColourText()
\r
408 return showColourText;
\r
411 public void setColourText(boolean state)
\r
413 showColourText = state;
\r
416 public void setShowBoxes(boolean state) {
\r
420 public boolean getWrapAlignment() {
\r
421 return wrapAlignment;
\r
423 public boolean getShowText() {
\r
426 public boolean getShowBoxes() {
\r
430 public char getGapCharacter() {
\r
431 return getAlignment().getGapCharacter();
\r
433 public void setGapCharacter(char gap) {
\r
434 if (getAlignment() != null) {
\r
435 getAlignment().setGapCharacter(gap);
\r
438 public void setThreshold(int thresh) {
\r
439 threshold = thresh;
\r
441 public int getThreshold() {
\r
444 public void setIncrement(int inc) {
\r
447 public int getIncrement() {
\r
450 public int getIndex(int y) {
\r
452 int starty = getStartSeq();
\r
453 int endy = getEndSeq();
\r
455 for (int i = starty; i <= endy; i++) {
\r
456 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {
\r
457 int y2 = y1 + getCharHeight();
\r
459 if (y>=y1 && y <=y2) {
\r
470 public ColumnSelection getColumnSelection() {
\r
474 public void resetSeqLimits(int height) {
\r
475 setEndSeq(height/getCharHeight());
\r
477 public void setCurrentTree(NJTree tree) {
\r
478 currentTree = tree;
\r
480 public NJTree getCurrentTree() {
\r
481 return currentTree;
\r
484 public void setRenderer(RendererI rend) {
\r
485 this.renderer = rend;
\r
488 public RendererI getRenderer() {
\r
492 public void setColourAppliesToAllGroups(boolean b)
\r
493 { colourAppliesToAllGroups = b; }
\r
495 public boolean getColourAppliesToAllGroups()
\r
496 {return colourAppliesToAllGroups; }
\r
498 public boolean getShowFullId()
\r
503 public void setShowFullId(boolean b)
\r
508 public boolean getShowAnnotation()
\r
510 return showAnnotation;
\r
513 public void setShowAnnotation(boolean b)
\r
515 showAnnotation = b;
\r
518 public boolean getScaleAboveWrapped()
\r
519 { return scaleAboveWrapped;}
\r
521 public boolean getScaleLeftWrapped()
\r
522 { return scaleLeftWrapped; }
\r
524 public boolean getScaleRightWrapped()
\r
525 { return scaleRightWrapped; }
\r
527 public void setScaleAboveWrapped(boolean b)
\r
528 { scaleAboveWrapped = b; }
\r
530 public void setScaleLeftWrapped(boolean b)
\r
531 { scaleLeftWrapped = b; }
\r
533 public void setScaleRightWrapped(boolean b)
\r
534 { scaleRightWrapped = b; }
\r