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
77 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
81 this.endRes = al.getWidth() - 1;
\r
83 this.endSeq = al.getHeight() - 1;
\r
88 String param = applet.getParameter("showFullId");
\r
91 showFullId = Boolean.valueOf(param).booleanValue();
\r
94 param = applet.getParameter("showAnnotation");
\r
97 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
100 param = applet.getParameter("showConservation");
\r
103 showConservation = Boolean.valueOf(param).booleanValue();
\r
106 param = applet.getParameter("showQuality");
\r
109 showQuality = Boolean.valueOf(param).booleanValue();
\r
112 param = applet.getParameter("showConsensus");
\r
115 showConsensus = Boolean.valueOf(param).booleanValue();
\r
118 // We must set conservation and consensus before setting colour,
\r
119 // as Blosum and Clustal require this to be done
\r
120 updateConservation();
\r
123 if (applet != null && applet.getParameter("defaultColour") != null)
\r
125 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
126 applet.getParameter("defaultColour"));
\r
127 if (globalColourScheme != null)
\r
129 globalColourScheme.setConsensus(vconsensus);
\r
134 public void showSequenceFeatures(boolean b)
\r
136 showSequenceFeatures = b;
\r
139 public Vector vconsensus;
\r
140 AlignmentAnnotation consensus;
\r
141 AlignmentAnnotation conservation;
\r
142 AlignmentAnnotation quality;
\r
144 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
146 public void updateConservation()
\r
148 Conservation cons = new jalview.analysis.Conservation("All",
\r
149 jalview.schemes.ResidueProperties.propHash, 3,
\r
150 alignment.getSequences(), 0,
\r
151 alignment.getWidth() - 1);
\r
153 cons.verdict(false, ConsPercGaps);
\r
154 cons.findQuality();
\r
155 int alWidth = alignment.getWidth();
\r
156 Annotation[] annotations = new Annotation[alWidth];
\r
157 Annotation[] qannotations = new Annotation[alWidth];
\r
158 String sequence = cons.getConsSequence().getSequence();
\r
159 float minR, minG, minB, maxR, maxG, maxB;
\r
163 maxR = 1.0f - minR;
\r
164 maxG = 0.9f - minG;
\r
165 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
168 float qmin = cons.qualityRange[0].floatValue();
\r
169 float qmax = cons.qualityRange[1].floatValue();
\r
171 for (int i = 0; i < alWidth; i++)
\r
176 value = Integer.parseInt(sequence.charAt(i) + "");
\r
178 catch (Exception ex)
\r
180 if (sequence.charAt(i) == '*')
\r
184 if (sequence.charAt(i) == '+')
\r
189 float vprop = value - min;
\r
192 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
194 new Color(minR + maxR * vprop,
\r
195 minG + maxG * vprop,
\r
196 minB + maxB * vprop));
\r
198 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
199 vprop = value - qmin;
\r
201 qannotations[i] = new Annotation(" ",
\r
202 String.valueOf(value), ' ', value,
\r
204 Color(minR + maxR * vprop,
\r
205 minG + maxG * vprop,
\r
206 minB + maxB * vprop));
\r
209 if (conservation == null)
\r
211 conservation = new AlignmentAnnotation("Conservation",
\r
212 "Conservation of total alignment less than " +
\r
213 ConsPercGaps + "% gaps",
\r
215 0f, // cons.qualityRange[0].floatValue(),
\r
216 11f, // cons.qualityRange[1].floatValue()
\r
218 if (showConservation)
\r
220 alignment.addAnnotation(conservation);
\r
222 quality = new AlignmentAnnotation("Quality",
\r
223 "Alignment Quality based on Blosum62 scores",
\r
225 cons.qualityRange[0].floatValue(),
\r
226 cons.qualityRange[1].floatValue(),
\r
230 alignment.addAnnotation(quality);
\r
235 conservation.annotations = annotations;
\r
236 quality.annotations = qannotations;
\r
237 quality.graphMax = cons.qualityRange[1].floatValue();
\r
242 public void updateConsensus()
\r
244 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
246 // this routine prevents vconsensus becoming a new object each time
\r
247 // consenus is calculated. Important for speed of Blosum62
\r
248 // and PID colouring of alignment
\r
249 if (vconsensus == null)
\r
251 vconsensus = alignment.getAAFrequency();
\r
255 Vector temp = alignment.getAAFrequency();
\r
256 vconsensus.removeAllElements();
\r
257 Enumeration e = temp.elements();
\r
258 while (e.hasMoreElements())
\r
260 vconsensus.addElement(e.nextElement());
\r
263 Hashtable hash = null;
\r
264 for (int i = 0; i < alignment.getWidth(); i++)
\r
266 hash = (Hashtable) vconsensus.elementAt(i);
\r
267 float value = new Float(hash.get("maxCount").toString()).floatValue();
\r
268 value /= new Float(hash.get("size").toString()).floatValue();
\r
271 String maxRes = hash.get("maxResidue") + " ";
\r
272 String mouseOver = hash.get("maxResidue") + " ";
\r
273 if (maxRes.length() > 2)
\r
275 mouseOver = "[" + maxRes + "] ";
\r
279 mouseOver += (int) value + "%";
\r
280 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
284 if (consensus == null)
\r
286 consensus = new AlignmentAnnotation("Consensus",
\r
287 "PID", annotations, 0f, 100f, 1);
\r
290 alignment.addAnnotation(consensus);
\r
295 consensus.annotations = annotations;
\r
300 public SequenceGroup getSelectionGroup()
\r
302 return selectionGroup;
\r
305 public void setSelectionGroup(SequenceGroup sg)
\r
307 selectionGroup = sg;
\r
310 public boolean getConservationSelected()
\r
312 return conservationColourSelected;
\r
315 public void setConservationSelected(boolean b)
\r
317 conservationColourSelected = b;
\r
320 public boolean getAbovePIDThreshold()
\r
322 return abovePIDThreshold;
\r
325 public void setAbovePIDThreshold(boolean b)
\r
327 abovePIDThreshold = b;
\r
330 public int getStartRes()
\r
335 public int getEndRes()
\r
340 public int getStartSeq()
\r
345 public void setGlobalColourScheme(ColourSchemeI cs)
\r
347 globalColourScheme = cs;
\r
350 public ColourSchemeI getGlobalColourScheme()
\r
352 return globalColourScheme;
\r
355 public void setStartRes(int res)
\r
357 this.startRes = res;
\r
360 public void setStartSeq(int seq)
\r
362 this.startSeq = seq;
\r
365 public void setEndRes(int res)
\r
367 if (res > alignment.getWidth() - 1)
\r
369 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
370 res = alignment.getWidth() - 1;
\r
379 public void setEndSeq(int seq)
\r
381 if (seq > alignment.getHeight())
\r
383 seq = alignment.getHeight();
\r
392 public int getEndSeq()
\r
397 public void setFont(Font f)
\r
400 java.awt.Frame temp = new java.awt.Frame();
\r
402 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
403 setCharHeight(fm.getHeight());
\r
404 setCharWidth(fm.charWidth('M'));
\r
407 public Font getFont()
\r
412 public void setCharWidth(int w)
\r
414 this.charWidth = w;
\r
417 public int getCharWidth()
\r
422 public void setCharHeight(int h)
\r
424 this.charHeight = h;
\r
427 public int getCharHeight()
\r
432 public void setChunkWidth(int w)
\r
434 this.chunkWidth = w;
\r
437 public int getChunkWidth()
\r
442 public void setChunkHeight(int h)
\r
444 this.chunkHeight = h;
\r
447 public int getChunkHeight()
\r
449 return chunkHeight;
\r
452 public AlignmentI getAlignment()
\r
457 public void setAlignment(AlignmentI align)
\r
459 this.alignment = align;
\r
462 public void setWrapAlignment(boolean state)
\r
464 wrapAlignment = state;
\r
467 public void setShowText(boolean state)
\r
472 public void setRenderGaps(boolean state)
\r
474 renderGaps = state;
\r
477 public boolean getColourText()
\r
479 return showColourText;
\r
482 public void setColourText(boolean state)
\r
484 showColourText = state;
\r
487 public void setShowBoxes(boolean state)
\r
492 public boolean getWrapAlignment()
\r
494 return wrapAlignment;
\r
497 public boolean getShowText()
\r
502 public boolean getShowBoxes()
\r
507 public char getGapCharacter()
\r
509 return getAlignment().getGapCharacter();
\r
512 public void setGapCharacter(char gap)
\r
514 if (getAlignment() != null)
\r
516 getAlignment().setGapCharacter(gap);
\r
520 public void setThreshold(int thresh)
\r
522 threshold = thresh;
\r
525 public int getThreshold()
\r
530 public void setIncrement(int inc)
\r
535 public int getIncrement()
\r
540 public int getIndex(int y)
\r
543 int starty = getStartSeq();
\r
544 int endy = getEndSeq();
\r
546 for (int i = starty; i <= endy; i++)
\r
548 if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null)
\r
550 int y2 = y1 + getCharHeight();
\r
552 if (y >= y1 && y <= y2)
\r
566 public ColumnSelection getColumnSelection()
\r
571 public void resetSeqLimits(int height)
\r
573 setEndSeq(height / getCharHeight());
\r
576 public void setCurrentTree(NJTree tree)
\r
578 currentTree = tree;
\r
581 public NJTree getCurrentTree()
\r
583 return currentTree;
\r
586 public void setColourAppliesToAllGroups(boolean b)
\r
588 colourAppliesToAllGroups = b;
\r
591 public boolean getColourAppliesToAllGroups()
\r
593 return colourAppliesToAllGroups;
\r
596 public boolean getShowFullId()
\r
601 public void setShowFullId(boolean b)
\r
606 public boolean getShowAnnotation()
\r
608 return showAnnotation;
\r
611 public void setShowAnnotation(boolean b)
\r
613 showAnnotation = b;
\r
616 public boolean getScaleAboveWrapped()
\r
618 return scaleAboveWrapped;
\r
621 public boolean getScaleLeftWrapped()
\r
623 return scaleLeftWrapped;
\r
626 public boolean getScaleRightWrapped()
\r
628 return scaleRightWrapped;
\r
631 public void setScaleAboveWrapped(boolean b)
\r
633 scaleAboveWrapped = b;
\r
636 public void setScaleLeftWrapped(boolean b)
\r
638 scaleLeftWrapped = b;
\r
641 public void setScaleRightWrapped(boolean b)
\r
643 scaleRightWrapped = b;
\r