X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=0ec07c00ba0be93a8c8133bbcb2d26648f8b97b2;hb=9d33b5ee5b7c2973287147726e43f0c0486b4c0e;hp=60cee46bffe03d8c89b689a56e69c8716e36d151;hpb=3f91bb1385ab9ac8fdd15e3bc9378f5b554e1642;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 60cee46..0ec07c0 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -37,6 +37,8 @@ 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; @@ -57,6 +59,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; @@ -77,8 +80,8 @@ import java.util.Map; * @author jimp * */ -public abstract class AlignmentViewport implements AlignViewportI, - CommandListener, VamsasSource +public abstract class AlignmentViewport + implements AlignViewportI, CommandListener, VamsasSource { final protected ViewportRanges ranges; @@ -96,6 +99,7 @@ public abstract class AlignmentViewport implements AlignViewportI, protected Deque redoList = new ArrayDeque<>(); + /** * alignment displayed in the viewport. Please use get/setter */ @@ -405,6 +409,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** @@ -567,8 +572,6 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle.setSeqNameItalics(default1); } - - @Override public AlignmentI getAlignment() { @@ -605,10 +608,14 @@ public abstract class AlignmentViewport implements AlignViewportI, 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 @@ -642,6 +649,11 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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); } @@ -660,8 +672,8 @@ public abstract class AlignmentViewport implements AlignViewportI, sg.setColourScheme(cs); if (cs != null) { - sg.getGroupColourScheme() - .alignmentChanged(sg, hiddenRepSequences); + sg.getGroupColourScheme().alignmentChanged(sg, + hiddenRepSequences); } } } @@ -670,8 +682,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public ColourSchemeI getGlobalColourScheme() { - return residueShading == null ? null : residueShading - .getColourScheme(); + return residueShading == null ? null : residueShading.getColourScheme(); } @Override @@ -696,12 +707,21 @@ public abstract class AlignmentViewport implements AlignViewportI, 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; /** + * results of information annotation analysis for the visible portion of view + */ + protected List hinformation = new ArrayList<>(); + + /** * results of cDNA complement consensus visible portion of view */ protected Hashtable[] hcomplementConsensus = null; @@ -751,6 +771,30 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public void setSequenceInformationHashes(List info) + { + hinformation = info; + } + + @Override + public void setSequenceInformationHash(ProfilesI info, int index) + { + hinformation.set(index, info); + } + + @Override + public List getSequenceInformationHashes() + { + return hinformation; + } + + @Override + public ProfilesI getSequenceInformationHash(int index) + { + return hinformation.get(index); + } + + @Override public Hashtable[] getComplementConsensusHash() { return hcomplementConsensus; @@ -788,6 +832,18 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public List getInformationAnnotations() + { + return information; + } + + @Override + public AlignmentAnnotation getInformationAnnotation(int index) + { + return information.get(index); + } + + @Override public AlignmentAnnotation getAlignmentGapAnnotation() { return gapcounts; @@ -819,11 +875,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)); } } @@ -837,7 +893,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)); } @@ -868,8 +925,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)); @@ -878,6 +935,20 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + /** + * trigger update of information annotation + */ + @Override + public void updateInformation(final AlignmentViewPanel ap) + { + if (calculator + .getRegisteredWorkersOfClass(InformationThread.class) == null) + { + calculator.registerWorker(new InformationThread(this, ap)); + } + + } + // --------START Structure Conservation public void updateStrucConsensus(final AlignmentViewPanel ap) { @@ -893,7 +964,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)); } @@ -991,6 +1063,21 @@ public abstract class AlignmentViewport implements AlignViewportI, protected boolean showConsensusHistogram = true; /** + * should hmm profile be rendered by default + */ + protected boolean showHMMSequenceLogo = false; + + /** + * should hmm profile be rendered normalised to row height + */ + protected boolean normaliseHMMSequenceLogo = false; + + /** + * should information histograms be rendered by default + */ + protected boolean showInformationHistogram = true; + + /** * @return the showConsensusProfile */ @Override @@ -1000,6 +1087,15 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return showHMMSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1017,6 +1113,16 @@ public abstract class AlignmentViewport implements AlignViewportI, this.showSequenceLogo = showSequenceLogo; } + public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo) + { + if (showHMMSequenceLogo != this.showHMMSequenceLogo) + { + this.showHMMSequenceLogo = showHMMSequenceLogo; + calculator.updateAnnotationFor(InformationThread.class); + } + this.showHMMSequenceLogo = showHMMSequenceLogo; + } + /** * @param showConsensusHistogram * the showConsensusHistogram to set @@ -1027,6 +1133,15 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * @param showInformationHistogram + * the showInformationHistogram to set + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.showInformationHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1072,6 +1187,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.showInformationHistogram; + } + + /** * when set, updateAlignment will always ensure sequences are of equal length */ private boolean padGaps = false; @@ -1159,7 +1285,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public boolean hasHiddenColumns() { - return colSel != null + return alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(); } @@ -1182,8 +1308,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); } @@ -1230,6 +1356,16 @@ public abstract class AlignmentViewport implements AlignViewportI, } + public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) + { + ignoreBelowBackGroundFrequencyCalculation = b; + if (ap != null) + { + updateInformation(ap); + } + + } + private long sgrouphash = -1, colselhash = -1; /** @@ -1284,6 +1420,12 @@ public abstract class AlignmentViewport implements AlignViewportI, return ignoreGapsInConsensusCalculation; } + @Override + public boolean isIgnoreBelowBackground() + { + return ignoreBelowBackGroundFrequencyCalculation; + } + // property change stuff // JBPNote Prolly only need this in the applet version. private PropertyChangeSupport changeSupport = new PropertyChangeSupport( @@ -1390,6 +1532,9 @@ public abstract class AlignmentViewport implements AlignViewportI, // common hide/show seq stuff public void showAllHiddenSeqs() { + int startSeq = ranges.getStartSeq(); + int endSeq = ranges.getEndSeq(); + if (alignment.getHiddenSequences().getSize() > 0) { if (selectionGroup == null) @@ -1397,8 +1542,8 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup = new SequenceGroup(); selectionGroup.setEndRes(alignment.getWidth() - 1); } - List tmp = alignment.getHiddenSequences().showAll( - hiddenRepSequences); + List tmp = alignment.getHiddenSequences() + .showAll(hiddenRepSequences); for (SequenceI seq : tmp) { selectionGroup.addSequence(seq, false); @@ -1407,6 +1552,8 @@ public abstract class AlignmentViewport implements AlignViewportI, hiddenRepSequences = null; + ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); + firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event @@ -1416,8 +1563,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public void showSequence(int index) { - 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) @@ -1431,6 +1581,9 @@ 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(); } @@ -1452,6 +1605,11 @@ public abstract class AlignmentViewport implements AlignViewportI, public void hideSequence(SequenceI[] seq) { + /* + * cache offset to first visible sequence + */ + int startSeq = ranges.getStartSeq(); + if (seq != null) { for (int i = 0; i < seq.length; i++) @@ -1459,6 +1617,7 @@ public abstract class AlignmentViewport implements AlignViewportI, alignment.getHiddenSequences().hideSequence(seq[i]); setSequenceAnnotationsVisible(seq[i], false); } + ranges.setStartSeq(startSeq); firePropertyChange("alignment", null, alignment.getSequences()); } } @@ -1488,8 +1647,8 @@ 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); @@ -1579,8 +1738,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isHiddenRepSequence(SequenceI seq) { - return (hiddenRepSequences != null && hiddenRepSequences - .containsKey(seq)); + return (hiddenRepSequences != null + && hiddenRepSequences.containsKey(seq)); } /** @@ -1598,8 +1757,8 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public int adjustForHiddenSeqs(int alignmentIndex) { - return alignment.getHiddenSequences().adjustForHiddenSeqs( - alignmentIndex); + return alignment.getHiddenSequences() + .adjustForHiddenSeqs(alignmentIndex); } @Override @@ -1669,10 +1828,10 @@ public abstract class AlignmentViewport implements AlignViewportI, boolean selectedOnly, boolean markGroups) { return new AlignmentView(alignment, alignment.getHiddenColumns(), - selectionGroup, alignment.getHiddenColumns() != null + selectionGroup, + alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns(), - selectedOnly, - markGroups); + selectedOnly, markGroups); } @Override @@ -1718,8 +1877,8 @@ public abstract class AlignmentViewport implements AlignViewportI, if (alignment.getHiddenColumns() != null && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = alignment.getHiddenColumns().getVisibleSequenceStrings( - start, end, seqs); + selection = alignment.getHiddenColumns() + .getVisibleSequenceStrings(start, end, seqs); } else { @@ -1788,8 +1947,8 @@ public abstract class AlignmentViewport implements AlignViewportI, if (selectedOnly && selectionGroup != null) { alignment.getHiddenColumns().makeVisibleAnnotation( - selectionGroup.getStartRes(), - selectionGroup.getEndRes(), clone); + selectionGroup.getStartRes(), selectionGroup.getEndRes(), + clone); } else { @@ -1838,6 +1997,15 @@ public abstract class AlignmentViewport implements AlignViewportI, { 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(); @@ -1913,6 +2081,7 @@ public abstract class AlignmentViewport implements AlignViewportI, MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); + initGapCounts(); initComplementConsensus(); @@ -1970,6 +2139,35 @@ public abstract class AlignmentViewport implements AlignViewportI, } } + @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() @@ -1978,8 +2176,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { gapcounts = new AlignmentAnnotation("Occupancy", MessageManager.getString("label.occupancy_descr"), - new Annotation[1], 0f, - alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH); + new Annotation[1], 0f, alignment.getHeight(), + AlignmentAnnotation.BAR_GRAPH); gapcounts.hasText = true; gapcounts.autoCalculated = true; gapcounts.scaleColLabel = true; @@ -1997,8 +2195,8 @@ public abstract class AlignmentViewport implements AlignViewportI, { conservation = new AlignmentAnnotation("Conservation", MessageManager.formatMessage("label.conservation_descr", - getConsPercGaps()), new Annotation[1], - 0f, 11f, AlignmentAnnotation.BAR_GRAPH); + getConsPercGaps()), + new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH); conservation.hasText = true; conservation.autoCalculated = true; alignment.addAnnotation(conservation); @@ -2119,6 +2317,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 @@ -2156,6 +2357,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) { @@ -2478,8 +2682,8 @@ public abstract class AlignmentViewport implements AlignViewportI, viewStyle = new ViewStyle(settingsForView); if (residueShading != null) { - residueShading.setConservationApplied(settingsForView - .isConservationColourSelected()); + residueShading.setConservationApplied( + settingsForView.isConservationColourSelected()); } } @@ -2647,7 +2851,8 @@ public abstract class AlignmentViewport implements AlignViewportI, return sortAnnotationsBy; } - public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy) + public void setSortAnnotationsBy( + SequenceAnnotationOrder sortAnnotationsBy) { this.sortAnnotationsBy = sortAnnotationsBy; } @@ -2725,8 +2930,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; @@ -2757,7 +2962,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ int lastSeq = alignment.getHeight() - 1; List seqMappings = null; - for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + for (int seqNo = ranges + .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) @@ -2768,9 +2974,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; @@ -2870,4 +3076,45 @@ 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; + } }