JAL-2629 tweaks to Information annotation updating
[jalview.git] / src / jalview / workers / InformationThread.java
index 28b4962..c9696a5 100644 (file)
@@ -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<AlignmentAnnotation> 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 <code>group</code> 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 <code>infos</code> 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<AlignmentAnnotation> 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;
         }
       }