2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
26 import jalview.analysis.*;
\r
27 import jalview.bin.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.schemes.*;
\r
31 public class AlignViewport
\r
39 boolean showFullId = true;
\r
40 boolean showText = true;
\r
41 boolean showColourText = false;
\r
42 boolean showBoxes = true;
\r
43 boolean wrapAlignment = false;
\r
44 boolean renderGaps = true;
\r
45 boolean showSequenceFeatures = false;
\r
46 boolean showAnnotation = true;
\r
47 boolean showConservation = true;
\r
48 boolean showQuality = true;
\r
49 boolean showConsensus = true;
\r
51 boolean colourAppliesToAllGroups = true;
\r
52 ColourSchemeI globalColourScheme = null;
\r
53 boolean conservationColourSelected = false;
\r
54 boolean abovePIDThreshold = false;
\r
56 SequenceGroup selectionGroup = new SequenceGroup();
\r
63 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
64 AlignmentI alignment;
\r
66 ColumnSelection colSel = new ColumnSelection();
\r
71 NJTree currentTree = null;
\r
73 boolean scaleAboveWrapped = true;
\r
74 boolean scaleLeftWrapped = true;
\r
75 boolean scaleRightWrapped = true;
\r
77 public Vector vconsensus;
\r
78 AlignmentAnnotation consensus;
\r
79 AlignmentAnnotation conservation;
\r
80 AlignmentAnnotation quality;
\r
82 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
84 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
86 boolean ignoreGapsInConsensusCalculation = false;
\r
88 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
92 this.endRes = al.getWidth() - 1;
\r
94 this.endSeq = al.getHeight() - 1;
\r
99 String param = applet.getParameter("showFullId");
\r
102 showFullId = Boolean.valueOf(param).booleanValue();
\r
105 param = applet.getParameter("showAnnotation");
\r
108 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
111 param = applet.getParameter("showConservation");
\r
114 showConservation = Boolean.valueOf(param).booleanValue();
\r
117 param = applet.getParameter("showQuality");
\r
120 showQuality = Boolean.valueOf(param).booleanValue();
\r
123 param = applet.getParameter("showConsensus");
\r
126 showConsensus = Boolean.valueOf(param).booleanValue();
\r
129 // We must set conservation and consensus before setting colour,
\r
130 // as Blosum and Clustal require this to be done
\r
131 updateConservation();
\r
134 if (applet != null && applet.getParameter("defaultColour") != null)
\r
136 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
137 applet.getParameter("defaultColour"));
\r
138 if (globalColourScheme != null)
\r
140 globalColourScheme.setConsensus(vconsensus);
\r
145 public void showSequenceFeatures(boolean b)
\r
147 showSequenceFeatures = b;
\r
151 public void updateConservation()
\r
153 Conservation cons = new jalview.analysis.Conservation("All",
\r
154 jalview.schemes.ResidueProperties.propHash, 3,
\r
155 alignment.getSequences(), 0,
\r
156 alignment.getWidth() - 1);
\r
158 cons.verdict(false, ConsPercGaps);
\r
159 cons.findQuality();
\r
160 int alWidth = alignment.getWidth();
\r
161 Annotation[] annotations = new Annotation[alWidth];
\r
162 Annotation[] qannotations = new Annotation[alWidth];
\r
163 String sequence = cons.getConsSequence().getSequence();
\r
164 float minR, minG, minB, maxR, maxG, maxB;
\r
168 maxR = 1.0f - minR;
\r
169 maxG = 0.9f - minG;
\r
170 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
173 float qmin = cons.qualityRange[0].floatValue();
\r
174 float qmax = cons.qualityRange[1].floatValue();
\r
176 for (int i = 0; i < alWidth; i++)
\r
181 value = Integer.parseInt(sequence.charAt(i) + "");
\r
183 catch (Exception ex)
\r
185 if (sequence.charAt(i) == '*')
\r
189 if (sequence.charAt(i) == '+')
\r
194 float vprop = value - min;
\r
197 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
199 new Color(minR + maxR * vprop,
\r
200 minG + maxG * vprop,
\r
201 minB + maxB * vprop));
\r
203 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
204 vprop = value - qmin;
\r
206 qannotations[i] = new Annotation(" ",
\r
207 String.valueOf(value), ' ', value,
\r
209 Color(minR + maxR * vprop,
\r
210 minG + maxG * vprop,
\r
211 minB + maxB * vprop));
\r
214 if (conservation == null)
\r
216 conservation = new AlignmentAnnotation("Conservation",
\r
217 "Conservation of total alignment less than " +
\r
218 ConsPercGaps + "% gaps",
\r
220 0f, // cons.qualityRange[0].floatValue(),
\r
221 11f, // cons.qualityRange[1].floatValue()
\r
223 if (showConservation)
\r
225 alignment.addAnnotation(conservation);
\r
227 quality = new AlignmentAnnotation("Quality",
\r
228 "Alignment Quality based on Blosum62 scores",
\r
230 cons.qualityRange[0].floatValue(),
\r
231 cons.qualityRange[1].floatValue(),
\r
235 alignment.addAnnotation(quality);
\r
240 conservation.annotations = annotations;
\r
241 quality.annotations = qannotations;
\r
242 quality.graphMax = cons.qualityRange[1].floatValue();
\r
247 public void updateConsensus()
\r
249 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
251 // this routine prevents vconsensus becoming a new object each time
\r
252 // consenus is calculated. Important for speed of Blosum62
\r
253 // and PID colouring of alignment
\r
254 if (vconsensus == null)
\r
256 vconsensus = alignment.getAAFrequency();
\r
260 Vector temp = alignment.getAAFrequency();
\r
261 vconsensus.removeAllElements();
\r
262 Enumeration e = temp.elements();
\r
263 while (e.hasMoreElements())
\r
265 vconsensus.addElement(e.nextElement());
\r
268 Hashtable hash = null;
\r
269 for (int i = 0; i < alignment.getWidth(); i++)
\r
271 hash = (Hashtable) vconsensus.elementAt(i);
\r
273 if(ignoreGapsInConsensusCalculation)
\r
274 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
276 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
278 String maxRes = hash.get("maxResidue").toString();
\r
279 String mouseOver = hash.get("maxResidue") + " ";
\r
280 if (maxRes.length() > 1)
\r
282 mouseOver = "[" + maxRes + "] ";
\r
287 mouseOver += (int) value + "%";
\r
288 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
292 if (consensus == null)
\r
294 consensus = new AlignmentAnnotation("Consensus",
\r
295 "PID", annotations, 0f, 100f, 1);
\r
298 alignment.addAnnotation(consensus);
\r
303 consensus.annotations = annotations;
\r
306 if(globalColourScheme!=null)
\r
307 globalColourScheme.setConsensus(vconsensus);
\r
311 public SequenceGroup getSelectionGroup()
\r
313 return selectionGroup;
\r
316 public void setSelectionGroup(SequenceGroup sg)
\r
318 selectionGroup = sg;
\r
321 public boolean getConservationSelected()
\r
323 return conservationColourSelected;
\r
326 public void setConservationSelected(boolean b)
\r
328 conservationColourSelected = b;
\r
331 public boolean getAbovePIDThreshold()
\r
333 return abovePIDThreshold;
\r
336 public void setAbovePIDThreshold(boolean b)
\r
338 abovePIDThreshold = b;
\r
341 public int getStartRes()
\r
346 public int getEndRes()
\r
351 public int getStartSeq()
\r
356 public void setGlobalColourScheme(ColourSchemeI cs)
\r
358 globalColourScheme = cs;
\r
361 public ColourSchemeI getGlobalColourScheme()
\r
363 return globalColourScheme;
\r
366 public void setStartRes(int res)
\r
368 this.startRes = res;
\r
371 public void setStartSeq(int seq)
\r
373 this.startSeq = seq;
\r
376 public void setEndRes(int res)
\r
378 if (res > alignment.getWidth() - 1)
\r
380 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
381 res = alignment.getWidth() - 1;
\r
390 public void setEndSeq(int seq)
\r
392 if (seq > alignment.getHeight())
\r
394 seq = alignment.getHeight();
\r
403 public int getEndSeq()
\r
408 public void setFont(Font f)
\r
411 java.awt.Frame temp = new java.awt.Frame();
\r
413 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
414 setCharHeight(fm.getHeight());
\r
415 setCharWidth(fm.charWidth('M'));
\r
418 public Font getFont()
\r
423 public void setCharWidth(int w)
\r
425 this.charWidth = w;
\r
428 public int getCharWidth()
\r
433 public void setCharHeight(int h)
\r
435 this.charHeight = h;
\r
438 public int getCharHeight()
\r
443 public void setChunkWidth(int w)
\r
445 this.chunkWidth = w;
\r
448 public int getChunkWidth()
\r
453 public void setChunkHeight(int h)
\r
455 this.chunkHeight = h;
\r
458 public int getChunkHeight()
\r
460 return chunkHeight;
\r
463 public AlignmentI getAlignment()
\r
468 public void setAlignment(AlignmentI align)
\r
470 this.alignment = align;
\r
473 public void setWrapAlignment(boolean state)
\r
475 wrapAlignment = state;
\r
478 public void setShowText(boolean state)
\r
483 public void setRenderGaps(boolean state)
\r
485 renderGaps = state;
\r
488 public boolean getColourText()
\r
490 return showColourText;
\r
493 public void setColourText(boolean state)
\r
495 showColourText = state;
\r
498 public void setShowBoxes(boolean state)
\r
503 public boolean getWrapAlignment()
\r
505 return wrapAlignment;
\r
508 public boolean getShowText()
\r
513 public boolean getShowBoxes()
\r
518 public char getGapCharacter()
\r
520 return getAlignment().getGapCharacter();
\r
523 public void setGapCharacter(char gap)
\r
525 if (getAlignment() != null)
\r
527 getAlignment().setGapCharacter(gap);
\r
531 public void setThreshold(int thresh)
\r
533 threshold = thresh;
\r
536 public int getThreshold()
\r
541 public void setIncrement(int inc)
\r
546 public int getIncrement()
\r
551 public int getIndex(int y)
\r
554 int starty = getStartSeq();
\r
555 int endy = getEndSeq();
\r
557 for (int i = starty; i <= endy; i++)
\r
559 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
561 int y2 = y1 + getCharHeight();
\r
563 if (y >= y1 && y <= y2)
\r
577 public ColumnSelection getColumnSelection()
\r
582 public void resetSeqLimits(int height)
\r
584 setEndSeq(height / getCharHeight());
\r
587 public void setCurrentTree(NJTree tree)
\r
589 currentTree = tree;
\r
592 public NJTree getCurrentTree()
\r
594 return currentTree;
\r
597 public void setColourAppliesToAllGroups(boolean b)
\r
599 colourAppliesToAllGroups = b;
\r
602 public boolean getColourAppliesToAllGroups()
\r
604 return colourAppliesToAllGroups;
\r
607 public boolean getShowFullId()
\r
612 public void setShowFullId(boolean b)
\r
617 public boolean getShowAnnotation()
\r
619 return showAnnotation;
\r
622 public void setShowAnnotation(boolean b)
\r
624 showAnnotation = b;
\r
627 public boolean getScaleAboveWrapped()
\r
629 return scaleAboveWrapped;
\r
632 public boolean getScaleLeftWrapped()
\r
634 return scaleLeftWrapped;
\r
637 public boolean getScaleRightWrapped()
\r
639 return scaleRightWrapped;
\r
642 public void setScaleAboveWrapped(boolean b)
\r
644 scaleAboveWrapped = b;
\r
647 public void setScaleLeftWrapped(boolean b)
\r
649 scaleLeftWrapped = b;
\r
652 public void setScaleRightWrapped(boolean b)
\r
654 scaleRightWrapped = b;
\r
657 public void setIgnoreGapsConsensus(boolean b)
\r
659 ignoreGapsInConsensusCalculation = b;
\r
661 if (globalColourScheme!=null)
\r
663 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
664 ignoreGapsInConsensusCalculation);
\r
670 * Property change listener for changes in alignment
\r
672 * @param listener DOCUMENT ME!
\r
674 public void addPropertyChangeListener(
\r
675 java.beans.PropertyChangeListener listener)
\r
677 changeSupport.addPropertyChangeListener(listener);
\r
683 * @param listener DOCUMENT ME!
\r
685 public void removePropertyChangeListener(
\r
686 java.beans.PropertyChangeListener listener)
\r
688 changeSupport.removePropertyChangeListener(listener);
\r
692 * Property change listener for changes in alignment
\r
694 * @param prop DOCUMENT ME!
\r
695 * @param oldvalue DOCUMENT ME!
\r
696 * @param newvalue DOCUMENT ME!
\r
698 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
700 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
705 public boolean getIgnoreGapsConsensus()
\r
707 return ignoreGapsInConsensusCalculation;
\r