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
19 package jalview.gui;
\r
25 import jalview.analysis.*;
\r
26 import jalview.bin.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.schemes.*;
\r
30 public class AlignViewport
\r
36 boolean showFullId = false;
\r
37 boolean showText = true;
\r
38 boolean showColourText = false;
\r
39 boolean showBoxes = true;
\r
40 boolean wrapAlignment = false;
\r
41 boolean renderGaps = true;
\r
42 boolean showSequenceFeatures = false;
\r
43 boolean showAnnotation = true;
\r
44 boolean showConservation = true;
\r
45 boolean showQuality = true;
\r
46 boolean showIdentity = true;
\r
47 boolean colourAppliesToAllGroups = true;
\r
48 ColourSchemeI globalColourScheme = null;
\r
49 boolean conservationColourSelected = false;
\r
50 boolean abovePIDThreshold = false;
\r
51 SequenceGroup selectionGroup = new SequenceGroup();
\r
56 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
57 AlignmentI alignment;
\r
58 ColumnSelection colSel = new ColumnSelection();
\r
61 NJTree currentTree = null;
\r
62 boolean scaleAboveWrapped = false;
\r
63 boolean scaleLeftWrapped = true;
\r
64 boolean scaleRightWrapped = true;
\r
65 public Vector vconsensus;
\r
66 AlignmentAnnotation consensus;
\r
67 AlignmentAnnotation conservation;
\r
68 AlignmentAnnotation quality;
\r
69 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
71 // JBPNote Prolly only need this in the applet version.
\r
72 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
\r
73 PropertyChangeSupport(this);
\r
75 public AlignViewport(AlignmentI al)
\r
79 this.endRes = al.getWidth() - 1;
\r
81 this.endSeq = al.getHeight() - 1;
\r
83 updateFromPreferences();
\r
86 public void updateFromPreferences()
\r
88 showFullId = Preferences.showFullId;
\r
89 showAnnotation = Preferences.showAnnotation;
\r
90 showConservation = Preferences.showConservation;
\r
91 showQuality = Preferences.showQuality;
\r
92 showIdentity = Preferences.showIdentity;
\r
93 showFullId = Preferences.showFullId;
\r
95 String fontName = Preferences.fontName;
\r
96 String fontStyle = Preferences.fontStyle;
\r
97 String fontSize = Cache.getProperty("FONT_SIZE");
\r
99 if ( (fontName != null) && (fontStyle != null) && (fontSize != null))
\r
103 if (fontStyle.equals("bold"))
\r
107 else if (fontStyle.equals("italic"))
\r
112 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
\r
119 alignment.setGapCharacter(Preferences.gapSymbol);
\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 (Preferences.defaultColour != null)
\r
128 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
129 Preferences.defaultColour);
\r
131 if (globalColourScheme instanceof UserColourScheme)
\r
133 globalColourScheme = UserDefinedColours.loadDefaultColours();
\r
136 if (globalColourScheme != null)
\r
138 globalColourScheme.setConsensus(vconsensus);
\r
143 public void showSequenceFeatures(boolean b)
\r
145 showSequenceFeatures = b;
\r
148 public void updateConservation()
\r
150 Conservation cons = new jalview.analysis.Conservation("All",
\r
151 jalview.schemes.ResidueProperties.propHash, 3,
\r
152 alignment.getSequences(), 0, alignment.getWidth() - 1);
\r
154 cons.verdict(false, ConsPercGaps);
\r
155 cons.findQuality();
\r
157 int alWidth = alignment.getWidth();
\r
158 Annotation[] annotations = new Annotation[alWidth];
\r
159 Annotation[] qannotations = new Annotation[alWidth];
\r
160 String sequence = cons.getConsSequence().getSequence();
\r
170 maxR = 1.0f - minR;
\r
171 maxG = 0.9f - minG;
\r
172 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
176 float qmin = cons.qualityRange[0].floatValue();
\r
177 float qmax = cons.qualityRange[1].floatValue();
\r
179 for (int i = 0; i < alWidth; i++)
\r
185 value = Integer.parseInt(sequence.charAt(i) + "");
\r
187 catch (Exception ex)
\r
189 if (sequence.charAt(i) == '*')
\r
194 if (sequence.charAt(i) == '+')
\r
200 float vprop = value - min;
\r
202 annotations[i] = new Annotation(sequence.charAt(i) + "", "", ' ',
\r
204 new Color(minR + (maxR * vprop),
\r
205 minG + (maxG * vprop),
\r
206 minB + (maxB * vprop)));
\r
209 value = ( (Double) cons.quality.get(i)).floatValue();
\r
210 vprop = value - qmin;
\r
212 qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',
\r
214 new Color(minR + (maxR * vprop),
\r
215 minG + (maxG * vprop),
\r
216 minB + (maxB * vprop)));
\r
219 if (conservation == null)
\r
221 conservation = new AlignmentAnnotation("Conservation",
\r
222 "Conservation of total alignment less than " +
\r
223 ConsPercGaps + "% gaps",
\r
224 annotations, 0f, // cons.qualityRange[0].floatValue(),
\r
225 11f, // cons.qualityRange[1].floatValue()
\r
228 if (showConservation)
\r
230 alignment.addAnnotation(conservation);
\r
233 quality = new AlignmentAnnotation("Quality",
\r
234 "Alignment Quality based on Blosum62 scores",
\r
236 cons.qualityRange[0].floatValue(),
\r
237 cons.qualityRange[1].floatValue(), 1);
\r
241 alignment.addAnnotation(quality);
\r
246 conservation.annotations = annotations;
\r
247 quality.annotations = qannotations;
\r
248 quality.graphMax = cons.qualityRange[1].floatValue();
\r
252 public void updateConsensus()
\r
254 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
256 // this routine prevents vconsensus becoming a new object each time
\r
257 // consenus is calculated. Important for speed of Blosum62
\r
258 // and PID colouring of alignment
\r
259 if (vconsensus == null)
\r
261 vconsensus = alignment.getAAFrequency();
\r
265 Vector temp = alignment.getAAFrequency();
\r
266 vconsensus.clear();
\r
268 Enumeration e = temp.elements();
\r
270 while (e.hasMoreElements())
\r
272 vconsensus.add(e.nextElement());
\r
276 Hashtable hash = null;
\r
278 for (int i = 0; i < alignment.getWidth(); i++)
\r
280 hash = (Hashtable) vconsensus.elementAt(i);
\r
282 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
283 value /= Float.parseFloat(hash.get("size").toString());
\r
287 String maxRes = hash.get("maxResidue") + " ";
\r
288 String mouseOver = hash.get("maxResidue") + " ";
\r
290 if (maxRes.length() > 2)
\r
292 mouseOver = "[" + maxRes + "] ";
\r
296 mouseOver += ( (int) value + "%");
\r
297 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
300 if (consensus == null)
\r
302 consensus = new AlignmentAnnotation("Consensus", "PID",
\r
303 annotations, 0f, 100f, 1);
\r
307 alignment.addAnnotation(consensus);
\r
312 consensus.annotations = annotations;
\r
316 public SequenceGroup getSelectionGroup()
\r
318 return selectionGroup;
\r
321 public void setSelectionGroup(SequenceGroup sg)
\r
323 selectionGroup = sg;
\r
326 public boolean getConservationSelected()
\r
328 return conservationColourSelected;
\r
331 public void setConservationSelected(boolean b)
\r
333 conservationColourSelected = b;
\r
336 public boolean getAbovePIDThreshold()
\r
338 return abovePIDThreshold;
\r
341 public void setAbovePIDThreshold(boolean b)
\r
343 abovePIDThreshold = b;
\r
346 public int getStartRes()
\r
351 public int getEndRes()
\r
356 public int getStartSeq()
\r
361 public void setGlobalColourScheme(ColourSchemeI cs)
\r
363 globalColourScheme = cs;
\r
366 public ColourSchemeI getGlobalColourScheme()
\r
368 return globalColourScheme;
\r
371 public void setStartRes(int res)
\r
373 this.startRes = res;
\r
376 public void setStartSeq(int seq)
\r
378 this.startSeq = seq;
\r
381 public void setEndRes(int res)
\r
383 if (res > (alignment.getWidth() - 1))
\r
385 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
386 res = alignment.getWidth() - 1;
\r
397 public void setEndSeq(int seq)
\r
399 if (seq > alignment.getHeight())
\r
401 seq = alignment.getHeight();
\r
412 public int getEndSeq()
\r
417 public void setFont(Font f)
\r
421 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
424 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
425 setCharHeight(fm.getHeight());
\r
426 setCharWidth(fm.charWidth('M'));
\r
429 public Font getFont()
\r
434 public void setCharWidth(int w)
\r
436 this.charWidth = w;
\r
439 public int getCharWidth()
\r
444 public void setCharHeight(int h)
\r
446 this.charHeight = h;
\r
449 public int getCharHeight()
\r
454 public void setChunkWidth(int w)
\r
456 this.chunkWidth = w;
\r
459 public int getChunkWidth()
\r
464 public void setChunkHeight(int h)
\r
466 this.chunkHeight = h;
\r
469 public int getChunkHeight()
\r
471 return chunkHeight;
\r
474 public AlignmentI getAlignment()
\r
479 public void setAlignment(AlignmentI align)
\r
481 this.alignment = align;
\r
484 public void setWrapAlignment(boolean state)
\r
486 wrapAlignment = state;
\r
489 public void setShowText(boolean state)
\r
494 public void setRenderGaps(boolean state)
\r
496 renderGaps = state;
\r
499 public boolean getColourText()
\r
501 return showColourText;
\r
504 public void setColourText(boolean state)
\r
506 showColourText = state;
\r
509 public void setShowBoxes(boolean state)
\r
514 public boolean getWrapAlignment()
\r
516 return wrapAlignment;
\r
519 public boolean getShowText()
\r
524 public boolean getShowBoxes()
\r
529 public char getGapCharacter()
\r
531 return getAlignment().getGapCharacter();
\r
534 public void setGapCharacter(char gap)
\r
536 if (getAlignment() != null)
\r
538 getAlignment().setGapCharacter(gap);
\r
542 public void setThreshold(int thresh)
\r
544 threshold = thresh;
\r
547 public int getThreshold()
\r
552 public void setIncrement(int inc)
\r
557 public int getIncrement()
\r
562 public int getIndex(int y)
\r
565 int starty = getStartSeq();
\r
566 int endy = getEndSeq();
\r
568 for (int i = starty; i <= endy; i++)
\r
570 if ( (i < alignment.getHeight()) &&
\r
571 (alignment.getSequenceAt(i) != null))
\r
573 int y2 = y1 + getCharHeight();
\r
575 if ( (y >= y1) && (y <= y2))
\r
591 public ColumnSelection getColumnSelection()
\r
596 public void resetSeqLimits(int height)
\r
598 setEndSeq(height / getCharHeight());
\r
601 public void setCurrentTree(NJTree tree)
\r
603 currentTree = tree;
\r
606 public NJTree getCurrentTree()
\r
608 return currentTree;
\r
611 public void setColourAppliesToAllGroups(boolean b)
\r
613 colourAppliesToAllGroups = b;
\r
616 public boolean getColourAppliesToAllGroups()
\r
618 return colourAppliesToAllGroups;
\r
621 public boolean getShowFullId()
\r
626 public void setShowFullId(boolean b)
\r
631 public boolean getShowAnnotation()
\r
633 return showAnnotation;
\r
636 public void setShowAnnotation(boolean b)
\r
638 showAnnotation = b;
\r
641 public boolean getScaleAboveWrapped()
\r
643 return scaleAboveWrapped;
\r
646 public boolean getScaleLeftWrapped()
\r
648 return scaleLeftWrapped;
\r
651 public boolean getScaleRightWrapped()
\r
653 return scaleRightWrapped;
\r
656 public void setScaleAboveWrapped(boolean b)
\r
658 scaleAboveWrapped = b;
\r
661 public void setScaleLeftWrapped(boolean b)
\r
663 scaleLeftWrapped = b;
\r
666 public void setScaleRightWrapped(boolean b)
\r
668 scaleRightWrapped = b;
\r
671 public void addPropertyChangeListener(
\r
672 java.beans.PropertyChangeListener listener)
\r
674 changeSupport.addPropertyChangeListener(listener);
\r
677 public void removePropertyChangeListener(
\r
678 java.beans.PropertyChangeListener listener)
\r
680 changeSupport.removePropertyChangeListener(listener);
\r
683 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
685 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r