X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=1366ada6cc7acd4188e867b289fb0e6aa827d015;hb=620da661f54acba8fdb13f388dbed8b77d9113ed;hp=72cd31607cf1a7d5d5594162073457d98945d1a1;hpb=b948e764c92b0954100f216927114b2c9720b76c;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 72cd316..1366ada 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,35 +20,56 @@ */ package jalview.viewmodel; +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; +import jalview.analysis.TreeModel; import jalview.api.AlignCalcManagerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeaturesDisplayedI; +import jalview.api.ViewStyleI; +import jalview.commands.CommandI; +import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenSequences; +import jalview.datamodel.ProfilesI; +import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.schemes.Blosum62ColourScheme; +import jalview.renderer.ResidueShader; +import jalview.renderer.ResidueShaderI; import jalview.schemes.ColourSchemeI; -import jalview.schemes.PIDColourScheme; -import jalview.schemes.ResidueProperties; +import jalview.structure.CommandListener; +import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; +import jalview.util.Comparison; +import jalview.util.MapList; +import jalview.util.MappingUtils; +import jalview.util.MessageManager; +import jalview.viewmodel.styles.ViewStyle; import jalview.workers.AlignCalcManager; +import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; import jalview.workers.StrucConsensusThread; import java.awt.Color; +import java.beans.PropertyChangeSupport; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.BitSet; +import java.util.Deque; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Vector; /** * base class holding visualization and analysis attributes and common logic for @@ -57,691 +78,1172 @@ import java.util.Vector; * @author jimp * */ -public abstract class AlignmentViewport implements AlignViewportI +public abstract class AlignmentViewport + implements AlignViewportI, CommandListener, VamsasSource { - /** - * alignment displayed in the viewport. Please use get/setter - */ - protected AlignmentI alignment; + protected ViewportRanges ranges; - protected String sequenceSetID; + protected ViewStyleI viewStyle = new ViewStyle(); /** - * probably unused indicator that view is of a dataset rather than an - * alignment + * A viewport that hosts the cDna view of this (protein), or vice versa (if + * set). */ - protected boolean isDataset = false; + AlignViewportI codingComplement = null; - private Map hiddenRepSequences; + FeaturesDisplayedI featuresDisplayed = null; - protected ColumnSelection colSel = new ColumnSelection(); + protected Deque historyList = new ArrayDeque<>(); - public boolean autoCalculateConsensus = true; + protected Deque redoList = new ArrayDeque<>(); - protected boolean autoCalculateStrucConsensus = true; + /** + * alignment displayed in the viewport. Please use get/setter + */ + protected AlignmentI alignment; - protected boolean ignoreGapsInConsensusCalculation = false; + public AlignmentViewport(AlignmentI al) + { + setAlignment(al); + ranges = new ViewportRanges(al); + } - protected ColourSchemeI globalColourScheme = null; + /** + * @param name + * @see jalview.api.ViewStyleI#setFontName(java.lang.String) + */ + @Override + public void setFontName(String name) + { + viewStyle.setFontName(name); + } /** - * gui state - changes to colour scheme propagated to all groups + * @param style + * @see jalview.api.ViewStyleI#setFontStyle(int) */ - private boolean colourAppliesToAllGroups; + @Override + public void setFontStyle(int style) + { + viewStyle.setFontStyle(style); + } /** - * @param value - * indicating if subsequent colourscheme changes will be propagated - * to all groups + * @param size + * @see jalview.api.ViewStyleI#setFontSize(int) */ - public void setColourAppliesToAllGroups(boolean b) + @Override + public void setFontSize(int size) { - colourAppliesToAllGroups = b; + viewStyle.setFontSize(size); } /** - * - * - * @return flag indicating if colourchanges propagated to all groups + * @return + * @see jalview.api.ViewStyleI#getFontStyle() */ - public boolean getColourAppliesToAllGroups() + @Override + public int getFontStyle() { - return colourAppliesToAllGroups; + return viewStyle.getFontStyle(); } - boolean abovePIDThreshold = false; + /** + * @return + * @see jalview.api.ViewStyleI#getFontName() + */ + @Override + public String getFontName() + { + return viewStyle.getFontName(); + } /** - * GUI state - * - * @return true if percent identity threshold is applied to shading + * @return + * @see jalview.api.ViewStyleI#getFontSize() */ - public boolean getAbovePIDThreshold() + @Override + public int getFontSize() { - return abovePIDThreshold; + return viewStyle.getFontSize(); } /** - * GUI state - * - * - * @param b - * indicate if percent identity threshold is applied to shading + * @param upperCasebold + * @see jalview.api.ViewStyleI#setUpperCasebold(boolean) */ - public void setAbovePIDThreshold(boolean b) + @Override + public void setUpperCasebold(boolean upperCasebold) { - abovePIDThreshold = b; + viewStyle.setUpperCasebold(upperCasebold); } - int threshold; + /** + * @return + * @see jalview.api.ViewStyleI#isUpperCasebold() + */ + @Override + public boolean isUpperCasebold() + { + return viewStyle.isUpperCasebold(); + } /** - * DOCUMENT ME! - * - * @param thresh - * DOCUMENT ME! + * @return + * @see jalview.api.ViewStyleI#isSeqNameItalics() */ - public void setThreshold(int thresh) + @Override + public boolean isSeqNameItalics() { - threshold = thresh; + return viewStyle.isSeqNameItalics(); } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * @param colourByReferenceSeq + * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean) */ - public int getThreshold() + @Override + public void setColourByReferenceSeq(boolean colourByReferenceSeq) { - return threshold; + viewStyle.setColourByReferenceSeq(colourByReferenceSeq); } - int increment; + /** + * @param b + * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean) + */ + @Override + public void setColourAppliesToAllGroups(boolean b) + { + viewStyle.setColourAppliesToAllGroups(b); + } /** - * - * @param inc - * set the scalar for bleaching colourschemes according to degree of - * conservation + * @return + * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups() */ - public void setIncrement(int inc) + @Override + public boolean getColourAppliesToAllGroups() { - increment = inc; + return viewStyle.getColourAppliesToAllGroups(); } /** - * GUI State - * - * @return get scalar for bleaching colourschemes by conservation + * @return + * @see jalview.api.ViewStyleI#getAbovePIDThreshold() */ - public int getIncrement() + @Override + public boolean getAbovePIDThreshold() { - return increment; + return viewStyle.getAbovePIDThreshold(); } - boolean conservationColourSelected = false; + /** + * @param inc + * @see jalview.api.ViewStyleI#setIncrement(int) + */ + @Override + public void setIncrement(int inc) + { + viewStyle.setIncrement(inc); + } /** - * GUI state - * - * @return true if conservation based shading is enabled + * @return + * @see jalview.api.ViewStyleI#getIncrement() */ - public boolean getConservationSelected() + @Override + public int getIncrement() { - return conservationColourSelected; + return viewStyle.getIncrement(); } /** - * GUI state - * * @param b - * enable conservation based shading + * @see jalview.api.ViewStyleI#setConservationSelected(boolean) */ + @Override public void setConservationSelected(boolean b) { - conservationColourSelected = b; + viewStyle.setConservationSelected(b); } + /** + * @param show + * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean) + */ @Override - public void setGlobalColourScheme(ColourSchemeI cs) + public void setShowHiddenMarkers(boolean show) { - // TODO: logic refactored from AlignFrame changeColour - - // autorecalc stuff should be changed to rely on the worker system - // check to see if we should implement a changeColour(cs) method rather than - // put th logic in here - // - means that caller decides if they want to just modify state and defer - // calculation till later or to do all calculations in thread. - // via changecolour - globalColourScheme = cs; - boolean recalc = false; - if (cs != null) - { - cs.setConservationApplied(recalc = getConservationSelected()); - if (getAbovePIDThreshold() || cs instanceof PIDColourScheme - || cs instanceof Blosum62ColourScheme) - { - recalc = true; - cs.setThreshold(threshold, ignoreGapsInConsensusCalculation); - } - else - { - cs.setThreshold(0, ignoreGapsInConsensusCalculation); - } - if (recalc) - { - cs.setConsensus(hconsensus); - cs.setConservation(hconservation); - } - cs.alignmentChanged(alignment, hiddenRepSequences); - } - if (getColourAppliesToAllGroups()) - { - for (SequenceGroup sg : getAlignment().getGroups()) - { - if (cs == null) - { - sg.cs = null; - continue; - } - sg.cs = cs.applyTo(sg, getHiddenRepSequences()); - sg.setConsPercGaps(ConsPercGaps); - if (getAbovePIDThreshold() || cs instanceof PIDColourScheme - || cs instanceof Blosum62ColourScheme) - { - sg.cs.setThreshold(threshold, getIgnoreGapsConsensus()); - recalc = true; - } - else - { - sg.cs.setThreshold(0, getIgnoreGapsConsensus()); - } - - if (getConservationSelected()) - { - sg.cs.setConservationApplied(true); - recalc = true; - } - else - { - sg.cs.setConservation(null); - // sg.cs.setThreshold(0, getIgnoreGapsConsensus()); - } - if (recalc) - { - sg.recalcConservation(); - } - else - { - sg.cs.alignmentChanged(sg, hiddenRepSequences); - } - } - } - + viewStyle.setShowHiddenMarkers(show); } + /** + * @return + * @see jalview.api.ViewStyleI#getShowHiddenMarkers() + */ @Override - public ColourSchemeI getGlobalColourScheme() + public boolean getShowHiddenMarkers() { - return globalColourScheme; + return viewStyle.getShowHiddenMarkers(); } - protected AlignmentAnnotation consensus; - - protected AlignmentAnnotation strucConsensus; - - protected AlignmentAnnotation conservation; - - protected AlignmentAnnotation quality; - - protected AlignmentAnnotation[] groupConsensus; - - protected AlignmentAnnotation[] groupConservation; - /** - * results of alignment consensus analysis for visible portion of view + * @param b + * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean) */ - protected Hashtable[] hconsensus = null; + @Override + public void setScaleRightWrapped(boolean b) + { + viewStyle.setScaleRightWrapped(b); + } /** - * results of secondary structure base pair consensus for visible portion of - * view + * @param b + * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean) */ - protected Hashtable[] hStrucConsensus = null; - - protected Conservation hconservation = null; - @Override - public void setConservation(Conservation cons) + public void setScaleLeftWrapped(boolean b) { - hconservation = cons; + viewStyle.setScaleLeftWrapped(b); } /** - * percentage gaps allowed in a column before all amino acid properties should - * be considered unconserved + * @param b + * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean) */ - int ConsPercGaps = 25; // JBPNote : This should be a scalable property! - @Override - public int getConsPercGaps() + public void setScaleAboveWrapped(boolean b) { - return ConsPercGaps; + viewStyle.setScaleAboveWrapped(b); } + /** + * @return + * @see jalview.api.ViewStyleI#getScaleLeftWrapped() + */ @Override - public void setSequenceConsensusHash(Hashtable[] hconsensus) + public boolean getScaleLeftWrapped() { - this.hconsensus = hconsensus; - + return viewStyle.getScaleLeftWrapped(); } + /** + * @return + * @see jalview.api.ViewStyleI#getScaleAboveWrapped() + */ @Override - public Hashtable[] getSequenceConsensusHash() + public boolean getScaleAboveWrapped() { - return hconsensus; + return viewStyle.getScaleAboveWrapped(); } + /** + * @return + * @see jalview.api.ViewStyleI#getScaleRightWrapped() + */ @Override - public Hashtable[] getRnaStructureConsensusHash() + public boolean getScaleRightWrapped() { - return hStrucConsensus; + return viewStyle.getScaleRightWrapped(); } + /** + * @param b + * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean) + */ @Override - public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus) + public void setAbovePIDThreshold(boolean b) { - this.hStrucConsensus = hStrucConsensus; - + viewStyle.setAbovePIDThreshold(b); } + /** + * @param thresh + * @see jalview.api.ViewStyleI#setThreshold(int) + */ @Override - public AlignmentAnnotation getAlignmentQualityAnnot() + public void setThreshold(int thresh) { - return quality; + viewStyle.setThreshold(thresh); } + /** + * @return + * @see jalview.api.ViewStyleI#getThreshold() + */ @Override - public AlignmentAnnotation getAlignmentConservationAnnotation() + public int getThreshold() { - return conservation; + return viewStyle.getThreshold(); } + /** + * @return + * @see jalview.api.ViewStyleI#getShowJVSuffix() + */ @Override - public AlignmentAnnotation getAlignmentConsensusAnnotation() + public boolean getShowJVSuffix() { - return consensus; + return viewStyle.getShowJVSuffix(); } + /** + * @param b + * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean) + */ @Override - public AlignmentAnnotation getAlignmentStrucConsensusAnnotation() + public void setShowJVSuffix(boolean b) { - return strucConsensus; + viewStyle.setShowJVSuffix(b); } - protected AlignCalcManagerI calculator = new AlignCalcManager(); - /** - * trigger update of conservation annotation + * @param state + * @see jalview.api.ViewStyleI#setWrapAlignment(boolean) */ - public void updateConservation(final AlignmentViewPanel ap) + @Override + public void setWrapAlignment(boolean state) { - // see note in mantis : issue number 8585 - if (alignment.isNucleotide() || conservation == null - || !autoCalculateConsensus) - { - return; - } - if (calculator - .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null) - { - calculator.registerWorker(new jalview.workers.ConservationThread( - this, ap)); - } + viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** - * trigger update of consensus annotation + * @param state + * @see jalview.api.ViewStyleI#setShowText(boolean) */ - public void updateConsensus(final AlignmentViewPanel ap) + @Override + public void setShowText(boolean state) { - // see note in mantis : issue number 8585 - if (consensus == null || !autoCalculateConsensus) - { - return; - } - if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null) - { - calculator.registerWorker(new ConsensusThread(this, ap)); - } + viewStyle.setShowText(state); } - // --------START Structure Conservation - public void updateStrucConsensus(final AlignmentViewPanel ap) + /** + * @param state + * @see jalview.api.ViewStyleI#setRenderGaps(boolean) + */ + @Override + public void setRenderGaps(boolean state) { - if (autoCalculateStrucConsensus && strucConsensus == null - && alignment.isNucleotide() && alignment.hasRNAStructure()) - { - // secondary structure has been added - so init the consensus line - initRNAStructure(); - } - - // see note in mantis : issue number 8585 - if (strucConsensus == null || !autoCalculateStrucConsensus) - { - return; - } - if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null) - { - calculator.registerWorker(new StrucConsensusThread(this, ap)); - } - } - - public boolean isCalcInProgress() - { - return calculator.isWorking(); - } - - @Override - public boolean isCalculationInProgress( - AlignmentAnnotation alignmentAnnotation) - { - if (!alignmentAnnotation.autoCalculated) - { - return false; - } - if (calculator.workingInvolvedWith(alignmentAnnotation)) - { - // System.err.println("grey out ("+alignmentAnnotation.label+")"); - return true; - } - return false; + viewStyle.setRenderGaps(state); } + /** + * @return + * @see jalview.api.ViewStyleI#getColourText() + */ @Override - public boolean isClosed() + public boolean getColourText() { - // TODO: check that this isClosed is only true after panel is closed, not - // before it is fully constructed. - return alignment == null; + return viewStyle.getColourText(); } + /** + * @param state + * @see jalview.api.ViewStyleI#setColourText(boolean) + */ @Override - public AlignCalcManagerI getCalcManager() + public void setColourText(boolean state) { - return calculator; + viewStyle.setColourText(state); } /** - * should conservation rows be shown for groups - */ - protected boolean showGroupConservation = false; - - /** - * should consensus rows be shown for groups - */ - protected boolean showGroupConsensus = false; - - /** - * should consensus profile be rendered by default - */ - protected boolean showSequenceLogo = false; - - /** - * should consensus profile be rendered normalised to row height - */ - protected boolean normaliseSequenceLogo = false; - - /** - * should consensus histograms be rendered by default - */ - protected boolean showConsensusHistogram = true; - - /** - * @return the showConsensusProfile + * @return + * @see jalview.api.ViewStyleI#getWrapAlignment() */ @Override - public boolean isShowSequenceLogo() + public boolean getWrapAlignment() { - return showSequenceLogo; + return viewStyle.getWrapAlignment(); } /** - * @param showSequenceLogo - * the new value + * @return + * @see jalview.api.ViewStyleI#getShowText() */ - public void setShowSequenceLogo(boolean showSequenceLogo) + @Override + public boolean getShowText() { - if (showSequenceLogo != this.showSequenceLogo) - { - // TODO: decouple settings setting from calculation when refactoring - // annotation update method from alignframe to viewport - this.showSequenceLogo = showSequenceLogo; - calculator.updateAnnotationFor(ConsensusThread.class); - calculator.updateAnnotationFor(StrucConsensusThread.class); - } - this.showSequenceLogo = showSequenceLogo; + return viewStyle.getShowText(); } /** - * @param showConsensusHistogram - * the showConsensusHistogram to set + * @return + * @see jalview.api.ViewStyleI#getWrappedWidth() */ - public void setShowConsensusHistogram(boolean showConsensusHistogram) + @Override + public int getWrappedWidth() { - this.showConsensusHistogram = showConsensusHistogram; + return viewStyle.getWrappedWidth(); } /** - * @return the showGroupConservation + * @param w + * @see jalview.api.ViewStyleI#setWrappedWidth(int) */ - public boolean isShowGroupConservation() + @Override + public void setWrappedWidth(int w) { - return showGroupConservation; + viewStyle.setWrappedWidth(w); } /** - * @param showGroupConservation - * the showGroupConservation to set + * @return + * @see jalview.api.ViewStyleI#getCharHeight() */ - public void setShowGroupConservation(boolean showGroupConservation) + @Override + public int getCharHeight() { - this.showGroupConservation = showGroupConservation; + return viewStyle.getCharHeight(); } /** - * @return the showGroupConsensus + * @param h + * @see jalview.api.ViewStyleI#setCharHeight(int) */ - public boolean isShowGroupConsensus() + @Override + public void setCharHeight(int h) { - return showGroupConsensus; + viewStyle.setCharHeight(h); } /** - * @param showGroupConsensus - * the showGroupConsensus to set + * @return + * @see jalview.api.ViewStyleI#getCharWidth() */ - public void setShowGroupConsensus(boolean showGroupConsensus) + @Override + public int getCharWidth() { - this.showGroupConsensus = showGroupConsensus; + return viewStyle.getCharWidth(); } /** - * - * @return flag to indicate if the consensus histogram should be rendered by - * default + * @param w + * @see jalview.api.ViewStyleI#setCharWidth(int) */ @Override - public boolean isShowConsensusHistogram() + public void setCharWidth(int w) { - return this.showConsensusHistogram; + viewStyle.setCharWidth(w); } /** - * show non-conserved residues only - */ - protected boolean showUnconserved = false; - - /** - * when set, updateAlignment will always ensure sequences are of equal length - */ - private boolean padGaps = false; - - /** - * when set, alignment should be reordered according to a newly opened tree + * @return + * @see jalview.api.ViewStyleI#getShowBoxes() */ - public boolean sortByTree = false; - - public boolean getShowUnconserved() - { - return showUnconserved; - } - - public void setShowUnconserved(boolean showunconserved) + @Override + public boolean getShowBoxes() { - showUnconserved = showunconserved; + return viewStyle.getShowBoxes(); } /** - * @param showNonconserved - * the showUnconserved to set + * @return + * @see jalview.api.ViewStyleI#getShowUnconserved() */ - public void setShowunconserved(boolean displayNonconserved) + @Override + public boolean getShowUnconserved() { - this.showUnconserved = displayNonconserved; + return viewStyle.getShowUnconserved(); } /** - * - * - * @return null or the currently selected sequence region + * @param showunconserved + * @see jalview.api.ViewStyleI#setShowUnconserved(boolean) */ @Override - public SequenceGroup getSelectionGroup() + public void setShowUnconserved(boolean showunconserved) { - return selectionGroup; + viewStyle.setShowUnconserved(showunconserved); } /** - * Set the selection group for this window. - * - * @param sg - * - group holding references to sequences in this alignment view - * + * @param default1 + * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean) */ @Override - public void setSelectionGroup(SequenceGroup sg) + public void setSeqNameItalics(boolean default1) { - selectionGroup = sg; + viewStyle.setSeqNameItalics(default1); } - public void setHiddenColumns(ColumnSelection colsel) + @Override + public AlignmentI getAlignment() { - this.colSel = colsel; - if (colSel.getHiddenColumns() != null) - { - hasHiddenColumns = true; - } + return alignment; } @Override - public ColumnSelection getColumnSelection() + public char getGapCharacter() { - return colSel; + return alignment.getGapCharacter(); } - public void setColumnSelection(ColumnSelection colSel) - { - this.colSel = colSel; - } + protected String sequenceSetID; /** - * - * @return + * probably unused indicator that view is of a dataset rather than an + * alignment */ - @Override - public Map getHiddenRepSequences() + protected boolean isDataset = false; + + public void setDataset(boolean b) { - return hiddenRepSequences; + isDataset = b; } - @Override - public void setHiddenRepSequences( - Map hiddenRepSequences) + public boolean isDataset() { - this.hiddenRepSequences = hiddenRepSequences; + return isDataset; } - protected boolean hasHiddenColumns = false; + private Map hiddenRepSequences; - public void updateHiddenColumns() - { - hasHiddenColumns = colSel.getHiddenColumns() != null; - } + protected ColumnSelection colSel = new ColumnSelection(); - protected boolean hasHiddenRows = false; + public boolean autoCalculateConsensus = true; - public boolean hasHiddenRows() - { - return hasHiddenRows; - } + protected boolean autoCalculateStrucConsensus = true; - protected SequenceGroup selectionGroup; + protected boolean ignoreGapsInConsensusCalculation = false; - public void setSequenceSetId(String newid) - { - if (sequenceSetID != null) - { - System.err - .println("Warning - overwriting a sequenceSetId for a viewport!"); - } - sequenceSetID = new String(newid); - } + protected ResidueShaderI residueShading = new ResidueShader(); @Override - public String getSequenceSetId() + public void setGlobalColourScheme(ColourSchemeI cs) { - if (sequenceSetID == null) + // TODO: logic refactored from AlignFrame changeColour - + // TODO: autorecalc stuff should be changed to rely on the worker system + // check to see if we should implement a changeColour(cs) method rather than + // put the logic in here + // - means that caller decides if they want to just modify state and defer + // calculation till later or to do all calculations in thread. + // via changecolour + + /* + * only instantiate alignment colouring once, thereafter update it; + * this means that any conservation or PID threshold settings + * persist when the alignment colour scheme is changed + */ + if (residueShading == null) { - sequenceSetID = alignment.hashCode() + ""; + residueShading = new ResidueShader(viewStyle); } + residueShading.setColourScheme(cs); - return sequenceSetID; - } - - /** - * unique viewId for synchronizing state (e.g. with stored Jalview Project) - * - */ - protected String viewId = null; + // TODO: do threshold and increment belong in ViewStyle or ResidueShader? + // ...problem: groups need these, but do not currently have a ViewStyle - public String getViewId() - { - if (viewId == null) + if (cs != null) { - viewId = this.getSequenceSetId() + "." + this.hashCode() + ""; + if (getConservationSelected()) + { + residueShading.setConservation(hconservation); + } + /* + * reset conservation flag in case just set to false if + * Conservation was null (calculation still in progress) + */ + residueShading.setConservationApplied(getConservationSelected()); + residueShading.alignmentChanged(alignment, hiddenRepSequences); } - return viewId; - } - public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap) - { - ignoreGapsInConsensusCalculation = b; - if (ap != null) + /* + * if 'apply colour to all groups' is selected... do so + * (but don't transfer any colour threshold settings to groups) + */ + if (getColourAppliesToAllGroups()) { - updateConsensus(ap); - if (globalColourScheme != null) + for (SequenceGroup sg : getAlignment().getGroups()) { - globalColourScheme.setThreshold(globalColourScheme.getThreshold(), - ignoreGapsInConsensusCalculation); + /* + * retain any colour thresholds per group while + * changing choice of colour scheme (JAL-2386) + */ + sg.setColourScheme(cs); + if (cs != null) + { + sg.getGroupColourScheme().alignmentChanged(sg, + hiddenRepSequences); + } } } + } + @Override + public ColourSchemeI getGlobalColourScheme() + { + return residueShading == null ? null : residueShading.getColourScheme(); } - private long sgrouphash = -1, colselhash = -1; + @Override + public ResidueShaderI getResidueShading() + { + return residueShading; + } + + protected AlignmentAnnotation consensus; + + protected AlignmentAnnotation complementConsensus; + + protected AlignmentAnnotation gapcounts; + + protected AlignmentAnnotation strucConsensus; + + protected AlignmentAnnotation conservation; + + protected AlignmentAnnotation quality; + + protected AlignmentAnnotation[] groupConsensus; + + protected AlignmentAnnotation[] groupConservation; /** - * checks current SelectionGroup against record of last hash value, and + * results of alignment consensus analysis for visible portion of view + */ + protected ProfilesI hconsensus = null; + + /** + * results of cDNA complement consensus visible portion of view + */ + protected Hashtable[] hcomplementConsensus = null; + + /** + * results of secondary structure base pair consensus for visible portion of + * view + */ + protected Hashtable[] hStrucConsensus = null; + + protected Conservation hconservation = null; + + @Override + public void setConservation(Conservation cons) + { + hconservation = cons; + } + + /** + * percentage gaps allowed in a column before all amino acid properties should + * be considered unconserved + */ + int ConsPercGaps = 25; // JBPNote : This should be a scalable property! + + @Override + public int getConsPercGaps() + { + return ConsPercGaps; + } + + @Override + public void setSequenceConsensusHash(ProfilesI hconsensus) + { + this.hconsensus = hconsensus; + } + + @Override + public void setComplementConsensusHash(Hashtable[] hconsensus) + { + this.hcomplementConsensus = hconsensus; + } + + @Override + public ProfilesI getSequenceConsensusHash() + { + return hconsensus; + } + + @Override + public Hashtable[] getComplementConsensusHash() + { + return hcomplementConsensus; + } + + @Override + public Hashtable[] getRnaStructureConsensusHash() + { + return hStrucConsensus; + } + + @Override + public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus) + { + this.hStrucConsensus = hStrucConsensus; + + } + + @Override + public AlignmentAnnotation getAlignmentQualityAnnot() + { + return quality; + } + + @Override + public AlignmentAnnotation getAlignmentConservationAnnotation() + { + return conservation; + } + + @Override + public AlignmentAnnotation getAlignmentConsensusAnnotation() + { + return consensus; + } + + @Override + public AlignmentAnnotation getAlignmentGapAnnotation() + { + return gapcounts; + } + + @Override + public AlignmentAnnotation getComplementConsensusAnnotation() + { + return complementConsensus; + } + + @Override + public AlignmentAnnotation getAlignmentStrucConsensusAnnotation() + { + return strucConsensus; + } + + protected AlignCalcManagerI calculator = new AlignCalcManager(); + + /** + * trigger update of conservation annotation + */ + public void updateConservation(final AlignmentViewPanel ap) + { + // see note in mantis : issue number 8585 + if (alignment.isNucleotide() + || (conservation == null && quality == null) + || !autoCalculateConsensus) + { + return; + } + if (calculator.getRegisteredWorkersOfClass( + jalview.workers.ConservationThread.class) == null) + { + calculator.registerWorker( + new jalview.workers.ConservationThread(this, ap)); + } + } + + /** + * trigger update of consensus annotation + */ + public void updateConsensus(final AlignmentViewPanel ap) + { + // see note in mantis : issue number 8585 + if (consensus == null || !autoCalculateConsensus) + { + return; + } + if (calculator + .getRegisteredWorkersOfClass(ConsensusThread.class) == null) + { + calculator.registerWorker(new ConsensusThread(this, ap)); + } + + /* + * A separate thread to compute cDNA consensus for a protein alignment + * which has mapping to cDNA + */ + final AlignmentI al = this.getAlignment(); + if (!al.isNucleotide() && al.getCodonFrames() != null + && !al.getCodonFrames().isEmpty()) + { + /* + * fudge - check first for protein-to-nucleotide mappings + * (we don't want to do this for protein-to-protein) + */ + boolean doConsensus = false; + for (AlignedCodonFrame mapping : al.getCodonFrames()) + { + // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame? + MapList[] mapLists = mapping.getdnaToProt(); + // mapLists can be empty if project load has not finished resolving seqs + if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3) + { + doConsensus = true; + break; + } + } + if (doConsensus) + { + if (calculator.getRegisteredWorkersOfClass( + ComplementConsensusThread.class) == null) + { + calculator + .registerWorker(new ComplementConsensusThread(this, ap)); + } + } + } + } + + // --------START Structure Conservation + public void updateStrucConsensus(final AlignmentViewPanel ap) + { + if (autoCalculateStrucConsensus && strucConsensus == null + && alignment.isNucleotide() && alignment.hasRNAStructure()) + { + // secondary structure has been added - so init the consensus line + initRNAStructure(); + } + + // see note in mantis : issue number 8585 + if (strucConsensus == null || !autoCalculateStrucConsensus) + { + return; + } + if (calculator.getRegisteredWorkersOfClass( + StrucConsensusThread.class) == null) + { + calculator.registerWorker(new StrucConsensusThread(this, ap)); + } + } + + public boolean isCalcInProgress() + { + return calculator.isWorking(); + } + + @Override + public boolean isCalculationInProgress( + AlignmentAnnotation alignmentAnnotation) + { + if (!alignmentAnnotation.autoCalculated) + { + return false; + } + if (calculator.workingInvolvedWith(alignmentAnnotation)) + { + // System.err.println("grey out ("+alignmentAnnotation.label+")"); + return true; + } + return false; + } + + public void setAlignment(AlignmentI align) + { + this.alignment = align; + } + + /** + * Clean up references when this viewport is closed + */ + @Override + public void dispose() + { + /* + * defensively null out references to large objects in case + * this object is not garbage collected (as if!) + */ + consensus = null; + complementConsensus = null; + strucConsensus = null; + conservation = null; + quality = null; + groupConsensus = null; + groupConservation = null; + hconsensus = null; + hconservation = null; + hcomplementConsensus = null; + gapcounts = null; + calculator = null; + residueShading = null; // may hold a reference to Consensus + changeSupport = null; + ranges = null; + currentTree = null; + selectionGroup = null; + setAlignment(null); + } + + @Override + public boolean isClosed() + { + // TODO: check that this isClosed is only true after panel is closed, not + // before it is fully constructed. + return alignment == null; + } + + @Override + public AlignCalcManagerI getCalcManager() + { + return calculator; + } + + /** + * should conservation rows be shown for groups + */ + protected boolean showGroupConservation = false; + + /** + * should consensus rows be shown for groups + */ + protected boolean showGroupConsensus = false; + + /** + * should consensus profile be rendered by default + */ + protected boolean showSequenceLogo = false; + + /** + * should consensus profile be rendered normalised to row height + */ + protected boolean normaliseSequenceLogo = false; + + /** + * should consensus histograms be rendered by default + */ + protected boolean showConsensusHistogram = true; + + /** + * @return the showConsensusProfile + */ + @Override + public boolean isShowSequenceLogo() + { + return showSequenceLogo; + } + + /** + * @param showSequenceLogo + * the new value + */ + public void setShowSequenceLogo(boolean showSequenceLogo) + { + if (showSequenceLogo != this.showSequenceLogo) + { + // TODO: decouple settings setting from calculation when refactoring + // annotation update method from alignframe to viewport + this.showSequenceLogo = showSequenceLogo; + calculator.updateAnnotationFor(ConsensusThread.class); + calculator.updateAnnotationFor(ComplementConsensusThread.class); + calculator.updateAnnotationFor(StrucConsensusThread.class); + } + this.showSequenceLogo = showSequenceLogo; + } + + /** + * @param showConsensusHistogram + * the showConsensusHistogram to set + */ + public void setShowConsensusHistogram(boolean showConsensusHistogram) + { + this.showConsensusHistogram = showConsensusHistogram; + } + + /** + * @return the showGroupConservation + */ + public boolean isShowGroupConservation() + { + return showGroupConservation; + } + + /** + * @param showGroupConservation + * the showGroupConservation to set + */ + public void setShowGroupConservation(boolean showGroupConservation) + { + this.showGroupConservation = showGroupConservation; + } + + /** + * @return the showGroupConsensus + */ + public boolean isShowGroupConsensus() + { + return showGroupConsensus; + } + + /** + * @param showGroupConsensus + * the showGroupConsensus to set + */ + public void setShowGroupConsensus(boolean showGroupConsensus) + { + this.showGroupConsensus = showGroupConsensus; + } + + /** + * + * @return flag to indicate if the consensus histogram should be rendered by + * default + */ + @Override + public boolean isShowConsensusHistogram() + { + return this.showConsensusHistogram; + } + + /** + * when set, updateAlignment will always ensure sequences are of equal length + */ + private boolean padGaps = false; + + /** + * when set, alignment should be reordered according to a newly opened tree + */ + public boolean sortByTree = false; + + /** + * + * + * @return null or the currently selected sequence region + */ + @Override + public SequenceGroup getSelectionGroup() + { + return selectionGroup; + } + + /** + * Set the selection group for this window. Also sets the current alignment as + * the context for the group, if it does not already have one. + * + * @param sg + * - group holding references to sequences in this alignment view + * + */ + @Override + public void setSelectionGroup(SequenceGroup sg) + { + selectionGroup = sg; + if (sg != null && sg.getContext() == null) + { + sg.setContext(alignment); + } + } + + public void setHiddenColumns(HiddenColumns hidden) + { + this.alignment.setHiddenColumns(hidden); + } + + @Override + public ColumnSelection getColumnSelection() + { + return colSel; + } + + @Override + public void setColumnSelection(ColumnSelection colSel) + { + this.colSel = colSel; + if (colSel != null) + { + updateHiddenColumns(); + } + isColSelChanged(true); + } + + /** + * + * @return + */ + @Override + public Map getHiddenRepSequences() + { + return hiddenRepSequences; + } + + @Override + public void setHiddenRepSequences( + Map hiddenRepSequences) + { + this.hiddenRepSequences = hiddenRepSequences; + } + + @Override + public boolean hasSelectedColumns() + { + ColumnSelection columnSelection = getColumnSelection(); + return columnSelection != null && columnSelection.hasSelectedColumns(); + } + + @Override + public boolean hasHiddenColumns() + { + return alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(); + } + + public void updateHiddenColumns() + { + // this method doesn't really do anything now. But - it could, since a + // column Selection could be in the process of modification + // hasHiddenColumns = colSel.hasHiddenColumns(); + } + + @Override + public boolean hasHiddenRows() + { + return alignment.getHiddenSequences().getSize() > 0; + } + + protected SequenceGroup selectionGroup; + + public void setSequenceSetId(String newid) + { + if (sequenceSetID != null) + { + System.err.println( + "Warning - overwriting a sequenceSetId for a viewport!"); + } + sequenceSetID = new String(newid); + } + + @Override + public String getSequenceSetId() + { + if (sequenceSetID == null) + { + sequenceSetID = alignment.hashCode() + ""; + } + + return sequenceSetID; + } + + /** + * unique viewId for synchronizing state (e.g. with stored Jalview Project) + * + */ + protected String viewId = null; + + @Override + public String getViewId() + { + if (viewId == null) + { + viewId = this.getSequenceSetId() + "." + this.hashCode() + ""; + } + return viewId; + } + + public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap) + { + ignoreGapsInConsensusCalculation = b; + if (ap != null) + { + updateConsensus(ap); + if (residueShading != null) + { + residueShading.setThreshold(residueShading.getThreshold(), + ignoreGapsInConsensusCalculation); + } + } + + } + + private long sgrouphash = -1, colselhash = -1; + + /** + * checks current SelectionGroup against record of last hash value, and * updates record. * * @param b @@ -774,8 +1276,7 @@ public abstract class AlignmentViewport implements AlignViewportI */ public boolean isColSelChanged(boolean b) { - int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel - .hashCode(); + int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { if (b) @@ -788,15 +1289,14 @@ public abstract class AlignmentViewport implements AlignViewportI } @Override - public boolean getIgnoreGapsConsensus() + public boolean isIgnoreGapsConsensus() { return ignoreGapsInConsensusCalculation; } - // / property change stuff - + // property change stuff // JBPNote Prolly only need this in the applet version. - private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport( + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); protected boolean showConservation = true; @@ -805,7 +1305,18 @@ public abstract class AlignmentViewport implements AlignViewportI protected boolean showConsensus = true; - Hashtable sequenceColours; + protected boolean showOccupancy = true; + + private Map sequenceColours = new HashMap<>(); + + protected SequenceAnnotationOrder sortAnnotationsBy = null; + + protected boolean showAutocalculatedAbove; + + /** + * when set, view will scroll to show the highlighted position + */ + private boolean followHighlight = true; /** * Property change listener for changes in alignment @@ -828,7 +1339,10 @@ public abstract class AlignmentViewport implements AlignViewportI public void removePropertyChangeListener( java.beans.PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); + if (changeSupport != null) + { + changeSupport.removePropertyChangeListener(listener); + } } /** @@ -851,49 +1365,47 @@ public abstract class AlignmentViewport implements AlignViewportI public void hideSelectedColumns() { - if (colSel.size() < 1) + if (colSel.isEmpty()) { return; } - colSel.hideSelectedColumns(); + colSel.hideSelectedColumns(alignment); setSelectionGroup(null); - - hasHiddenColumns = true; + isColSelChanged(true); } public void hideColumns(int start, int end) { if (start == end) { - colSel.hideColumns(start); + colSel.hideSelectedColumns(start, alignment.getHiddenColumns()); } else { - colSel.hideColumns(start, end); + alignment.getHiddenColumns().hideColumns(start, end); } - - hasHiddenColumns = true; + isColSelChanged(true); } public void showColumn(int col) { - colSel.revealHiddenColumns(col); - if (colSel.getHiddenColumns() == null) - { - hasHiddenColumns = false; - } + alignment.getHiddenColumns().revealHiddenColumns(col, colSel); + isColSelChanged(true); } public void showAllHiddenColumns() { - colSel.revealAllHiddenColumns(); - hasHiddenColumns = false; + alignment.getHiddenColumns().revealAllHiddenColumns(colSel); + isColSelChanged(true); } // common hide/show seq stuff public void showAllHiddenSeqs() { + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + if (alignment.getHiddenSequences().getSize() > 0) { if (selectionGroup == null) @@ -901,17 +1413,18 @@ public abstract class AlignmentViewport implements AlignViewportI selectionGroup = new SequenceGroup(); selectionGroup.setEndRes(alignment.getWidth() - 1); } - List tmp = alignment.getHiddenSequences().showAll( - hiddenRepSequences); + List tmp = alignment.getHiddenSequences() + .showAll(hiddenRepSequences); for (SequenceI seq : tmp) { selectionGroup.addSequence(seq, false); setSequenceAnnotationsVisible(seq, true); } - hasHiddenRows = false; hiddenRepSequences = null; + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event @@ -921,8 +1434,10 @@ public abstract class AlignmentViewport implements AlignViewportI public void showSequence(int index) { - List tmp = alignment.getHiddenSequences().showSequence( - index, + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + + List tmp = alignment.getHiddenSequences().showSequence(index, hiddenRepSequences); if (tmp.size() > 0) { @@ -937,12 +1452,9 @@ public abstract class AlignmentViewport implements AlignViewportI selectionGroup.addSequence(seq, false); setSequenceAnnotationsVisible(seq, true); } - // JBPNote: refactor: only update flag if we modified visiblity (used to - // do this regardless) - if (alignment.getHiddenSequences().getSize() < 1) - { - hasHiddenRows = false; - } + + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); sendSelection(); } @@ -964,6 +1476,11 @@ public abstract class AlignmentViewport implements AlignViewportI public void hideSequence(SequenceI[] seq) { + /* + * cache offset to first visible sequence + */ + int startSeq = ranges.getStartSeq(); + if (seq != null) { for (int i = 0; i < seq.length; i++) @@ -971,12 +1488,45 @@ public abstract class AlignmentViewport implements AlignViewportI alignment.getHiddenSequences().hideSequence(seq[i]); setSequenceAnnotationsVisible(seq[i], false); } - hasHiddenRows = true; + ranges.setStartSeq(startSeq); firePropertyChange("alignment", null, alignment.getSequences()); } } /** + * Hides the specified sequence, or the sequences it represents + * + * @param sequence + * the sequence to hide, or keep as representative + * @param representGroup + * if true, hide the current selection group except for the + * representative sequence + */ + public void hideSequences(SequenceI sequence, boolean representGroup) + { + if (selectionGroup == null || selectionGroup.getSize() < 1) + { + hideSequence(new SequenceI[] { sequence }); + return; + } + + if (representGroup) + { + hideRepSequences(sequence, selectionGroup); + setSelectionGroup(null); + return; + } + + int gsize = selectionGroup.getSize(); + SequenceI[] hseqs = selectionGroup.getSequences() + .toArray(new SequenceI[gsize]); + + hideSequence(hseqs); + setSelectionGroup(null); + sendSelection(); + } + + /** * Set visibility for any annotations for the given sequence. * * @param sequenceI @@ -984,11 +1534,15 @@ public abstract class AlignmentViewport implements AlignViewportI protected void setSequenceAnnotationsVisible(SequenceI sequenceI, boolean visible) { - for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation()) + AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation(); + if (anns != null) { - if (ann.sequenceRef == sequenceI) + for (AlignmentAnnotation ann : anns) { - ann.visible = visible; + if (ann.sequenceRef == sequenceI) + { + ann.visible = visible; + } } } } @@ -1003,7 +1557,7 @@ public abstract class AlignmentViewport implements AlignViewportI if (hiddenRepSequences == null) { - hiddenRepSequences = new Hashtable(); + hiddenRepSequences = new Hashtable<>(); } hiddenRepSequences.put(repSequence, sg); @@ -1029,44 +1583,62 @@ public abstract class AlignmentViewport implements AlignViewportI } + /** + * + * @return null or the current reference sequence + */ + public SequenceI getReferenceSeq() + { + return alignment.getSeqrep(); + } + + /** + * @param seq + * @return true iff seq is the reference for the alignment + */ + public boolean isReferenceSeq(SequenceI seq) + { + return alignment.getSeqrep() == seq; + } + + /** + * + * @param seq + * @return true if there are sequences represented by this sequence that are + * currently hidden + */ public boolean isHiddenRepSequence(SequenceI seq) { - return alignment.getSeqrep()==seq || (hiddenRepSequences != null + return (hiddenRepSequences != null && hiddenRepSequences.containsKey(seq)); } + /** + * + * @param seq + * @return null or a sequence group containing the sequences that seq + * represents + */ public SequenceGroup getRepresentedSequences(SequenceI seq) { return (SequenceGroup) (hiddenRepSequences == null ? null : hiddenRepSequences.get(seq)); } + @Override public int adjustForHiddenSeqs(int alignmentIndex) { - return alignment.getHiddenSequences().adjustForHiddenSeqs( - alignmentIndex); + return alignment.getHiddenSequences() + .adjustForHiddenSeqs(alignmentIndex); } - // Selection manipulation - /** - * broadcast selection to any interested parties - */ - public abstract void sendSelection(); - + @Override public void invertColumnSelection() { - colSel.invertColumnSelection(0, alignment.getWidth()); + colSel.invertColumnSelection(0, alignment.getWidth(), alignment); } - /** - * This method returns an array of new SequenceI objects derived from the - * whole alignment or just the current selection with start and end points - * adjusted - * - * @note if you need references to the actual SequenceI objects in the - * alignment or currently selected then use getSequenceSelection() - * @return selection as new sequenceI objects - */ + @Override public SequenceI[] getSelectionAsNewSequence() { SequenceI[] sequences; @@ -1081,10 +1653,8 @@ public abstract class AlignmentViewport implements AlignViewportI AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation(); for (int i = 0; i < sequences.length; i++) { - sequences[i] = new Sequence(sequences[i], annots); // construct new - // sequence with - // subset of visible - // annotation + // construct new sequence with subset of visible annotation + sequences[i] = new Sequence(sequences[i], annots); } } else @@ -1095,12 +1665,6 @@ public abstract class AlignmentViewport implements AlignViewportI return sequences; } - /** - * get the currently selected sequence objects or all the sequences in the - * alignment. - * - * @return array of references to sequence objects - */ @Override public SequenceI[] getSequenceSelection() { @@ -1116,31 +1680,6 @@ public abstract class AlignmentViewport implements AlignViewportI return sequences; } - /** - * This method returns the visible alignment as text, as seen on the GUI, ie - * if columns are hidden they will not be returned in the result. Use this for - * calculating trees, PCA, redundancy etc on views which contain hidden - * columns. - * - * @return String[] - */ - @Override - public jalview.datamodel.CigarArray getViewAsCigars( - boolean selectedRegionOnly) - { - return new jalview.datamodel.CigarArray(alignment, - (hasHiddenColumns ? colSel : null), - (selectedRegionOnly ? selectionGroup : null)); - } - - /** - * return a compact representation of the current alignment selection to pass - * to an analysis function - * - * @param selectedOnly - * boolean true to just return the selected view - * @return AlignmentView - */ @Override public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly) @@ -1148,37 +1687,27 @@ public abstract class AlignmentViewport implements AlignViewportI return getAlignmentView(selectedOnly, false); } - /** - * return a compact representation of the current alignment selection to pass - * to an analysis function - * - * @param selectedOnly - * boolean true to just return the selected view - * @param markGroups - * boolean true to annotate the alignment view with groups on the - * alignment (and intersecting with selected region if selectedOnly - * is true) - * @return AlignmentView - */ @Override public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly, boolean markGroups) { - return new AlignmentView(alignment, colSel, selectionGroup, - hasHiddenColumns, selectedOnly, markGroups); + return new AlignmentView(alignment, alignment.getHiddenColumns(), + selectionGroup, + alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(), + selectedOnly, markGroups); } - /** - * This method returns the visible alignment as text, as seen on the GUI, ie - * if columns are hidden they will not be returned in the result. Use this for - * calculating trees, PCA, redundancy etc on views which contain hidden - * columns. - * - * @return String[] - */ @Override public String[] getViewAsString(boolean selectedRegionOnly) { + return getViewAsString(selectedRegionOnly, true); + } + + @Override + public String[] getViewAsString(boolean selectedRegionOnly, + boolean exportHiddenSeqs) + { String[] selection = null; SequenceI[] seqs = null; int i, iSize; @@ -1192,15 +1721,32 @@ public abstract class AlignmentViewport implements AlignViewportI } else { - iSize = alignment.getHeight(); - seqs = alignment.getSequencesArray(); - end = alignment.getWidth(); + if (hasHiddenRows() && exportHiddenSeqs) + { + AlignmentI fullAlignment = alignment.getHiddenSequences() + .getFullAlignment(); + iSize = fullAlignment.getHeight(); + seqs = fullAlignment.getSequencesArray(); + end = fullAlignment.getWidth(); + } + else + { + iSize = alignment.getHeight(); + seqs = alignment.getSequencesArray(); + end = alignment.getWidth(); + } } selection = new String[iSize]; - if (hasHiddenColumns) + if (alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = colSel.getVisibleSequenceStrings(start, end, seqs); + for (i = 0; i < iSize; i++) + { + Iterator blocks = alignment.getHiddenColumns() + .getVisContigsIterator(start, end + 1, false); + selection[i] = seqs[i].getSequenceStringFromIterator(blocks); + } } else { @@ -1213,31 +1759,24 @@ public abstract class AlignmentViewport implements AlignViewportI return selection; } - /** - * return visible region boundaries within given column range - * - * @param min - * first column (inclusive, from 0) - * @param max - * last column (exclusive) - * @return int[][] range of {start,end} visible positions - */ - public int[][] getVisibleRegionBoundaries(int min, int max) + @Override + public List getVisibleRegionBoundaries(int min, int max) { - Vector regions = new Vector(); + ArrayList regions = new ArrayList<>(); int start = min; int end = max; do { - if (hasHiddenColumns) + HiddenColumns hidden = alignment.getHiddenColumns(); + if (hidden != null && hidden.hasHiddenColumns()) { if (start == 0) { - start = colSel.adjustForHiddenColumns(start); + start = hidden.visibleToAbsoluteColumn(start); } - end = colSel.getHiddenBoundaryRight(start); + end = hidden.getNextHiddenBoundary(false, start); if (start == end) { end = max; @@ -1248,39 +1787,40 @@ public abstract class AlignmentViewport implements AlignViewportI } } - regions.addElement(new int[] - { start, end }); + regions.add(new int[] { start, end }); - if (hasHiddenColumns) + if (hidden != null && hidden.hasHiddenColumns()) { - start = colSel.adjustForHiddenColumns(end); - start = colSel.getHiddenBoundaryLeft(start) + 1; + start = hidden.visibleToAbsoluteColumn(end); + start = hidden.getNextHiddenBoundary(true, start) + 1; } } while (end < max); int[][] startEnd = new int[regions.size()][2]; - regions.copyInto(startEnd); - - return startEnd; - + return regions; } @Override - public List getVisibleAlignmentAnnotation(boolean selectedOnly) + public List getVisibleAlignmentAnnotation( + boolean selectedOnly) { - ArrayList ala = new ArrayList(); + ArrayList ala = new ArrayList<>(); AlignmentAnnotation[] aa; - if ((aa=alignment.getAlignmentAnnotation())!=null) + if ((aa = alignment.getAlignmentAnnotation()) != null) { - for (AlignmentAnnotation annot:aa) + for (AlignmentAnnotation annot : aa) { AlignmentAnnotation clone = new AlignmentAnnotation(annot); - if (selectedOnly && selectionGroup!=null) + if (selectedOnly && selectionGroup != null) + { + clone.makeVisibleAnnotation( + selectionGroup.getStartRes(), selectionGroup.getEndRes(), + alignment.getHiddenColumns()); + } + else { - colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone); - } else { - colSel.makeVisibleAnnotation(clone); + clone.makeVisibleAnnotation(alignment.getHiddenColumns()); } ala.add(clone); } @@ -1288,18 +1828,13 @@ public abstract class AlignmentViewport implements AlignViewportI return ala; } - /** - * @return the padGaps - */ + @Override public boolean isPadGaps() { return padGaps; } - /** - * @param padGaps - * the padGaps to set - */ + @Override public void setPadGaps(boolean padGaps) { this.padGaps = padGaps; @@ -1311,6 +1846,7 @@ public abstract class AlignmentViewport implements AlignViewportI * * @param ap */ + @Override public void alignmentChanged(AlignmentViewPanel ap) { if (isPadGaps()) @@ -1349,7 +1885,7 @@ public abstract class AlignmentViewport implements AlignViewportI selectionGroup.setEndRes(alWidth - 1); } - resetAllColourSchemes(); + updateAllColourSchemes(); calculator.restartWorkers(); // alignment.adjustSequenceAnnotations(); } @@ -1357,19 +1893,19 @@ public abstract class AlignmentViewport implements AlignViewportI /** * reset scope and do calculations for all applied colourschemes on alignment */ - void resetAllColourSchemes() + void updateAllColourSchemes() { - ColourSchemeI cs = globalColourScheme; - if (cs != null) + ResidueShaderI rs = residueShading; + if (rs != null) { - cs.alignmentChanged(alignment, hiddenRepSequences); + rs.alignmentChanged(alignment, hiddenRepSequences); - cs.setConsensus(hconsensus); - if (cs.conservationApplied()) + rs.setConsensus(hconsensus); + if (rs.conservationApplied()) { - cs.setConservation(Conservation.calculateConservation("All", - ResidueProperties.propHash, 3, alignment.getSequences(), 0, - alignment.getWidth(), false, getConsPercGaps(), false)); + rs.setConservation(Conservation.calculateConservation("All", + alignment.getSequences(), 0, alignment.getWidth(), false, + getConsPercGaps(), false)); } } @@ -1400,21 +1936,83 @@ public abstract class AlignmentViewport implements AlignViewportI { initRNAStructure(); } - initConsensus(); + consensus = new AlignmentAnnotation("Consensus", + MessageManager.getString("label.consensus_descr"), + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + initConsensus(consensus); + initGapCounts(); + + initComplementConsensus(); } } - private void initConsensus() + /** + * If this is a protein alignment and there are mappings to cDNA, adds the + * cDNA consensus annotation and returns true, else returns false. + */ + public boolean initComplementConsensus() { + if (!alignment.isNucleotide()) + { + final List codonMappings = alignment + .getCodonFrames(); + if (codonMappings != null && !codonMappings.isEmpty()) + { + boolean doConsensus = false; + for (AlignedCodonFrame mapping : codonMappings) + { + // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame? + MapList[] mapLists = mapping.getdnaToProt(); + // mapLists can be empty if project load has not finished resolving + // seqs + if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3) + { + doConsensus = true; + break; + } + } + if (doConsensus) + { + complementConsensus = new AlignmentAnnotation("cDNA Consensus", + MessageManager + .getString("label.complement_consensus_descr"), + new Annotation[1], 0f, 100f, + AlignmentAnnotation.BAR_GRAPH); + initConsensus(complementConsensus); + return true; + } + } + } + return false; + } - consensus = new AlignmentAnnotation("Consensus", "PID", - new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); - consensus.hasText = true; - consensus.autoCalculated = true; + private void initConsensus(AlignmentAnnotation aa) + { + aa.hasText = true; + aa.autoCalculated = true; if (showConsensus) { - alignment.addAnnotation(consensus); + alignment.addAnnotation(aa); + } + } + + // these should be extracted from the view model - style and settings for + // derived annotation + private void initGapCounts() + { + if (showOccupancy) + { + gapcounts = new AlignmentAnnotation("Occupancy", + MessageManager.getString("label.occupancy_descr"), + new Annotation[1], 0f, alignment.getHeight(), + AlignmentAnnotation.BAR_GRAPH); + gapcounts.hasText = true; + gapcounts.autoCalculated = true; + gapcounts.scaleColLabel = true; + gapcounts.graph = AlignmentAnnotation.BAR_GRAPH; + + alignment.addAnnotation(gapcounts); } } @@ -1425,9 +2023,9 @@ public abstract class AlignmentViewport implements AlignViewportI if (conservation == null) { conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " - + getConsPercGaps() + "% gaps", new Annotation[1], - 0f, 11f, AlignmentAnnotation.BAR_GRAPH); + MessageManager.formatMessage("label.conservation_descr", + getConsPercGaps()), + new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); conservation.hasText = true; conservation.autoCalculated = true; alignment.addAnnotation(conservation); @@ -1442,7 +2040,7 @@ public abstract class AlignmentViewport implements AlignViewportI if (quality == null) { quality = new AlignmentAnnotation("Quality", - "Alignment Quality based on Blosum62 scores", + MessageManager.getString("label.quality_descr"), new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); quality.hasText = true; quality.autoCalculated = true; @@ -1455,7 +2053,8 @@ public abstract class AlignmentViewport implements AlignViewportI { if (alignment.hasRNAStructure() && strucConsensus == null) { - strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID", + strucConsensus = new AlignmentAnnotation("StrucConsensus", + MessageManager.getString("label.strucconsensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); strucConsensus.hasText = true; strucConsensus.autoCalculated = true; @@ -1472,60 +2071,61 @@ public abstract class AlignmentViewport implements AlignViewportI * * @see jalview.api.AlignViewportI#calcPanelHeight() */ + @Override public int calcPanelHeight() { // setHeight of panels - AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation(); + AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation(); int height = 0; int charHeight = getCharHeight(); - if (aa != null) + if (anns != null) { BitSet graphgrp = new BitSet(); - for (int i = 0; i < aa.length; i++) + for (AlignmentAnnotation aa : anns) { - if (aa[i] == null) + if (aa == null) { System.err.println("Null annotation row: ignoring."); continue; } - if (!aa[i].visible) + if (!aa.visible) { continue; } - if (aa[i].graphGroup > -1) + if (aa.graphGroup > -1) { - if (graphgrp.get(aa[i].graphGroup)) + if (graphgrp.get(aa.graphGroup)) { continue; } else { - graphgrp.set(aa[i].graphGroup); + graphgrp.set(aa.graphGroup); } } - aa[i].height = 0; + aa.height = 0; - if (aa[i].hasText) + if (aa.hasText) { - aa[i].height += charHeight; + aa.height += charHeight; } - if (aa[i].hasIcons) + if (aa.hasIcons) { - aa[i].height += 16; + aa.height += 16; } - if (aa[i].graph > 0) + if (aa.graph > 0) { - aa[i].height += aa[i].graphHeight; + aa.height += aa.graphHeight; } - if (aa[i].height == 0) + if (aa.height == 0) { - aa[i].height = 20; + aa.height = 20; } - height += aa[i].height; + height += aa.height; } } if (height == 0) @@ -1559,7 +2159,7 @@ public abstract class AlignmentViewport implements AlignViewportI // intersect alignment annotation with alignment groups AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation(); - List oldrfs = new ArrayList(); + List oldrfs = new ArrayList<>(); if (aan != null) { for (int an = 0; an < aan.length; an++) @@ -1603,183 +2203,755 @@ public abstract class AlignmentViewport implements AlignViewportI } oldrfs.clear(); } + + @Override + public boolean isDisplayReferenceSeq() + { + return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq(); + } + + @Override + public void setDisplayReferenceSeq(boolean displayReferenceSeq) + { + viewStyle.setDisplayReferenceSeq(displayReferenceSeq); + } + + @Override + public boolean isColourByReferenceSeq() + { + return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq(); + } + + @Override + public Color getSequenceColour(SequenceI seq) + { + Color sqc = sequenceColours.get(seq); + return (sqc == null ? Color.white : sqc); + } + + @Override + public void setSequenceColour(SequenceI seq, Color col) + { + if (col == null) + { + sequenceColours.remove(seq); + } + else + { + sequenceColours.put(seq, col); + } + } + + @Override + public void updateSequenceIdColours() + { + for (SequenceGroup sg : alignment.getGroups()) + { + if (sg.idColour != null) + { + for (SequenceI s : sg.getSequences(getHiddenRepSequences())) + { + sequenceColours.put(s, sg.idColour); + } + } + } + } + + @Override + public void clearSequenceColours() + { + sequenceColours.clear(); + }; + + @Override + public AlignViewportI getCodingComplement() + { + return this.codingComplement; + } + + /** + * Set this as the (cDna/protein) complement of the given viewport. Also + * ensures the reverse relationship is set on the given viewport. + */ + @Override + public void setCodingComplement(AlignViewportI av) + { + if (this == av) + { + System.err.println("Ignoring recursive setCodingComplement request"); + } + else + { + this.codingComplement = av; + // avoid infinite recursion! + if (av.getCodingComplement() != this) + { + av.setCodingComplement(this); + } + } + } + + @Override + public boolean isNucleotide() + { + return getAlignment() == null ? false : getAlignment().isNucleotide(); + } + + @Override + public FeaturesDisplayedI getFeaturesDisplayed() + { + return featuresDisplayed; + } + + @Override + public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI) + { + featuresDisplayed = featuresDisplayedI; + } + + @Override + public boolean areFeaturesDisplayed() + { + return featuresDisplayed != null + && featuresDisplayed.getRegisteredFeaturesCount() > 0; + } + + /** + * set the flag + * + * @param b + * features are displayed if true + */ + @Override + public void setShowSequenceFeatures(boolean b) + { + viewStyle.setShowSequenceFeatures(b); + } + + @Override + public boolean isShowSequenceFeatures() + { + return viewStyle.isShowSequenceFeatures(); + } + + @Override + public void setShowSequenceFeaturesHeight(boolean selected) + { + viewStyle.setShowSequenceFeaturesHeight(selected); + } + + @Override + public boolean isShowSequenceFeaturesHeight() + { + return viewStyle.isShowSequenceFeaturesHeight(); + } + + @Override + public void setShowAnnotation(boolean b) + { + viewStyle.setShowAnnotation(b); + } + + @Override + public boolean isShowAnnotation() + { + return viewStyle.isShowAnnotation(); + } + + @Override + public boolean isRightAlignIds() + { + return viewStyle.isRightAlignIds(); + } + + @Override + public void setRightAlignIds(boolean rightAlignIds) + { + viewStyle.setRightAlignIds(rightAlignIds); + } + + @Override + public boolean getConservationSelected() + { + return viewStyle.getConservationSelected(); + } + + @Override + public void setShowBoxes(boolean state) + { + viewStyle.setShowBoxes(state); + } + + /** + * @return + * @see jalview.api.ViewStyleI#getTextColour() + */ + @Override + public Color getTextColour() + { + return viewStyle.getTextColour(); + } + + /** + * @return + * @see jalview.api.ViewStyleI#getTextColour2() + */ + @Override + public Color getTextColour2() + { + return viewStyle.getTextColour2(); + } + + /** + * @return + * @see jalview.api.ViewStyleI#getThresholdTextColour() + */ + @Override + public int getThresholdTextColour() + { + return viewStyle.getThresholdTextColour(); + } + + /** + * @return + * @see jalview.api.ViewStyleI#isConservationColourSelected() + */ + @Override + public boolean isConservationColourSelected() + { + return viewStyle.isConservationColourSelected(); + } + + /** + * @return + * @see jalview.api.ViewStyleI#isRenderGaps() + */ + @Override + public boolean isRenderGaps() + { + return viewStyle.isRenderGaps(); + } + /** - * show the reference sequence in the alignment view + * @return + * @see jalview.api.ViewStyleI#isShowColourText() */ - private boolean displayReferenceSeq=false; + @Override + public boolean isShowColourText() + { + return viewStyle.isShowColourText(); + } + /** - * colour according to the reference sequence defined on the alignment + * @param conservationColourSelected + * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean) */ - private boolean colourByReferenceSeq=false; + @Override + public void setConservationColourSelected( + boolean conservationColourSelected) + { + viewStyle.setConservationColourSelected(conservationColourSelected); + } - public boolean isDisplayReferenceSeq() + /** + * @param showColourText + * @see jalview.api.ViewStyleI#setShowColourText(boolean) + */ + @Override + public void setShowColourText(boolean showColourText) { - return alignment.hasSeqrep() && displayReferenceSeq; + viewStyle.setShowColourText(showColourText); } - public void setDisplayReferenceSeq(boolean displayReferenceSeq) + /** + * @param textColour + * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color) + */ + @Override + public void setTextColour(Color textColour) { - this.displayReferenceSeq = displayReferenceSeq; + viewStyle.setTextColour(textColour); } - public boolean isColourByReferenceSeq() + /** + * @param thresholdTextColour + * @see jalview.api.ViewStyleI#setThresholdTextColour(int) + */ + @Override + public void setThresholdTextColour(int thresholdTextColour) { - return alignment.hasSeqrep() && colourByReferenceSeq; + viewStyle.setThresholdTextColour(thresholdTextColour); } - public void setColourByReferenceSeq(boolean colourByReferenceSeq) + /** + * @param textColour2 + * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color) + */ + @Override + public void setTextColour2(Color textColour2) { - this.colourByReferenceSeq = colourByReferenceSeq; + viewStyle.setTextColour2(textColour2); } @Override - public Color getSequenceColour(SequenceI seq) + public ViewStyleI getViewStyle() { - Color sqc = Color.white; - if (sequenceColours != null) - { - sqc = (Color) sequenceColours.get(seq); - if (sqc == null) - { - sqc = Color.white; - } - } - return sqc; + return new ViewStyle(viewStyle); } @Override - public void setSequenceColour(SequenceI seq, Color col) + public void setViewStyle(ViewStyleI settingsForView) { - if (sequenceColours == null) + viewStyle = new ViewStyle(settingsForView); + if (residueShading != null) { - sequenceColours = new Hashtable(); + residueShading.setConservationApplied( + settingsForView.isConservationColourSelected()); } + } - if (col == null) - { - sequenceColours.remove(seq); - } - else - { - sequenceColours.put(seq, col); - } + @Override + public boolean sameStyle(ViewStyleI them) + { + return viewStyle.sameStyle(them); } + /** + * @return + * @see jalview.api.ViewStyleI#getIdWidth() + */ @Override - public void updateSequenceIdColours() + public int getIdWidth() { - if (sequenceColours == null) - { - sequenceColours = new Hashtable(); - } - for (SequenceGroup sg : alignment.getGroups()) - { - if (sg.idColour != null) - { - for (SequenceI s : sg.getSequences(getHiddenRepSequences())) - { - sequenceColours.put(s, sg.idColour); - } - } - } + return viewStyle.getIdWidth(); } + /** + * @param i + * @see jalview.api.ViewStyleI#setIdWidth(int) + */ @Override - public void clearSequenceColours() + public void setIdWidth(int i) { - sequenceColours = null; - }; + viewStyle.setIdWidth(i); + } - FeaturesDisplayedI featuresDisplayed = null; + /** + * @return + * @see jalview.api.ViewStyleI#isCentreColumnLabels() + */ + @Override + public boolean isCentreColumnLabels() + { + return viewStyle.isCentreColumnLabels(); + } + /** + * @param centreColumnLabels + * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean) + */ @Override - public FeaturesDisplayedI getFeaturesDisplayed() + public void setCentreColumnLabels(boolean centreColumnLabels) { - return featuresDisplayed; + viewStyle.setCentreColumnLabels(centreColumnLabels); } - public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI) + /** + * @param showdbrefs + * @see jalview.api.ViewStyleI#setShowDBRefs(boolean) + */ + @Override + public void setShowDBRefs(boolean showdbrefs) { - featuresDisplayed = featuresDisplayedI; + viewStyle.setShowDBRefs(showdbrefs); } - public boolean areFeaturesDisplayed() + /** + * @return + * @see jalview.api.ViewStyleI#isShowDBRefs() + */ + @Override + public boolean isShowDBRefs() + { + return viewStyle.isShowDBRefs(); + } + + /** + * @return + * @see jalview.api.ViewStyleI#isShowNPFeats() + */ + @Override + public boolean isShowNPFeats() { - return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0; + return viewStyle.isShowNPFeats(); } /** - * display setting for showing/hiding sequence features on alignment view + * @param shownpfeats + * @see jalview.api.ViewStyleI#setShowNPFeats(boolean) */ - boolean showSequenceFeatures = false; + @Override + public void setShowNPFeats(boolean shownpfeats) + { + viewStyle.setShowNPFeats(shownpfeats); + } + + public abstract StructureSelectionManager getStructureSelectionManager(); /** - * set the flag + * Add one command to the command history list. * - * @param b - * features are displayed if true + * @param command + */ + public void addToHistoryList(CommandI command) + { + if (this.historyList != null) + { + this.historyList.push(command); + broadcastCommand(command, false); + } + } + + protected void broadcastCommand(CommandI command, boolean undo) + { + getStructureSelectionManager().commandPerformed(command, undo, + getVamsasSource()); + } + + /** + * Add one command to the command redo list. + * + * @param command + */ + public void addToRedoList(CommandI command) + { + if (this.redoList != null) + { + this.redoList.push(command); + } + broadcastCommand(command, true); + } + + /** + * Clear the command redo list. */ + public void clearRedoList() + { + if (this.redoList != null) + { + this.redoList.clear(); + } + } + + public void setHistoryList(Deque list) + { + this.historyList = list; + } + + public Deque getHistoryList() + { + return this.historyList; + } + + public void setRedoList(Deque list) + { + this.redoList = list; + } + + public Deque getRedoList() + { + return this.redoList; + } + @Override - public void setShowSequenceFeatures(boolean b) + public VamsasSource getVamsasSource() + { + return this; + } + + public SequenceAnnotationOrder getSortAnnotationsBy() + { + return sortAnnotationsBy; + } + + public void setSortAnnotationsBy( + SequenceAnnotationOrder sortAnnotationsBy) + { + this.sortAnnotationsBy = sortAnnotationsBy; + } + + public boolean isShowAutocalculatedAbove() + { + return showAutocalculatedAbove; + } + + public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove) { - showSequenceFeatures = b; + this.showAutocalculatedAbove = showAutocalculatedAbove; } + @Override - public boolean isShowSequenceFeatures() + public boolean isScaleProteinAsCdna() { - return showSequenceFeatures; + return viewStyle.isScaleProteinAsCdna(); } - boolean showSeqFeaturesHeight; + @Override + public void setScaleProteinAsCdna(boolean b) + { + viewStyle.setScaleProteinAsCdna(b); + } - public void setShowSequenceFeaturesHeight(boolean selected) + @Override + public boolean isProteinFontAsCdna() { - showSeqFeaturesHeight = selected; + return viewStyle.isProteinFontAsCdna(); } - public boolean isShowSequenceFeaturesHeight() + @Override + public void setProteinFontAsCdna(boolean b) + { + viewStyle.setProteinFontAsCdna(b); + } + + /** + * @return true if view should scroll to show the highlighted region of a + * sequence + * @return + */ + @Override + public final boolean isFollowHighlight() { - return showSeqFeaturesHeight; + return followHighlight; } - private boolean showAnnotation = true; + @Override + public final void setFollowHighlight(boolean b) + { + this.followHighlight = b; + } - private boolean rightAlignIds = false; + @Override + public ViewportRanges getRanges() + { + return ranges; + } /** - * DOCUMENT ME! + * Helper method to populate the SearchResults with the location in the + * complementary alignment to scroll to, in order to match this one. * - * @return DOCUMENT ME! + * @param sr + * the SearchResults to add to + * @return the offset (below top of visible region) of the matched sequence */ - public boolean getShowAnnotation() + protected int findComplementScrollTarget(SearchResultsI sr) { - return isShowAnnotation(); + final AlignViewportI complement = getCodingComplement(); + if (complement == null || !complement.isFollowHighlight()) + { + return 0; + } + boolean iAmProtein = !getAlignment().isNucleotide(); + AlignmentI proteinAlignment = iAmProtein ? getAlignment() + : complement.getAlignment(); + if (proteinAlignment == null) + { + return 0; + } + final List mappings = proteinAlignment + .getCodonFrames(); + + /* + * Heuristic: find the first mapped sequence (if any) with a non-gapped + * residue in the middle column of the visible region. Scroll the + * complementary alignment to line up the corresponding residue. + */ + int seqOffset = 0; + SequenceI sequence = null; + + /* + * locate 'middle' column (true middle if an odd number visible, left of + * middle if an even number visible) + */ + int middleColumn = ranges.getStartRes() + + (ranges.getEndRes() - ranges.getStartRes()) / 2; + final HiddenSequences hiddenSequences = getAlignment() + .getHiddenSequences(); + + /* + * searching to the bottom of the alignment gives smoother scrolling across + * all gapped visible regions + */ + int lastSeq = alignment.getHeight() - 1; + List seqMappings = null; + for (int seqNo = ranges + .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++) + { + sequence = getAlignment().getSequenceAt(seqNo); + if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) + { + continue; + } + if (Comparison.isGap(sequence.getCharAt(middleColumn))) + { + continue; + } + seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence, + mappings, + getCodingComplement().getAlignment().getSequences()); + if (!seqMappings.isEmpty()) + { + break; + } + } + + if (sequence == null || seqMappings == null || seqMappings.isEmpty()) + { + /* + * No ungapped mapped sequence in middle column - do nothing + */ + return 0; + } + MappingUtils.addSearchResults(sr, sequence, + sequence.findPosition(middleColumn), seqMappings); + return seqOffset; } /** - * DOCUMENT ME! + * synthesize a column selection if none exists so it covers the given + * selection group. if wholewidth is false, no column selection is made if the + * selection group covers the whole alignment width. * - * @param b - * DOCUMENT ME! + * @param sg + * @param wholewidth */ - public void setShowAnnotation(boolean b) + public void expandColSelection(SequenceGroup sg, boolean wholewidth) { - showAnnotation = b; + int sgs, sge; + if (sg != null && (sgs = sg.getStartRes()) >= 0 + && sg.getStartRes() <= (sge = sg.getEndRes()) + && !this.hasSelectedColumns()) + { + if (!wholewidth && alignment.getWidth() == (1 + sge - sgs)) + { + // do nothing + return; + } + if (colSel == null) + { + colSel = new ColumnSelection(); + } + for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++) + { + colSel.addElement(cspos); + } + } } - public boolean isShowAnnotation() + /** + * hold status of current selection group - defined on alignment or not. + */ + private boolean selectionIsDefinedGroup = false; + + @Override + public boolean isSelectionDefinedGroup() { - return showAnnotation; + if (selectionGroup == null) + { + return false; + } + if (isSelectionGroupChanged(true)) + { + selectionIsDefinedGroup = false; + List gps = alignment.getGroups(); + if (gps == null || gps.size() == 0) + { + selectionIsDefinedGroup = false; + } + else + { + selectionIsDefinedGroup = gps.contains(selectionGroup); + } + } + return selectionGroup.isDefined() || selectionIsDefinedGroup; } - public boolean isRightAlignIds() + /** + * null, or currently highlighted results on this view + */ + private SearchResultsI searchResults = null; + + protected TreeModel currentTree = null; + + @Override + public boolean hasSearchResults() { - return rightAlignIds; + return searchResults != null; } - public void setRightAlignIds(boolean rightAlignIds) + @Override + public void setSearchResults(SearchResultsI results) + { + searchResults = results; + } + + @Override + public SearchResultsI getSearchResults() + { + return searchResults; + } + + /** + * get the consensus sequence as displayed under the PID consensus annotation + * row. + * + * @return consensus sequence as a new sequence object + */ + public SequenceI getConsensusSeq() + { + if (consensus == null) + { + updateConsensus(null); + } + if (consensus == null) + { + return null; + } + StringBuffer seqs = new StringBuffer(); + for (int i = 0; i < consensus.annotations.length; i++) + { + Annotation annotation = consensus.annotations[i]; + if (annotation != null) + { + String description = annotation.description; + if (description != null && description.startsWith("[")) + { + // consensus is a tie - just pick the first one + seqs.append(description.charAt(1)); + } + else + { + seqs.append(annotation.displayCharacter); + } + } + } + + SequenceI sq = new Sequence("Consensus", seqs.toString()); + sq.setDescription("Percentage Identity Consensus " + + ((ignoreGapsInConsensusCalculation) ? " without gaps" : "")); + return sq; + } + + @Override + public void setCurrentTree(TreeModel tree) { - this.rightAlignIds = rightAlignIds; + currentTree = tree; } + @Override + public TreeModel getCurrentTree() + { + return currentTree; + } }