JAL - 3690 AlignCalc rebuilt - FutureTask-based manager
[jalview.git] / src / jalview / workers / InformationThread.java
index d42598c..c8084b9 100644 (file)
@@ -44,73 +44,38 @@ public class InformationThread extends AlignCalcWorker
   @Override
   public void run()
   {
-    if (calcMan.isPending(this))
+    if (alignViewport.getAlignment().getHmmSequences().isEmpty())
     {
       return;
     }
-    calcMan.notifyStart(this);
-    // long started = System.currentTimeMillis();
-
-    try
+    if (alignViewport.isClosed())
     {
-      if (calcMan.isPending(this))
-      {
-        // another instance of this is waiting to run
-        calcMan.workerComplete(this);
-        return;
-      }
-      while (!calcMan.notifyWorking(this))
-      {
-        // another thread in progress, wait my turn
-        try
-        {
-          if (ap != null)
-          {
-            ap.paintAlignment(false, false);
-          }
-          Thread.sleep(200);
-        } catch (Exception ex)
-        {
-          ex.printStackTrace();
-        }
-      }
-      if (alignViewport.isClosed())
-      {
-        abortAndDestroy();
-        return;
-      }
+      abortAndDestroy();
+      return;
+    }
 
-      AlignmentI alignment = alignViewport.getAlignment();
-      int aWidth = alignment == null ? -1 : alignment.getWidth();
-      if (aWidth < 0)
-      {
-        calcMan.workerComplete(this);
-        return;
-      }
+    AlignmentI alignment = alignViewport.getAlignment();
+    int aWidth = alignment == null ? -1 : alignment.getWidth();
+    if (aWidth < 0)
+    {
+      return;
+    }
 
-      /*
-       * compute information profiles for any HMM consensus sequences
-       * for the alignment or sub-groups
-       */
-      computeProfiles(alignment);
+    /*
+     * compute information profiles for any HMM consensus sequences
+     * for the alignment or sub-groups
+     */
+    computeProfiles(alignment);
 
-      /*
-       * construct the corresponding annotations
-       */
-      updateAnnotation();
+    /*
+     * construct the corresponding annotations
+     */
+    updateAnnotation();
 
-      if (ap != null)
-      {
-        ap.adjustAnnotationHeight();
-        ap.paintAlignment(true, true);
-      }
-    } catch (OutOfMemoryError error)
+    if (ap != null)
     {
-      calcMan.disableWorker(this);
-      ap.raiseOOMWarning("calculating information", error);
-    } finally
-    {
-      calcMan.workerComplete(this);
+      ap.adjustAnnotationHeight();
+      ap.paintAlignment(true, true);
     }
   }
 
@@ -129,10 +94,10 @@ public class InformationThread extends AlignCalcWorker
     /*
      * alignment HMM profile
      */
-    SequenceI seq = alignment.getHmmConsensus();
-    if (seq != null)
+    List<SequenceI> seqs = alignment.getHmmSequences();
+    if (!seqs.isEmpty())
     {
-      HiddenMarkovModel hmm = seq.getHMM();
+      HiddenMarkovModel hmm = seqs.get(0).getHMM();
       ProfilesI hmmProfiles = AAFrequency.calculateHMMProfiles(hmm, width,
               0, width, alignViewport.isIgnoreBelowBackground(),
               alignViewport.isInfoLetterHeight());
@@ -145,10 +110,10 @@ public class InformationThread extends AlignCalcWorker
     List<SequenceGroup> groups = alignment.getGroups();
     for (SequenceGroup group : groups)
     {
-      seq = group.getHmmConsensus();
-      if (seq != null)
+      seqs = group.getHmmSequences();
+      if (!seqs.isEmpty())
       {
-        HiddenMarkovModel hmm = seq.getHMM();
+        HiddenMarkovModel hmm = seqs.get(0).getHMM();
         ProfilesI hmmProfiles = AAFrequency.calculateHMMProfiles(hmm, width,
                 0, width, group.isIgnoreBelowBackground(),
                 group.isUseInfoLetterHeight());
@@ -174,7 +139,7 @@ public class InformationThread extends AlignCalcWorker
    */
   protected AlignmentAnnotation getGapAnnotation()
   {
-    return alignViewport.getOccupancyAnnotation();
+               return alignViewport.getAlignmentGapAnnotation();
   }
 
   /**
@@ -193,20 +158,28 @@ public class InformationThread extends AlignCalcWorker
     /*
      * annotation for alignment HMM consensus if present
      */
-    SequenceI hmmSeq = alignment.getHmmConsensus();
-    ProfilesI profile = alignViewport.getHmmProfiles();
-    float m = updateInformationAnnotation(hmmSeq, profile, null, infos);
-    maxInformation = Math.max(maxInformation, m);
+    List<SequenceI> hmmSeqs = alignment.getHmmSequences();
+    if (!hmmSeqs.isEmpty())
+    {
+      ProfilesI profile = alignViewport.getHmmProfiles();
+      float m = updateInformationAnnotation(hmmSeqs.get(0), profile, null,
+              infos);
+      maxInformation = Math.max(maxInformation, m);
+    }
 
     /*
      * annotation for group HMM consensus if present
      */
     for (SequenceGroup group : alignment.getGroups())
     {
-      hmmSeq = group.getHmmConsensus();
-      ProfilesI profiles = group.getHmmProfiles();
-      m = updateInformationAnnotation(hmmSeq, profiles, group, infos);
-      maxInformation = Math.max(maxInformation, m);
+      hmmSeqs = group.getHmmSequences();
+      if (!hmmSeqs.isEmpty())
+      {
+        ProfilesI profiles = group.getHmmProfiles();
+        float m = updateInformationAnnotation(hmmSeqs.get(0), profiles,
+                group, infos);
+        maxInformation = Math.max(maxInformation, m);
+      }
     }
 
     /*