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 public Vector vconsensus;
\r
77 AlignmentAnnotation consensus;
\r
78 AlignmentAnnotation conservation;
\r
79 AlignmentAnnotation quality;
\r
81 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
83 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
85 boolean ignoreGapsInConsensusCalculation = false;
\r
87 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
91 this.endRes = al.getWidth() - 1;
\r
93 this.endSeq = al.getHeight() - 1;
\r
98 String param = applet.getParameter("showFullId");
\r
101 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
104 param = applet.getParameter("showAnnotation");
\r
107 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
110 param = applet.getParameter("showConservation");
\r
113 showConservation = Boolean.valueOf(param).booleanValue();
\r
116 param = applet.getParameter("showQuality");
\r
119 showQuality = Boolean.valueOf(param).booleanValue();
\r
122 param = applet.getParameter("showConsensus");
\r
125 showConsensus = Boolean.valueOf(param).booleanValue();
\r
128 // We must set conservation and consensus before setting colour,
\r
129 // as Blosum and Clustal require this to be done
\r
130 updateConservation();
\r
133 if (applet != null && applet.getParameter("defaultColour") != null)
\r
135 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
136 applet.getParameter("defaultColour"));
\r
137 if (globalColourScheme != null)
\r
139 globalColourScheme.setConsensus(vconsensus);
\r
144 public void showSequenceFeatures(boolean b)
\r
146 showSequenceFeatures = b;
\r
150 public void updateConservation()
\r
152 if(alignment.isNucleotide())
\r
155 Conservation cons = new jalview.analysis.Conservation("All",
\r
156 jalview.schemes.ResidueProperties.propHash, 3,
\r
157 alignment.getSequences(), 0,
\r
158 alignment.getWidth() - 1);
\r
160 cons.verdict(false, ConsPercGaps);
\r
161 cons.findQuality();
\r
162 int alWidth = alignment.getWidth();
\r
163 Annotation[] annotations = new Annotation[alWidth];
\r
164 Annotation[] qannotations = new Annotation[alWidth];
\r
165 String sequence = cons.getConsSequence().getSequence();
\r
166 float minR, minG, minB, maxR, maxG, maxB;
\r
170 maxR = 1.0f - minR;
\r
171 maxG = 0.9f - minG;
\r
172 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
175 float qmin = cons.qualityRange[0].floatValue();
\r
176 float qmax = cons.qualityRange[1].floatValue();
\r
178 for (int i = 0; i < alWidth; i++)
\r
183 value = Integer.parseInt(sequence.charAt(i) + "");
\r
185 catch (Exception ex)
\r
187 if (sequence.charAt(i) == '*')
\r
191 if (sequence.charAt(i) == '+')
\r
196 float vprop = value - min;
\r
199 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
201 new Color(minR + maxR * vprop,
\r
202 minG + maxG * vprop,
\r
203 minB + maxB * vprop));
\r
205 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
206 vprop = value - qmin;
\r
208 qannotations[i] = new Annotation(" ",
\r
209 String.valueOf(value), ' ', value,
\r
211 Color(minR + maxR * vprop,
\r
212 minG + maxG * vprop,
\r
213 minB + maxB * vprop));
\r
216 if (conservation == null)
\r
218 conservation = new AlignmentAnnotation("Conservation",
\r
219 "Conservation of total alignment less than " +
\r
220 ConsPercGaps + "% gaps",
\r
222 0f, // cons.qualityRange[0].floatValue(),
\r
223 11f, // cons.qualityRange[1].floatValue()
\r
225 if (showConservation)
\r
227 alignment.addAnnotation(conservation);
\r
229 quality = new AlignmentAnnotation("Quality",
\r
230 "Alignment Quality based on Blosum62 scores",
\r
232 cons.qualityRange[0].floatValue(),
\r
233 cons.qualityRange[1].floatValue(),
\r
237 alignment.addAnnotation(quality);
\r
242 conservation.annotations = annotations;
\r
243 quality.annotations = qannotations;
\r
244 quality.graphMax = cons.qualityRange[1].floatValue();
\r
249 public void updateConsensus()
\r
251 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
253 // this routine prevents vconsensus becoming a new object each time
\r
254 // consenus is calculated. Important for speed of Blosum62
\r
255 // and PID colouring of alignment
\r
256 if (vconsensus == null)
\r
258 vconsensus = alignment.getAAFrequency();
\r
262 Vector temp = alignment.getAAFrequency();
\r
263 vconsensus.removeAllElements();
\r
264 Enumeration e = temp.elements();
\r
265 while (e.hasMoreElements())
\r
267 vconsensus.addElement(e.nextElement());
\r
270 Hashtable hash = null;
\r
271 for (int i = 0; i < alignment.getWidth(); i++)
\r
273 hash = (Hashtable) vconsensus.elementAt(i);
\r
275 if(ignoreGapsInConsensusCalculation)
\r
276 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
278 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
280 String maxRes = hash.get("maxResidue").toString();
\r
281 String mouseOver = hash.get("maxResidue") + " ";
\r
282 if (maxRes.length() > 1)
\r
284 mouseOver = "[" + maxRes + "] ";
\r
289 mouseOver += (int) value + "%";
\r
290 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
294 if (consensus == null)
\r
296 consensus = new AlignmentAnnotation("Consensus",
\r
297 "PID", annotations, 0f, 100f, 1);
\r
300 alignment.addAnnotation(consensus);
\r
305 consensus.annotations = annotations;
\r
308 if(globalColourScheme!=null)
\r
309 globalColourScheme.setConsensus(vconsensus);
\r
313 public SequenceGroup getSelectionGroup()
\r
315 return selectionGroup;
\r
318 public void setSelectionGroup(SequenceGroup sg)
\r
320 selectionGroup = sg;
\r
323 public boolean getConservationSelected()
\r
325 return conservationColourSelected;
\r
328 public void setConservationSelected(boolean b)
\r
330 conservationColourSelected = b;
\r
333 public boolean getAbovePIDThreshold()
\r
335 return abovePIDThreshold;
\r
338 public void setAbovePIDThreshold(boolean b)
\r
340 abovePIDThreshold = b;
\r
343 public int getStartRes()
\r
348 public int getEndRes()
\r
353 public int getStartSeq()
\r
358 public void setGlobalColourScheme(ColourSchemeI cs)
\r
360 globalColourScheme = cs;
\r
363 public ColourSchemeI getGlobalColourScheme()
\r
365 return globalColourScheme;
\r
368 public void setStartRes(int res)
\r
370 this.startRes = res;
\r
373 public void setStartSeq(int seq)
\r
375 this.startSeq = seq;
\r
378 public void setEndRes(int res)
\r
380 if (res > alignment.getWidth() - 1)
\r
382 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
383 res = alignment.getWidth() - 1;
\r
392 public void setEndSeq(int seq)
\r
394 if (seq > alignment.getHeight())
\r
396 seq = alignment.getHeight();
\r
405 public int getEndSeq()
\r
410 public void setFont(Font f)
\r
413 java.awt.Frame temp = new java.awt.Frame();
\r
415 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
416 setCharHeight(fm.getHeight());
\r
417 setCharWidth(fm.charWidth('M'));
\r
420 public Font getFont()
\r
425 public void setCharWidth(int w)
\r
427 this.charWidth = w;
\r
430 public int getCharWidth()
\r
435 public void setCharHeight(int h)
\r
437 this.charHeight = h;
\r
440 public int getCharHeight()
\r
445 public void setWrappedWidth(int w)
\r
447 this.wrappedWidth = w;
\r
450 public int getwrappedWidth()
\r
452 return wrappedWidth;
\r
455 public AlignmentI getAlignment()
\r
460 public void setAlignment(AlignmentI align)
\r
462 this.alignment = align;
\r
465 public void setWrapAlignment(boolean state)
\r
467 wrapAlignment = state;
\r
470 public void setShowText(boolean state)
\r
475 public void setRenderGaps(boolean state)
\r
477 renderGaps = state;
\r
480 public boolean getColourText()
\r
482 return showColourText;
\r
485 public void setColourText(boolean state)
\r
487 showColourText = state;
\r
490 public void setShowBoxes(boolean state)
\r
495 public boolean getWrapAlignment()
\r
497 return wrapAlignment;
\r
500 public boolean getShowText()
\r
505 public boolean getShowBoxes()
\r
510 public char getGapCharacter()
\r
512 return getAlignment().getGapCharacter();
\r
515 public void setGapCharacter(char gap)
\r
517 if (getAlignment() != null)
\r
519 getAlignment().setGapCharacter(gap);
\r
523 public void setThreshold(int thresh)
\r
525 threshold = thresh;
\r
528 public int getThreshold()
\r
533 public void setIncrement(int inc)
\r
538 public int getIncrement()
\r
543 public int getIndex(int y)
\r
546 int starty = getStartSeq();
\r
547 int endy = getEndSeq();
\r
549 for (int i = starty; i <= endy; i++)
\r
551 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
553 int y2 = y1 + getCharHeight();
\r
555 if (y >= y1 && y <= y2)
\r
569 public ColumnSelection getColumnSelection()
\r
574 public void resetSeqLimits(int height)
\r
576 setEndSeq(height / getCharHeight());
\r
579 public void setCurrentTree(NJTree tree)
\r
581 currentTree = tree;
\r
584 public NJTree getCurrentTree()
\r
586 return currentTree;
\r
589 public void setColourAppliesToAllGroups(boolean b)
\r
591 colourAppliesToAllGroups = b;
\r
594 public boolean getColourAppliesToAllGroups()
\r
596 return colourAppliesToAllGroups;
\r
599 public boolean getShowJVSuffix()
\r
601 return showJVSuffix;
\r
604 public void setShowJVSuffix(boolean b)
\r
609 public boolean getShowAnnotation()
\r
611 return showAnnotation;
\r
614 public void setShowAnnotation(boolean b)
\r
616 showAnnotation = b;
\r
619 public boolean getScaleAboveWrapped()
\r
621 return scaleAboveWrapped;
\r
624 public boolean getScaleLeftWrapped()
\r
626 return scaleLeftWrapped;
\r
629 public boolean getScaleRightWrapped()
\r
631 return scaleRightWrapped;
\r
634 public void setScaleAboveWrapped(boolean b)
\r
636 scaleAboveWrapped = b;
\r
639 public void setScaleLeftWrapped(boolean b)
\r
641 scaleLeftWrapped = b;
\r
644 public void setScaleRightWrapped(boolean b)
\r
646 scaleRightWrapped = b;
\r
649 public void setIgnoreGapsConsensus(boolean b)
\r
651 ignoreGapsInConsensusCalculation = b;
\r
653 if (globalColourScheme!=null)
\r
655 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
656 ignoreGapsInConsensusCalculation);
\r
662 * Property change listener for changes in alignment
\r
664 * @param listener DOCUMENT ME!
\r
666 public void addPropertyChangeListener(
\r
667 java.beans.PropertyChangeListener listener)
\r
669 changeSupport.addPropertyChangeListener(listener);
\r
675 * @param listener DOCUMENT ME!
\r
677 public void removePropertyChangeListener(
\r
678 java.beans.PropertyChangeListener listener)
\r
680 changeSupport.removePropertyChangeListener(listener);
\r
684 * Property change listener for changes in alignment
\r
686 * @param prop DOCUMENT ME!
\r
687 * @param oldvalue DOCUMENT ME!
\r
688 * @param newvalue DOCUMENT ME!
\r
690 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
692 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
697 public boolean getIgnoreGapsConsensus()
\r
699 return ignoreGapsInConsensusCalculation;
\r