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 = new SequenceGroup();
\r
65 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
66 AlignmentI alignment;
\r
68 ColumnSelection colSel = new ColumnSelection();
\r
73 NJTree currentTree = null;
\r
75 boolean scaleAboveWrapped = true;
\r
76 boolean scaleLeftWrapped = true;
\r
77 boolean scaleRightWrapped = true;
\r
79 // The following vector holds the features which are
\r
80 // currently visible, in the correct order or rendering
\r
81 Hashtable featuresDisplayed = null;
\r
84 public Vector vconsensus;
\r
85 AlignmentAnnotation consensus;
\r
86 AlignmentAnnotation conservation;
\r
87 AlignmentAnnotation quality;
\r
89 boolean autocalculateConsensus = true;
\r
91 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
93 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
95 boolean ignoreGapsInConsensusCalculation = false;
\r
97 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
101 this.endRes = al.getWidth() - 1;
\r
103 this.endSeq = al.getHeight() - 1;
\r
106 if (applet != null)
\r
108 String param = applet.getParameter("showFullId");
\r
111 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
114 param = applet.getParameter("showAnnotation");
\r
117 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
120 param = applet.getParameter("showConservation");
\r
123 showConservation = Boolean.valueOf(param).booleanValue();
\r
126 param = applet.getParameter("showQuality");
\r
129 showQuality = Boolean.valueOf(param).booleanValue();
\r
132 param = applet.getParameter("showConsensus");
\r
135 showConsensus = Boolean.valueOf(param).booleanValue();
\r
138 // We must set conservation and consensus before setting colour,
\r
139 // as Blosum and Clustal require this to be done
\r
140 updateConservation();
\r
143 if (applet != null && applet.getParameter("defaultColour") != null)
\r
145 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
146 applet.getParameter("defaultColour"));
\r
147 if (globalColourScheme != null)
\r
149 globalColourScheme.setConsensus(vconsensus);
\r
154 public void showSequenceFeatures(boolean b)
\r
156 showSequenceFeatures = b;
\r
159 public boolean getShowSequenceFeatures()
\r
161 return showSequenceFeatures;
\r
165 public void updateConservation()
\r
167 if(alignment.isNucleotide())
\r
170 Conservation cons = new jalview.analysis.Conservation("All",
\r
171 jalview.schemes.ResidueProperties.propHash, 3,
\r
172 alignment.getSequences(), 0,
\r
173 alignment.getWidth() - 1);
\r
175 cons.verdict(false, ConsPercGaps);
\r
176 cons.findQuality();
\r
177 int alWidth = alignment.getWidth();
\r
178 Annotation[] annotations = new Annotation[alWidth];
\r
179 Annotation[] qannotations = new Annotation[alWidth];
\r
180 String sequence = cons.getConsSequence().getSequence();
\r
181 float minR, minG, minB, maxR, maxG, maxB;
\r
185 maxR = 1.0f - minR;
\r
186 maxG = 0.9f - minG;
\r
187 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
190 float qmin = cons.qualityRange[0].floatValue();
\r
191 float qmax = cons.qualityRange[1].floatValue();
\r
193 for (int i = 0; i < alWidth; i++)
\r
198 value = Integer.parseInt(sequence.charAt(i) + "");
\r
200 catch (Exception ex)
\r
202 if (sequence.charAt(i) == '*')
\r
206 if (sequence.charAt(i) == '+')
\r
211 float vprop = value - min;
\r
214 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
216 new Color(minR + maxR * vprop,
\r
217 minG + maxG * vprop,
\r
218 minB + maxB * vprop));
\r
220 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
221 vprop = value - qmin;
\r
223 qannotations[i] = new Annotation(" ",
\r
224 String.valueOf(value), ' ', value,
\r
226 Color(minR + maxR * vprop,
\r
227 minG + maxG * vprop,
\r
228 minB + maxB * vprop));
\r
231 if (conservation == null)
\r
233 conservation = new AlignmentAnnotation("Conservation",
\r
234 "Conservation of total alignment less than " +
\r
235 ConsPercGaps + "% gaps",
\r
237 0f, // cons.qualityRange[0].floatValue(),
\r
238 11f, // cons.qualityRange[1].floatValue()
\r
239 AlignmentAnnotation.BAR_GRAPH);
\r
240 if (showConservation)
\r
242 alignment.addAnnotation(conservation);
\r
244 quality = new AlignmentAnnotation("Quality",
\r
245 "Alignment Quality based on Blosum62 scores",
\r
247 cons.qualityRange[0].floatValue(),
\r
248 cons.qualityRange[1].floatValue(),
\r
249 AlignmentAnnotation.BAR_GRAPH);
\r
252 alignment.addAnnotation(quality);
\r
257 conservation.annotations = annotations;
\r
258 quality.annotations = qannotations;
\r
259 quality.graphMax = cons.qualityRange[1].floatValue();
\r
264 public void updateConsensus()
\r
266 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
268 // this routine prevents vconsensus becoming a new object each time
\r
269 // consenus is calculated. Important for speed of Blosum62
\r
270 // and PID colouring of alignment
\r
271 if (vconsensus == null)
\r
273 vconsensus = alignment.getAAFrequency();
\r
277 Vector temp = alignment.getAAFrequency();
\r
278 vconsensus.removeAllElements();
\r
279 Enumeration e = temp.elements();
\r
280 while (e.hasMoreElements())
\r
282 vconsensus.addElement(e.nextElement());
\r
285 Hashtable hash = null;
\r
286 for (int i = 0; i < alignment.getWidth(); i++)
\r
288 hash = (Hashtable) vconsensus.elementAt(i);
\r
290 if(ignoreGapsInConsensusCalculation)
\r
291 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
293 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
295 String maxRes = hash.get("maxResidue").toString();
\r
296 String mouseOver = hash.get("maxResidue") + " ";
\r
297 if (maxRes.length() > 1)
\r
299 mouseOver = "[" + maxRes + "] ";
\r
304 mouseOver += (int) value + "%";
\r
305 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
309 if (consensus == null)
\r
311 consensus = new AlignmentAnnotation("Consensus",
\r
312 "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
\r
315 alignment.addAnnotation(consensus);
\r
320 consensus.annotations = annotations;
\r
323 if(globalColourScheme!=null)
\r
324 globalColourScheme.setConsensus(vconsensus);
\r
328 public SequenceGroup getSelectionGroup()
\r
330 return selectionGroup;
\r
333 public void setSelectionGroup(SequenceGroup sg)
\r
335 selectionGroup = sg;
\r
338 public boolean getConservationSelected()
\r
340 return conservationColourSelected;
\r
343 public void setConservationSelected(boolean b)
\r
345 conservationColourSelected = b;
\r
348 public boolean getAbovePIDThreshold()
\r
350 return abovePIDThreshold;
\r
353 public void setAbovePIDThreshold(boolean b)
\r
355 abovePIDThreshold = b;
\r
358 public int getStartRes()
\r
363 public int getEndRes()
\r
368 public int getStartSeq()
\r
373 public void setGlobalColourScheme(ColourSchemeI cs)
\r
375 globalColourScheme = cs;
\r
378 public ColourSchemeI getGlobalColourScheme()
\r
380 return globalColourScheme;
\r
383 public void setStartRes(int res)
\r
385 this.startRes = res;
\r
388 public void setStartSeq(int seq)
\r
390 this.startSeq = seq;
\r
393 public void setEndRes(int res)
\r
395 if (res > alignment.getWidth() - 1)
\r
397 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
398 res = alignment.getWidth() - 1;
\r
407 public void setEndSeq(int seq)
\r
409 if (seq > alignment.getHeight())
\r
411 seq = alignment.getHeight();
\r
420 public int getEndSeq()
\r
425 public void setFont(Font f)
\r
428 java.awt.Frame temp = new java.awt.Frame();
\r
430 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
431 setCharHeight(fm.getHeight());
\r
432 setCharWidth(fm.charWidth('M'));
\r
435 public Font getFont()
\r
440 public void setCharWidth(int w)
\r
442 this.charWidth = w;
\r
445 public int getCharWidth()
\r
450 public void setCharHeight(int h)
\r
452 this.charHeight = h;
\r
455 public int getCharHeight()
\r
460 public void setWrappedWidth(int w)
\r
462 this.wrappedWidth = w;
\r
465 public int getwrappedWidth()
\r
467 return wrappedWidth;
\r
470 public AlignmentI getAlignment()
\r
475 public void setAlignment(AlignmentI align)
\r
477 this.alignment = align;
\r
480 public void setWrapAlignment(boolean state)
\r
482 wrapAlignment = state;
\r
485 public void setShowText(boolean state)
\r
490 public void setRenderGaps(boolean state)
\r
492 renderGaps = state;
\r
495 public boolean getColourText()
\r
497 return showColourText;
\r
500 public void setColourText(boolean state)
\r
502 showColourText = state;
\r
505 public void setShowBoxes(boolean state)
\r
510 public boolean getWrapAlignment()
\r
512 return wrapAlignment;
\r
515 public boolean getShowText()
\r
520 public boolean getShowBoxes()
\r
525 public char getGapCharacter()
\r
527 return getAlignment().getGapCharacter();
\r
530 public void setGapCharacter(char gap)
\r
532 if (getAlignment() != null)
\r
534 getAlignment().setGapCharacter(gap);
\r
538 public void setThreshold(int thresh)
\r
540 threshold = thresh;
\r
543 public int getThreshold()
\r
548 public void setIncrement(int inc)
\r
553 public int getIncrement()
\r
558 public int getIndex(int y)
\r
561 int starty = getStartSeq();
\r
562 int endy = getEndSeq();
\r
564 for (int i = starty; i <= endy; i++)
\r
566 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
568 int y2 = y1 + getCharHeight();
\r
570 if (y >= y1 && y <= y2)
\r
584 public ColumnSelection getColumnSelection()
\r
589 public void resetSeqLimits(int height)
\r
591 setEndSeq(height / getCharHeight());
\r
594 public void setCurrentTree(NJTree tree)
\r
596 currentTree = tree;
\r
599 public NJTree getCurrentTree()
\r
601 return currentTree;
\r
604 public void setColourAppliesToAllGroups(boolean b)
\r
606 colourAppliesToAllGroups = b;
\r
609 public boolean getColourAppliesToAllGroups()
\r
611 return colourAppliesToAllGroups;
\r
614 public boolean getShowJVSuffix()
\r
616 return showJVSuffix;
\r
619 public void setShowJVSuffix(boolean b)
\r
624 public boolean getShowAnnotation()
\r
626 return showAnnotation;
\r
629 public void setShowAnnotation(boolean b)
\r
631 showAnnotation = b;
\r
634 public boolean getScaleAboveWrapped()
\r
636 return scaleAboveWrapped;
\r
639 public boolean getScaleLeftWrapped()
\r
641 return scaleLeftWrapped;
\r
644 public boolean getScaleRightWrapped()
\r
646 return scaleRightWrapped;
\r
649 public void setScaleAboveWrapped(boolean b)
\r
651 scaleAboveWrapped = b;
\r
654 public void setScaleLeftWrapped(boolean b)
\r
656 scaleLeftWrapped = b;
\r
659 public void setScaleRightWrapped(boolean b)
\r
661 scaleRightWrapped = b;
\r
664 public void setIgnoreGapsConsensus(boolean b)
\r
666 ignoreGapsInConsensusCalculation = b;
\r
668 if (globalColourScheme!=null)
\r
670 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
671 ignoreGapsInConsensusCalculation);
\r
677 * Property change listener for changes in alignment
\r
679 * @param listener DOCUMENT ME!
\r
681 public void addPropertyChangeListener(
\r
682 java.beans.PropertyChangeListener listener)
\r
684 changeSupport.addPropertyChangeListener(listener);
\r
690 * @param listener DOCUMENT ME!
\r
692 public void removePropertyChangeListener(
\r
693 java.beans.PropertyChangeListener listener)
\r
695 changeSupport.removePropertyChangeListener(listener);
\r
699 * Property change listener for changes in alignment
\r
701 * @param prop DOCUMENT ME!
\r
702 * @param oldvalue DOCUMENT ME!
\r
703 * @param newvalue DOCUMENT ME!
\r
705 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
707 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
712 public boolean getIgnoreGapsConsensus()
\r
714 return ignoreGapsInConsensusCalculation;
\r