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 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
144 if (applet != null && applet.getParameter("defaultColour") != null)
\r
146 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
147 applet.getParameter("defaultColour"));
\r
148 if (globalColourScheme != null)
\r
150 globalColourScheme.setConsensus(vconsensus);
\r
155 public void showSequenceFeatures(boolean b)
\r
157 showSequenceFeatures = b;
\r
160 public boolean getShowSequenceFeatures()
\r
162 return showSequenceFeatures;
\r
166 public void updateConservation()
\r
168 if(alignment.isNucleotide())
\r
171 Conservation cons = new jalview.analysis.Conservation("All",
\r
172 jalview.schemes.ResidueProperties.propHash, 3,
\r
173 alignment.getSequences(), 0,
\r
174 alignment.getWidth() - 1);
\r
176 cons.verdict(false, ConsPercGaps);
\r
177 cons.findQuality();
\r
178 int alWidth = alignment.getWidth();
\r
179 Annotation[] annotations = new Annotation[alWidth];
\r
180 Annotation[] qannotations = new Annotation[alWidth];
\r
181 String sequence = cons.getConsSequence().getSequence();
\r
182 float minR, minG, minB, maxR, maxG, maxB;
\r
186 maxR = 1.0f - minR;
\r
187 maxG = 0.9f - minG;
\r
188 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
191 float qmin = cons.qualityRange[0].floatValue();
\r
192 float qmax = cons.qualityRange[1].floatValue();
\r
194 for (int i = 0; i < alWidth; i++)
\r
199 value = Integer.parseInt(sequence.charAt(i) + "");
\r
201 catch (Exception ex)
\r
203 if (sequence.charAt(i) == '*')
\r
207 if (sequence.charAt(i) == '+')
\r
212 float vprop = value - min;
\r
215 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
217 new Color(minR + maxR * vprop,
\r
218 minG + maxG * vprop,
\r
219 minB + maxB * vprop));
\r
221 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
222 vprop = value - qmin;
\r
224 qannotations[i] = new Annotation(" ",
\r
225 String.valueOf(value), ' ', value,
\r
227 Color(minR + maxR * vprop,
\r
228 minG + maxG * vprop,
\r
229 minB + maxB * vprop));
\r
232 if (conservation == null)
\r
234 conservation = new AlignmentAnnotation("Conservation",
\r
235 "Conservation of total alignment less than " +
\r
236 ConsPercGaps + "% gaps",
\r
238 0f, // cons.qualityRange[0].floatValue(),
\r
239 11f, // cons.qualityRange[1].floatValue()
\r
240 AlignmentAnnotation.BAR_GRAPH);
\r
241 if (showConservation)
\r
243 alignment.addAnnotation(conservation);
\r
245 quality = new AlignmentAnnotation("Quality",
\r
246 "Alignment Quality based on Blosum62 scores",
\r
248 cons.qualityRange[0].floatValue(),
\r
249 cons.qualityRange[1].floatValue(),
\r
250 AlignmentAnnotation.BAR_GRAPH);
\r
253 alignment.addAnnotation(quality);
\r
258 conservation.annotations = annotations;
\r
259 quality.annotations = qannotations;
\r
260 quality.graphMax = cons.qualityRange[1].floatValue();
\r
265 public void updateConsensus()
\r
267 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
269 // this routine prevents vconsensus becoming a new object each time
\r
270 // consenus is calculated. Important for speed of Blosum62
\r
271 // and PID colouring of alignment
\r
272 if (vconsensus == null)
\r
274 vconsensus = alignment.getAAFrequency();
\r
278 Vector temp = alignment.getAAFrequency();
\r
279 vconsensus.removeAllElements();
\r
280 Enumeration e = temp.elements();
\r
281 while (e.hasMoreElements())
\r
283 vconsensus.addElement(e.nextElement());
\r
286 Hashtable hash = null;
\r
287 for (int i = 0; i < alignment.getWidth(); i++)
\r
289 hash = (Hashtable) vconsensus.elementAt(i);
\r
291 if(ignoreGapsInConsensusCalculation)
\r
292 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
294 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
296 String maxRes = hash.get("maxResidue").toString();
\r
297 String mouseOver = hash.get("maxResidue") + " ";
\r
298 if (maxRes.length() > 1)
\r
300 mouseOver = "[" + maxRes + "] ";
\r
305 mouseOver += (int) value + "%";
\r
306 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
310 if (consensus == null)
\r
312 consensus = new AlignmentAnnotation("Consensus",
\r
313 "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
\r
316 alignment.addAnnotation(consensus);
\r
321 consensus.annotations = annotations;
\r
324 if(globalColourScheme!=null)
\r
325 globalColourScheme.setConsensus(vconsensus);
\r
329 public SequenceGroup getSelectionGroup()
\r
331 return selectionGroup;
\r
334 public void setSelectionGroup(SequenceGroup sg)
\r
336 selectionGroup = sg;
\r
339 public boolean getConservationSelected()
\r
341 return conservationColourSelected;
\r
344 public void setConservationSelected(boolean b)
\r
346 conservationColourSelected = b;
\r
349 public boolean getAbovePIDThreshold()
\r
351 return abovePIDThreshold;
\r
354 public void setAbovePIDThreshold(boolean b)
\r
356 abovePIDThreshold = b;
\r
359 public int getStartRes()
\r
364 public int getEndRes()
\r
369 public int getStartSeq()
\r
374 public void setGlobalColourScheme(ColourSchemeI cs)
\r
376 globalColourScheme = cs;
\r
379 public ColourSchemeI getGlobalColourScheme()
\r
381 return globalColourScheme;
\r
384 public void setStartRes(int res)
\r
386 this.startRes = res;
\r
389 public void setStartSeq(int seq)
\r
391 this.startSeq = seq;
\r
394 public void setEndRes(int res)
\r
396 if (res > alignment.getWidth() - 1)
\r
398 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
399 res = alignment.getWidth() - 1;
\r
408 public void setEndSeq(int seq)
\r
410 if (seq > alignment.getHeight())
\r
412 seq = alignment.getHeight();
\r
421 public int getEndSeq()
\r
426 java.awt.Frame nullFrame;
\r
427 public void setFont(Font f)
\r
430 if(nullFrame == null)
\r
432 nullFrame = new java.awt.Frame();
\r
433 nullFrame.addNotify();
\r
436 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
437 setCharHeight(fm.getHeight());
\r
438 setCharWidth(fm.charWidth('M'));
\r
441 public Font getFont()
\r
446 public void setCharWidth(int w)
\r
448 this.charWidth = w;
\r
451 public int getCharWidth()
\r
456 public void setCharHeight(int h)
\r
458 this.charHeight = h;
\r
461 public int getCharHeight()
\r
466 public void setWrappedWidth(int w)
\r
468 this.wrappedWidth = w;
\r
471 public int getwrappedWidth()
\r
473 return wrappedWidth;
\r
476 public AlignmentI getAlignment()
\r
481 public void setAlignment(AlignmentI align)
\r
483 this.alignment = align;
\r
486 public void setWrapAlignment(boolean state)
\r
488 wrapAlignment = state;
\r
491 public void setShowText(boolean state)
\r
496 public void setRenderGaps(boolean state)
\r
498 renderGaps = state;
\r
501 public boolean getColourText()
\r
503 return showColourText;
\r
506 public void setColourText(boolean state)
\r
508 showColourText = state;
\r
511 public void setShowBoxes(boolean state)
\r
516 public boolean getWrapAlignment()
\r
518 return wrapAlignment;
\r
521 public boolean getShowText()
\r
526 public boolean getShowBoxes()
\r
531 public char getGapCharacter()
\r
533 return getAlignment().getGapCharacter();
\r
536 public void setGapCharacter(char gap)
\r
538 if (getAlignment() != null)
\r
540 getAlignment().setGapCharacter(gap);
\r
544 public void setThreshold(int thresh)
\r
546 threshold = thresh;
\r
549 public int getThreshold()
\r
554 public void setIncrement(int inc)
\r
559 public int getIncrement()
\r
564 public int getIndex(int y)
\r
567 int starty = getStartSeq();
\r
568 int endy = getEndSeq();
\r
570 for (int i = starty; i <= endy; i++)
\r
572 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
574 int y2 = y1 + getCharHeight();
\r
576 if (y >= y1 && y <= y2)
\r
590 public ColumnSelection getColumnSelection()
\r
595 public void resetSeqLimits(int height)
\r
597 setEndSeq(height / getCharHeight());
\r
600 public void setCurrentTree(NJTree tree)
\r
602 currentTree = tree;
\r
605 public NJTree getCurrentTree()
\r
607 return currentTree;
\r
610 public void setColourAppliesToAllGroups(boolean b)
\r
612 colourAppliesToAllGroups = b;
\r
615 public boolean getColourAppliesToAllGroups()
\r
617 return colourAppliesToAllGroups;
\r
620 public boolean getShowJVSuffix()
\r
622 return showJVSuffix;
\r
625 public void setShowJVSuffix(boolean b)
\r
630 public boolean getShowAnnotation()
\r
632 return showAnnotation;
\r
635 public void setShowAnnotation(boolean b)
\r
637 showAnnotation = b;
\r
640 public boolean getScaleAboveWrapped()
\r
642 return scaleAboveWrapped;
\r
645 public boolean getScaleLeftWrapped()
\r
647 return scaleLeftWrapped;
\r
650 public boolean getScaleRightWrapped()
\r
652 return scaleRightWrapped;
\r
655 public void setScaleAboveWrapped(boolean b)
\r
657 scaleAboveWrapped = b;
\r
660 public void setScaleLeftWrapped(boolean b)
\r
662 scaleLeftWrapped = b;
\r
665 public void setScaleRightWrapped(boolean b)
\r
667 scaleRightWrapped = b;
\r
670 public void setIgnoreGapsConsensus(boolean b)
\r
672 ignoreGapsInConsensusCalculation = b;
\r
674 if (globalColourScheme!=null)
\r
676 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
677 ignoreGapsInConsensusCalculation);
\r
683 * Property change listener for changes in alignment
\r
685 * @param listener DOCUMENT ME!
\r
687 public void addPropertyChangeListener(
\r
688 java.beans.PropertyChangeListener listener)
\r
690 changeSupport.addPropertyChangeListener(listener);
\r
696 * @param listener DOCUMENT ME!
\r
698 public void removePropertyChangeListener(
\r
699 java.beans.PropertyChangeListener listener)
\r
701 changeSupport.removePropertyChangeListener(listener);
\r
705 * Property change listener for changes in alignment
\r
707 * @param prop DOCUMENT ME!
\r
708 * @param oldvalue DOCUMENT ME!
\r
709 * @param newvalue DOCUMENT ME!
\r
711 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
713 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
718 public boolean getIgnoreGapsConsensus()
\r
720 return ignoreGapsInConsensusCalculation;
\r