X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=179bfa0a3a4658cb30feba6291f759965c084cb9;hb=cc4dc8e354640ad8b2c5b522f7a61a469546fa10;hp=536f76722459a14a585174bbd7dd333f0d4e454d;hpb=f35dfec0655116f4eb1afec4997eb496683687f6;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 536f767..179bfa0 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -23,7 +23,8 @@ package jalview.viewmodel; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; -import jalview.api.AlignCalcManagerI; +import jalview.api.AlignCalcManagerI2; +import jalview.api.AlignCalcWorkerI; import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; @@ -56,10 +57,12 @@ import jalview.util.MapList; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.styles.ViewStyle; -import jalview.workers.AlignCalcManager; +import jalview.workers.AlignCalcManager2; import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; +import jalview.workers.InformationThread; import jalview.workers.StrucConsensusThread; +import jalview.ws2.WebServiceExecutor; import java.awt.Color; import java.beans.PropertyChangeSupport; @@ -83,6 +86,9 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { + public static final String PROPERTY_ALIGNMENT = "alignment"; + public static final String PROPERTY_SEQUENCE = "sequence"; + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -103,6 +109,27 @@ public abstract class AlignmentViewport * 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) { @@ -590,7 +617,7 @@ public abstract class AlignmentViewport * alignment */ protected boolean isDataset = false; - + public void setDataset(boolean b) { isDataset = b; @@ -605,14 +632,35 @@ public abstract class AlignmentViewport protected ColumnSelection colSel = new ColumnSelection(); - public boolean autoCalculateConsensus = true; + protected boolean autoCalculateConsensusAndConservation = true; + + public boolean getAutoCalculateConsensusAndConservation() + { // BH 2019.07.24 + return autoCalculateConsensusAndConservation; + } + + public void setAutoCalculateConsensusAndConservation(boolean b) + { + autoCalculateConsensusAndConservation = b; + } protected boolean autoCalculateStrucConsensus = true; + public boolean getAutoCalculateStrucConsensus() + { // BH 2019.07.24 + return autoCalculateStrucConsensus; + } + + public void setAutoCalculateStrucConsensus(boolean b) + { + autoCalculateStrucConsensus = b; + } + + protected boolean ignoreGapsInConsensusCalculation = false; protected ResidueShaderI residueShading = new ResidueShader(); - + @Override public void setGlobalColourScheme(ColourSchemeI cs) { @@ -686,7 +734,7 @@ public abstract class AlignmentViewport { return residueShading; } - + protected AlignmentAnnotation consensus; protected AlignmentAnnotation complementConsensus; @@ -720,7 +768,7 @@ public abstract class AlignmentViewport protected Hashtable[] hStrucConsensus = null; protected Conservation hconservation = null; - + @Override public void setConservation(Conservation cons) { @@ -759,6 +807,18 @@ public abstract class AlignmentViewport } @Override + public void setHmmProfiles(ProfilesI info) + { + hmmProfiles = info; + } + + @Override + public ProfilesI getHmmProfiles() + { + return hmmProfiles; + } + + @Override public Hashtable[] getComplementConsensusHash() { return hcomplementConsensus; @@ -814,7 +874,7 @@ public abstract class AlignmentViewport return strucConsensus; } - protected AlignCalcManagerI calculator = new AlignCalcManager(); + protected AlignCalcManagerI2 calculator = new AlignCalcManager2(); /** * trigger update of conservation annotation @@ -824,12 +884,12 @@ public abstract class AlignmentViewport // see note in mantis : issue number 8585 if (alignment.isNucleotide() || (conservation == null && quality == null) - || !autoCalculateConsensus) + || !autoCalculateConsensusAndConservation) { return; } - if (calculator.getRegisteredWorkersOfClass( - jalview.workers.ConservationThread.class) == null) + if (calculator.getWorkersOfClass( + jalview.workers.ConservationThread.class).isEmpty()) { calculator.registerWorker( new jalview.workers.ConservationThread(this, ap)); @@ -842,12 +902,11 @@ public abstract class AlignmentViewport public void updateConsensus(final AlignmentViewPanel ap) { // see note in mantis : issue number 8585 - if (consensus == null || !autoCalculateConsensus) + if (consensus == null || !autoCalculateConsensusAndConservation) { return; } - if (calculator - .getRegisteredWorkersOfClass(ConsensusThread.class) == null) + if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty()) { calculator.registerWorker(new ConsensusThread(this, ap)); } @@ -878,16 +937,23 @@ public abstract class AlignmentViewport } if (doConsensus) { - if (calculator.getRegisteredWorkersOfClass( - ComplementConsensusThread.class) == null) + if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty()) { - calculator - .registerWorker(new ComplementConsensusThread(this, ap)); + calculator.registerWorker(new ComplementConsensusThread(this, ap)); } } } } + @Override + public void initInformationWorker(final AlignmentViewPanel ap) + { + if (calculator.getWorkersOfClass(InformationThread.class).isEmpty()) + { + calculator.registerWorker(new InformationThread(this, ap)); + } + } + // --------START Structure Conservation public void updateStrucConsensus(final AlignmentViewPanel ap) { @@ -903,8 +969,7 @@ public abstract class AlignmentViewport { return; } - if (calculator.getRegisteredWorkersOfClass( - StrucConsensusThread.class) == null) + if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty()) { calculator.registerWorker(new StrucConsensusThread(this, ap)); } @@ -923,7 +988,7 @@ public abstract class AlignmentViewport { return false; } - if (calculator.workingInvolvedWith(alignmentAnnotation)) + if (calculator.isWorkingWithAnnotation(alignmentAnnotation)) { // System.err.println("grey out ("+alignmentAnnotation.label+")"); return true; @@ -931,6 +996,13 @@ public abstract class AlignmentViewport return false; } + private WebServiceExecutor wsExecutor = new WebServiceExecutor(); + + public WebServiceExecutor getWSExecutor() + { + return wsExecutor; + } + public void setAlignment(AlignmentI align) { this.alignment = align; @@ -951,13 +1023,17 @@ public abstract class AlignmentViewport strucConsensus = null; conservation = null; quality = null; + consensusProfiles = null; groupConsensus = null; groupConservation = null; hconsensus = null; hconservation = null; hcomplementConsensus = null; gapcounts = null; + calculator.shutdown(); calculator = null; + wsExecutor.shutdown(); + wsExecutor = null; residueShading = null; // may hold a reference to Consensus changeSupport = null; ranges = null; @@ -975,7 +1051,7 @@ public abstract class AlignmentViewport } @Override - public AlignCalcManagerI getCalcManager() + public AlignCalcManagerI2 getCalcManager() { return calculator; } @@ -1006,6 +1082,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 @@ -1015,6 +1106,15 @@ public abstract class AlignmentViewport } /** + * @return the showInformationProfile + */ + @Override + public boolean isShowHMMSequenceLogo() + { + return hmmShowSequenceLogo; + } + + /** * @param showSequenceLogo * the new value */ @@ -1025,13 +1125,31 @@ public abstract class AlignmentViewport // TODO: decouple settings setting from calculation when refactoring // annotation update method from alignframe to viewport this.showSequenceLogo = showSequenceLogo; - calculator.updateAnnotationFor(ConsensusThread.class); - calculator.updateAnnotationFor(ComplementConsensusThread.class); - calculator.updateAnnotationFor(StrucConsensusThread.class); + for (AlignCalcWorkerI worker : calculator.getWorkers()) + { + if (worker.getClass().equals(ConsensusThread.class) || + worker.getClass().equals(ComplementConsensusThread.class) || + worker.getClass().equals(StrucConsensusThread.class)) + { + worker.updateAnnotation(); + } + } } 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 @@ -1042,6 +1160,14 @@ public abstract class AlignmentViewport } /** + * @param showInformationHistogram + */ + public void setShowInformationHistogram(boolean showInformationHistogram) + { + this.hmmShowHistogram = showInformationHistogram; + } + + /** * @return the showGroupConservation */ public boolean isShowGroupConservation() @@ -1087,6 +1213,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; @@ -1242,7 +1379,16 @@ public abstract class AlignmentViewport 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; @@ -1275,21 +1421,22 @@ public abstract class AlignmentViewport * checks current colsel against record of last hash value, and optionally * updates record. * - * @param b + * @param updateHash * update the record of last hash value * @return true if colsel changed since last call (when b is true) */ - public boolean isColSelChanged(boolean b) + public boolean isColSelChanged(boolean updateHash) { int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { - if (b) + if (updateHash) { colselhash = hc; } return true; } + notifySequence(); return false; } @@ -1299,6 +1446,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( @@ -1350,22 +1509,6 @@ public abstract class AlignmentViewport } } - /** - * Property change listener for changes in alignment - * - * @param prop - * DOCUMENT ME! - * @param oldvalue - * DOCUMENT ME! - * @param newvalue - * DOCUMENT ME! - */ - public void firePropertyChange(String prop, Object oldvalue, - Object newvalue) - { - changeSupport.firePropertyChange(prop, oldvalue, newvalue); - } - // common hide/show column stuff public void hideSelectedColumns() @@ -1430,13 +1573,14 @@ public abstract class AlignmentViewport ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event + notifySequence(); sendSelection(); } } + public void showSequence(int index) { int startSeq = ranges.getStartSeq(); @@ -1459,8 +1603,7 @@ public abstract class AlignmentViewport } ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); sendSelection(); } } @@ -1494,7 +1637,7 @@ public abstract class AlignmentViewport setSequenceAnnotationsVisible(seq[i], false); } ranges.setStartSeq(startSeq); - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); } } @@ -1859,11 +2002,11 @@ public abstract class AlignmentViewport { alignment.padGaps(); } - if (autoCalculateConsensus) + if (autoCalculateConsensusAndConservation) { updateConsensus(ap); } - if (hconsensus != null && autoCalculateConsensus) + if (hconsensus != null && autoCalculateConsensusAndConservation) { updateConservation(ap); } @@ -1893,7 +2036,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** @@ -1946,6 +2088,7 @@ public abstract class AlignmentViewport MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); + initGapCounts(); initComplementConsensus(); @@ -2152,6 +2295,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 @@ -2189,6 +2335,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) { @@ -2720,6 +2869,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 @@ -2949,6 +3122,19 @@ public abstract class AlignmentViewport 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) { @@ -2991,6 +3177,27 @@ public abstract class AlignmentViewport return ed; } + @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 @@ -3054,4 +3261,61 @@ public abstract class AlignmentViewport 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 }); + } + } + } + + /** + * Notify TreePanel and AlignmentPanel of some sort of alignment change. + */ + public void notifyAlignment() + { + changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences()); + } + + /** + * Notify AlignmentPanel of a sequence column selection or visibility changes. + */ + public void notifySequence() + { + changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null); + } }