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 showDBPrefix = true;
\r
40 boolean showJVSuffix = true;
\r
41 boolean showText = true;
\r
42 boolean showColourText = false;
\r
43 boolean showBoxes = true;
\r
44 boolean wrapAlignment = false;
\r
45 boolean renderGaps = true;
\r
46 boolean showSequenceFeatures = false;
\r
47 boolean showAnnotation = true;
\r
48 boolean showConservation = true;
\r
49 boolean showQuality = true;
\r
50 boolean showConsensus = true;
\r
52 boolean colourAppliesToAllGroups = true;
\r
53 ColourSchemeI globalColourScheme = null;
\r
54 boolean conservationColourSelected = false;
\r
55 boolean abovePIDThreshold = false;
\r
57 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 showJVSuffix = 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 if(alignment.isNucleotide())
\r
156 Conservation cons = new jalview.analysis.Conservation("All",
\r
157 jalview.schemes.ResidueProperties.propHash, 3,
\r
158 alignment.getSequences(), 0,
\r
159 alignment.getWidth() - 1);
\r
161 cons.verdict(false, ConsPercGaps);
\r
162 cons.findQuality();
\r
163 int alWidth = alignment.getWidth();
\r
164 Annotation[] annotations = new Annotation[alWidth];
\r
165 Annotation[] qannotations = new Annotation[alWidth];
\r
166 String sequence = cons.getConsSequence().getSequence();
\r
167 float minR, minG, minB, maxR, maxG, maxB;
\r
171 maxR = 1.0f - minR;
\r
172 maxG = 0.9f - minG;
\r
173 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
176 float qmin = cons.qualityRange[0].floatValue();
\r
177 float qmax = cons.qualityRange[1].floatValue();
\r
179 for (int i = 0; i < alWidth; i++)
\r
184 value = Integer.parseInt(sequence.charAt(i) + "");
\r
186 catch (Exception ex)
\r
188 if (sequence.charAt(i) == '*')
\r
192 if (sequence.charAt(i) == '+')
\r
197 float vprop = value - min;
\r
200 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
202 new Color(minR + maxR * vprop,
\r
203 minG + maxG * vprop,
\r
204 minB + maxB * vprop));
\r
206 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
207 vprop = value - qmin;
\r
209 qannotations[i] = new Annotation(" ",
\r
210 String.valueOf(value), ' ', value,
\r
212 Color(minR + maxR * vprop,
\r
213 minG + maxG * vprop,
\r
214 minB + maxB * vprop));
\r
217 if (conservation == null)
\r
219 conservation = new AlignmentAnnotation("Conservation",
\r
220 "Conservation of total alignment less than " +
\r
221 ConsPercGaps + "% gaps",
\r
223 0f, // cons.qualityRange[0].floatValue(),
\r
224 11f, // cons.qualityRange[1].floatValue()
\r
226 if (showConservation)
\r
228 alignment.addAnnotation(conservation);
\r
230 quality = new AlignmentAnnotation("Quality",
\r
231 "Alignment Quality based on Blosum62 scores",
\r
233 cons.qualityRange[0].floatValue(),
\r
234 cons.qualityRange[1].floatValue(),
\r
238 alignment.addAnnotation(quality);
\r
243 conservation.annotations = annotations;
\r
244 quality.annotations = qannotations;
\r
245 quality.graphMax = cons.qualityRange[1].floatValue();
\r
250 public void updateConsensus()
\r
252 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
254 // this routine prevents vconsensus becoming a new object each time
\r
255 // consenus is calculated. Important for speed of Blosum62
\r
256 // and PID colouring of alignment
\r
257 if (vconsensus == null)
\r
259 vconsensus = alignment.getAAFrequency();
\r
263 Vector temp = alignment.getAAFrequency();
\r
264 vconsensus.removeAllElements();
\r
265 Enumeration e = temp.elements();
\r
266 while (e.hasMoreElements())
\r
268 vconsensus.addElement(e.nextElement());
\r
271 Hashtable hash = null;
\r
272 for (int i = 0; i < alignment.getWidth(); i++)
\r
274 hash = (Hashtable) vconsensus.elementAt(i);
\r
276 if(ignoreGapsInConsensusCalculation)
\r
277 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
279 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
281 String maxRes = hash.get("maxResidue").toString();
\r
282 String mouseOver = hash.get("maxResidue") + " ";
\r
283 if (maxRes.length() > 1)
\r
285 mouseOver = "[" + maxRes + "] ";
\r
290 mouseOver += (int) value + "%";
\r
291 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
295 if (consensus == null)
\r
297 consensus = new AlignmentAnnotation("Consensus",
\r
298 "PID", annotations, 0f, 100f, 1);
\r
301 alignment.addAnnotation(consensus);
\r
306 consensus.annotations = annotations;
\r
309 if(globalColourScheme!=null)
\r
310 globalColourScheme.setConsensus(vconsensus);
\r
314 public SequenceGroup getSelectionGroup()
\r
316 return selectionGroup;
\r
319 public void setSelectionGroup(SequenceGroup sg)
\r
321 selectionGroup = sg;
\r
324 public boolean getConservationSelected()
\r
326 return conservationColourSelected;
\r
329 public void setConservationSelected(boolean b)
\r
331 conservationColourSelected = b;
\r
334 public boolean getAbovePIDThreshold()
\r
336 return abovePIDThreshold;
\r
339 public void setAbovePIDThreshold(boolean b)
\r
341 abovePIDThreshold = b;
\r
344 public int getStartRes()
\r
349 public int getEndRes()
\r
354 public int getStartSeq()
\r
359 public void setGlobalColourScheme(ColourSchemeI cs)
\r
361 globalColourScheme = cs;
\r
364 public ColourSchemeI getGlobalColourScheme()
\r
366 return globalColourScheme;
\r
369 public void setStartRes(int res)
\r
371 this.startRes = res;
\r
374 public void setStartSeq(int seq)
\r
376 this.startSeq = seq;
\r
379 public void setEndRes(int res)
\r
381 if (res > alignment.getWidth() - 1)
\r
383 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
384 res = alignment.getWidth() - 1;
\r
393 public void setEndSeq(int seq)
\r
395 if (seq > alignment.getHeight())
\r
397 seq = alignment.getHeight();
\r
406 public int getEndSeq()
\r
411 public void setFont(Font f)
\r
414 java.awt.Frame temp = new java.awt.Frame();
\r
416 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
417 setCharHeight(fm.getHeight());
\r
418 setCharWidth(fm.charWidth('M'));
\r
421 public Font getFont()
\r
426 public void setCharWidth(int w)
\r
428 this.charWidth = w;
\r
431 public int getCharWidth()
\r
436 public void setCharHeight(int h)
\r
438 this.charHeight = h;
\r
441 public int getCharHeight()
\r
446 public void setWrappedWidth(int w)
\r
448 this.wrappedWidth = w;
\r
451 public int getwrappedWidth()
\r
453 return wrappedWidth;
\r
456 public AlignmentI getAlignment()
\r
461 public void setAlignment(AlignmentI align)
\r
463 this.alignment = align;
\r
466 public void setWrapAlignment(boolean state)
\r
468 wrapAlignment = state;
\r
471 public void setShowText(boolean state)
\r
476 public void setRenderGaps(boolean state)
\r
478 renderGaps = state;
\r
481 public boolean getColourText()
\r
483 return showColourText;
\r
486 public void setColourText(boolean state)
\r
488 showColourText = state;
\r
491 public void setShowBoxes(boolean state)
\r
496 public boolean getWrapAlignment()
\r
498 return wrapAlignment;
\r
501 public boolean getShowText()
\r
506 public boolean getShowBoxes()
\r
511 public char getGapCharacter()
\r
513 return getAlignment().getGapCharacter();
\r
516 public void setGapCharacter(char gap)
\r
518 if (getAlignment() != null)
\r
520 getAlignment().setGapCharacter(gap);
\r
524 public void setThreshold(int thresh)
\r
526 threshold = thresh;
\r
529 public int getThreshold()
\r
534 public void setIncrement(int inc)
\r
539 public int getIncrement()
\r
544 public int getIndex(int y)
\r
547 int starty = getStartSeq();
\r
548 int endy = getEndSeq();
\r
550 for (int i = starty; i <= endy; i++)
\r
552 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
554 int y2 = y1 + getCharHeight();
\r
556 if (y >= y1 && y <= y2)
\r
570 public ColumnSelection getColumnSelection()
\r
575 public void resetSeqLimits(int height)
\r
577 setEndSeq(height / getCharHeight());
\r
580 public void setCurrentTree(NJTree tree)
\r
582 currentTree = tree;
\r
585 public NJTree getCurrentTree()
\r
587 return currentTree;
\r
590 public void setColourAppliesToAllGroups(boolean b)
\r
592 colourAppliesToAllGroups = b;
\r
595 public boolean getColourAppliesToAllGroups()
\r
597 return colourAppliesToAllGroups;
\r
600 public boolean getShowJVSuffix()
\r
602 return showJVSuffix;
\r
605 public void setShowJVSuffix(boolean b)
\r
610 public boolean getShowDBPrefix()
\r
612 return showDBPrefix;
\r
615 public void setShowDBPrefix(boolean b)
\r
620 public boolean getShowAnnotation()
\r
622 return showAnnotation;
\r
625 public void setShowAnnotation(boolean b)
\r
627 showAnnotation = b;
\r
630 public boolean getScaleAboveWrapped()
\r
632 return scaleAboveWrapped;
\r
635 public boolean getScaleLeftWrapped()
\r
637 return scaleLeftWrapped;
\r
640 public boolean getScaleRightWrapped()
\r
642 return scaleRightWrapped;
\r
645 public void setScaleAboveWrapped(boolean b)
\r
647 scaleAboveWrapped = b;
\r
650 public void setScaleLeftWrapped(boolean b)
\r
652 scaleLeftWrapped = b;
\r
655 public void setScaleRightWrapped(boolean b)
\r
657 scaleRightWrapped = b;
\r
660 public void setIgnoreGapsConsensus(boolean b)
\r
662 ignoreGapsInConsensusCalculation = b;
\r
664 if (globalColourScheme!=null)
\r
666 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
667 ignoreGapsInConsensusCalculation);
\r
673 * Property change listener for changes in alignment
\r
675 * @param listener DOCUMENT ME!
\r
677 public void addPropertyChangeListener(
\r
678 java.beans.PropertyChangeListener listener)
\r
680 changeSupport.addPropertyChangeListener(listener);
\r
686 * @param listener DOCUMENT ME!
\r
688 public void removePropertyChangeListener(
\r
689 java.beans.PropertyChangeListener listener)
\r
691 changeSupport.removePropertyChangeListener(listener);
\r
695 * Property change listener for changes in alignment
\r
697 * @param prop DOCUMENT ME!
\r
698 * @param oldvalue DOCUMENT ME!
\r
699 * @param newvalue DOCUMENT ME!
\r
701 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
703 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
708 public boolean getIgnoreGapsConsensus()
\r
710 return ignoreGapsInConsensusCalculation;
\r