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
21 import jalview.analysis.*;
\r
23 import jalview.bin.*;
\r
25 import jalview.datamodel.*;
\r
27 import jalview.schemes.*;
\r
38 * @version $Revision$
\r
40 public class AlignViewport
\r
46 boolean showFullId = false;
\r
47 boolean showText = true;
\r
48 boolean showColourText = false;
\r
49 boolean showBoxes = true;
\r
50 boolean wrapAlignment = false;
\r
51 boolean renderGaps = true;
\r
52 boolean showSequenceFeatures = false;
\r
53 boolean showAnnotation = true;
\r
54 boolean showConservation = true;
\r
55 boolean showQuality = true;
\r
56 boolean showIdentity = true;
\r
57 boolean colourAppliesToAllGroups = true;
\r
58 ColourSchemeI globalColourScheme = null;
\r
59 boolean conservationColourSelected = false;
\r
60 boolean abovePIDThreshold = false;
\r
61 SequenceGroup selectionGroup = new SequenceGroup();
\r
66 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
67 AlignmentI alignment;
\r
68 ColumnSelection colSel = new ColumnSelection();
\r
71 NJTree currentTree = null;
\r
72 boolean scaleAboveWrapped = false;
\r
73 boolean scaleLeftWrapped = true;
\r
74 boolean scaleRightWrapped = true;
\r
76 /** DOCUMENT ME!! */
\r
77 public Vector vconsensus;
\r
78 AlignmentAnnotation consensus;
\r
79 AlignmentAnnotation conservation;
\r
80 AlignmentAnnotation quality;
\r
82 /** DOCUMENT ME!! */
\r
83 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
85 // JBPNote Prolly only need this in the applet version.
\r
86 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
89 * Creates a new AlignViewport object.
\r
91 * @param al DOCUMENT ME!
\r
93 public AlignViewport(AlignmentI al)
\r
97 this.endRes = al.getWidth() - 1;
\r
99 this.endSeq = al.getHeight() - 1;
\r
101 updateFromPreferences();
\r
107 public void updateFromPreferences()
\r
109 showFullId = Preferences.showFullId;
\r
110 showAnnotation = Preferences.showAnnotation;
\r
111 showConservation = Preferences.showConservation;
\r
112 showQuality = Preferences.showQuality;
\r
113 showIdentity = Preferences.showIdentity;
\r
114 showFullId = Preferences.showFullId;
\r
116 String fontName = Preferences.fontName;
\r
117 String fontStyle = Preferences.fontStyle;
\r
118 String fontSize = Cache.getProperty("FONT_SIZE");
\r
120 if ((fontName != null) && (fontStyle != null) && (fontSize != null))
\r
124 if (fontStyle.equals("bold"))
\r
128 else if (fontStyle.equals("italic"))
\r
133 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
\r
140 alignment.setGapCharacter(Preferences.gapSymbol);
\r
142 // We must set conservation and consensus before setting colour,
\r
143 // as Blosum and Clustal require this to be done
\r
144 updateConservation();
\r
147 if (Preferences.defaultColour != null)
\r
149 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
150 Preferences.defaultColour);
\r
152 if (globalColourScheme instanceof UserColourScheme)
\r
154 globalColourScheme = UserDefinedColours.loadDefaultColours();
\r
157 if (globalColourScheme != null)
\r
159 globalColourScheme.setConsensus(vconsensus);
\r
167 * @param b DOCUMENT ME!
\r
169 public void showSequenceFeatures(boolean b)
\r
171 showSequenceFeatures = b;
\r
177 public void updateConservation()
\r
179 Conservation cons = new jalview.analysis.Conservation("All",
\r
180 jalview.schemes.ResidueProperties.propHash, 3,
\r
181 alignment.getSequences(), 0, alignment.getWidth() - 1);
\r
183 cons.verdict(false, ConsPercGaps);
\r
184 cons.findQuality();
\r
186 int alWidth = alignment.getWidth();
\r
187 Annotation[] annotations = new Annotation[alWidth];
\r
188 Annotation[] qannotations = new Annotation[alWidth];
\r
189 String sequence = cons.getConsSequence().getSequence();
\r
199 maxR = 1.0f - minR;
\r
200 maxG = 0.9f - minG;
\r
201 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
205 float qmin = cons.qualityRange[0].floatValue();
\r
206 float qmax = cons.qualityRange[1].floatValue();
\r
208 for (int i = 0; i < alWidth; i++)
\r
214 value = Integer.parseInt(sequence.charAt(i) + "");
\r
216 catch (Exception ex)
\r
218 if (sequence.charAt(i) == '*')
\r
223 if (sequence.charAt(i) == '+')
\r
229 float vprop = value - min;
\r
231 annotations[i] = new Annotation(sequence.charAt(i) + "",
\r
232 String.valueOf(value), ' ', value,
\r
233 new Color(minR + (maxR * vprop), minG + (maxG * vprop),
\r
234 minB + (maxB * vprop)));
\r
237 value = ((Double) cons.quality.get(i)).floatValue();
\r
238 vprop = value - qmin;
\r
240 qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',
\r
242 new Color(minR + (maxR * vprop), minG + (maxG * vprop),
\r
243 minB + (maxB * vprop)));
\r
246 if (conservation == null)
\r
248 conservation = new AlignmentAnnotation("Conservation",
\r
249 "Conservation of total alignment less than " +
\r
250 ConsPercGaps + "% gaps", annotations, 0f, // cons.qualityRange[0].floatValue(),
\r
251 11f, // cons.qualityRange[1].floatValue()
\r
254 if (showConservation)
\r
256 alignment.addAnnotation(conservation);
\r
259 quality = new AlignmentAnnotation("Quality",
\r
260 "Alignment Quality based on Blosum62 scores", qannotations,
\r
261 cons.qualityRange[0].floatValue(),
\r
262 cons.qualityRange[1].floatValue(), 1);
\r
266 alignment.addAnnotation(quality);
\r
271 conservation.annotations = annotations;
\r
272 quality.annotations = qannotations;
\r
273 quality.graphMax = cons.qualityRange[1].floatValue();
\r
280 public void updateConsensus()
\r
282 Annotation[] annotations = new Annotation[alignment.getWidth()];
\r
284 // this routine prevents vconsensus becoming a new object each time
\r
285 // consenus is calculated. Important for speed of Blosum62
\r
286 // and PID colouring of alignment
\r
287 if (vconsensus == null)
\r
289 vconsensus = alignment.getAAFrequency();
\r
293 Vector temp = alignment.getAAFrequency();
\r
294 vconsensus.clear();
\r
296 Enumeration e = temp.elements();
\r
298 while (e.hasMoreElements())
\r
300 vconsensus.add(e.nextElement());
\r
304 Hashtable hash = null;
\r
306 for (int i = 0; i < alignment.getWidth(); i++)
\r
308 hash = (Hashtable) vconsensus.elementAt(i);
\r
310 float value = Float.parseFloat(hash.get("maxCount").toString());
\r
311 value /= Float.parseFloat(hash.get("size").toString());
\r
315 String maxRes = hash.get("maxResidue") + " ";
\r
316 String mouseOver = hash.get("maxResidue") + " ";
\r
318 if (maxRes.length() > 2)
\r
320 mouseOver = "[" + maxRes + "] ";
\r
324 mouseOver += ((int) value + "%");
\r
325 annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
328 if (consensus == null)
\r
330 consensus = new AlignmentAnnotation("Consensus", "PID",
\r
331 annotations, 0f, 100f, 1);
\r
335 alignment.addAnnotation(consensus);
\r
340 consensus.annotations = annotations;
\r
347 * @return DOCUMENT ME!
\r
349 public SequenceGroup getSelectionGroup()
\r
351 return selectionGroup;
\r
357 * @param sg DOCUMENT ME!
\r
359 public void setSelectionGroup(SequenceGroup sg)
\r
361 selectionGroup = sg;
\r
367 * @return DOCUMENT ME!
\r
369 public boolean getConservationSelected()
\r
371 return conservationColourSelected;
\r
377 * @param b DOCUMENT ME!
\r
379 public void setConservationSelected(boolean b)
\r
381 conservationColourSelected = b;
\r
387 * @return DOCUMENT ME!
\r
389 public boolean getAbovePIDThreshold()
\r
391 return abovePIDThreshold;
\r
397 * @param b DOCUMENT ME!
\r
399 public void setAbovePIDThreshold(boolean b)
\r
401 abovePIDThreshold = b;
\r
407 * @return DOCUMENT ME!
\r
409 public int getStartRes()
\r
417 * @return DOCUMENT ME!
\r
419 public int getEndRes()
\r
427 * @return DOCUMENT ME!
\r
429 public int getStartSeq()
\r
437 * @param cs DOCUMENT ME!
\r
439 public void setGlobalColourScheme(ColourSchemeI cs)
\r
441 globalColourScheme = cs;
\r
447 * @return DOCUMENT ME!
\r
449 public ColourSchemeI getGlobalColourScheme()
\r
451 return globalColourScheme;
\r
457 * @param res DOCUMENT ME!
\r
459 public void setStartRes(int res)
\r
461 this.startRes = res;
\r
467 * @param seq DOCUMENT ME!
\r
469 public void setStartSeq(int seq)
\r
471 this.startSeq = seq;
\r
477 * @param res DOCUMENT ME!
\r
479 public void setEndRes(int res)
\r
481 if (res > (alignment.getWidth() - 1))
\r
483 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
484 res = alignment.getWidth() - 1;
\r
498 * @param seq DOCUMENT ME!
\r
500 public void setEndSeq(int seq)
\r
502 if (seq > alignment.getHeight())
\r
504 seq = alignment.getHeight();
\r
518 * @return DOCUMENT ME!
\r
520 public int getEndSeq()
\r
528 * @param f DOCUMENT ME!
\r
530 public void setFont(Font f)
\r
534 javax.swing.JFrame temp = new javax.swing.JFrame();
\r
537 java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);
\r
538 setCharHeight(fm.getHeight());
\r
539 setCharWidth(fm.charWidth('M'));
\r
545 * @return DOCUMENT ME!
\r
547 public Font getFont()
\r
555 * @param w DOCUMENT ME!
\r
557 public void setCharWidth(int w)
\r
559 this.charWidth = w;
\r
565 * @return DOCUMENT ME!
\r
567 public int getCharWidth()
\r
575 * @param h DOCUMENT ME!
\r
577 public void setCharHeight(int h)
\r
579 this.charHeight = h;
\r
585 * @return DOCUMENT ME!
\r
587 public int getCharHeight()
\r
595 * @param w DOCUMENT ME!
\r
597 public void setChunkWidth(int w)
\r
599 this.chunkWidth = w;
\r
605 * @return DOCUMENT ME!
\r
607 public int getChunkWidth()
\r
615 * @param h DOCUMENT ME!
\r
617 public void setChunkHeight(int h)
\r
619 this.chunkHeight = h;
\r
625 * @return DOCUMENT ME!
\r
627 public int getChunkHeight()
\r
629 return chunkHeight;
\r
635 * @return DOCUMENT ME!
\r
637 public AlignmentI getAlignment()
\r
645 * @param align DOCUMENT ME!
\r
647 public void setAlignment(AlignmentI align)
\r
649 this.alignment = align;
\r
655 * @param state DOCUMENT ME!
\r
657 public void setWrapAlignment(boolean state)
\r
659 wrapAlignment = state;
\r
665 * @param state DOCUMENT ME!
\r
667 public void setShowText(boolean state)
\r
675 * @param state DOCUMENT ME!
\r
677 public void setRenderGaps(boolean state)
\r
679 renderGaps = state;
\r
685 * @return DOCUMENT ME!
\r
687 public boolean getColourText()
\r
689 return showColourText;
\r
695 * @param state DOCUMENT ME!
\r
697 public void setColourText(boolean state)
\r
699 showColourText = state;
\r
705 * @param state DOCUMENT ME!
\r
707 public void setShowBoxes(boolean state)
\r
715 * @return DOCUMENT ME!
\r
717 public boolean getWrapAlignment()
\r
719 return wrapAlignment;
\r
725 * @return DOCUMENT ME!
\r
727 public boolean getShowText()
\r
735 * @return DOCUMENT ME!
\r
737 public boolean getShowBoxes()
\r
745 * @return DOCUMENT ME!
\r
747 public char getGapCharacter()
\r
749 return getAlignment().getGapCharacter();
\r
755 * @param gap DOCUMENT ME!
\r
757 public void setGapCharacter(char gap)
\r
759 if (getAlignment() != null)
\r
761 getAlignment().setGapCharacter(gap);
\r
768 * @param thresh DOCUMENT ME!
\r
770 public void setThreshold(int thresh)
\r
772 threshold = thresh;
\r
778 * @return DOCUMENT ME!
\r
780 public int getThreshold()
\r
788 * @param inc DOCUMENT ME!
\r
790 public void setIncrement(int inc)
\r
798 * @return DOCUMENT ME!
\r
800 public int getIncrement()
\r
808 * @param y DOCUMENT ME!
\r
810 * @return DOCUMENT ME!
\r
812 public int getIndex(int y)
\r
815 int starty = getStartSeq();
\r
816 int endy = getEndSeq();
\r
818 for (int i = starty; i <= endy; i++)
\r
820 if ((i < alignment.getHeight()) &&
\r
821 (alignment.getSequenceAt(i) != null))
\r
823 int y2 = y1 + getCharHeight();
\r
825 if ((y >= y1) && (y <= y2))
\r
844 * @return DOCUMENT ME!
\r
846 public ColumnSelection getColumnSelection()
\r
854 * @param height DOCUMENT ME!
\r
856 public void resetSeqLimits(int height)
\r
858 setEndSeq(height / getCharHeight());
\r
864 * @param tree DOCUMENT ME!
\r
866 public void setCurrentTree(NJTree tree)
\r
868 currentTree = tree;
\r
874 * @return DOCUMENT ME!
\r
876 public NJTree getCurrentTree()
\r
878 return currentTree;
\r
884 * @param b DOCUMENT ME!
\r
886 public void setColourAppliesToAllGroups(boolean b)
\r
888 colourAppliesToAllGroups = b;
\r
894 * @return DOCUMENT ME!
\r
896 public boolean getColourAppliesToAllGroups()
\r
898 return colourAppliesToAllGroups;
\r
904 * @return DOCUMENT ME!
\r
906 public boolean getShowFullId()
\r
914 * @param b DOCUMENT ME!
\r
916 public void setShowFullId(boolean b)
\r
924 * @return DOCUMENT ME!
\r
926 public boolean getShowAnnotation()
\r
928 return showAnnotation;
\r
934 * @param b DOCUMENT ME!
\r
936 public void setShowAnnotation(boolean b)
\r
938 showAnnotation = b;
\r
944 * @return DOCUMENT ME!
\r
946 public boolean getScaleAboveWrapped()
\r
948 return scaleAboveWrapped;
\r
954 * @return DOCUMENT ME!
\r
956 public boolean getScaleLeftWrapped()
\r
958 return scaleLeftWrapped;
\r
964 * @return DOCUMENT ME!
\r
966 public boolean getScaleRightWrapped()
\r
968 return scaleRightWrapped;
\r
974 * @param b DOCUMENT ME!
\r
976 public void setScaleAboveWrapped(boolean b)
\r
978 scaleAboveWrapped = b;
\r
984 * @param b DOCUMENT ME!
\r
986 public void setScaleLeftWrapped(boolean b)
\r
988 scaleLeftWrapped = b;
\r
994 * @param b DOCUMENT ME!
\r
996 public void setScaleRightWrapped(boolean b)
\r
998 scaleRightWrapped = b;
\r
1004 * @param listener DOCUMENT ME!
\r
1006 public void addPropertyChangeListener(
\r
1007 java.beans.PropertyChangeListener listener)
\r
1009 changeSupport.addPropertyChangeListener(listener);
\r
1015 * @param listener DOCUMENT ME!
\r
1017 public void removePropertyChangeListener(
\r
1018 java.beans.PropertyChangeListener listener)
\r
1020 changeSupport.removePropertyChangeListener(listener);
\r
1026 * @param prop DOCUMENT ME!
\r
1027 * @param oldvalue DOCUMENT ME!
\r
1028 * @param newvalue DOCUMENT ME!
\r
1030 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
1032 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r