2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
24 import jalview.analysis.*;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.structure.SelectionSource;
31 import jalview.structure.VamsasSource;
32 import jalview.viewmodel.AlignmentViewport;
33 import jalview.workers.ConservationThread;
34 import jalview.workers.ConsensusThread;
36 public class AlignViewport extends AlignmentViewport implements AlignViewportI, SelectionSource, VamsasSource
46 boolean cursorMode = false;
48 boolean showJVSuffix = true;
50 boolean showText = true;
52 boolean showColourText = false;
54 boolean showBoxes = true;
56 boolean wrapAlignment = false;
58 boolean renderGaps = true;
60 boolean showSequenceFeatures = false;
62 boolean showAnnotation = true;
64 boolean showConservation = true;
66 boolean showQuality = true;
68 boolean showConsensus = true;
70 boolean upperCasebold = false;
72 boolean colourAppliesToAllGroups = true;
74 boolean conservationColourSelected = false;
76 boolean abovePIDThreshold = false;
84 Font font = new Font("SansSerif", Font.PLAIN, 10);
86 boolean validCharWidth = true;
92 NJTree currentTree = null;
94 boolean scaleAboveWrapped = true;
96 boolean scaleLeftWrapped = true;
98 boolean scaleRightWrapped = true;
100 // The following vector holds the features which are
101 // currently visible, in the correct order or rendering
102 public Hashtable featuresDisplayed;
105 boolean showHiddenMarkers = true;
107 public jalview.bin.JalviewLite applet;
109 Hashtable sequenceColours;
113 Stack historyList = new Stack();
115 Stack redoList = new Stack();
117 public void finalize() {
124 public AlignViewport(AlignmentI al, JalviewLite applet)
126 calculator = new jalview.workers.AlignCalcManager();
127 this.applet = applet;
129 // we always pad gaps
130 this.setPadGaps(true);
132 this.endRes = al.getWidth() - 1;
134 this.endSeq = al.getHeight() - 1;
137 // get the width and height scaling factors if they were specified
138 String param = applet.getParameter("widthScale");
143 widthScale = new Float(param).floatValue();
144 } catch (Exception e)
147 if (widthScale <= 1.0)
150 .println("Invalid alignment character width scaling factor ("
151 + widthScale + "). Ignoring.");
157 .println("Alignment character width scaling factor is now "
161 param = applet.getParameter("heightScale");
166 heightScale = new Float(param).floatValue();
167 } catch (Exception e)
170 if (heightScale <= 1.0)
173 .println("Invalid alignment character height scaling factor ("
174 + heightScale + "). Ignoring.");
180 .println("Alignment character height scaling factor is now "
187 MAC = new jalview.util.Platform().isAMac();
191 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
193 showAnnotation = applet.getDefaultParameter("showAnnotation", showAnnotation);
195 showConservation = applet.getDefaultParameter("showConservation", showConservation);
197 showQuality = applet.getDefaultParameter("showQuality", showQuality);
199 showConsensus = applet.getDefaultParameter("showConsensus", showConsensus);
201 showUnconserved = applet.getDefaultParameter("showUnconserved", showUnconserved);
203 String param = applet.getParameter("upperCase");
206 if (param.equalsIgnoreCase("bold"))
208 upperCasebold = true;
211 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
213 followHighlight = applet.getDefaultParameter("automaticScrolling",followHighlight);
214 followSelection = followHighlight;
216 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo", showSequenceLogo);
218 normaliseSequenceLogo = applet.getDefaultParameter("normaliseSequenceLogo", normaliseSequenceLogo);
220 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus);
222 showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation);
224 showConsensusHistogram = applet.getDefaultParameter("showConsensusHistogram", showConsensusHistogram);
230 String colour = applet.getParameter("defaultColour");
234 colour = applet.getParameter("userDefinedColour");
237 colour = "User Defined";
243 globalColourScheme = ColourSchemeProperty.getColour(alignment,
245 if (globalColourScheme != null)
247 globalColourScheme.setConsensus(hconsensus);
251 if (applet.getParameter("userDefinedColour") != null)
253 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
254 .getParameter("userDefinedColour"));
257 if (hconsensus == null)
259 if (!alignment.isNucleotide())
261 conservation = new AlignmentAnnotation("Conservation",
262 "Conservation of total alignment less than " + getConsPercGaps()
263 + "% gaps", new Annotation[1], 0f, 11f,
264 AlignmentAnnotation.BAR_GRAPH);
265 conservation.hasText = true;
266 conservation.autoCalculated = true;
268 if (showConservation)
270 alignment.addAnnotation(conservation);
275 quality = new AlignmentAnnotation("Quality",
276 "Alignment Quality based on Blosum62 scores",
277 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
278 quality.hasText = true;
279 quality.autoCalculated = true;
281 alignment.addAnnotation(quality);
285 consensus = new AlignmentAnnotation("Consensus", "PID",
286 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
287 consensus.hasText = true;
288 consensus.autoCalculated = true;
292 alignment.addAnnotation(consensus);
298 public void showSequenceFeatures(boolean b)
300 showSequenceFeatures = b;
303 public boolean getShowSequenceFeatures()
305 return showSequenceFeatures;
310 * get the consensus sequence as displayed under the PID consensus annotation
313 * @return consensus sequence as a new sequence object
315 public SequenceI getConsensusSeq()
317 if (consensus == null)
319 updateConsensus(null);
321 if (consensus == null)
325 StringBuffer seqs = new StringBuffer();
326 for (int i = 0; i < consensus.annotations.length; i++)
328 if (consensus.annotations[i] != null)
330 if (consensus.annotations[i].description.charAt(0) == '[')
332 seqs.append(consensus.annotations[i].description.charAt(1));
336 seqs.append(consensus.annotations[i].displayCharacter);
340 SequenceI sq = new Sequence("Consensus", seqs.toString());
341 sq.setDescription("Percentage Identity Consensus "
342 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
346 public boolean getConservationSelected()
348 return conservationColourSelected;
351 public void setConservationSelected(boolean b)
353 conservationColourSelected = b;
356 public boolean getAbovePIDThreshold()
358 return abovePIDThreshold;
361 public void setAbovePIDThreshold(boolean b)
363 abovePIDThreshold = b;
366 public int getStartRes()
371 public int getEndRes()
376 public int getStartSeq()
381 public void setStartRes(int res)
386 public void setStartSeq(int seq)
391 public void setEndRes(int res)
393 if (res > alignment.getWidth() - 1)
395 // log.System.out.println(" Corrected res from " + res + " to maximum " +
396 // (alignment.getWidth()-1));
397 res = alignment.getWidth() - 1;
406 public void setEndSeq(int seq)
408 if (seq > alignment.getHeight())
410 seq = alignment.getHeight();
419 public int getEndSeq()
424 java.awt.Frame nullFrame;
426 protected FeatureSettings featureSettings = null;
428 private float heightScale = 1, widthScale = 1;
430 public void setFont(Font f)
433 if (nullFrame == null)
435 nullFrame = new java.awt.Frame();
436 nullFrame.addNotify();
439 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
440 setCharHeight((int) (heightScale * fm.getHeight()));
441 charWidth = (int) (widthScale * fm.charWidth('M'));
445 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
446 fm = nullFrame.getGraphics().getFontMetrics(f2);
447 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
451 public Font getFont()
456 public int getCharWidth()
461 public void setCharHeight(int h)
466 public int getCharHeight()
471 public void setWrappedWidth(int w)
473 this.wrappedWidth = w;
476 public int getwrappedWidth()
481 public AlignmentI getAlignment()
486 public void setAlignment(AlignmentI align)
488 this.alignment = align;
491 public void setWrapAlignment(boolean state)
493 wrapAlignment = state;
496 public void setShowText(boolean state)
501 public void setRenderGaps(boolean state)
506 public boolean getColourText()
508 return showColourText;
511 public void setColourText(boolean state)
513 showColourText = state;
516 public void setShowBoxes(boolean state)
521 public boolean getWrapAlignment()
523 return wrapAlignment;
526 public boolean getShowText()
531 public boolean getShowBoxes()
536 public char getGapCharacter()
538 return getAlignment().getGapCharacter();
541 public void setGapCharacter(char gap)
543 if (getAlignment() != null)
545 getAlignment().setGapCharacter(gap);
549 public void setThreshold(int thresh)
554 public int getThreshold()
559 public void setIncrement(int inc)
564 public int getIncrement()
569 public void resetSeqLimits(int height)
571 setEndSeq(height / getCharHeight());
574 public void setCurrentTree(NJTree tree)
579 public NJTree getCurrentTree()
584 public void setColourAppliesToAllGroups(boolean b)
586 colourAppliesToAllGroups = b;
589 public boolean getColourAppliesToAllGroups()
591 return colourAppliesToAllGroups;
594 public boolean getShowJVSuffix()
599 public void setShowJVSuffix(boolean b)
604 public boolean getShowAnnotation()
606 return showAnnotation;
609 public void setShowAnnotation(boolean b)
614 public boolean getScaleAboveWrapped()
616 return scaleAboveWrapped;
619 public boolean getScaleLeftWrapped()
621 return scaleLeftWrapped;
624 public boolean getScaleRightWrapped()
626 return scaleRightWrapped;
629 public void setScaleAboveWrapped(boolean b)
631 scaleAboveWrapped = b;
634 public void setScaleLeftWrapped(boolean b)
636 scaleLeftWrapped = b;
639 public void setScaleRightWrapped(boolean b)
641 scaleRightWrapped = b;
644 public void setIgnoreGapsConsensus(boolean b)
646 ignoreGapsInConsensusCalculation = b;
647 updateConsensus(null);
648 if (globalColourScheme != null)
650 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
651 ignoreGapsInConsensusCalculation);
660 public boolean getShowHiddenMarkers()
662 return showHiddenMarkers;
665 public void setShowHiddenMarkers(boolean show)
667 showHiddenMarkers = show;
670 public Color getSequenceColour(SequenceI seq)
672 if (sequenceColours == null || !sequenceColours.containsKey(seq))
678 return (Color) sequenceColours.get(seq);
682 public void setSequenceColour(SequenceI seq, Color col)
684 if (sequenceColours == null)
686 sequenceColours = new Hashtable();
691 sequenceColours.remove(seq);
695 sequenceColours.put(seq, col);
699 boolean centreColumnLabels;
701 public boolean getCentreColumnLabels()
703 return centreColumnLabels;
706 public void updateSequenceIdColours()
708 Vector groups = alignment.getGroups();
709 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
711 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
712 if (sg.idColour != null)
714 Vector sqs = sg.getSequences(getHiddenRepSequences());
715 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
717 this.setSequenceColour((SequenceI) sqs.elementAt(s), sg.idColour);
723 public boolean followHighlight = true;
725 public boolean getFollowHighlight()
727 return followHighlight;
730 public boolean followSelection = true;
733 * @return true if view selection should always follow the selections
734 * broadcast by other selection sources
736 public boolean getFollowSelection()
738 return followSelection;
740 public void sendSelection()
742 jalview.structure.StructureSelectionManager
743 .getStructureSelectionManager(applet).sendSelection(
744 new SequenceGroup(getSelectionGroup()),
745 new ColumnSelection(getColumnSelection()), this);
752 * synthesize a column selection if none exists so it covers the given
753 * selection group. if wholewidth is false, no column selection is made if the
754 * selection group covers the whole alignment width.
759 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
763 && (sgs = sg.getStartRes()) >= 0
764 && sg.getStartRes() <= (sge = sg.getEndRes())
765 && (colSel == null || colSel.getSelected() == null || colSel
766 .getSelected().size() == 0))
768 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
775 colSel = new ColumnSelection();
777 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
779 colSel.addElement(cspos);
785 public boolean hasHiddenColumns()
787 return hasHiddenColumns;
790 public boolean isNormaliseSequenceLogo()
792 return normaliseSequenceLogo;
795 public void setNormaliseSequenceLogo(boolean state)
797 normaliseSequenceLogo = state;
802 * @return true if alignment characters should be displayed
804 public boolean isValidCharWidth()
806 return validCharWidth;