From 752bd6197b82c59d196b26a62edba81f16be2604 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 24 Sep 2012 17:39:34 +0100 Subject: [PATCH] JAL-958 JAL-966 refactor group/alignment associated conservation, consensus and logo logic to core model --- src/jalview/api/AlignViewportI.java | 10 ++++ src/jalview/appletgui/AlignmentPanel.java | 64 ++--------------------- src/jalview/gui/AlignmentPanel.java | 61 +--------------------- src/jalview/viewmodel/AlignmentViewport.java | 70 ++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 119 deletions(-) diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 54a1d6f..61b2950 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -117,4 +117,14 @@ public interface AlignViewportI void setHiddenRepSequences( Map hiddenRepSequences); + /** + * hides or shows dynamic annotation rows based on groups and group and alignment associated auto-annotation state flags + * apply the current group/autoannotation settings to the alignment view. + * Usually you should call the AlignmentViewPanel.adjustAnnotationHeight() method afterwards to ensure the annotation panel bounds are set correctly. + * @param applyGlobalSettings - apply to all autoannotation rows or just the ones associated with the current visible region + * @param preserveNewGroupSettings - don't apply global settings to groups which don't already have group associated annotation + */ + void updateGroupAnnotationSettings(boolean applyGlobalSettings, + boolean preserveNewGroupSettings); + } diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index ba6d873..fffe55a 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -906,65 +906,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme public void updateAnnotation(boolean applyGlobalSettings) { - // TODO: this should be merged with other annotation update stuff - that - // sits on AlignViewport - boolean updateCalcs = false; - boolean conv = av.isShowGroupConservation(); - boolean cons = av.isShowGroupConsensus(); - boolean showprf = av.isShowSequenceLogo(); - boolean showConsHist = av.isShowConsensusHistogram(); - - boolean sortg = true; - - // remove old automatic annotation - // add any new annotation - - ; // OrderedBy(av.alignment.getSequencesArray()); - // intersect alignment annotation with alignment groups - - AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation(); - Hashtable oldrfs = new Hashtable(); - if (aan != null) - { - for (int an = 0; an < aan.length; an++) - { - if (aan[an].autoCalculated && aan[an].groupRef != null) - { - oldrfs.put(aan[an].groupRef, aan[an].groupRef); - av.getAlignment().deleteAnnotation(aan[an]); - aan[an] = null; - } - } - } - if (av.getAlignment().getGroups()!= null) - { - for (SequenceGroup sg:av.getAlignment().getGroups()) - { - updateCalcs = false; - if (applyGlobalSettings || !oldrfs.containsKey(sg)) - { - // set defaults for this group's conservation/consensus - sg.setshowSequenceLogo(showprf); - sg.setShowConsensusHistogram(showConsHist); - } - if (conv) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConservationRow(), 0); - } - if (cons) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConsensus(), 0); - } - // refresh the annotation rows - if (updateCalcs) - { - sg.recalcConservation(); - } - } - } - oldrfs.clear(); + updateAnnotation(applyGlobalSettings, false); + } + public void updateAnnotation(boolean applyGlobalSettings, boolean preserveNewGroupSettings) + { + av.updateGroupAnnotationSettings(applyGlobalSettings, preserveNewGroupSettings); adjustAnnotationHeight(); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index bcdd620..ad7b995 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1402,66 +1402,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } public void updateAnnotation(boolean applyGlobalSettings, boolean preserveNewGroupSettings) { - // TODO: this should be merged with other annotation update stuff - that - // sits on AlignViewport - boolean updateCalcs = false; - boolean conv = av.isShowGroupConservation(); - boolean cons = av.isShowGroupConsensus(); - boolean showprf = av.isShowSequenceLogo(); - boolean showConsHist = av.isShowConsensusHistogram(); - boolean normLogo = av.isNormaliseSequenceLogo(); - - boolean sortg = true; - - // remove old automatic annotation - // add any new annotation - - // intersect alignment annotation with alignment groups - - AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation(); - Hashtable oldrfs = new Hashtable(); - if (aan != null) - { - for (int an = 0; an < aan.length; an++) - { - if (aan[an].autoCalculated && aan[an].groupRef != null) - { - oldrfs.put(aan[an].groupRef, aan[an].groupRef); - av.getAlignment().deleteAnnotation(aan[an]); - aan[an] = null; - } - } - } - if (av.getAlignment().getGroups()!=null) - { - for (SequenceGroup sg:av.getAlignment().getGroups()) - { - updateCalcs = false; - if (applyGlobalSettings || (!preserveNewGroupSettings && !oldrfs.containsKey(sg))) - { - // set defaults for this group's conservation/consensus - sg.setshowSequenceLogo(showprf); - sg.setShowConsensusHistogram(showConsHist); - sg.setNormaliseSequenceLogo(normLogo); - } - if (conv) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConservationRow(), 0); - } - if (cons) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConsensus(), 0); - } - // refresh the annotation rows - if (updateCalcs) - { - sg.recalcConservation(); - } - } - } - oldrfs.clear(); + av.updateGroupAnnotationSettings(applyGlobalSettings, preserveNewGroupSettings); adjustAnnotationHeight(); } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 27af11e..4ea4656 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -40,6 +40,7 @@ import jalview.workers.AlignCalcManager; import jalview.workers.ConsensusThread; import jalview.workers.StrucConsensusThread; +import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -1445,4 +1446,73 @@ public abstract class AlignmentViewport implements AlignViewportI } return height; } + + @Override + public void updateGroupAnnotationSettings(boolean applyGlobalSettings, + boolean preserveNewGroupSettings) + { + boolean updateCalcs = false; + boolean conv = isShowGroupConservation(); + boolean cons = isShowGroupConsensus(); + boolean showprf = isShowSequenceLogo(); + boolean showConsHist = isShowConsensusHistogram(); + boolean normLogo = isNormaliseSequenceLogo(); + + /** + * TODO reorder the annotation rows according to group/sequence ordering on alignment + */ + boolean sortg = true; + + // remove old automatic annotation + // add any new annotation + + // intersect alignment annotation with alignment groups + + AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation(); + List oldrfs = new ArrayList(); + if (aan != null) + { + for (int an = 0; an < aan.length; an++) + { + if (aan[an].autoCalculated && aan[an].groupRef != null) + { + oldrfs.add(aan[an].groupRef); + alignment.deleteAnnotation(aan[an]); + aan[an] = null; + } + } + } + if (alignment.getGroups() != null) + { + for (SequenceGroup sg : alignment.getGroups()) + { + updateCalcs = false; + if (applyGlobalSettings + || (!preserveNewGroupSettings && !oldrfs.contains(sg))) + { + // set defaults for this group's conservation/consensus + sg.setshowSequenceLogo(showprf); + sg.setShowConsensusHistogram(showConsHist); + sg.setNormaliseSequenceLogo(normLogo); + } + if (conv) + { + updateCalcs = true; + alignment.addAnnotation(sg.getConservationRow(), 0); + } + if (cons) + { + updateCalcs = true; + alignment.addAnnotation(sg.getConsensus(), 0); + } + // refresh the annotation rows + if (updateCalcs) + { + sg.recalcConservation(); + } + } + } + oldrfs.clear(); + } + } -- 1.7.10.2