X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=a9334ff46e15ac0c93d85b0ba4ca33ad5c0936b8;hb=3609d4b908fa64cab35f2348401baab3347188fc;hp=0eb13dfb946f5a04415b4ce49963f33ca7ce9bd9;hpb=8af8526d7448904c67db19f41e237a0eedd55a74;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 0eb13df..a9334ff 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,12 +34,9 @@ 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.ProfileI; -import jalview.datamodel.Profiles; import jalview.datamodel.ProfilesI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; @@ -70,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; @@ -83,7 +82,7 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { - final protected ViewportRanges ranges; + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -99,11 +98,31 @@ public abstract class AlignmentViewport protected Deque redoList = new ArrayDeque<>(); - /** * alignment displayed in the viewport. Please use get/setter */ protected AlignmentI alignment; + + /* + * probably unused indicator that view is of a dataset rather than an + * alignment + */ + + protected boolean ignoreBelowBackGroundFrequencyCalculation = false; + + protected boolean infoLetterHeight = false; + + protected AlignmentAnnotation occupancy; + + /** + * results of alignment consensus analysis for visible portion of view + */ + protected ProfilesI consensusProfiles; + + /** + * HMM profile for the alignment + */ + protected ProfilesI hmmProfiles; public AlignmentViewport(AlignmentI al) { @@ -409,6 +428,7 @@ public abstract class AlignmentViewport public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** @@ -590,7 +610,7 @@ public abstract class AlignmentViewport * alignment */ protected boolean isDataset = false; - + public void setDataset(boolean b) { isDataset = b; @@ -607,16 +627,12 @@ public abstract class AlignmentViewport public boolean autoCalculateConsensus = true; - public boolean autoCalculateInformation = true; - protected boolean autoCalculateStrucConsensus = true; protected boolean ignoreGapsInConsensusCalculation = false; - protected boolean ignoreBelowBackGroundFrequencyCalculation = false; - protected ResidueShaderI residueShading = new ResidueShader(); - + @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -648,6 +664,11 @@ public abstract class AlignmentViewport { 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); } @@ -663,7 +684,8 @@ public abstract class AlignmentViewport * 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, @@ -684,7 +706,7 @@ public abstract class AlignmentViewport { return residueShading; } - + protected AlignmentAnnotation consensus; protected AlignmentAnnotation complementConsensus; @@ -701,17 +723,11 @@ public abstract class AlignmentViewport protected AlignmentAnnotation[] groupConservation; - protected List groupInformation = new ArrayList<>(); - - protected List information = new ArrayList<>(); - /** * results of alignment consensus analysis for visible portion of view */ protected ProfilesI hconsensus = null; - protected List hinformation = new ArrayList<>(); - /** * results of cDNA complement consensus visible portion of view */ @@ -724,7 +740,7 @@ public abstract class AlignmentViewport protected Hashtable[] hStrucConsensus = null; protected Conservation hconservation = null; - + @Override public void setConservation(Conservation cons) { @@ -762,27 +778,15 @@ public abstract class AlignmentViewport } @Override - public void setSequenceInformationHashes(List info) + public void setHmmProfiles(ProfilesI info) { - hinformation = info; + hmmProfiles = info; } @Override - public void setSequenceInformationHash(ProfilesI info, int index) + public ProfilesI getHmmProfiles() { - hinformation.set(index, info); - } - - @Override - public List getSequenceInformationHashes() - { - return hinformation; - } - - @Override - public ProfilesI getSequenceInformationHash(int index) - { - return hinformation.get(index); + return hmmProfiles; } @Override @@ -823,18 +827,6 @@ public abstract class AlignmentViewport } @Override - public List getInformationAnnotations() - { - return information; - } - - @Override - public AlignmentAnnotation getInformationAnnotation(int index) - { - return information.get(index); - } - - @Override public AlignmentAnnotation getAlignmentGapAnnotation() { return gapcounts; @@ -926,18 +918,14 @@ public abstract class AlignmentViewport } } - /** - * trigger update of information annotation - */ @Override - public void updateInformation(final AlignmentViewPanel ap) + public void initInformationWorker(final AlignmentViewPanel ap) { if (calculator .getRegisteredWorkersOfClass(InformationThread.class) == null) { calculator.registerWorker(new InformationThread(this, ap)); } - } // --------START Structure Conservation @@ -1003,14 +991,19 @@ public abstract class AlignmentViewport strucConsensus = null; conservation = null; quality = null; + consensusProfiles = null; groupConsensus = null; groupConservation = null; hconsensus = null; + hconservation = null; hcomplementConsensus = null; - // colour scheme may hold reference to consensus - residueShading = null; - // TODO remove listeners from changeSupport? + gapcounts = null; + calculator = null; + residueShading = null; // may hold a reference to Consensus changeSupport = null; + ranges = null; + currentTree = null; + selectionGroup = null; setAlignment(null); } @@ -1056,17 +1049,17 @@ public abstract class AlignmentViewport /** * should hmm profile be rendered by default */ - protected boolean showHMMSequenceLogo = false; + protected boolean hmmShowSequenceLogo = false; /** * should hmm profile be rendered normalised to row height */ - protected boolean normaliseHMMSequenceLogo = false; + protected boolean hmmNormaliseSequenceLogo = false; /** * should information histograms be rendered by default */ - protected boolean showInformationHistogram = true; + protected boolean hmmShowHistogram = true; /** * @return the showConsensusProfile @@ -1083,7 +1076,7 @@ public abstract class AlignmentViewport @Override public boolean isShowHMMSequenceLogo() { - return showHMMSequenceLogo; + return hmmShowSequenceLogo; } /** @@ -1106,12 +1099,14 @@ public abstract class AlignmentViewport public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo) { - if (showHMMSequenceLogo != this.showHMMSequenceLogo) + if (showHMMSequenceLogo != this.hmmShowSequenceLogo) { - this.showHMMSequenceLogo = showHMMSequenceLogo; - calculator.updateAnnotationFor(InformationThread.class); + this.hmmShowSequenceLogo = showHMMSequenceLogo; + // TODO: updateAnnotation if description (tooltip) will show + // profile in place of information content? + // calculator.updateAnnotationFor(InformationThread.class); } - this.showHMMSequenceLogo = showHMMSequenceLogo; + this.hmmShowSequenceLogo = showHMMSequenceLogo; } /** @@ -1125,11 +1120,10 @@ public abstract class AlignmentViewport /** * @param showInformationHistogram - * the showInformationHistogram to set */ public void setShowInformationHistogram(boolean showInformationHistogram) { - this.showInformationHistogram = showInformationHistogram; + this.hmmShowHistogram = showInformationHistogram; } /** @@ -1185,7 +1179,7 @@ public abstract class AlignmentViewport @Override public boolean isShowInformationHistogram() { - return this.showInformationHistogram; + return this.hmmShowHistogram; } /** @@ -1276,7 +1270,7 @@ public abstract class AlignmentViewport @Override public boolean hasHiddenColumns() { - return colSel != null + return alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(); } @@ -1344,17 +1338,16 @@ public abstract class AlignmentViewport ignoreGapsInConsensusCalculation); } } - } public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) { ignoreBelowBackGroundFrequencyCalculation = b; - if (ap != null) - { - updateInformation(ap); - } + } + public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap) + { + infoLetterHeight = b; } private long sgrouphash = -1, colselhash = -1; @@ -1417,6 +1410,12 @@ public abstract class AlignmentViewport 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( @@ -1462,7 +1461,10 @@ public abstract class AlignmentViewport public void removePropertyChangeListener( java.beans.PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); + if (changeSupport != null) + { + changeSupport.removePropertyChangeListener(listener); + } } /** @@ -1523,6 +1525,9 @@ public abstract class AlignmentViewport // common hide/show seq stuff public void showAllHiddenSeqs() { + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + if (alignment.getHiddenSequences().getSize() > 0) { if (selectionGroup == null) @@ -1540,6 +1545,8 @@ public abstract class AlignmentViewport hiddenRepSequences = null; + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event @@ -1549,6 +1556,9 @@ public abstract class AlignmentViewport public void showSequence(int index) { + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + List tmp = alignment.getHiddenSequences().showSequence(index, hiddenRepSequences); if (tmp.size() > 0) @@ -1564,6 +1574,9 @@ public abstract class AlignmentViewport selectionGroup.addSequence(seq, false); setSequenceAnnotationsVisible(seq, true); } + + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); sendSelection(); } @@ -1585,6 +1598,11 @@ public abstract class AlignmentViewport 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++) @@ -1592,6 +1610,7 @@ public abstract class AlignmentViewport alignment.getHiddenSequences().hideSequence(seq[i]); setSequenceAnnotationsVisible(seq[i], false); } + ranges.setStartSeq(startSeq); firePropertyChange("alignment", null, alignment.getSequences()); } } @@ -1739,6 +1758,7 @@ public abstract class AlignmentViewport public void invertColumnSelection() { colSel.invertColumnSelection(0, alignment.getWidth(), alignment); + isColSelChanged(true); } @Override @@ -1784,13 +1804,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) { @@ -1802,7 +1815,8 @@ public abstract class AlignmentViewport boolean selectedOnly, boolean markGroups) { return new AlignmentView(alignment, alignment.getHiddenColumns(), - selectionGroup, alignment.getHiddenColumns() != null + selectionGroup, + alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(), selectedOnly, markGroups); } @@ -1850,8 +1864,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 { @@ -1878,10 +1896,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; @@ -1896,8 +1914,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); @@ -1919,13 +1937,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); } @@ -1970,15 +1988,6 @@ public abstract class AlignmentViewport { updateStrucConsensus(ap); } - updateInformation(ap); - - List hmmSequences; - hmmSequences = alignment.getHMMConsensusSequences(false); - - for (SequenceI seq : hmmSequences) - { - seq.updateHMMMapping(); - } // Reset endRes of groups if beyond alignment width int alWidth = alignment.getWidth(); @@ -2001,7 +2010,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -2112,35 +2120,6 @@ public abstract class AlignmentViewport } } - @Override - public void initInformation() - { - for (SequenceI seq : alignment.getHMMConsensusSequences(false)) - { - if (!seq.hasHMMAnnotation()) - { - AlignmentAnnotation information; - information = new AlignmentAnnotation(seq.getName(), - MessageManager.getString("label.information_description"), - new Annotation[1], 0f, 6.52f, - AlignmentAnnotation.BAR_GRAPH); - information.hasText = true; - information.autoCalculated = true; - information.hasText = true; - information.autoCalculated = false; - information.sequenceRef = seq; - information.setCalcId("HMM annotation"); - this.information.add(information); - hinformation.add(new Profiles(new ProfileI[1])); - alignment.addAnnotation(information); - seq.updateHMMMapping(); - seq.setHasInfo(true); - seq.addAlignmentAnnotation(information); - } - } - - } - // these should be extracted from the view model - style and settings for // derived annotation private void initGapCounts() @@ -2330,7 +2309,7 @@ public abstract class AlignmentViewport sg.setshowSequenceLogo(showprf); sg.setShowConsensusHistogram(showConsHist); sg.setNormaliseSequenceLogo(normLogo); - sg.setshowHMMSequenceLogo(showHMMPrf); + sg.setShowHMMSequenceLogo(showHMMPrf); sg.setShowInformationHistogram(showInfoHist); sg.setNormaliseHMMSequenceLogo(normHMMLogo); } @@ -2864,6 +2843,30 @@ public abstract class AlignmentViewport viewStyle.setProteinFontAsCdna(b); } + @Override + public void setShowComplementFeatures(boolean b) + { + viewStyle.setShowComplementFeatures(b); + } + + @Override + public boolean isShowComplementFeatures() + { + return viewStyle.isShowComplementFeatures(); + } + + @Override + public void setShowComplementFeaturesOnTop(boolean b) + { + viewStyle.setShowComplementFeaturesOnTop(b); + } + + @Override + public boolean isShowComplementFeaturesOnTop() + { + return viewStyle.isShowComplementFeaturesOnTop(); + } + /** * @return true if view should scroll to show the highlighted region of a * sequence @@ -2936,7 +2939,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)) @@ -3032,6 +3035,8 @@ public abstract class AlignmentViewport */ private SearchResultsI searchResults = null; + protected TreeModel currentTree = null; + @Override public boolean hasSearchResults() { @@ -3051,10 +3056,196 @@ public abstract class AlignmentViewport } /** - * Gets the selected hidden Markov model + * get the consensus sequence as displayed under the PID consensus annotation + * row. * - * @return + * @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); + } + } + + /** + * Filters out sequences with an eValue higher than the specified value. The + * filtered sequences are hidden or deleted. Sequences with no eValues are also + * filtered out. + * + * @param eValue + * @param delete + */ + public void filterByEvalue(double eValue) + { + for (SequenceI seq : alignment.getSequencesArray()) + { + if ((seq.getAnnotation("Search Scores") == null + || seq.getAnnotation("Search Scores")[0].getEValue() > eValue) + && seq.getHMM() == null) + { + hideSequence(new SequenceI[] { seq }); + } + } + } + + /** + * Filters out sequences with an score lower than the specified value. The + * filtered sequences are hidden or deleted. + * + * @param score + * @param delete + */ + public void filterByScore(double score) + { + for (SequenceI seq : alignment.getSequencesArray()) + { + if ((seq.getAnnotation("Search Scores") == null + || seq.getAnnotation("Search Scores")[0] + .getBitScore() < score) + && seq.getHMM() == null) + { + hideSequence(new SequenceI[] { seq }); + } + } + } }