JAL-2599 fix for information annotation buttons
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 61b0b00..91caebc 100644 (file)
@@ -57,6 +57,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;
@@ -606,6 +607,8 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   public boolean autoCalculateConsensus = true;
 
+  public boolean autoCalculateInformation = true;
+
   protected boolean autoCalculateStrucConsensus = true;
 
   protected boolean ignoreGapsInConsensusCalculation = false;
@@ -699,7 +702,14 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   protected AlignmentAnnotation[] groupConservation;
 
-  protected AlignmentAnnotation informationContent;
+  protected AlignmentAnnotation[] groupInformation;
+
+  protected AlignmentAnnotation information;
+
+  /**
+   * results of alignment information analysis for visible portion of view
+   */
+  protected ProfilesI hinformation = null;
 
   /**
    * results of alignment consensus analysis for visible portion of view
@@ -756,6 +766,18 @@ public abstract class AlignmentViewport implements AlignViewportI,
   }
 
   @Override
+  public ProfilesI setSequenceInformationHash()
+  {
+    return hinformation;
+  }
+
+  @Override
+  public ProfilesI getSequenceInformationHash()
+  {
+    return hinformation;
+  }
+
+  @Override
   public Hashtable[] getComplementConsensusHash()
   {
     return hcomplementConsensus;
@@ -795,7 +817,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
   @Override
   public AlignmentAnnotation getAlignmentInformationAnnotation()
   {
-    return informationContent;
+    return information;
   }
 
   @Override
@@ -889,6 +911,23 @@ public abstract class AlignmentViewport implements AlignViewportI,
     }
   }
 
+  /**
+   * trigger update of information annotation
+   */
+  public void updateInformation(final AlignmentViewPanel ap)
+  {
+    if (information == null)
+    {
+      return;
+    }
+    if (calculator
+            .getRegisteredWorkersOfClass(InformationThread.class) == null)
+    {
+      calculator.registerWorker(new InformationThread(this, ap));
+    }
+
+  }
+
   // --------START Structure Conservation
   public void updateStrucConsensus(final AlignmentViewPanel ap)
   {
@@ -946,6 +985,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
      * defensively null out references to large objects in case
      * this object is not garbage collected (as if!)
      */
+    information = null;
     consensus = null;
     complementConsensus = null;
     strucConsensus = null;
@@ -1057,6 +1097,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
     if (showHMMSequenceLogo != this.showHMMSequenceLogo)
     {
       this.showHMMSequenceLogo = showHMMSequenceLogo;
+      calculator.updateAnnotationFor(InformationThread.class);
     }
     this.showHMMSequenceLogo = showHMMSequenceLogo;
   }
@@ -1299,12 +1340,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
     ignoreBelowBackGroundFrequencyCalculation = b;
     if (ap != null)
     {
-      // updateConsensus(ap);
-      if (residueShading != null)
-      {
-        residueShading.setThreshold(residueShading.getThreshold(),
-                ignoreBelowBackGroundFrequencyCalculation);
-      }
+      updateInformation(ap);
     }
 
   }
@@ -1923,6 +1959,10 @@ public abstract class AlignmentViewport implements AlignViewportI,
     {
       updateStrucConsensus(ap);
     }
+    if (information != null)
+    {
+      updateInformation(ap);
+    }
 
     // Reset endRes of groups if beyond alignment width
     int alWidth = alignment.getWidth();
@@ -1959,6 +1999,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
       rs.alignmentChanged(alignment, hiddenRepSequences);
 
       rs.setConsensus(hconsensus);
+      rs.setInformation(hinformation);
       if (rs.conservationApplied())
       {
         rs.setConservation(Conservation.calculateConservation("All",
@@ -2005,6 +2046,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
     }
   }
 
+
   /**
    * If this is a protein alignment and there are mappings to cDNA, adds the
    * cDNA consensus annotation and returns true, else returns false.
@@ -2056,6 +2098,19 @@ public abstract class AlignmentViewport implements AlignViewportI,
     }
   }
 
+  public void initInformation(SequenceI hmmSequence)
+  {
+    information = new AlignmentAnnotation("Information",
+            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 = hmmSequence;
+    alignment.addAnnotation(information);
+  }
+
   // these should be extracted from the view model - style and settings for
   // derived annotation
   private void initGapCounts()
@@ -2205,6 +2260,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
@@ -2242,6 +2300,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)
         {