X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=39a1c187827064fc414351c485e0cc212f80241a;hb=b5667f39acdf309cd92881b73edfda591e0acaf4;hp=b62c61c9cffe688064c0fce22f56256aafadf286;hpb=79631ef84a124bfefa84c24b85dc77883366ad4a;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index b62c61c..39a1c18 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -22,6 +22,7 @@ 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; @@ -33,8 +34,8 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; 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.ProfilesI; import jalview.datamodel.SearchResultsI; @@ -51,10 +52,12 @@ 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.InformationThread; import jalview.workers.StrucConsensusThread; import java.awt.Color; @@ -65,6 +68,7 @@ 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; @@ -75,10 +79,10 @@ import java.util.Map; * @author jimp * */ -public abstract class AlignmentViewport implements AlignViewportI, - CommandListener, VamsasSource +public abstract class AlignmentViewport + implements AlignViewportI, CommandListener, VamsasSource { - protected ViewportPositionProps posProps; + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -90,9 +94,79 @@ 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<>(); + + protected String sequenceSetID; + + /* + * probably unused indicator that view is of a dataset rather than an + * alignment + */ + protected boolean isDataset = false; + + private Map hiddenRepSequences; + + protected ColumnSelection colSel = new ColumnSelection(); + + public boolean autoCalculateConsensus = true; + + protected boolean autoCalculateStrucConsensus = true; + + protected boolean ignoreGapsInConsensusCalculation = false; + + protected boolean ignoreBelowBackGroundFrequencyCalculation = false; + + protected boolean infoLetterHeight = false; + + protected ResidueShaderI residueShading = new ResidueShader(); + + protected AlignmentAnnotation consensus; + + protected AlignmentAnnotation complementConsensus; + + protected AlignmentAnnotation occupancy; + + protected AlignmentAnnotation strucConsensus; + + protected AlignmentAnnotation conservation; + + protected AlignmentAnnotation quality; + + /** + * alignment displayed in the viewport + */ + private AlignmentI alignment; + + /** + * results of alignment consensus analysis for visible portion of view + */ + protected ProfilesI consensusProfiles; + + /** + * HMM profile for the alignment + */ + protected ProfilesI hmmProfiles; + + /** + * results of cDNA complement consensus visible portion of view + */ + protected Hashtable[] hcomplementConsensus; + + /** + * results of secondary structure base pair consensus for visible portion of + * view + */ + protected Hashtable[] hStrucConsensus; + + protected Conservation hconservation; + + public AlignmentViewport(AlignmentI al) + { + setAlignment(al); + ranges = new ViewportRanges(al); + } /** * @param name @@ -392,6 +466,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** @@ -554,11 +629,6 @@ 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() { @@ -571,14 +641,6 @@ public abstract class AlignmentViewport implements AlignViewportI, return alignment.getGapCharacter(); } - protected String sequenceSetID; - - /** - * probably unused indicator that view is of a dataset rather than an - * alignment - */ - protected boolean isDataset = false; - public void setDataset(boolean b) { isDataset = b; @@ -589,18 +651,6 @@ public abstract class AlignmentViewport implements AlignViewportI, return isDataset; } - - - // protected ColumnSelection colSel = new ColumnSelection(); - - public boolean autoCalculateConsensus = true; - - protected boolean autoCalculateStrucConsensus = true; - - protected boolean ignoreGapsInConsensusCalculation = false; - - protected ResidueShaderI residueShading; - @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -632,7 +682,12 @@ public abstract class AlignmentViewport implements AlignViewportI, { residueShading.setConservation(hconservation); } - residueShading.alignmentChanged(alignment, getHiddenRepSequences()); + /* + * reset conservation flag in case just set to false if + * Conservation was null (calculation still in progress) + */ + residueShading.setConservationApplied(getConservationSelected()); + residueShading.alignmentChanged(alignment, hiddenRepSequences); } /* @@ -647,12 +702,12 @@ public abstract class AlignmentViewport implements AlignViewportI, * retain any colour thresholds per group while * changing choice of colour scheme (JAL-2386) */ - sg.setColourScheme(cs); + sg.setColourScheme( + cs == null ? null : cs.getInstance(this, sg)); if (cs != null) { - sg.getGroupColourScheme() -.alignmentChanged(sg, - getHiddenRepSequences()); + sg.getGroupColourScheme().alignmentChanged(sg, + hiddenRepSequences); } } } @@ -661,8 +716,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public ColourSchemeI getGlobalColourScheme() { - return residueShading == null ? null : residueShading - .getColourScheme(); + return residueShading == null ? null : residueShading.getColourScheme(); } @Override @@ -670,39 +724,6 @@ public abstract class AlignmentViewport implements AlignViewportI, { return residueShading; } - - protected AlignmentAnnotation consensus; - - protected AlignmentAnnotation complementConsensus; - - 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 - */ - 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) { @@ -722,9 +743,9 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public void setSequenceConsensusHash(ProfilesI hconsensus) + public void setConsensusProfiles(ProfilesI hconsensus) { - this.hconsensus = hconsensus; + this.consensusProfiles = hconsensus; } @Override @@ -734,9 +755,21 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public ProfilesI getSequenceConsensusHash() + public ProfilesI getConsensusProfiles() { - return hconsensus; + return consensusProfiles; + } + + @Override + public void setHmmProfiles(ProfilesI info) + { + hmmProfiles = info; + } + + @Override + public ProfilesI getHmmProfiles() + { + return hmmProfiles; } @Override @@ -777,6 +810,12 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public AlignmentAnnotation getOccupancyAnnotation() + { + return occupancy; + } + + @Override public AlignmentAnnotation getComplementConsensusAnnotation() { return complementConsensus; @@ -802,11 +841,11 @@ public abstract class AlignmentViewport implements AlignViewportI, { return; } - if (calculator - .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null) + if (calculator.getRegisteredWorkersOfClass( + jalview.workers.ConservationThread.class) == null) { - calculator.registerWorker(new jalview.workers.ConservationThread( - this, ap)); + calculator.registerWorker( + new jalview.workers.ConservationThread(this, ap)); } } @@ -820,7 +859,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { return; } - if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null) + if (calculator + .getRegisteredWorkersOfClass(ConsensusThread.class) == null) { calculator.registerWorker(new ConsensusThread(this, ap)); } @@ -851,8 +891,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } if (doConsensus) { - if (calculator - .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null) + if (calculator.getRegisteredWorkersOfClass( + ComplementConsensusThread.class) == null) { calculator .registerWorker(new ComplementConsensusThread(this, ap)); @@ -861,6 +901,16 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + @Override + public void initInformationWorker(final AlignmentViewPanel ap) + { + if (calculator + .getRegisteredWorkersOfClass(InformationThread.class) == null) + { + calculator.registerWorker(new InformationThread(this, ap)); + } + } + // --------START Structure Conservation public void updateStrucConsensus(final AlignmentViewPanel ap) { @@ -876,7 +926,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { return; } - if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null) + if (calculator.getRegisteredWorkersOfClass( + StrucConsensusThread.class) == null) { calculator.registerWorker(new StrucConsensusThread(this, ap)); } @@ -923,14 +974,16 @@ public abstract class AlignmentViewport implements AlignViewportI, strucConsensus = null; conservation = null; quality = null; - groupConsensus = null; - groupConservation = null; - hconsensus = null; + consensusProfiles = null; + hconservation = null; hcomplementConsensus = null; - // colour scheme may hold reference to consensus - residueShading = null; - // TODO remove listeners from changeSupport? + occupancy = null; + calculator = null; + residueShading = null; // may hold a reference to Consensus changeSupport = null; + ranges = null; + currentTree = null; + selectionGroup = null; setAlignment(null); } @@ -974,6 +1027,21 @@ public abstract class AlignmentViewport implements AlignViewportI, protected boolean showConsensusHistogram = true; /** + * should hmm profile be rendered by default + */ + protected boolean hmmShowSequenceLogo = false; + + /** + * should hmm profile be rendered normalised to row height + */ + protected boolean hmmNormaliseSequenceLogo = false; + + /** + * should information histograms be rendered by default + */ + protected boolean hmmShowHistogram = true; + + /** * @return the showConsensusProfile */ @Override @@ -983,6 +1051,15 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return hmmShowSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1000,6 +1077,18 @@ public abstract class AlignmentViewport implements AlignViewportI, this.showSequenceLogo = showSequenceLogo; } + public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo) + { + if (showHMMSequenceLogo != this.hmmShowSequenceLogo) + { + this.hmmShowSequenceLogo = showHMMSequenceLogo; + // TODO: updateAnnotation if description (tooltip) will show + // profile in place of information content? + // calculator.updateAnnotationFor(InformationThread.class); + } + this.hmmShowSequenceLogo = showHMMSequenceLogo; + } + /** * @param showConsensusHistogram * the showConsensusHistogram to set @@ -1010,6 +1099,14 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @param showInformationHistogram + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.hmmShowHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1055,6 +1152,17 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * + * @return flag to indicate if the information content histogram should be + * rendered by default + */ + @Override + public boolean isShowInformationHistogram() + { + return this.hmmShowHistogram; + } + + /** * when set, updateAlignment will always ensure sequences are of equal length */ private boolean padGaps = false; @@ -1093,29 +1201,26 @@ public abstract class AlignmentViewport implements AlignViewportI, } } - public void setHiddenColumns(ColumnSelection colsel) + public void setHiddenColumns(HiddenColumns hidden) { - posProps.setHiddenColumns(colsel); - // this.colSel = colsel; + this.alignment.setHiddenColumns(hidden); } @Override public ColumnSelection getColumnSelection() { - return posProps.getColumnSelection(); - // return colSel; + return colSel; } @Override public void setColumnSelection(ColumnSelection colSel) { - posProps.setColumnSelection(colSel); - /*this.colSel = colSel; + this.colSel = colSel; if (colSel != null) { updateHiddenColumns(); } - isColSelChanged(true);*/ + isColSelChanged(true); } /** @@ -1125,14 +1230,14 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public Map getHiddenRepSequences() { - return posProps.getHiddenRepSequences(); + return hiddenRepSequences; } @Override public void setHiddenRepSequences( Map hiddenRepSequences) { - posProps.getHiddenRepSequences(); + this.hiddenRepSequences = hiddenRepSequences; } @Override @@ -1145,8 +1250,8 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public boolean hasHiddenColumns() { - return posProps.hasHiddenColumns(); - // return colSel != null && colSel.hasHiddenColumns(); + return alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(); } public void updateHiddenColumns() @@ -1168,8 +1273,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (sequenceSetID != null) { - System.err - .println("Warning - overwriting a sequenceSetId for a viewport!"); + System.err.println( + "Warning - overwriting a sequenceSetId for a viewport!"); } sequenceSetID = new String(newid); } @@ -1206,17 +1311,25 @@ public abstract class AlignmentViewport implements AlignViewportI, ignoreGapsInConsensusCalculation = b; if (ap != null) { - updateConsensus(ap); if (residueShading != null) { residueShading.setThreshold(residueShading.getThreshold(), ignoreGapsInConsensusCalculation); } } + } + + public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) + { + ignoreBelowBackGroundFrequencyCalculation = b; + } + public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap) + { + infoLetterHeight = b; } - private long sgrouphash = -1; + private long sgrouphash = -1, colselhash = -1; /** * checks current SelectionGroup against record of last hash value, and @@ -1252,8 +1365,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isColSelChanged(boolean b) { - return posProps.isColSelChanged(b); - /*int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); + int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { if (b) @@ -1262,7 +1374,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } return true; } - return false;*/ + return false; } @Override @@ -1271,6 +1383,18 @@ public abstract class AlignmentViewport implements AlignViewportI, return ignoreGapsInConsensusCalculation; } + @Override + public boolean isIgnoreBelowBackground() + { + return ignoreBelowBackGroundFrequencyCalculation; + } + + @Override + public boolean isInfoLetterHeight() + { + return infoLetterHeight; + } + // property change stuff // JBPNote Prolly only need this in the applet version. private PropertyChangeSupport changeSupport = new PropertyChangeSupport( @@ -1282,7 +1406,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; @@ -1293,14 +1419,6 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private boolean followHighlight = true; - /*private int startRes; - - private int endRes; - - private int startSeq; - - private int endSeq;*/ - /** * Property change listener for changes in alignment * @@ -1322,7 +1440,10 @@ public abstract class AlignmentViewport implements AlignViewportI, public void removePropertyChangeListener( java.beans.PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); + if (changeSupport != null) + { + changeSupport.removePropertyChangeListener(listener); + } } /** @@ -1343,21 +1464,6 @@ public abstract class AlignmentViewport implements AlignViewportI, // common hide/show column stuff - public void hideColumns(int start, int end) - { - posProps.hideColumns(start, end); - } - - public void showColumn(int col) - { - posProps.showColumn(col); - } - - public void showAllHiddenColumns() - { - posProps.showAllHiddenColumns(); - } - public void hideSelectedColumns() { if (colSel.isEmpty()) @@ -1365,47 +1471,75 @@ public abstract class AlignmentViewport implements AlignViewportI, return; } - colSel.hideSelectedColumns(); + colSel.hideSelectedColumns(alignment); setSelectionGroup(null); isColSelChanged(true); } + public void hideColumns(int start, int end) + { + if (start == end) + { + colSel.hideSelectedColumns(start, alignment.getHiddenColumns()); + } + else + { + alignment.getHiddenColumns().hideColumns(start, end); + } + isColSelChanged(true); + } + + public void showColumn(int col) + { + alignment.getHiddenColumns().revealHiddenColumns(col, colSel); + isColSelChanged(true); + } + public void showAllHiddenColumns() + { + alignment.getHiddenColumns().revealAllHiddenColumns(colSel); + isColSelChanged(true); + } // common hide/show seq stuff public void showAllHiddenSeqs() { - selectionGroup = posProps.showAllHiddenSeqs(selectionGroup); + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); - /* if (alignment.getHiddenSequences().getSize() > 0) - { - if (selectionGroup == null) - { - selectionGroup = new SequenceGroup(); - selectionGroup.setEndRes(alignment.getWidth() - 1); - } - List tmp = alignment.getHiddenSequences().showAll( - hiddenRepSequences); - for (SequenceI seq : tmp) - { - selectionGroup.addSequence(seq, false); - setSequenceAnnotationsVisible(seq, true); - } + if (alignment.getHiddenSequences().getSize() > 0) + { + if (selectionGroup == null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(alignment.getWidth() - 1); + } + List tmp = alignment.getHiddenSequences() + .showAll(hiddenRepSequences); + for (SequenceI seq : tmp) + { + selectionGroup.addSequence(seq, false); + setSequenceAnnotationsVisible(seq, true); + } + + hiddenRepSequences = null; - hiddenRepSequences = null; + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - firePropertyChange("alignment", null, alignment.getSequences()); - // used to set hasHiddenRows/hiddenRepSequences here, after the property - // changed event - sendSelection(); - }*/ + firePropertyChange("alignment", null, alignment.getSequences()); + // used to set hasHiddenRows/hiddenRepSequences here, after the property + // changed event + sendSelection(); + } } public void showSequence(int index) { - posProps.showSequence(index, selectionGroup); - /*List tmp = alignment.getHiddenSequences().showSequence( - index, hiddenRepSequences); + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + + List tmp = alignment.getHiddenSequences().showSequence(index, + hiddenRepSequences); if (tmp.size() > 0) { if (selectionGroup == null) @@ -1419,15 +1553,17 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup.addSequence(seq, false); setSequenceAnnotationsVisible(seq, true); } + + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); sendSelection(); - }*/ + } } public void hideAllSelectedSeqs() { - posProps.hideAllSelectedSeqs(selectionGroup); - /*if (selectionGroup == null || selectionGroup.getSize() < 1) + if (selectionGroup == null || selectionGroup.getSize() < 1) { return; } @@ -1436,21 +1572,26 @@ public abstract class AlignmentViewport implements AlignViewportI, hideSequence(seqs); - setSelectionGroup(null);*/ + setSelectionGroup(null); } public void hideSequence(SequenceI[] seq) { - posProps.hideSequence(seq); - /*if (seq != null) + /* + * cache offset to first visible sequence + */ + int startSeq = ranges.getStartSeq(); + + if (seq != null) { for (int i = 0; i < seq.length; i++) { alignment.getHiddenSequences().hideSequence(seq[i]); setSequenceAnnotationsVisible(seq[i], false); } + ranges.setStartSeq(startSeq); firePropertyChange("alignment", null, alignment.getSequences()); - }*/ + } } /** @@ -1464,8 +1605,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public void hideSequences(SequenceI sequence, boolean representGroup) { - posProps.hideSequences(sequence, representGroup, selectionGroup); - /*if (selectionGroup == null || selectionGroup.getSize() < 1) + if (selectionGroup == null || selectionGroup.getSize() < 1) { hideSequence(new SequenceI[] { sequence }); return; @@ -1479,19 +1619,38 @@ public abstract class AlignmentViewport implements AlignViewportI, } int gsize = selectionGroup.getSize(); - SequenceI[] hseqs = selectionGroup.getSequences().toArray( - new SequenceI[gsize]); + SequenceI[] hseqs = selectionGroup.getSequences() + .toArray(new SequenceI[gsize]); hideSequence(hseqs); setSelectionGroup(null); - sendSelection();*/ + sendSelection(); } + /** + * Set visibility for any annotations for the given sequence. + * + * @param sequenceI + */ + protected void setSequenceAnnotationsVisible(SequenceI sequenceI, + boolean visible) + { + AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation(); + if (anns != null) + { + for (AlignmentAnnotation ann : anns) + { + if (ann.sequenceRef == sequenceI) + { + ann.visible = visible; + } + } + } + } public void hideRepSequences(SequenceI repSequence, SequenceGroup sg) { - posProps.hideRepSequences(repSequence, sg); - /*int sSize = sg.getSize(); + int sSize = sg.getSize(); if (sSize < 2) { return; @@ -1499,7 +1658,7 @@ public abstract class AlignmentViewport implements AlignViewportI, if (hiddenRepSequences == null) { - hiddenRepSequences = new Hashtable(); + hiddenRepSequences = new Hashtable<>(); } hiddenRepSequences.put(repSequence, sg); @@ -1521,7 +1680,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } sg.setSeqrep(repSequence); // note: not done in 2.7applet sg.setHidereps(true); // note: not done in 2.7applet - hideSequence(seqs);*/ + hideSequence(seqs); } @@ -1551,9 +1710,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isHiddenRepSequence(SequenceI seq) { - return posProps.isHiddenRepSequence(seq); - // return (hiddenRepSequences != null && hiddenRepSequences - // .containsKey(seq)); + return (hiddenRepSequences != null + && hiddenRepSequences.containsKey(seq)); } /** @@ -1564,24 +1722,22 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public SequenceGroup getRepresentedSequences(SequenceI seq) { - return posProps.getRepresentedSequences(seq); - // return (SequenceGroup) (hiddenRepSequences == null ? null - // : hiddenRepSequences.get(seq)); + return (SequenceGroup) (hiddenRepSequences == null ? null + : hiddenRepSequences.get(seq)); } @Override public int adjustForHiddenSeqs(int alignmentIndex) { - return posProps.adjustForHiddenSeqs(alignmentIndex); - // return alignment.getHiddenSequences().adjustForHiddenSeqs( - // alignmentIndex); + return alignment.getHiddenSequences() + .adjustForHiddenSeqs(alignmentIndex); } @Override public void invertColumnSelection() { - posProps.invertColumnSelection(); - // colSel.invertColumnSelection(0, alignment.getWidth()); + colSel.invertColumnSelection(0, alignment.getWidth(), alignment); + isColSelChanged(true); } @Override @@ -1605,7 +1761,8 @@ public abstract class AlignmentViewport implements AlignViewportI, } else { - sequences = selectionGroup.getSelectionAsNewSequences(alignment); + sequences = selectionGroup.getSelectionAsNewSequences(alignment, + true); } return sequences; @@ -1627,13 +1784,6 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public CigarArray getViewAsCigars(boolean selectedRegionOnly) - { - return new CigarArray(alignment, posProps.getColumnSelection(), - (selectedRegionOnly ? selectionGroup : null)); - } - - @Override public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly) { @@ -1644,9 +1794,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly, boolean markGroups) { - return new AlignmentView(alignment, posProps.getColumnSelection(), - selectionGroup, posProps.hasHiddenColumns(), selectedOnly, - markGroups); + return new AlignmentView(alignment, alignment.getHiddenColumns(), + selectionGroup, + alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(), + selectedOnly, markGroups); } @Override @@ -1689,9 +1841,15 @@ public abstract class AlignmentViewport implements AlignViewportI, } selection = new String[iSize]; - if (posProps.hasHiddenColumns()) + if (alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = posProps.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 { @@ -1707,52 +1865,50 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public List getVisibleRegionBoundaries(int min, int max) { - return posProps.getVisibleRegionBoundaries(min, max); - /* ArrayList regions = new ArrayList(); - int start = min; - int end = max; + ArrayList regions = new ArrayList<>(); + int start = min; + int end = max; - do + do + { + HiddenColumns hidden = alignment.getHiddenColumns(); + if (hidden != null && hidden.hasHiddenColumns()) + { + if (start == 0) { - if (colSel != null && colSel.hasHiddenColumns()) - { - if (start == 0) - { - start = colSel.adjustForHiddenColumns(start); - } - - end = colSel.getHiddenBoundaryRight(start); - if (start == end) - { - end = max; - } - if (end > max) - { - end = max; - } - } + start = hidden.visibleToAbsoluteColumn(start); + } + + end = hidden.getNextHiddenBoundary(false, start); + if (start == end) + { + end = max; + } + if (end > max) + { + end = max; + } + } - regions.add(new int[] { start, end }); + regions.add(new int[] { start, end }); - if (posProps.hasHiddenColumns()) - { - start = colSel.adjustForHiddenColumns(end); - start = colSel.getHiddenBoundaryLeft(start) + 1; - } - } while (end < max); + if (hidden != null && hidden.hasHiddenColumns()) + { + start = hidden.visibleToAbsoluteColumn(end); + start = hidden.getNextHiddenBoundary(true, start) + 1; + } + } while (end < max); - int[][] startEnd = new int[regions.size()][2]; + int[][] startEnd = new int[regions.size()][2]; - return regions;*/ + return regions; } @Override public List getVisibleAlignmentAnnotation( boolean selectedOnly) { - return posProps.getVisibleAlignmentAnnotation(selectedOnly, - selectionGroup); - /*ArrayList ala = new ArrayList(); + ArrayList ala = new ArrayList<>(); AlignmentAnnotation[] aa; if ((aa = alignment.getAlignmentAnnotation()) != null) { @@ -1761,17 +1917,18 @@ public abstract class AlignmentViewport implements AlignViewportI, AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), - selectionGroup.getEndRes(), clone); + clone.makeVisibleAnnotation( + selectionGroup.getStartRes(), selectionGroup.getEndRes(), + alignment.getHiddenColumns()); } else { - colSel.makeVisibleAnnotation(clone); + clone.makeVisibleAnnotation(alignment.getHiddenColumns()); } ala.add(clone); } } - return ala;*/ + return ala; } @Override @@ -1799,18 +1956,6 @@ public abstract class AlignmentViewport implements AlignViewportI, { alignment.padGaps(); } - if (autoCalculateConsensus) - { - updateConsensus(ap); - } - if (hconsensus != null && autoCalculateConsensus) - { - updateConservation(ap); - } - if (autoCalculateStrucConsensus) - { - updateStrucConsensus(ap); - } // Reset endRes of groups if beyond alignment width int alWidth = alignment.getWidth(); @@ -1833,7 +1978,6 @@ public abstract class AlignmentViewport implements AlignViewportI, updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -1844,9 +1988,9 @@ public abstract class AlignmentViewport implements AlignViewportI, ResidueShaderI rs = residueShading; if (rs != null) { - rs.alignmentChanged(alignment, posProps.getHiddenRepSequences()); + rs.alignmentChanged(alignment, hiddenRepSequences); - rs.setConsensus(hconsensus); + rs.setConsensus(consensusProfiles); if (rs.conservationApplied()) { rs.setConservation(Conservation.calculateConservation("All", @@ -1859,7 +2003,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (sg.cs != null) { - sg.cs.alignmentChanged(sg, posProps.getHiddenRepSequences()); + sg.cs.alignmentChanged(sg, hiddenRepSequences); } sg.recalcConservation(); } @@ -1871,7 +2015,7 @@ public abstract class AlignmentViewport implements AlignViewportI, // depending on if the user wants to see the annotation or not in a // specific alignment - if (hconsensus == null && !isDataset) + if (consensusProfiles == null && !isDataset) { if (!alignment.isNucleotide()) { @@ -1882,19 +2026,22 @@ 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); + initOccupancy(); + 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()) { @@ -1918,12 +2065,16 @@ public abstract class AlignmentViewport implements AlignViewportI, 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) @@ -1937,6 +2088,25 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + // these should be extracted from the view model - style and settings for + // derived annotation + private void initOccupancy() + { + if (showOccupancy) + { + occupancy = new AlignmentAnnotation("Occupancy", + MessageManager.getString("label.occupancy_descr"), + new Annotation[1], 0f, alignment.getHeight(), + AlignmentAnnotation.BAR_GRAPH); + occupancy.hasText = true; + occupancy.autoCalculated = true; + occupancy.scaleColLabel = true; + occupancy.graph = AlignmentAnnotation.BAR_GRAPH; + + alignment.addAnnotation(occupancy); + } + } + private void initConservation() { if (showConservation) @@ -1944,9 +2114,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); @@ -1961,7 +2131,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; @@ -1974,7 +2144,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; @@ -2066,6 +2237,9 @@ public abstract class AlignmentViewport implements AlignViewportI, boolean showprf = isShowSequenceLogo(); boolean showConsHist = isShowConsensusHistogram(); boolean normLogo = isNormaliseSequenceLogo(); + boolean showHMMPrf = isShowHMMSequenceLogo(); + boolean showInfoHist = isShowInformationHistogram(); + boolean normHMMLogo = isNormaliseHMMSequenceLogo(); /** * TODO reorder the annotation rows according to group/sequence ordering on @@ -2079,7 +2253,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++) @@ -2103,6 +2277,9 @@ public abstract class AlignmentViewport implements AlignViewportI, sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); + sg.setShowHMMSequenceLogo(showHMMPrf); + sg.setShowInformationHistogram(showInfoHist); + sg.setNormaliseHMMSequenceLogo(normHMMLogo); } if (conv) { @@ -2425,8 +2602,8 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle = new ViewStyle(settingsForView); if (residueShading != null) { - residueShading.setConservationApplied(settingsForView - .isConservationColourSelected()); + residueShading.setConservationApplied( + settingsForView.isConservationColourSelected()); } } @@ -2594,7 +2771,8 @@ public abstract class AlignmentViewport implements AlignViewportI, return sortAnnotationsBy; } - public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy) + public void setSortAnnotationsBy( + SequenceAnnotationOrder sortAnnotationsBy) { this.sortAnnotationsBy = sortAnnotationsBy; } @@ -2621,6 +2799,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 @@ -2639,76 +2829,9 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public ViewportPositionProps getPosProps() - { - return posProps; - } - - @Override - public int getStartRes() - { - return posProps.getStartRes(); - } - - @Override - public int getEndRes() - { - return posProps.getEndRes(); - } - - @Override - public int getStartSeq() - { - return posProps.getStartSeq(); - } - - public void setStartRes(int res) - { - posProps.setStartRes(res); - // this.startRes = res; - } - - public void setStartSeq(int seq) - { - posProps.setStartSeq(seq); - // this.startSeq = seq; - } - - public void setEndRes(int res) - { - posProps.setEndRes(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) - { - posProps.setEndSeq(seq); - /*if (seq > alignment.getHeight()) - { - seq = alignment.getHeight(); - } - if (seq < 0) - { - seq = 0; - } - this.endSeq = seq;*/ - } - - @Override - public int getEndSeq() + public ViewportRanges getRanges() { - return posProps.getEndSeq(); - // return endSeq; + return ranges; } /** @@ -2727,8 +2850,8 @@ public abstract class AlignmentViewport implements AlignViewportI, return 0; } boolean iAmProtein = !getAlignment().isNucleotide(); - AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement - .getAlignment(); + AlignmentI proteinAlignment = iAmProtein ? getAlignment() + : complement.getAlignment(); if (proteinAlignment == null) { return 0; @@ -2748,7 +2871,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(); @@ -2758,7 +2882,8 @@ 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)) @@ -2769,9 +2894,9 @@ public abstract class AlignmentViewport implements AlignViewportI, { continue; } - seqMappings = MappingUtils - .findMappingsForSequenceAndOthers(sequence, mappings, - getCodingComplement().getAlignment().getSequences()); + seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence, + mappings, + getCodingComplement().getAlignment().getSequences()); if (!seqMappings.isEmpty()) { break; @@ -2800,11 +2925,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public void expandColSelection(SequenceGroup sg, boolean wholewidth) { - if (!this.hasSelectedColumns()) - { - posProps.expandColSelection(sg, wholewidth); - } - /*int sgs, sge; + int sgs, sge; if (sg != null && (sgs = sg.getStartRes()) >= 0 && sg.getStartRes() <= (sge = sg.getEndRes()) && !this.hasSelectedColumns()) @@ -2822,7 +2943,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { colSel.addElement(cspos); } - }*/ + } } /** @@ -2830,7 +2951,6 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private boolean selectionIsDefinedGroup = false; - @Override public boolean isSelectionDefinedGroup() { @@ -2851,8 +2971,7 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionIsDefinedGroup = gps.contains(selectionGroup); } } - return selectionGroup.getContext() == alignment - || selectionIsDefinedGroup; + return selectionGroup.isDefined() || selectionIsDefinedGroup; } /** @@ -2860,6 +2979,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private SearchResultsI searchResults = null; + protected TreeModel currentTree = null; + @Override public boolean hasSearchResults() { @@ -2877,4 +2998,156 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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; + } + + public boolean hasReferenceAnnotation() + { + AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation(); + for (AlignmentAnnotation annot : annots) + { + if ("RF".equals(annot.label) || annot.label.contains("Reference")) + { + return true; + } + } + return false; + } + + @Override + public void setCurrentTree(TreeModel tree) + { + currentTree = tree; + } + + @Override + public TreeModel getCurrentTree() + { + return currentTree; + } + + @Override + public boolean isNormaliseSequenceLogo() + { + return normaliseSequenceLogo; + } + + public void setNormaliseSequenceLogo(boolean state) + { + normaliseSequenceLogo = state; + } + + @Override + public boolean isNormaliseHMMSequenceLogo() + { + return hmmNormaliseSequenceLogo; + } + + public void setNormaliseHMMSequenceLogo(boolean state) + { + hmmNormaliseSequenceLogo = state; + } + + /** + * flag set to indicate if structure views might be out of sync with sequences + * in the alignment + */ + + private boolean needToUpdateStructureViews = false; + + @Override + public boolean isUpdateStructures() + { + return needToUpdateStructureViews; + } + + @Override + public void setUpdateStructures(boolean update) + { + needToUpdateStructureViews = update; + } + + @Override + public boolean needToUpdateStructureViews() + { + boolean update = needToUpdateStructureViews; + needToUpdateStructureViews = false; + return update; + } + + @Override + public void addSequenceGroup(SequenceGroup sequenceGroup) + { + alignment.addGroup(sequenceGroup); + + Color col = sequenceGroup.idColour; + if (col != null) + { + col = col.brighter(); + + for (SequenceI sq : sequenceGroup.getSequences()) + { + setSequenceColour(sq, col); + } + } + + if (codingComplement != null) + { + SequenceGroup mappedGroup = MappingUtils + .mapSequenceGroup(sequenceGroup, this, codingComplement); + if (mappedGroup.getSequences().size() > 0) + { + codingComplement.getAlignment().addGroup(mappedGroup); + + if (col != null) + { + for (SequenceI seq : mappedGroup.getSequences()) + { + codingComplement.setSequenceColour(seq, col); + } + } + } + // propagate the structure view update flag according to our own setting + codingComplement.setUpdateStructures(needToUpdateStructureViews); + } + } }