Merge branch 'develop' into features/mchmmer
[jalview.git] / src / jalview / analysis / AAFrequency.java
index 72b3d00..85a9bb0 100755 (executable)
@@ -161,10 +161,9 @@ public class AAFrequency
                   "WARNING: Consensus skipping null sequence - possible race condition.");
           continue;
         }
-        char[] seq = sequences[row].getSequence();
-        if (seq.length > column)
+        if (sequences[row].getLength() > column)
         {
-          char c = seq[column];
+          char c = sequences[row].getCharAt(column);
           residueCounts.add(c);
           if (Comparison.isNucleotide(c))
           {
@@ -224,7 +223,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 +233,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 +371,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 +383,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 +398,7 @@ public class AAFrequency
          * shorter than alignment width
          */
         information.annotations[i] = null;
-        return;
+        return 0;
       }
 
       HiddenMarkovModel hmm;
@@ -422,9 +420,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 +903,7 @@ public class AAFrequency
    * @return
    */
   public static int[] extractHMMProfile(HiddenMarkovModel hmm, int column,
-          boolean removeBelowBackground)
+          boolean removeBelowBackground, boolean infoHeight)
   {
 
     if (hmm != null)
@@ -914,7 +919,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 +972,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 +986,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());
   }