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
155 public void updateConservation()
\r
157 if(alignment.isNucleotide())
\r
160 Conservation cons = new jalview.analysis.Conservation("All",
\r
161 jalview.schemes.ResidueProperties.propHash, 3,
\r
162 alignment.getSequences(), 0,
\r
163 alignment.getWidth() - 1);
\r
165 cons.verdict(false, ConsPercGaps);
\r
166 cons.findQuality();
\r
167 int alWidth = alignment.getWidth();
\r
168 Annotation[] annotations = new Annotation[alWidth];
\r
169 Annotation[] qannotations = new Annotation[alWidth];
\r
170 String sequence = cons.getConsSequence().getSequence();
\r
171 float minR, minG, minB, maxR, maxG, maxB;
\r
175 maxR = 1.0f - minR;
\r
176 maxG = 0.9f - minG;
\r
177 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
180 float qmin = cons.qualityRange[0].floatValue();
\r
181 float qmax = cons.qualityRange[1].floatValue();
\r
183 for (int i = 0; i < alWidth; i++)
\r
188 value = Integer.parseInt(sequence.charAt(i) + "");
\r
190 catch (Exception ex)
\r
192 if (sequence.charAt(i) == '*')
\r
196 if (sequence.charAt(i) == '+')
\r
201 float vprop = value - min;
\r
204 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
206 new Color(minR + maxR * vprop,
\r
207 minG + maxG * vprop,
\r
208 minB + maxB * vprop));
\r
210 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
211 vprop = value - qmin;
\r
213 qannotations[i] = new Annotation(" ",
\r
214 String.valueOf(value), ' ', value,
\r
216 Color(minR + maxR * vprop,
\r
217 minG + maxG * vprop,
\r
218 minB + maxB * vprop));
\r
221 if (conservation == null)
\r
223 conservation = new AlignmentAnnotation("Conservation",
\r
224 "Conservation of total alignment less than " +
\r
225 ConsPercGaps + "% gaps",
\r
227 0f, // cons.qualityRange[0].floatValue(),
\r
228 11f, // cons.qualityRange[1].floatValue()
\r
229 AlignmentAnnotation.BAR_GRAPH);
\r
230 if (showConservation)
\r
232 alignment.addAnnotation(conservation);
\r
234 quality = new AlignmentAnnotation("Quality",
\r
235 "Alignment Quality based on Blosum62 scores",
\r
237 cons.qualityRange[0].floatValue(),
\r
238 cons.qualityRange[1].floatValue(),
\r
239 AlignmentAnnotation.BAR_GRAPH);
\r
242 alignment.addAnnotation(quality);
\r
247 conservation.annotations = annotations;
\r
248 quality.annotations = qannotations;
\r
249 quality.graphMax = cons.qualityRange[1].floatValue();
\r
254 public void updateConsensus()
\r
256 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
258 // this routine prevents vconsensus becoming a new object each time
\r
259 // consenus is calculated. Important for speed of Blosum62
\r
260 // and PID colouring of alignment
\r
261 if (vconsensus == null)
\r
263 vconsensus = alignment.getAAFrequency();
\r
267 Vector temp = alignment.getAAFrequency();
\r
268 vconsensus.removeAllElements();
\r
269 Enumeration e = temp.elements();
\r
270 while (e.hasMoreElements())
\r
272 vconsensus.addElement(e.nextElement());
\r
275 Hashtable hash = null;
\r
276 for (int i = 0; i < alignment.getWidth(); i++)
\r
278 hash = (Hashtable) vconsensus.elementAt(i);
\r
280 if(ignoreGapsInConsensusCalculation)
\r
281 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
283 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
285 String maxRes = hash.get("maxResidue").toString();
\r
286 String mouseOver = hash.get("maxResidue") + " ";
\r
287 if (maxRes.length() > 1)
\r
289 mouseOver = "[" + maxRes + "] ";
\r
294 mouseOver += (int) value + "%";
\r
295 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
299 if (consensus == null)
\r
301 consensus = new AlignmentAnnotation("Consensus",
\r
302 "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
\r
305 alignment.addAnnotation(consensus);
\r
310 consensus.annotations = annotations;
\r
313 if(globalColourScheme!=null)
\r
314 globalColourScheme.setConsensus(vconsensus);
\r
318 public SequenceGroup getSelectionGroup()
\r
320 return selectionGroup;
\r
323 public void setSelectionGroup(SequenceGroup sg)
\r
325 selectionGroup = sg;
\r
328 public boolean getConservationSelected()
\r
330 return conservationColourSelected;
\r
333 public void setConservationSelected(boolean b)
\r
335 conservationColourSelected = b;
\r
338 public boolean getAbovePIDThreshold()
\r
340 return abovePIDThreshold;
\r
343 public void setAbovePIDThreshold(boolean b)
\r
345 abovePIDThreshold = b;
\r
348 public int getStartRes()
\r
353 public int getEndRes()
\r
358 public int getStartSeq()
\r
363 public void setGlobalColourScheme(ColourSchemeI cs)
\r
365 globalColourScheme = cs;
\r
368 public ColourSchemeI getGlobalColourScheme()
\r
370 return globalColourScheme;
\r
373 public void setStartRes(int res)
\r
375 this.startRes = res;
\r
378 public void setStartSeq(int seq)
\r
380 this.startSeq = seq;
\r
383 public void setEndRes(int res)
\r
385 if (res > alignment.getWidth() - 1)
\r
387 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
388 res = alignment.getWidth() - 1;
\r
397 public void setEndSeq(int seq)
\r
399 if (seq > alignment.getHeight())
\r
401 seq = alignment.getHeight();
\r
410 public int getEndSeq()
\r
415 public void setFont(Font f)
\r
418 java.awt.Frame temp = new java.awt.Frame();
\r
420 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
421 setCharHeight(fm.getHeight());
\r
422 setCharWidth(fm.charWidth('M'));
\r
425 public Font getFont()
\r
430 public void setCharWidth(int w)
\r
432 this.charWidth = w;
\r
435 public int getCharWidth()
\r
440 public void setCharHeight(int h)
\r
442 this.charHeight = h;
\r
445 public int getCharHeight()
\r
450 public void setWrappedWidth(int w)
\r
452 this.wrappedWidth = w;
\r
455 public int getwrappedWidth()
\r
457 return wrappedWidth;
\r
460 public AlignmentI getAlignment()
\r
465 public void setAlignment(AlignmentI align)
\r
467 this.alignment = align;
\r
470 public void setWrapAlignment(boolean state)
\r
472 wrapAlignment = state;
\r
475 public void setShowText(boolean state)
\r
480 public void setRenderGaps(boolean state)
\r
482 renderGaps = state;
\r
485 public boolean getColourText()
\r
487 return showColourText;
\r
490 public void setColourText(boolean state)
\r
492 showColourText = state;
\r
495 public void setShowBoxes(boolean state)
\r
500 public boolean getWrapAlignment()
\r
502 return wrapAlignment;
\r
505 public boolean getShowText()
\r
510 public boolean getShowBoxes()
\r
515 public char getGapCharacter()
\r
517 return getAlignment().getGapCharacter();
\r
520 public void setGapCharacter(char gap)
\r
522 if (getAlignment() != null)
\r
524 getAlignment().setGapCharacter(gap);
\r
528 public void setThreshold(int thresh)
\r
530 threshold = thresh;
\r
533 public int getThreshold()
\r
538 public void setIncrement(int inc)
\r
543 public int getIncrement()
\r
548 public int getIndex(int y)
\r
551 int starty = getStartSeq();
\r
552 int endy = getEndSeq();
\r
554 for (int i = starty; i <= endy; i++)
\r
556 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
558 int y2 = y1 + getCharHeight();
\r
560 if (y >= y1 && y <= y2)
\r
574 public ColumnSelection getColumnSelection()
\r
579 public void resetSeqLimits(int height)
\r
581 setEndSeq(height / getCharHeight());
\r
584 public void setCurrentTree(NJTree tree)
\r
586 currentTree = tree;
\r
589 public NJTree getCurrentTree()
\r
591 return currentTree;
\r
594 public void setColourAppliesToAllGroups(boolean b)
\r
596 colourAppliesToAllGroups = b;
\r
599 public boolean getColourAppliesToAllGroups()
\r
601 return colourAppliesToAllGroups;
\r
604 public boolean getShowJVSuffix()
\r
606 return showJVSuffix;
\r
609 public void setShowJVSuffix(boolean b)
\r
614 public boolean getShowAnnotation()
\r
616 return showAnnotation;
\r
619 public void setShowAnnotation(boolean b)
\r
621 showAnnotation = b;
\r
624 public boolean getScaleAboveWrapped()
\r
626 return scaleAboveWrapped;
\r
629 public boolean getScaleLeftWrapped()
\r
631 return scaleLeftWrapped;
\r
634 public boolean getScaleRightWrapped()
\r
636 return scaleRightWrapped;
\r
639 public void setScaleAboveWrapped(boolean b)
\r
641 scaleAboveWrapped = b;
\r
644 public void setScaleLeftWrapped(boolean b)
\r
646 scaleLeftWrapped = b;
\r
649 public void setScaleRightWrapped(boolean b)
\r
651 scaleRightWrapped = b;
\r
654 public void setIgnoreGapsConsensus(boolean b)
\r
656 ignoreGapsInConsensusCalculation = b;
\r
658 if (globalColourScheme!=null)
\r
660 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
661 ignoreGapsInConsensusCalculation);
\r
667 * Property change listener for changes in alignment
\r
669 * @param listener DOCUMENT ME!
\r
671 public void addPropertyChangeListener(
\r
672 java.beans.PropertyChangeListener listener)
\r
674 changeSupport.addPropertyChangeListener(listener);
\r
680 * @param listener DOCUMENT ME!
\r
682 public void removePropertyChangeListener(
\r
683 java.beans.PropertyChangeListener listener)
\r
685 changeSupport.removePropertyChangeListener(listener);
\r
689 * Property change listener for changes in alignment
\r
691 * @param prop DOCUMENT ME!
\r
692 * @param oldvalue DOCUMENT ME!
\r
693 * @param newvalue DOCUMENT ME!
\r
695 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
697 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
702 public boolean getIgnoreGapsConsensus()
\r
704 return ignoreGapsInConsensusCalculation;
\r