JAL-958 JAL-966 refactor group/alignment associated conservation, consensus and logo...
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 27af11e..4ea4656 100644 (file)
@@ -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<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
+    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();
+  }
+
 }