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
40 boolean cursorMode = false;
\r
42 boolean showJVSuffix = true;
\r
43 boolean showText = true;
\r
44 boolean showColourText = false;
\r
45 boolean showBoxes = true;
\r
46 boolean wrapAlignment = false;
\r
47 boolean renderGaps = true;
\r
48 boolean showSequenceFeatures = false;
\r
49 boolean showAnnotation = true;
\r
50 boolean showConservation = true;
\r
51 boolean showQuality = true;
\r
52 boolean showConsensus = true;
\r
54 boolean colourAppliesToAllGroups = true;
\r
55 ColourSchemeI globalColourScheme = null;
\r
56 boolean conservationColourSelected = false;
\r
57 boolean abovePIDThreshold = false;
\r
59 SequenceGroup selectionGroup;
\r
65 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
66 boolean validCharWidth = true;
\r
67 AlignmentI alignment;
\r
69 ColumnSelection colSel = new ColumnSelection();
\r
74 NJTree currentTree = null;
\r
76 boolean scaleAboveWrapped = true;
\r
77 boolean scaleLeftWrapped = true;
\r
78 boolean scaleRightWrapped = true;
\r
80 // The following vector holds the features which are
\r
81 // currently visible, in the correct order or rendering
\r
82 Hashtable featuresDisplayed;
\r
85 public Vector vconsensus;
\r
86 AlignmentAnnotation consensus;
\r
87 AlignmentAnnotation conservation;
\r
88 AlignmentAnnotation quality;
\r
90 boolean autocalculateConsensus = true;
\r
92 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
94 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
96 boolean ignoreGapsInConsensusCalculation = false;
\r
98 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
102 this.endRes = al.getWidth() - 1;
\r
104 this.endSeq = al.getHeight() - 1;
\r
107 if (applet != null)
\r
109 String param = applet.getParameter("showFullId");
\r
112 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
115 param = applet.getParameter("showAnnotation");
\r
118 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
121 param = applet.getParameter("showConservation");
\r
124 showConservation = Boolean.valueOf(param).booleanValue();
\r
127 param = applet.getParameter("showQuality");
\r
130 showQuality = Boolean.valueOf(param).booleanValue();
\r
133 param = applet.getParameter("showConsensus");
\r
136 showConsensus = Boolean.valueOf(param).booleanValue();
\r
139 // We must set conservation and consensus before setting colour,
\r
140 // as Blosum and Clustal require this to be done
\r
141 updateConservation();
\r
145 if (applet != null)
\r
147 String colour = applet.getParameter("defaultColour");
\r
151 colour = applet.getParameter("userDefinedColour");
\r
153 colour = "User Defined";
\r
158 globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);
\r
159 if (globalColourScheme != null)
\r
161 globalColourScheme.setConsensus(vconsensus);
\r
165 if(applet.getParameter("userDefinedColour")!=null)
\r
167 ((UserColourScheme)globalColourScheme).parseAppletParameter(
\r
168 applet.getParameter("userDefinedColour"));
\r
175 public void showSequenceFeatures(boolean b)
\r
177 showSequenceFeatures = b;
\r
180 public boolean getShowSequenceFeatures()
\r
182 return showSequenceFeatures;
\r
186 public void updateConservation()
\r
188 if(alignment.isNucleotide())
\r
191 Conservation cons = new jalview.analysis.Conservation("All",
\r
192 jalview.schemes.ResidueProperties.propHash, 3,
\r
193 alignment.getSequences(), 0,
\r
194 alignment.getWidth() - 1);
\r
196 cons.verdict(false, ConsPercGaps);
\r
197 cons.findQuality();
\r
198 int alWidth = alignment.getWidth();
\r
199 Annotation[] annotations = new Annotation[alWidth];
\r
200 Annotation[] qannotations = new Annotation[alWidth];
\r
201 String sequence = cons.getConsSequence().getSequence();
\r
202 float minR, minG, minB, maxR, maxG, maxB;
\r
206 maxR = 1.0f - minR;
\r
207 maxG = 0.9f - minG;
\r
208 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
211 float qmin = cons.qualityRange[0].floatValue();
\r
212 float qmax = cons.qualityRange[1].floatValue();
\r
214 for (int i = 0; i < alWidth; i++)
\r
219 value = Integer.parseInt(sequence.charAt(i) + "");
\r
221 catch (Exception ex)
\r
223 if (sequence.charAt(i) == '*')
\r
227 if (sequence.charAt(i) == '+')
\r
232 float vprop = value - min;
\r
235 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
237 new Color(minR + maxR * vprop,
\r
238 minG + maxG * vprop,
\r
239 minB + maxB * vprop));
\r
241 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
242 vprop = value - qmin;
\r
244 qannotations[i] = new Annotation(" ",
\r
245 String.valueOf(value), ' ', value,
\r
247 Color(minR + maxR * vprop,
\r
248 minG + maxG * vprop,
\r
249 minB + maxB * vprop));
\r
252 if (conservation == null)
\r
254 conservation = new AlignmentAnnotation("Conservation",
\r
255 "Conservation of total alignment less than " +
\r
256 ConsPercGaps + "% gaps",
\r
258 0f, // cons.qualityRange[0].floatValue(),
\r
259 11f, // cons.qualityRange[1].floatValue()
\r
260 AlignmentAnnotation.BAR_GRAPH);
\r
261 if (showConservation)
\r
263 alignment.addAnnotation(conservation);
\r
265 quality = new AlignmentAnnotation("Quality",
\r
266 "Alignment Quality based on Blosum62 scores",
\r
268 cons.qualityRange[0].floatValue(),
\r
269 cons.qualityRange[1].floatValue(),
\r
270 AlignmentAnnotation.BAR_GRAPH);
\r
273 alignment.addAnnotation(quality);
\r
278 conservation.annotations = annotations;
\r
279 quality.annotations = qannotations;
\r
280 quality.graphMax = cons.qualityRange[1].floatValue();
\r
285 public void updateConsensus()
\r
287 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
289 // this routine prevents vconsensus becoming a new object each time
\r
290 // consenus is calculated. Important for speed of Blosum62
\r
291 // and PID colouring of alignment
\r
292 if (vconsensus == null)
\r
294 vconsensus = alignment.getAAFrequency();
\r
298 Vector temp = alignment.getAAFrequency();
\r
299 vconsensus.removeAllElements();
\r
300 Enumeration e = temp.elements();
\r
301 while (e.hasMoreElements())
\r
303 vconsensus.addElement(e.nextElement());
\r
306 Hashtable hash = null;
\r
307 for (int i = 0; i < alignment.getWidth(); i++)
\r
309 hash = (Hashtable) vconsensus.elementAt(i);
\r
311 if(ignoreGapsInConsensusCalculation)
\r
312 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
314 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
316 String maxRes = hash.get("maxResidue").toString();
\r
317 String mouseOver = hash.get("maxResidue") + " ";
\r
318 if (maxRes.length() > 1)
\r
320 mouseOver = "[" + maxRes + "] ";
\r
325 mouseOver += (int) value + "%";
\r
326 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
330 if (consensus == null)
\r
332 consensus = new AlignmentAnnotation("Consensus",
\r
333 "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
\r
336 alignment.addAnnotation(consensus);
\r
341 consensus.annotations = annotations;
\r
344 if(globalColourScheme!=null)
\r
345 globalColourScheme.setConsensus(vconsensus);
\r
349 public SequenceGroup getSelectionGroup()
\r
351 return selectionGroup;
\r
354 public void setSelectionGroup(SequenceGroup sg)
\r
356 selectionGroup = sg;
\r
359 public boolean getConservationSelected()
\r
361 return conservationColourSelected;
\r
364 public void setConservationSelected(boolean b)
\r
366 conservationColourSelected = b;
\r
369 public boolean getAbovePIDThreshold()
\r
371 return abovePIDThreshold;
\r
374 public void setAbovePIDThreshold(boolean b)
\r
376 abovePIDThreshold = b;
\r
379 public int getStartRes()
\r
384 public int getEndRes()
\r
389 public int getStartSeq()
\r
394 public void setGlobalColourScheme(ColourSchemeI cs)
\r
396 globalColourScheme = cs;
\r
399 public ColourSchemeI getGlobalColourScheme()
\r
401 return globalColourScheme;
\r
404 public void setStartRes(int res)
\r
406 this.startRes = res;
\r
409 public void setStartSeq(int seq)
\r
411 this.startSeq = seq;
\r
414 public void setEndRes(int res)
\r
416 if (res > alignment.getWidth() - 1)
\r
418 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
419 res = alignment.getWidth() - 1;
\r
428 public void setEndSeq(int seq)
\r
430 if (seq > alignment.getHeight())
\r
432 seq = alignment.getHeight();
\r
441 public int getEndSeq()
\r
446 java.awt.Frame nullFrame;
\r
447 public void setFont(Font f)
\r
450 if(nullFrame == null)
\r
452 nullFrame = new java.awt.Frame();
\r
453 nullFrame.addNotify();
\r
456 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
457 setCharHeight(fm.getHeight());
\r
458 setCharWidth(fm.charWidth('M'));
\r
461 public Font getFont()
\r
466 public void setCharWidth(int w)
\r
468 this.charWidth = w;
\r
471 public int getCharWidth()
\r
476 public void setCharHeight(int h)
\r
478 this.charHeight = h;
\r
481 public int getCharHeight()
\r
486 public void setWrappedWidth(int w)
\r
488 this.wrappedWidth = w;
\r
491 public int getwrappedWidth()
\r
493 return wrappedWidth;
\r
496 public AlignmentI getAlignment()
\r
501 public void setAlignment(AlignmentI align)
\r
503 this.alignment = align;
\r
506 public void setWrapAlignment(boolean state)
\r
508 wrapAlignment = state;
\r
511 public void setShowText(boolean state)
\r
516 public void setRenderGaps(boolean state)
\r
518 renderGaps = state;
\r
521 public boolean getColourText()
\r
523 return showColourText;
\r
526 public void setColourText(boolean state)
\r
528 showColourText = state;
\r
531 public void setShowBoxes(boolean state)
\r
536 public boolean getWrapAlignment()
\r
538 return wrapAlignment;
\r
541 public boolean getShowText()
\r
546 public boolean getShowBoxes()
\r
551 public char getGapCharacter()
\r
553 return getAlignment().getGapCharacter();
\r
556 public void setGapCharacter(char gap)
\r
558 if (getAlignment() != null)
\r
560 getAlignment().setGapCharacter(gap);
\r
564 public void setThreshold(int thresh)
\r
566 threshold = thresh;
\r
569 public int getThreshold()
\r
574 public void setIncrement(int inc)
\r
579 public int getIncrement()
\r
584 public int getIndex(int y)
\r
587 int starty = getStartSeq();
\r
588 int endy = getEndSeq();
\r
590 for (int i = starty; i <= endy; i++)
\r
592 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
594 int y2 = y1 + getCharHeight();
\r
596 if (y >= y1 && y <= y2)
\r
610 public ColumnSelection getColumnSelection()
\r
615 public void resetSeqLimits(int height)
\r
617 setEndSeq(height / getCharHeight());
\r
620 public void setCurrentTree(NJTree tree)
\r
622 currentTree = tree;
\r
625 public NJTree getCurrentTree()
\r
627 return currentTree;
\r
630 public void setColourAppliesToAllGroups(boolean b)
\r
632 colourAppliesToAllGroups = b;
\r
635 public boolean getColourAppliesToAllGroups()
\r
637 return colourAppliesToAllGroups;
\r
640 public boolean getShowJVSuffix()
\r
642 return showJVSuffix;
\r
645 public void setShowJVSuffix(boolean b)
\r
650 public boolean getShowAnnotation()
\r
652 return showAnnotation;
\r
655 public void setShowAnnotation(boolean b)
\r
657 showAnnotation = b;
\r
660 public boolean getScaleAboveWrapped()
\r
662 return scaleAboveWrapped;
\r
665 public boolean getScaleLeftWrapped()
\r
667 return scaleLeftWrapped;
\r
670 public boolean getScaleRightWrapped()
\r
672 return scaleRightWrapped;
\r
675 public void setScaleAboveWrapped(boolean b)
\r
677 scaleAboveWrapped = b;
\r
680 public void setScaleLeftWrapped(boolean b)
\r
682 scaleLeftWrapped = b;
\r
685 public void setScaleRightWrapped(boolean b)
\r
687 scaleRightWrapped = b;
\r
690 public void setIgnoreGapsConsensus(boolean b)
\r
692 ignoreGapsInConsensusCalculation = b;
\r
694 if (globalColourScheme!=null)
\r
696 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
697 ignoreGapsInConsensusCalculation);
\r
703 * Property change listener for changes in alignment
\r
705 * @param listener DOCUMENT ME!
\r
707 public void addPropertyChangeListener(
\r
708 java.beans.PropertyChangeListener listener)
\r
710 changeSupport.addPropertyChangeListener(listener);
\r
716 * @param listener DOCUMENT ME!
\r
718 public void removePropertyChangeListener(
\r
719 java.beans.PropertyChangeListener listener)
\r
721 changeSupport.removePropertyChangeListener(listener);
\r
725 * Property change listener for changes in alignment
\r
727 * @param prop DOCUMENT ME!
\r
728 * @param oldvalue DOCUMENT ME!
\r
729 * @param newvalue DOCUMENT ME!
\r
731 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
733 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
738 public boolean getIgnoreGapsConsensus()
\r
740 return ignoreGapsInConsensusCalculation;
\r