X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=60cee46bffe03d8c89b689a56e69c8716e36d151;hb=136c0793b90b72b928c4d77dc109dd5c644e00d3;hp=d3df56c92f8d495b480136f4620cd9793d0b66ac;hpb=6cedd15f7decf9a291f380f9bb57c939a1082aef;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index d3df56c..60cee46 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -35,22 +35,24 @@ import jalview.datamodel.AlignmentView; import jalview.datamodel.Annotation; import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; -import jalview.datamodel.SearchResults; +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; @@ -58,6 +60,7 @@ 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; @@ -77,6 +80,8 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { + final protected ViewportRanges ranges; + protected ViewStyleI viewStyle = new ViewStyle(); /** @@ -87,9 +92,20 @@ public abstract class AlignmentViewport implements AlignViewportI, FeaturesDisplayedI featuresDisplayed = null; - protected Deque historyList = new ArrayDeque(); + protected Deque historyList = new ArrayDeque<>(); - protected Deque redoList = new ArrayDeque(); + protected Deque redoList = new ArrayDeque<>(); + + /** + * alignment displayed in the viewport. Please use get/setter + */ + protected AlignmentI alignment; + + public AlignmentViewport(AlignmentI al) + { + setAlignment(al); + ranges = new ViewportRanges(al); + } /** * @param name @@ -551,10 +567,7 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle.setSeqNameItalics(default1); } - /** - * alignment displayed in the viewport. Please use get/setter - */ - protected AlignmentI alignment; + @Override public AlignmentI getAlignment() @@ -596,7 +609,7 @@ public abstract class AlignmentViewport implements AlignViewportI, protected boolean ignoreGapsInConsensusCalculation = false; - protected ColourSchemeI globalColourScheme = null; + protected ResidueShaderI residueShading = new ResidueShader(); @Override public void setGlobalColourScheme(ColourSchemeI cs) @@ -604,73 +617,51 @@ public abstract class AlignmentViewport implements AlignViewportI, // 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 th logic in here + // 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 - globalColourScheme = cs; - boolean recalc = false; + + /* + * 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) + { + residueShading = new ResidueShader(viewStyle); + } + residueShading.setColourScheme(cs); + + // TODO: do threshold and increment belong in ViewStyle or ResidueShader? + // ...problem: groups need these, but do not currently have a ViewStyle + if (cs != null) { - cs.setConservationApplied(recalc = getConservationSelected()); - if (getAbovePIDThreshold() || cs instanceof PIDColourScheme - || cs instanceof Blosum62ColourScheme) + if (getConservationSelected()) { - recalc = true; - cs.setThreshold(viewStyle.getThreshold(), - ignoreGapsInConsensusCalculation); + residueShading.setConservation(hconservation); } - else - { - cs.setThreshold(0, ignoreGapsInConsensusCalculation); - } - if (recalc) - { - cs.setConsensus(hconsensus); - cs.setConservation(hconservation); - } - cs.alignmentChanged(alignment, hiddenRepSequences); + residueShading.alignmentChanged(alignment, hiddenRepSequences); } + + /* + * if 'apply colour to all groups' is selected... do so + * (but don't transfer any colour threshold settings to groups) + */ 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(viewStyle.getThreshold(), - isIgnoreGapsConsensus()); - recalc = true; - } - else - { - sg.cs.setThreshold(0, isIgnoreGapsConsensus()); - } - - if (getConservationSelected()) - { - sg.cs.setConservationApplied(true); - recalc = true; - } - else - { - sg.cs.setConservation(null); - // sg.cs.setThreshold(0, getIgnoreGapsConsensus()); - } - if (recalc) - { - sg.recalcConservation(); - } - else + /* + * retain any colour thresholds per group while + * changing choice of colour scheme (JAL-2386) + */ + sg.setColourScheme(cs); + if (cs != null) { - sg.cs.alignmentChanged(sg, hiddenRepSequences); + sg.getGroupColourScheme() + .alignmentChanged(sg, hiddenRepSequences); } } } @@ -679,13 +670,22 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public ColourSchemeI getGlobalColourScheme() { - return globalColourScheme; + return residueShading == null ? null : residueShading + .getColourScheme(); + } + + @Override + public ResidueShaderI getResidueShading() + { + return residueShading; } protected AlignmentAnnotation consensus; protected AlignmentAnnotation complementConsensus; + protected AlignmentAnnotation gapcounts; + protected AlignmentAnnotation strucConsensus; protected AlignmentAnnotation conservation; @@ -699,7 +699,7 @@ public abstract class AlignmentViewport implements AlignViewportI, /** * results of alignment consensus analysis for visible portion of view */ - protected Hashtable[] hconsensus = null; + protected ProfilesI hconsensus = null; /** * results of cDNA complement consensus visible portion of view @@ -733,7 +733,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public void setSequenceConsensusHash(Hashtable[] hconsensus) + public void setSequenceConsensusHash(ProfilesI hconsensus) { this.hconsensus = hconsensus; } @@ -745,7 +745,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public Hashtable[] getSequenceConsensusHash() + public ProfilesI getSequenceConsensusHash() { return hconsensus; } @@ -788,6 +788,12 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public AlignmentAnnotation getAlignmentGapAnnotation() + { + return gapcounts; + } + + @Override public AlignmentAnnotation getComplementConsensusAnnotation() { return complementConsensus; @@ -807,7 +813,8 @@ public abstract class AlignmentViewport implements AlignViewportI, public void updateConservation(final AlignmentViewPanel ap) { // see note in mantis : issue number 8585 - if (alignment.isNucleotide() || conservation == null + if (alignment.isNucleotide() + || (conservation == null && quality == null) || !autoCalculateConsensus) { return; @@ -844,14 +851,22 @@ public abstract class AlignmentViewport implements AlignViewportI, && !al.getCodonFrames().isEmpty()) { /* - * fudge - check first mapping is protein-to-nucleotide + * fudge - check first for protein-to-nucleotide mappings * (we don't want to do this for protein-to-protein) */ - AlignedCodonFrame mapping = al.getCodonFrames().iterator().next(); - // 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) + 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) @@ -905,6 +920,37 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; + hcomplementConsensus = null; + // colour scheme may hold reference to consensus + residueShading = null; + // TODO remove listeners from changeSupport? + changeSupport = null; + setAlignment(null); + } + @Override public boolean isClosed() { @@ -1047,7 +1093,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** - * Set the selection group for this window. + * 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 @@ -1057,11 +1104,15 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setSelectionGroup(SequenceGroup sg) { selectionGroup = sg; + if (sg != null && sg.getContext() == null) + { + sg.setContext(alignment); + } } - public void setHiddenColumns(ColumnSelection colsel) + public void setHiddenColumns(HiddenColumns hidden) { - this.colSel = colsel; + this.alignment.setHiddenColumns(hidden); } @Override @@ -1099,9 +1150,17 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public boolean hasSelectedColumns() + { + ColumnSelection columnSelection = getColumnSelection(); + return columnSelection != null && columnSelection.hasSelectedColumns(); + } + + @Override public boolean hasHiddenColumns() { - return colSel != null && colSel.hasHiddenColumns(); + return colSel != null + && alignment.getHiddenColumns().hasHiddenColumns(); } public void updateHiddenColumns() @@ -1162,9 +1221,9 @@ public abstract class AlignmentViewport implements AlignViewportI, if (ap != null) { updateConsensus(ap); - if (globalColourScheme != null) + if (residueShading != null) { - globalColourScheme.setThreshold(globalColourScheme.getThreshold(), + residueShading.setThreshold(residueShading.getThreshold(), ignoreGapsInConsensusCalculation); } } @@ -1225,10 +1284,9 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; @@ -1237,7 +1295,9 @@ public abstract class AlignmentViewport implements AlignViewportI, protected boolean showConsensus = true; - private Map sequenceColours = new HashMap(); + protected boolean showOccupancy = true; + + private Map sequenceColours = new HashMap<>(); protected SequenceAnnotationOrder sortAnnotationsBy = null; @@ -1248,15 +1308,6 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private boolean followHighlight = true; - // TODO private with getters and setters? - public int startRes; - - public int endRes; - - public int startSeq; - - public int endSeq; - /** * Property change listener for changes in alignment * @@ -1306,7 +1357,7 @@ public abstract class AlignmentViewport implements AlignViewportI, return; } - colSel.hideSelectedColumns(); + colSel.hideSelectedColumns(alignment); setSelectionGroup(null); isColSelChanged(true); } @@ -1315,24 +1366,24 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (start == end) { - colSel.hideColumns(start); + colSel.hideSelectedColumns(start, alignment.getHiddenColumns()); } else { - colSel.hideColumns(start, end); + alignment.getHiddenColumns().hideColumns(start, end); } isColSelChanged(true); } public void showColumn(int col) { - colSel.revealHiddenColumns(col); + alignment.getHiddenColumns().revealHiddenColumns(col, colSel); isColSelChanged(true); } public void showAllHiddenColumns() { - colSel.revealAllHiddenColumns(); + alignment.getHiddenColumns().revealAllHiddenColumns(colSel); isColSelChanged(true); } @@ -1476,7 +1527,7 @@ public abstract class AlignmentViewport implements AlignViewportI, if (hiddenRepSequences == null) { - hiddenRepSequences = new Hashtable(); + hiddenRepSequences = new Hashtable<>(); } hiddenRepSequences.put(repSequence, sg); @@ -1529,7 +1580,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public boolean isHiddenRepSequence(SequenceI seq) { return (hiddenRepSequences != null && hiddenRepSequences - .containsKey(seq)); + .containsKey(seq)); } /** @@ -1554,7 +1605,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public void invertColumnSelection() { - colSel.invertColumnSelection(0, alignment.getWidth()); + colSel.invertColumnSelection(0, alignment.getWidth(), alignment); } @Override @@ -1602,7 +1653,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public CigarArray getViewAsCigars(boolean selectedRegionOnly) { - return new CigarArray(alignment, colSel, + return new CigarArray(alignment, alignment.getHiddenColumns(), (selectedRegionOnly ? selectionGroup : null)); } @@ -1617,8 +1668,10 @@ public abstract class AlignmentViewport implements AlignViewportI, public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly, boolean markGroups) { - return new AlignmentView(alignment, colSel, selectionGroup, - colSel != null && colSel.hasHiddenColumns(), selectedOnly, + return new AlignmentView(alignment, alignment.getHiddenColumns(), + selectionGroup, alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(), + selectedOnly, markGroups); } @@ -1662,9 +1715,11 @@ public abstract class AlignmentViewport implements AlignViewportI, } selection = new String[iSize]; - if (colSel != null && colSel.hasHiddenColumns()) + if (alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = colSel.getVisibleSequenceStrings(start, end, seqs); + selection = alignment.getHiddenColumns().getVisibleSequenceStrings( + start, end, seqs); } else { @@ -1680,20 +1735,21 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public List getVisibleRegionBoundaries(int min, int max) { - ArrayList regions = new ArrayList(); + ArrayList regions = new ArrayList<>(); int start = min; int end = max; do { - if (colSel != null && colSel.hasHiddenColumns()) + HiddenColumns hidden = alignment.getHiddenColumns(); + if (hidden != null && hidden.hasHiddenColumns()) { if (start == 0) { - start = colSel.adjustForHiddenColumns(start); + start = hidden.adjustForHiddenColumns(start); } - end = colSel.getHiddenBoundaryRight(start); + end = hidden.getHiddenBoundaryRight(start); if (start == end) { end = max; @@ -1706,10 +1762,10 @@ public abstract class AlignmentViewport implements AlignViewportI, regions.add(new int[] { start, end }); - if (colSel != null && colSel.hasHiddenColumns()) + if (hidden != null && hidden.hasHiddenColumns()) { - start = colSel.adjustForHiddenColumns(end); - start = colSel.getHiddenBoundaryLeft(start) + 1; + start = hidden.adjustForHiddenColumns(end); + start = hidden.getHiddenBoundaryLeft(start) + 1; } } while (end < max); @@ -1722,7 +1778,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public List getVisibleAlignmentAnnotation( boolean selectedOnly) { - ArrayList ala = new ArrayList(); + ArrayList ala = new ArrayList<>(); AlignmentAnnotation[] aa; if ((aa = alignment.getAlignmentAnnotation()) != null) { @@ -1731,12 +1787,13 @@ public abstract class AlignmentViewport implements AlignViewportI, AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), + alignment.getHiddenColumns().makeVisibleAnnotation( + selectionGroup.getStartRes(), selectionGroup.getEndRes(), clone); } else { - colSel.makeVisibleAnnotation(clone); + alignment.getHiddenColumns().makeVisibleAnnotation(clone); } ala.add(clone); } @@ -1801,7 +1858,7 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup.setEndRes(alWidth - 1); } - resetAllColourSchemes(); + updateAllColourSchemes(); calculator.restartWorkers(); // alignment.adjustSequenceAnnotations(); } @@ -1809,19 +1866,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)); } } @@ -1852,19 +1909,21 @@ public abstract class AlignmentViewport implements AlignViewportI, { initRNAStructure(); } - consensus = new AlignmentAnnotation("Consensus", "PID", + consensus = new AlignmentAnnotation("Consensus", + MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); + initGapCounts(); initComplementConsensus(); } } /** - * If this is a protein alignment and there are mappings to cDNA, add the cDNA - * consensus annotation. + * If this is a protein alignment and there are mappings to cDNA, adds the + * cDNA consensus annotation and returns true, else returns false. */ - public void initComplementConsensus() + public boolean initComplementConsensus() { if (!alignment.isNucleotide()) { @@ -1872,20 +1931,32 @@ public abstract class AlignmentViewport implements AlignViewportI, .getCodonFrames(); if (codonMappings != null && !codonMappings.isEmpty()) { - // fudge: check mappings are not protein-to-protein - // TODO: nicer - AlignedCodonFrame mapping = codonMappings.iterator().next(); - MapList[] mapLists = mapping.getdnaToProt(); - // mapLists can be empty if project load has not finished resolving seqs - if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3) + 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", - "PID for cDNA", new Annotation[1], 0f, 100f, + MessageManager + .getString("label.complement_consensus_descr"), + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(complementConsensus); + return true; } } } + return false; } private void initConsensus(AlignmentAnnotation aa) @@ -1899,6 +1970,25 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + // 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); + } + } + private void initConservation() { if (showConservation) @@ -1906,8 +1996,8 @@ public abstract class AlignmentViewport implements AlignViewportI, if (conservation == null) { conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " - + getConsPercGaps() + "% gaps", new Annotation[1], + MessageManager.formatMessage("label.conservation_descr", + getConsPercGaps()), new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); conservation.hasText = true; conservation.autoCalculated = true; @@ -1923,7 +2013,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; @@ -1936,7 +2026,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; @@ -2041,7 +2132,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++) @@ -2385,6 +2476,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setViewStyle(ViewStyleI settingsForView) { viewStyle = new ViewStyle(settingsForView); + if (residueShading != null) + { + residueShading.setConservationApplied(settingsForView + .isConservationColourSelected()); + } } @Override @@ -2578,6 +2674,18 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle.setScaleProteinAsCdna(b); } + @Override + public boolean isProteinFontAsCdna() + { + return viewStyle.isProteinFontAsCdna(); + } + + @Override + public void setProteinFontAsCdna(boolean b) + { + viewStyle.setProteinFontAsCdna(b); + } + /** * @return true if view should scroll to show the highlighted region of a * sequence @@ -2595,63 +2703,10 @@ public abstract class AlignmentViewport implements AlignViewportI, this.followHighlight = b; } - public int getStartRes() - { - return startRes; - } - @Override - public int getEndRes() + public ViewportRanges getRanges() { - return endRes; - } - - public int getStartSeq() - { - return startSeq; - } - - public void setStartRes(int res) - { - this.startRes = res; - } - - public void setStartSeq(int seq) - { - this.startSeq = seq; - } - - public void setEndRes(int res) - { - if (res > alignment.getWidth() - 1) - { - // log.System.out.println(" Corrected res from " + res + " to maximum " + - // (alignment.getWidth()-1)); - res = alignment.getWidth() - 1; - } - if (res < 0) - { - res = 0; - } - this.endRes = res; - } - - public void setEndSeq(int seq) - { - if (seq > alignment.getHeight()) - { - seq = alignment.getHeight(); - } - if (seq < 0) - { - seq = 0; - } - this.endSeq = seq; - } - - public int getEndSeq() - { - return endSeq; + return ranges; } /** @@ -2662,7 +2717,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * the SearchResults to add to * @return the offset (below top of visible region) of the matched sequence */ - protected int findComplementScrollTarget(SearchResults sr) + protected int findComplementScrollTarget(SearchResultsI sr) { final AlignViewportI complement = getCodingComplement(); if (complement == null || !complement.isFollowHighlight()) @@ -2691,7 +2746,8 @@ public abstract class AlignmentViewport implements AlignViewportI, * locate 'middle' column (true middle if an odd number visible, left of * middle if an even number visible) */ - int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2; + int middleColumn = ranges.getStartRes() + + (ranges.getEndRes() - ranges.getStartRes()) / 2; final HiddenSequences hiddenSequences = getAlignment() .getHiddenSequences(); @@ -2701,7 +2757,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ int lastSeq = alignment.getHeight() - 1; List seqMappings = null; - for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) @@ -2714,7 +2770,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } seqMappings = MappingUtils .findMappingsForSequenceAndOthers(sequence, mappings, - getCodingComplement().getAlignment()); + getCodingComplement().getAlignment().getSequences()); if (!seqMappings.isEmpty()) { break; @@ -2744,11 +2800,9 @@ public abstract class AlignmentViewport implements AlignViewportI, public void expandColSelection(SequenceGroup sg, boolean wholewidth) { int sgs, sge; - if (sg != null - && (sgs = sg.getStartRes()) >= 0 + if (sg != null && (sgs = sg.getStartRes()) >= 0 && sg.getStartRes() <= (sge = sg.getEndRes()) - && (colSel == null || colSel.getSelected() == null || colSel - .getSelected().size() == 0)) + && !this.hasSelectedColumns()) { if (!wholewidth && alignment.getWidth() == (1 + sge - sgs)) { @@ -2766,5 +2820,54 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + /** + * hold status of current selection group - defined on alignment or not. + */ + private boolean selectionIsDefinedGroup = false; + + @Override + public boolean isSelectionDefinedGroup() + { + 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; + } + + /** + * null, or currently highlighted results on this view + */ + private SearchResultsI searchResults = null; + @Override + public boolean hasSearchResults() + { + return searchResults != null; + } + + @Override + public void setSearchResults(SearchResultsI results) + { + searchResults = results; + } + + @Override + public SearchResultsI getSearchResults() + { + return searchResults; + } }