X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=18c2aed5ccb2db613bdf425967e1a97d79e4207a;hb=f37c3fd4fe12799de498de5f397252e9f457fee9;hp=5d35775465d9d80082d8a682d8562e7c21bac48d;hpb=ac2aab2374e46ea0fd499a693f9e13958a3bfbca;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 5d35775..18c2aed 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,7 +34,6 @@ 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; @@ -57,6 +57,7 @@ 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; @@ -67,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; @@ -96,10 +98,69 @@ public abstract class AlignmentViewport 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; + /** - * alignment displayed in the viewport. Please use get/setter + * HMM profile for the alignment */ - protected AlignmentI 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) { @@ -580,14 +641,6 @@ public abstract class AlignmentViewport 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; @@ -598,18 +651,6 @@ public abstract class AlignmentViewport return isDataset; } - private Map hiddenRepSequences; - - protected ColumnSelection colSel = new ColumnSelection(); - - public boolean autoCalculateConsensus = true; - - protected boolean autoCalculateStrucConsensus = true; - - protected boolean ignoreGapsInConsensusCalculation = false; - - protected ResidueShaderI residueShading = new ResidueShader(); - @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -682,41 +723,6 @@ public abstract class AlignmentViewport { 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; - - /** - * 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) { @@ -736,9 +742,9 @@ public abstract class AlignmentViewport } @Override - public void setSequenceConsensusHash(ProfilesI hconsensus) + public void setConsensusProfiles(ProfilesI hconsensus) { - this.hconsensus = hconsensus; + this.consensusProfiles = hconsensus; } @Override @@ -748,9 +754,21 @@ public abstract class AlignmentViewport } @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 @@ -791,9 +809,9 @@ public abstract class AlignmentViewport } @Override - public AlignmentAnnotation getAlignmentGapAnnotation() + public AlignmentAnnotation getOccupancyAnnotation() { - return gapcounts; + return occupancy; } @Override @@ -882,6 +900,16 @@ public abstract class AlignmentViewport } } + @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) { @@ -945,18 +973,16 @@ public abstract class AlignmentViewport strucConsensus = null; conservation = null; quality = null; - groupConsensus = null; - groupConservation = null; - hconsensus = null; - hcomplementConsensus = null; + consensusProfiles = null; hconservation = null; - gapcounts = null; + hcomplementConsensus = null; + occupancy = null; calculator = null; - // colour scheme may hold reference to consensus - residueShading = null; - // TODO remove listeners from changeSupport? + residueShading = null; // may hold a reference to Consensus changeSupport = null; ranges = null; + currentTree = null; + selectionGroup = null; setAlignment(null); } @@ -1000,6 +1026,21 @@ public abstract class AlignmentViewport 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 @@ -1009,6 +1050,15 @@ public abstract class AlignmentViewport } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return hmmShowSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1026,6 +1076,18 @@ public abstract class AlignmentViewport 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 @@ -1036,6 +1098,14 @@ public abstract class AlignmentViewport } /** + * @param showInformationHistogram + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.hmmShowHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1081,6 +1151,17 @@ public abstract class AlignmentViewport } /** + * + * @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; @@ -1229,14 +1310,22 @@ public abstract class AlignmentViewport 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, colselhash = -1; @@ -1293,6 +1382,18 @@ public abstract class AlignmentViewport 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( @@ -1338,7 +1439,10 @@ public abstract class AlignmentViewport public void removePropertyChangeListener( java.beans.PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); + if (changeSupport != null) + { + changeSupport.removePropertyChangeListener(listener); + } } /** @@ -1677,13 +1781,6 @@ public abstract class AlignmentViewport } @Override - public CigarArray getViewAsCigars(boolean selectedRegionOnly) - { - return new CigarArray(alignment, alignment.getHiddenColumns(), - (selectedRegionOnly ? selectionGroup : null)); - } - - @Override public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly) { @@ -1744,8 +1841,12 @@ public abstract class AlignmentViewport if (alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = alignment.getHiddenColumns() - .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 { @@ -1772,10 +1873,10 @@ public abstract class AlignmentViewport { if (start == 0) { - start = hidden.adjustForHiddenColumns(start); + start = hidden.visibleToAbsoluteColumn(start); } - end = hidden.getHiddenBoundaryRight(start); + end = hidden.getNextHiddenBoundary(false, start); if (start == end) { end = max; @@ -1790,8 +1891,8 @@ public abstract class AlignmentViewport if (hidden != null && hidden.hasHiddenColumns()) { - start = hidden.adjustForHiddenColumns(end); - start = hidden.getHiddenBoundaryLeft(start) + 1; + start = hidden.visibleToAbsoluteColumn(end); + start = hidden.getNextHiddenBoundary(true, start) + 1; } } while (end < max); @@ -1813,13 +1914,13 @@ public abstract class AlignmentViewport AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - alignment.getHiddenColumns().makeVisibleAnnotation( + clone.makeVisibleAnnotation( selectionGroup.getStartRes(), selectionGroup.getEndRes(), - clone); + alignment.getHiddenColumns()); } else { - alignment.getHiddenColumns().makeVisibleAnnotation(clone); + clone.makeVisibleAnnotation(alignment.getHiddenColumns()); } ala.add(clone); } @@ -1852,18 +1953,6 @@ public abstract class AlignmentViewport { 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(); @@ -1886,7 +1975,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -1899,7 +1987,7 @@ public abstract class AlignmentViewport { rs.alignmentChanged(alignment, hiddenRepSequences); - rs.setConsensus(hconsensus); + rs.setConsensus(consensusProfiles); if (rs.conservationApplied()) { rs.setConservation(Conservation.calculateConservation("All", @@ -1924,7 +2012,7 @@ public abstract class AlignmentViewport // 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()) { @@ -1939,7 +2027,8 @@ public abstract class AlignmentViewport MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); - initGapCounts(); + + initOccupancy(); initComplementConsensus(); } @@ -1998,20 +2087,20 @@ public abstract class AlignmentViewport // these should be extracted from the view model - style and settings for // derived annotation - private void initGapCounts() + private void initOccupancy() { if (showOccupancy) { - gapcounts = new AlignmentAnnotation("Occupancy", + occupancy = 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; + occupancy.hasText = true; + occupancy.autoCalculated = true; + occupancy.scaleColLabel = true; + occupancy.graph = AlignmentAnnotation.BAR_GRAPH; - alignment.addAnnotation(gapcounts); + alignment.addAnnotation(occupancy); } } @@ -2145,6 +2234,9 @@ public abstract class AlignmentViewport 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 @@ -2182,6 +2274,9 @@ public abstract class AlignmentViewport sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); + sg.setShowHMMSequenceLogo(showHMMPrf); + sg.setShowInformationHistogram(showInfoHist); + sg.setNormaliseHMMSequenceLogo(normHMMLogo); } if (conv) { @@ -2785,7 +2880,7 @@ public abstract class AlignmentViewport int lastSeq = alignment.getHeight() - 1; List seqMappings = null; for (int seqNo = ranges - .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) @@ -2881,6 +2976,8 @@ public abstract class AlignmentViewport */ private SearchResultsI searchResults = null; + protected TreeModel currentTree = null; + @Override public boolean hasSearchResults() { @@ -2939,4 +3036,51 @@ public abstract class AlignmentViewport + ((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; + } }