JAL-2629 add option to set HMM Logo letter height to info content
[jalview.git] / src / jalview / analysis / AAFrequency.java
index 72b3d00..cc4f8f4 100755 (executable)
@@ -224,7 +224,7 @@ public class AAFrequency
    */
   public static ProfilesI calculateHMMProfiles(final HiddenMarkovModel hmm,
           int width, int start, int end, boolean saveFullProfile,
-          boolean removeBelowBackground)
+          boolean removeBelowBackground, boolean infoLetterHeight)
   {
     ProfileI[] result = new ProfileI[width];
     int symbolCount = hmm.getNumberOfSymbols();
@@ -234,7 +234,7 @@ public class AAFrequency
       for (char symbol : hmm.getSymbols())
       {
         int value = getAnalogueCount(hmm, column, symbol,
-                removeBelowBackground);
+                removeBelowBackground, infoLetterHeight);
         counts.put(symbol, value);
       }
       int maxCount = counts.getModalCount();
@@ -372,10 +372,9 @@ public class AAFrequency
    * @param nseq
    *          number of sequences
    */
-  public static void completeInformation(AlignmentAnnotation information,
-          ProfilesI profiles, int startCol, int endCol,
-          boolean ignoreBelowBackground,
-          boolean showSequenceLogo, long nseq)
+  public static float completeInformation(AlignmentAnnotation information,
+          ProfilesI profiles, int startCol, int endCol, long nseq,
+          Float currentMax)
   {
     // long now = System.currentTimeMillis();
     if (information == null || information.annotations == null
@@ -385,7 +384,7 @@ public class AAFrequency
        * called with a bad alignment annotation row 
        * wait for it to be initialised properly
        */
-      return;
+      return 0;
     }
 
     Float max = 0f;
@@ -400,7 +399,7 @@ public class AAFrequency
          * shorter than alignment width
          */
         information.annotations[i] = null;
-        return;
+        return 0;
       }
 
       HiddenMarkovModel hmm;
@@ -422,9 +421,16 @@ public class AAFrequency
                       .toUpperCase(hmm.getConsensusAtAlignColumn(i))),
               description, ' ', value);
     }
-    information.graphMax = max;
-    // long elapsed = System.currentTimeMillis() - now;
-    // System.out.println(-elapsed);
+    if (max > currentMax)
+    {
+      information.graphMax = max;
+      return max;
+    }
+    else
+    {
+      information.graphMax = currentMax;
+      return currentMax;
+    }
   }
 
   /**
@@ -898,7 +904,7 @@ public class AAFrequency
    * @return
    */
   public static int[] extractHMMProfile(HiddenMarkovModel hmm, int column,
-          boolean removeBelowBackground)
+          boolean removeBelowBackground, boolean infoHeight)
   {
 
     if (hmm != null)
@@ -914,7 +920,7 @@ public class AAFrequency
         char symbol = charList.get(i);
         symbols[i] = symbol;
         int value = getAnalogueCount(hmm, column, symbol,
-                removeBelowBackground);
+                removeBelowBackground, infoHeight);
         values[i] = value;
         totalCount += value;
       }
@@ -967,7 +973,7 @@ public class AAFrequency
    * @return
    */
   static int getAnalogueCount(HiddenMarkovModel hmm, int column,
-          char symbol, boolean removeBelowBackground)
+          char symbol, boolean removeBelowBackground, boolean infoHeight)
   {
     Double value;
 
@@ -981,6 +987,11 @@ public class AAFrequency
       return 0;
     }
 
+    if (infoHeight)
+    {
+      value = value * (Math.log(value / freq) / Math.log(2));
+    }
+
     value = value * 10000;
     return Math.round(value.floatValue());
   }