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 showFullId = 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
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
78 boolean ignoreGapsInConsensusCalculation = false;
\r
80 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
84 this.endRes = al.getWidth() - 1;
\r
86 this.endSeq = al.getHeight() - 1;
\r
91 String param = applet.getParameter("showFullId");
\r
94 showFullId = Boolean.valueOf(param).booleanValue();
\r
97 param = applet.getParameter("showAnnotation");
\r
100 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
103 param = applet.getParameter("showConservation");
\r
106 showConservation = Boolean.valueOf(param).booleanValue();
\r
109 param = applet.getParameter("showQuality");
\r
112 showQuality = Boolean.valueOf(param).booleanValue();
\r
115 param = applet.getParameter("showConsensus");
\r
118 showConsensus = Boolean.valueOf(param).booleanValue();
\r
121 // We must set conservation and consensus before setting colour,
\r
122 // as Blosum and Clustal require this to be done
\r
123 updateConservation();
\r
126 if (applet != null && applet.getParameter("defaultColour") != null)
\r
128 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
129 applet.getParameter("defaultColour"));
\r
130 if (globalColourScheme != null)
\r
132 globalColourScheme.setConsensus(vconsensus);
\r
137 public void showSequenceFeatures(boolean b)
\r
139 showSequenceFeatures = b;
\r
142 public Vector vconsensus;
\r
143 AlignmentAnnotation consensus;
\r
144 AlignmentAnnotation conservation;
\r
145 AlignmentAnnotation quality;
\r
147 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
149 public void updateConservation()
\r
151 Conservation cons = new jalview.analysis.Conservation("All",
\r
152 jalview.schemes.ResidueProperties.propHash, 3,
\r
153 alignment.getSequences(), 0,
\r
154 alignment.getWidth() - 1);
\r
156 cons.verdict(false, ConsPercGaps);
\r
157 cons.findQuality();
\r
158 int alWidth = alignment.getWidth();
\r
159 Annotation[] annotations = new Annotation[alWidth];
\r
160 Annotation[] qannotations = new Annotation[alWidth];
\r
161 String sequence = cons.getConsSequence().getSequence();
\r
162 float minR, minG, minB, maxR, maxG, maxB;
\r
166 maxR = 1.0f - minR;
\r
167 maxG = 0.9f - minG;
\r
168 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
171 float qmin = cons.qualityRange[0].floatValue();
\r
172 float qmax = cons.qualityRange[1].floatValue();
\r
174 for (int i = 0; i < alWidth; i++)
\r
179 value = Integer.parseInt(sequence.charAt(i) + "");
\r
181 catch (Exception ex)
\r
183 if (sequence.charAt(i) == '*')
\r
187 if (sequence.charAt(i) == '+')
\r
192 float vprop = value - min;
\r
195 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
197 new Color(minR + maxR * vprop,
\r
198 minG + maxG * vprop,
\r
199 minB + maxB * vprop));
\r
201 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
202 vprop = value - qmin;
\r
204 qannotations[i] = new Annotation(" ",
\r
205 String.valueOf(value), ' ', value,
\r
207 Color(minR + maxR * vprop,
\r
208 minG + maxG * vprop,
\r
209 minB + maxB * vprop));
\r
212 if (conservation == null)
\r
214 conservation = new AlignmentAnnotation("Conservation",
\r
215 "Conservation of total alignment less than " +
\r
216 ConsPercGaps + "% gaps",
\r
218 0f, // cons.qualityRange[0].floatValue(),
\r
219 11f, // cons.qualityRange[1].floatValue()
\r
221 if (showConservation)
\r
223 alignment.addAnnotation(conservation);
\r
225 quality = new AlignmentAnnotation("Quality",
\r
226 "Alignment Quality based on Blosum62 scores",
\r
228 cons.qualityRange[0].floatValue(),
\r
229 cons.qualityRange[1].floatValue(),
\r
233 alignment.addAnnotation(quality);
\r
238 conservation.annotations = annotations;
\r
239 quality.annotations = qannotations;
\r
240 quality.graphMax = cons.qualityRange[1].floatValue();
\r
245 public void updateConsensus()
\r
247 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
249 // this routine prevents vconsensus becoming a new object each time
\r
250 // consenus is calculated. Important for speed of Blosum62
\r
251 // and PID colouring of alignment
\r
252 if (vconsensus == null)
\r
254 vconsensus = alignment.getAAFrequency();
\r
258 Vector temp = alignment.getAAFrequency();
\r
259 vconsensus.removeAllElements();
\r
260 Enumeration e = temp.elements();
\r
261 while (e.hasMoreElements())
\r
263 vconsensus.addElement(e.nextElement());
\r
266 Hashtable hash = null;
\r
267 for (int i = 0; i < alignment.getWidth(); i++)
\r
269 hash = (Hashtable) vconsensus.elementAt(i);
\r
271 if(ignoreGapsInConsensusCalculation)
\r
272 value = ((Float)hash.get("pid_nogaps")).floatValue();
\r
274 value = ((Float)hash.get("pid_gaps")).floatValue();
\r
276 String maxRes = hash.get("maxResidue").toString();
\r
277 String mouseOver = hash.get("maxResidue") + " ";
\r
278 if (maxRes.length() > 1)
\r
280 mouseOver = "[" + maxRes + "] ";
\r
285 mouseOver += (int) value + "%";
\r
286 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
290 if (consensus == null)
\r
292 consensus = new AlignmentAnnotation("Consensus",
\r
293 "PID", annotations, 0f, 100f, 1);
\r
296 alignment.addAnnotation(consensus);
\r
301 consensus.annotations = annotations;
\r
306 public SequenceGroup getSelectionGroup()
\r
308 return selectionGroup;
\r
311 public void setSelectionGroup(SequenceGroup sg)
\r
313 selectionGroup = sg;
\r
316 public boolean getConservationSelected()
\r
318 return conservationColourSelected;
\r
321 public void setConservationSelected(boolean b)
\r
323 conservationColourSelected = b;
\r
326 public boolean getAbovePIDThreshold()
\r
328 return abovePIDThreshold;
\r
331 public void setAbovePIDThreshold(boolean b)
\r
333 abovePIDThreshold = b;
\r
336 public int getStartRes()
\r
341 public int getEndRes()
\r
346 public int getStartSeq()
\r
351 public void setGlobalColourScheme(ColourSchemeI cs)
\r
353 globalColourScheme = cs;
\r
356 public ColourSchemeI getGlobalColourScheme()
\r
358 return globalColourScheme;
\r
361 public void setStartRes(int res)
\r
363 this.startRes = res;
\r
366 public void setStartSeq(int seq)
\r
368 this.startSeq = seq;
\r
371 public void setEndRes(int res)
\r
373 if (res > alignment.getWidth() - 1)
\r
375 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
376 res = alignment.getWidth() - 1;
\r
385 public void setEndSeq(int seq)
\r
387 if (seq > alignment.getHeight())
\r
389 seq = alignment.getHeight();
\r
398 public int getEndSeq()
\r
403 public void setFont(Font f)
\r
406 java.awt.Frame temp = new java.awt.Frame();
\r
408 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
409 setCharHeight(fm.getHeight());
\r
410 setCharWidth(fm.charWidth('M'));
\r
413 public Font getFont()
\r
418 public void setCharWidth(int w)
\r
420 this.charWidth = w;
\r
423 public int getCharWidth()
\r
428 public void setCharHeight(int h)
\r
430 this.charHeight = h;
\r
433 public int getCharHeight()
\r
438 public void setChunkWidth(int w)
\r
440 this.chunkWidth = w;
\r
443 public int getChunkWidth()
\r
448 public void setChunkHeight(int h)
\r
450 this.chunkHeight = h;
\r
453 public int getChunkHeight()
\r
455 return chunkHeight;
\r
458 public AlignmentI getAlignment()
\r
463 public void setAlignment(AlignmentI align)
\r
465 this.alignment = align;
\r
468 public void setWrapAlignment(boolean state)
\r
470 wrapAlignment = state;
\r
473 public void setShowText(boolean state)
\r
478 public void setRenderGaps(boolean state)
\r
480 renderGaps = state;
\r
483 public boolean getColourText()
\r
485 return showColourText;
\r
488 public void setColourText(boolean state)
\r
490 showColourText = state;
\r
493 public void setShowBoxes(boolean state)
\r
498 public boolean getWrapAlignment()
\r
500 return wrapAlignment;
\r
503 public boolean getShowText()
\r
508 public boolean getShowBoxes()
\r
513 public char getGapCharacter()
\r
515 return getAlignment().getGapCharacter();
\r
518 public void setGapCharacter(char gap)
\r
520 if (getAlignment() != null)
\r
522 getAlignment().setGapCharacter(gap);
\r
526 public void setThreshold(int thresh)
\r
528 threshold = thresh;
\r
531 public int getThreshold()
\r
536 public void setIncrement(int inc)
\r
541 public int getIncrement()
\r
546 public int getIndex(int y)
\r
549 int starty = getStartSeq();
\r
550 int endy = getEndSeq();
\r
552 for (int i = starty; i <= endy; i++)
\r
554 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
556 int y2 = y1 + getCharHeight();
\r
558 if (y >= y1 && y <= y2)
\r
572 public ColumnSelection getColumnSelection()
\r
577 public void resetSeqLimits(int height)
\r
579 setEndSeq(height / getCharHeight());
\r
582 public void setCurrentTree(NJTree tree)
\r
584 currentTree = tree;
\r
587 public NJTree getCurrentTree()
\r
589 return currentTree;
\r
592 public void setColourAppliesToAllGroups(boolean b)
\r
594 colourAppliesToAllGroups = b;
\r
597 public boolean getColourAppliesToAllGroups()
\r
599 return colourAppliesToAllGroups;
\r
602 public boolean getShowFullId()
\r
607 public void setShowFullId(boolean b)
\r
612 public boolean getShowAnnotation()
\r
614 return showAnnotation;
\r
617 public void setShowAnnotation(boolean b)
\r
619 showAnnotation = b;
\r
622 public boolean getScaleAboveWrapped()
\r
624 return scaleAboveWrapped;
\r
627 public boolean getScaleLeftWrapped()
\r
629 return scaleLeftWrapped;
\r
632 public boolean getScaleRightWrapped()
\r
634 return scaleRightWrapped;
\r
637 public void setScaleAboveWrapped(boolean b)
\r
639 scaleAboveWrapped = b;
\r
642 public void setScaleLeftWrapped(boolean b)
\r
644 scaleLeftWrapped = b;
\r
647 public void setScaleRightWrapped(boolean b)
\r
649 scaleRightWrapped = b;
\r
652 public void setIgnoreGapsConsensus(boolean b)
\r
654 ignoreGapsInConsensusCalculation = b;
\r
656 if (globalColourScheme!=null && globalColourScheme instanceof ResidueColourScheme)
\r
658 ( (ResidueColourScheme) globalColourScheme).setThreshold(
\r
659 ( (ResidueColourScheme) globalColourScheme).getThreshold(),
\r
660 ignoreGapsInConsensusCalculation);
\r
666 public boolean getIgnoreGapsConsensus()
\r
668 return ignoreGapsInConsensusCalculation;
\r