From: gmungoc Date: Wed, 21 Mar 2018 16:41:17 +0000 (+0000) Subject: JAL-2629 tweaks to Information annotation updating X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=51d3f6808e74f158d2ba4807ae4dbf6001b94e2b;p=jalview.git JAL-2629 tweaks to Information annotation updating --- diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index bcee815..6b3cbe8 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -500,11 +500,12 @@ public interface AlignViewportI extends ViewStyleI ProfilesI getHmmProfiles(); /** - * Updates all information annotations. + * Registers and starts a worker thread to calculate Information Content + * annotation, if it is not already registered * * @param ap */ - void updateInformation(AlignmentViewPanel ap); + void initInformationWorker(AlignmentViewPanel ap); boolean isInfoLetterHeight(); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index ce18735..28aabe1 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -234,7 +234,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, alignPanel); viewport.updateConservation(alignPanel); viewport.updateConsensus(alignPanel); - viewport.updateInformation(alignPanel); + viewport.initInformationWorker(alignPanel); displayNonconservedMenuItem.setState(viewport.getShowUnconserved()); followMouseOverFlag.setState(viewport.isFollowHighlight()); diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 83d8ade..730434f 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -554,8 +554,8 @@ public class AlignmentPanel extends Panel // this is called after loading new annotation onto alignment if (alignFrame.getSize().height == 0) { - System.out.println( - "adjustAnnotationHeight frame size zero NEEDS FIXING"); + // panel not laid out yet? + return; } fontChanged(); validateAnnotationDimensions(true); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 054991a..3fc24d2 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -787,7 +787,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, ap.av.updateConservation(ap); ap.av.updateConsensus(ap); ap.av.updateStrucConsensus(ap); - ap.av.updateInformation(ap); + ap.av.initInformationWorker(ap); } } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 7cefa03..2e70ca1 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -558,7 +558,6 @@ public class AnnotationLabels extends JPanel @Override public void actionPerformed(ActionEvent e) { - av.updateInformation(ap); av.setShowHMMSequenceLogo(cprof.getState()); ap.repaint(); } diff --git a/src/jalview/hmmer/HMMBuild.java b/src/jalview/hmmer/HMMBuild.java index 6887cb5..373c160 100644 --- a/src/jalview/hmmer/HMMBuild.java +++ b/src/jalview/hmmer/HMMBuild.java @@ -9,7 +9,6 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; -import jalview.gui.AlignmentPanel; import jalview.gui.JvOptionPane; import jalview.io.DataSourceType; import jalview.io.FileParse; @@ -67,7 +66,7 @@ public class HMMBuild extends HmmerCommand af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), msgID); - AlignViewportI viewport = af.getViewport(); + AlignViewport viewport = af.getViewport(); try { /* @@ -81,9 +80,9 @@ public class HMMBuild extends HmmerCommand } } finally { - viewport.updateInformation(af.alignPanel); - af.buildColourMenu(); // to enable HMMER colour schemes af.setProgressBar("", msgID); + viewport.alignmentChanged(af.alignPanel); + af.buildColourMenu(); // to enable HMMER colour schemes } } @@ -335,18 +334,9 @@ public class HMMBuild extends HmmerCommand alignment.setHmmConsensus(hmmSeq); } - AlignViewport viewport = af.getViewport(); - if (viewport != null) + if (af.getSelectedHMM() == null) { - AlignmentPanel alignPanel = viewport.getAlignPanel(); - viewport.alignmentChanged(alignPanel); - alignPanel.adjustAnnotationHeight(); - viewport.updateSequenceIdColours(); - - if (alignPanel.alignFrame.getSelectedHMM() == null) - { - alignPanel.alignFrame.setSelectedHMMSequence(hmmSeq); - } + af.setSelectedHMMSequence(hmmSeq); } } } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index ab67202..1cd4a31 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -900,18 +900,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 @@ -1313,7 +1309,6 @@ public abstract class AlignmentViewport ignoreGapsInConsensusCalculation = b; if (ap != null) { - updateConsensus(ap); if (residueShading != null) { residueShading.setThreshold(residueShading.getThreshold(), @@ -1324,22 +1319,12 @@ public abstract class AlignmentViewport public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap) { - boolean was = ignoreBelowBackGroundFrequencyCalculation; ignoreBelowBackGroundFrequencyCalculation = b; - if (ap != null && was != b) - { - updateInformation(ap); - } } public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap) { - boolean was = infoLetterHeight; infoLetterHeight = b; - if (ap != null && was != b) - { - updateInformation(ap); - } } private long sgrouphash = -1, colselhash = -1; @@ -1967,20 +1952,20 @@ public abstract class AlignmentViewport { alignment.padGaps(); } - if (autoCalculateConsensus) - { - updateConsensus(ap); - } - if (consensusProfiles != null && autoCalculateConsensus) - { - updateConservation(ap); - } - if (autoCalculateStrucConsensus) - { - updateStrucConsensus(ap); - } - // initInformation(); - updateInformation(ap); + // if (autoCalculateConsensus) + // { + // updateConsensus(ap); + // } + // if (consensusProfiles != null && autoCalculateConsensus) + // { + // updateConservation(ap); + // } + // if (autoCalculateStrucConsensus) + // { + // updateStrucConsensus(ap); + // } + // + // updateInformation(ap); // Reset endRes of groups if beyond alignment width int alWidth = alignment.getWidth(); @@ -2003,7 +1988,6 @@ public abstract class AlignmentViewport updateAllColourSchemes(); calculator.restartWorkers(); - // alignment.adjustSequenceAnnotations(); } /** diff --git a/src/jalview/workers/InformationThread.java b/src/jalview/workers/InformationThread.java index 28b4962..c9696a5 100644 --- a/src/jalview/workers/InformationThread.java +++ b/src/jalview/workers/InformationThread.java @@ -12,6 +12,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import java.util.ArrayList; import java.util.List; /** @@ -24,8 +25,6 @@ public class InformationThread extends AlignCalcWorker { public static final String HMM_CALC_ID = "HMM"; - private float max = 0f; - /** * Constructor * @@ -80,17 +79,24 @@ public class InformationThread extends AlignCalcWorker abortAndDestroy(); return; } - AlignmentI alignment = alignViewport.getAlignment(); + AlignmentI alignment = alignViewport.getAlignment(); int aWidth = alignment == null ? -1 : alignment.getWidth(); - if (aWidth < 0) { calcMan.workerComplete(this); return; } + /* + * compute information profiles for any HMM consensus sequences + * for the alignment or sub-groups + */ computeProfiles(alignment); + + /* + * construct the corresponding annotations + */ updateAnnotation(); if (ap != null) @@ -181,14 +187,16 @@ public class InformationThread extends AlignCalcWorker { AlignmentI alignment = alignViewport.getAlignment(); - this.max = 0f; + float maxInformation = 0f; + List infos = new ArrayList<>(); /* * annotation for alignment HMM consensus if present */ SequenceI hmmSeq = alignment.getHmmConsensus(); ProfilesI profile = alignViewport.getHmmProfiles(); - updateInformationAnnotation(hmmSeq, profile, null); + float m = updateInformationAnnotation(hmmSeq, profile, null, infos); + maxInformation = Math.max(maxInformation, m); /* * annotation for group HMM consensus if present @@ -197,42 +205,52 @@ public class InformationThread extends AlignCalcWorker { hmmSeq = group.getHmmConsensus(); ProfilesI profiles = group.getHmmProfiles(); - updateInformationAnnotation(hmmSeq, profiles, group); + m = updateInformationAnnotation(hmmSeq, profiles, group, infos); + maxInformation = Math.max(maxInformation, m); } /* - * todo: this.max is not used, but acquires the maximum value of - * information in any of the annotations; set this as graphMax in all - * annotations to have them all scaled the same + * maxInformation holds the maximum value of information score; + * set this as graphMax in all annotations to scale them all the same */ + for (AlignmentAnnotation ann : infos) + { + ann.graphMax = maxInformation; + } } /** * Updates (and first constructs if necessary) an HMM Profile information * content annotation for a sequence. The group argument is null - * for the whole alignment annotation, not null for a subgroup annotation. + * for the whole alignment annotation, not null for a subgroup annotation. The + * updated annotation is added to the infos list. Answers the + * maximum information content value of any annotation (for use as a scaling + * factor for display). * * @param seq * @param profile * @param group + * @param infos * @return */ - protected AlignmentAnnotation updateInformationAnnotation(SequenceI seq, - ProfilesI profile, SequenceGroup group) + protected float updateInformationAnnotation(SequenceI seq, + ProfilesI profile, SequenceGroup group, + List infos) { if (seq == null || profile == null) { - return null; + return 0f; } AlignmentAnnotation ann = findOrCreateAnnotation(seq, group); seq.addAlignmentAnnotation(ann); + infos.add(ann); - max = AAFrequency.completeInformation(ann, profile, + float max = AAFrequency.completeInformation(ann, profile, profile.getStartColumn(), profile.getEndColumn() + 1); - return ann; + return max; } /** @@ -266,6 +284,7 @@ public class InformationThread extends AlignCalcWorker { info = ann; info.setSequenceRef(seq); + info.label = seq.getName(); // in case group name changed! break; } }