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 showJVSuffix = 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
62 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
63 AlignmentI alignment;
\r
65 ColumnSelection colSel = new ColumnSelection();
\r
70 NJTree currentTree = null;
\r
72 boolean scaleAboveWrapped = true;
\r
73 boolean scaleLeftWrapped = true;
\r
74 boolean scaleRightWrapped = true;
\r
76 // The following vector holds the features which are
\r
77 // currently visible, in the correct order or rendering
\r
78 Hashtable featuresDisplayed = null;
\r
81 public Vector vconsensus;
\r
82 AlignmentAnnotation consensus;
\r
83 AlignmentAnnotation conservation;
\r
84 AlignmentAnnotation quality;
\r
86 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
88 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
90 boolean ignoreGapsInConsensusCalculation = false;
\r
92 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
96 this.endRes = al.getWidth() - 1;
\r
98 this.endSeq = al.getHeight() - 1;
\r
101 if (applet != null)
\r
103 String param = applet.getParameter("showFullId");
\r
106 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
109 param = applet.getParameter("showAnnotation");
\r
112 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
115 param = applet.getParameter("showConservation");
\r
118 showConservation = Boolean.valueOf(param).booleanValue();
\r
121 param = applet.getParameter("showQuality");
\r
124 showQuality = Boolean.valueOf(param).booleanValue();
\r
127 param = applet.getParameter("showConsensus");
\r
130 showConsensus = Boolean.valueOf(param).booleanValue();
\r
133 // We must set conservation and consensus before setting colour,
\r
134 // as Blosum and Clustal require this to be done
\r
135 updateConservation();
\r
138 if (applet != null && applet.getParameter("defaultColour") != null)
\r
140 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
141 applet.getParameter("defaultColour"));
\r
142 if (globalColourScheme != null)
\r
144 globalColourScheme.setConsensus(vconsensus);
\r
149 public void showSequenceFeatures(boolean b)
\r
151 showSequenceFeatures = b;
\r
154 public boolean getShowSequenceFeatures()
\r
156 return showSequenceFeatures;
\r
160 public void updateConservation()
\r
162 if(alignment.isNucleotide())
\r
165 Conservation cons = new jalview.analysis.Conservation("All",
\r
166 jalview.schemes.ResidueProperties.propHash, 3,
\r
167 alignment.getSequences(), 0,
\r
168 alignment.getWidth() - 1);
\r
170 cons.verdict(false, ConsPercGaps);
\r
171 cons.findQuality();
\r
172 int alWidth = alignment.getWidth();
\r
173 Annotation[] annotations = new Annotation[alWidth];
\r
174 Annotation[] qannotations = new Annotation[alWidth];
\r
175 String sequence = cons.getConsSequence().getSequence();
\r
176 float minR, minG, minB, maxR, maxG, maxB;
\r
180 maxR = 1.0f - minR;
\r
181 maxG = 0.9f - minG;
\r
182 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
185 float qmin = cons.qualityRange[0].floatValue();
\r
186 float qmax = cons.qualityRange[1].floatValue();
\r
188 for (int i = 0; i < alWidth; i++)
\r
193 value = Integer.parseInt(sequence.charAt(i) + "");
\r
195 catch (Exception ex)
\r
197 if (sequence.charAt(i) == '*')
\r
201 if (sequence.charAt(i) == '+')
\r
206 float vprop = value - min;
\r
209 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
211 new Color(minR + maxR * vprop,
\r
212 minG + maxG * vprop,
\r
213 minB + maxB * vprop));
\r
215 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
216 vprop = value - qmin;
\r
218 qannotations[i] = new Annotation(" ",
\r
219 String.valueOf(value), ' ', value,
\r
221 Color(minR + maxR * vprop,
\r
222 minG + maxG * vprop,
\r
223 minB + maxB * vprop));
\r
226 if (conservation == null)
\r
228 conservation = new AlignmentAnnotation("Conservation",
\r
229 "Conservation of total alignment less than " +
\r
230 ConsPercGaps + "% gaps",
\r
232 0f, // cons.qualityRange[0].floatValue(),
\r
233 11f, // cons.qualityRange[1].floatValue()
\r
234 AlignmentAnnotation.BAR_GRAPH);
\r
235 if (showConservation)
\r
237 alignment.addAnnotation(conservation);
\r
239 quality = new AlignmentAnnotation("Quality",
\r
240 "Alignment Quality based on Blosum62 scores",
\r
242 cons.qualityRange[0].floatValue(),
\r
243 cons.qualityRange[1].floatValue(),
\r
244 AlignmentAnnotation.BAR_GRAPH);
\r
247 alignment.addAnnotation(quality);
\r
252 conservation.annotations = annotations;
\r
253 quality.annotations = qannotations;
\r
254 quality.graphMax = cons.qualityRange[1].floatValue();
\r
259 public void updateConsensus()
\r
261 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
263 // this routine prevents vconsensus becoming a new object each time
\r
264 // consenus is calculated. Important for speed of Blosum62
\r
265 // and PID colouring of alignment
\r
266 if (vconsensus == null)
\r
268 vconsensus = alignment.getAAFrequency();
\r
272 Vector temp = alignment.getAAFrequency();
\r
273 vconsensus.removeAllElements();
\r
274 Enumeration e = temp.elements();
\r
275 while (e.hasMoreElements())
\r
277 vconsensus.addElement(e.nextElement());
\r
280 Hashtable hash = null;
\r
281 for (int i = 0; i < alignment.getWidth(); i++)
\r
283 hash = (Hashtable) vconsensus.elementAt(i);
\r
285 if(ignoreGapsInConsensusCalculation)
\r
286 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
288 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
290 String maxRes = hash.get("maxResidue").toString();
\r
291 String mouseOver = hash.get("maxResidue") + " ";
\r
292 if (maxRes.length() > 1)
\r
294 mouseOver = "[" + maxRes + "] ";
\r
299 mouseOver += (int) value + "%";
\r
300 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
304 if (consensus == null)
\r
306 consensus = new AlignmentAnnotation("Consensus",
\r
307 "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
\r
310 alignment.addAnnotation(consensus);
\r
315 consensus.annotations = annotations;
\r
318 if(globalColourScheme!=null)
\r
319 globalColourScheme.setConsensus(vconsensus);
\r
323 public SequenceGroup getSelectionGroup()
\r
325 return selectionGroup;
\r
328 public void setSelectionGroup(SequenceGroup sg)
\r
330 selectionGroup = sg;
\r
333 public boolean getConservationSelected()
\r
335 return conservationColourSelected;
\r
338 public void setConservationSelected(boolean b)
\r
340 conservationColourSelected = b;
\r
343 public boolean getAbovePIDThreshold()
\r
345 return abovePIDThreshold;
\r
348 public void setAbovePIDThreshold(boolean b)
\r
350 abovePIDThreshold = b;
\r
353 public int getStartRes()
\r
358 public int getEndRes()
\r
363 public int getStartSeq()
\r
368 public void setGlobalColourScheme(ColourSchemeI cs)
\r
370 globalColourScheme = cs;
\r
373 public ColourSchemeI getGlobalColourScheme()
\r
375 return globalColourScheme;
\r
378 public void setStartRes(int res)
\r
380 this.startRes = res;
\r
383 public void setStartSeq(int seq)
\r
385 this.startSeq = seq;
\r
388 public void setEndRes(int res)
\r
390 if (res > alignment.getWidth() - 1)
\r
392 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
393 res = alignment.getWidth() - 1;
\r
402 public void setEndSeq(int seq)
\r
404 if (seq > alignment.getHeight())
\r
406 seq = alignment.getHeight();
\r
415 public int getEndSeq()
\r
420 public void setFont(Font f)
\r
423 java.awt.Frame temp = new java.awt.Frame();
\r
425 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
426 setCharHeight(fm.getHeight());
\r
427 setCharWidth(fm.charWidth('M'));
\r
430 public Font getFont()
\r
435 public void setCharWidth(int w)
\r
437 this.charWidth = w;
\r
440 public int getCharWidth()
\r
445 public void setCharHeight(int h)
\r
447 this.charHeight = h;
\r
450 public int getCharHeight()
\r
455 public void setWrappedWidth(int w)
\r
457 this.wrappedWidth = w;
\r
460 public int getwrappedWidth()
\r
462 return wrappedWidth;
\r
465 public AlignmentI getAlignment()
\r
470 public void setAlignment(AlignmentI align)
\r
472 this.alignment = align;
\r
475 public void setWrapAlignment(boolean state)
\r
477 wrapAlignment = state;
\r
480 public void setShowText(boolean state)
\r
485 public void setRenderGaps(boolean state)
\r
487 renderGaps = state;
\r
490 public boolean getColourText()
\r
492 return showColourText;
\r
495 public void setColourText(boolean state)
\r
497 showColourText = state;
\r
500 public void setShowBoxes(boolean state)
\r
505 public boolean getWrapAlignment()
\r
507 return wrapAlignment;
\r
510 public boolean getShowText()
\r
515 public boolean getShowBoxes()
\r
520 public char getGapCharacter()
\r
522 return getAlignment().getGapCharacter();
\r
525 public void setGapCharacter(char gap)
\r
527 if (getAlignment() != null)
\r
529 getAlignment().setGapCharacter(gap);
\r
533 public void setThreshold(int thresh)
\r
535 threshold = thresh;
\r
538 public int getThreshold()
\r
543 public void setIncrement(int inc)
\r
548 public int getIncrement()
\r
553 public int getIndex(int y)
\r
556 int starty = getStartSeq();
\r
557 int endy = getEndSeq();
\r
559 for (int i = starty; i <= endy; i++)
\r
561 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
563 int y2 = y1 + getCharHeight();
\r
565 if (y >= y1 && y <= y2)
\r
579 public ColumnSelection getColumnSelection()
\r
584 public void resetSeqLimits(int height)
\r
586 setEndSeq(height / getCharHeight());
\r
589 public void setCurrentTree(NJTree tree)
\r
591 currentTree = tree;
\r
594 public NJTree getCurrentTree()
\r
596 return currentTree;
\r
599 public void setColourAppliesToAllGroups(boolean b)
\r
601 colourAppliesToAllGroups = b;
\r
604 public boolean getColourAppliesToAllGroups()
\r
606 return colourAppliesToAllGroups;
\r
609 public boolean getShowJVSuffix()
\r
611 return showJVSuffix;
\r
614 public void setShowJVSuffix(boolean b)
\r
619 public boolean getShowAnnotation()
\r
621 return showAnnotation;
\r
624 public void setShowAnnotation(boolean b)
\r
626 showAnnotation = b;
\r
629 public boolean getScaleAboveWrapped()
\r
631 return scaleAboveWrapped;
\r
634 public boolean getScaleLeftWrapped()
\r
636 return scaleLeftWrapped;
\r
639 public boolean getScaleRightWrapped()
\r
641 return scaleRightWrapped;
\r
644 public void setScaleAboveWrapped(boolean b)
\r
646 scaleAboveWrapped = b;
\r
649 public void setScaleLeftWrapped(boolean b)
\r
651 scaleLeftWrapped = b;
\r
654 public void setScaleRightWrapped(boolean b)
\r
656 scaleRightWrapped = b;
\r
659 public void setIgnoreGapsConsensus(boolean b)
\r
661 ignoreGapsInConsensusCalculation = b;
\r
663 if (globalColourScheme!=null)
\r
665 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
666 ignoreGapsInConsensusCalculation);
\r
672 * Property change listener for changes in alignment
\r
674 * @param listener DOCUMENT ME!
\r
676 public void addPropertyChangeListener(
\r
677 java.beans.PropertyChangeListener listener)
\r
679 changeSupport.addPropertyChangeListener(listener);
\r
685 * @param listener DOCUMENT ME!
\r
687 public void removePropertyChangeListener(
\r
688 java.beans.PropertyChangeListener listener)
\r
690 changeSupport.removePropertyChangeListener(listener);
\r
694 * Property change listener for changes in alignment
\r
696 * @param prop DOCUMENT ME!
\r
697 * @param oldvalue DOCUMENT ME!
\r
698 * @param newvalue DOCUMENT ME!
\r
700 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
702 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
707 public boolean getIgnoreGapsConsensus()
\r
709 return ignoreGapsInConsensusCalculation;
\r