JAL-98 first working version
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 23 Sep 2016 12:30:02 +0000 (13:30 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 23 Sep 2016 12:30:02 +0000 (13:30 +0100)
src/jalview/analysis/AAFrequency.java
src/jalview/analysis/Profile.java

index ef09fe8..274a114 100755 (executable)
@@ -176,6 +176,7 @@ public class AAFrequency
       }
       else
       {
+        // FIXME iterate over values keys instead
         for (v = 'A'; v <= 'Z'; v++)
         {
           // TODO why ignore values[v] == 1?
@@ -315,55 +316,55 @@ public class AAFrequency
       {
         mouseOver.append(hci.get(AAFrequency.MAXRESIDUE) + " ");
       }
-      int[][] profile = (int[][]) hci.get(AAFrequency.PROFILE);
+      // int[][] profile = (int[][]) hci.get(AAFrequency.PROFILE);
+      Profile profile = (Profile) hci.get(AAFrequency.PROFILE);
       if (profile != null && includeAllConsSymbols)
       {
-        int sequenceCount = profile[1][0];
-        int nonGappedCount = profile[1][1];
+        int sequenceCount = profile.height;// profile[1][0];
+        int nonGappedCount = profile.nonGapped;// [1][1];
         int normalisedBy = ignoreGapsInConsensusCalculation ? nonGappedCount
                 : sequenceCount;
         mouseOver.setLength(0);
-        if (alphabet != null)
+        // TODO do this sort once only in calculate()?
+        // char[][] ca = new char[profile[0].length][];
+        // /int length = profile[0].length;
+        int length = profile.profile.size();
+        char[] ca = new char[length];
+        // float[] vl = new float[length];
+        int[] vl = new int[length];
+        for (int c = 0; c < ca.length; c++)
         {
-          for (int c = 0; c < alphabet.length; c++)
+          int theChar = profile.profile.keyAt(c);
+          ca[c] = (char) theChar;// c;
+          // ca[c] = new char[]
+          // { (char) c };
+          vl[c] = profile.profile.get(theChar);// profile[0][c];
+        }
+
+        /*
+         * sort characters into ascending order of their counts
+         */
+        QuickSort.sort(vl, ca);
+
+        /*
+         * traverse in reverse order (highest count first) to build tooltip
+         */
+        // for (int p = 0, c = ca.length - 1; profile[0][ca[c]] > 0; c--)
+        for (int p = 0, c = ca.length - 1; c >= 0; c--)
+        {
+          final char residue = ca[c];
+          if (residue != '-')
           {
-            float tval = profile[0][alphabet[c]] * 100f / normalisedBy;
+            // float tval = profile[0][residue] * 100f / normalisedBy;
+            // float tval = profile[0][residue] * 100f / normalisedBy;
+            float tval = (vl[c] * 100f) / normalisedBy;
             mouseOver
-                    .append(((c == 0) ? "" : "; "))
-                    .append(alphabet[c])
+                    .append((((p == 0) ? "" : "; ")))
+                    .append(residue)
                     .append(" ")
                     .append(((fmt != null) ? fmt.form(tval) : ((int) tval)))
                     .append("%");
-          }
-        }
-        else
-        {
-          // TODO do this sort once only in calculate()?
-          // char[][] ca = new char[profile[0].length][];
-          char[] ca = new char[profile[0].length];
-          float[] vl = new float[profile[0].length];
-          for (int c = 0; c < ca.length; c++)
-          {
-            ca[c] = (char) c;
-            // ca[c] = new char[]
-            // { (char) c };
-            vl[c] = profile[0][c];
-          }
-          QuickSort.sort(vl, ca);
-          for (int p = 0, c = ca.length - 1; profile[0][ca[c]] > 0; c--)
-          {
-            final char residue = ca[c];
-            if (residue != '-')
-            {
-              float tval = profile[0][residue] * 100f / normalisedBy;
-              mouseOver
-                      .append((((p == 0) ? "" : "; ")))
-                      .append(residue)
-                      .append(" ")
-                      .append(((fmt != null) ? fmt.form(tval)
-                              : ((int) tval))).append("%");
-              p++;
-            }
+            p++;
           }
         }
       }
@@ -442,13 +443,22 @@ public class AAFrequency
     int nextArrayPos = 2;
     int totalPercentage = 0;
     int distinctValuesCount = 0;
-    final int divisor = profile[1][ignoreGaps ? 1 : 0];
-    for (int c = ca.length - 1; profile[0][ca[c]] > 0; c--)
+    final int divisor = ignoreGaps ? profile.nonGapped : profile.height;
+    // final int divisor = profile[1][ignoreGaps ? 1 : 0];
+    int j = profile.profile.size();
+    for (int i = 0; i < j; i++)
+//    for (int c = ca.length - 1; profile[0][ca[c]] > 0; c--)
     {
-      if (ca[c] != '-')
+      int theChar = profile.profile.keyAt(i);
+      int charCount = profile.profile.get(theChar);
+    
+//      if (ca[c] != '-')
+        if (theChar != '-')
       {
-        rtnval[nextArrayPos++] = ca[c];
-        final int percentage = (int) (profile[0][ca[c]] * 100f / divisor);
+//        rtnval[nextArrayPos++] = ca[c];
+        rtnval[nextArrayPos++] = theChar;
+//        final int percentage = (int) (profile[0][ca[c]] * 100f / divisor);
+        final int percentage = (charCount * 100) / divisor;
         rtnval[nextArrayPos++] = percentage;
         totalPercentage += percentage;
         distinctValuesCount++;
index ac2728b..b5857c7 100644 (file)
@@ -12,17 +12,17 @@ public class Profile
   /*
    * the number of sequences in the profile
    */
-  public final int ht;
+  public final int height;
 
   /*
    * the number of non-gapped sequences in the profile
    */
   public final int nonGapped;
 
-  public Profile(SparseIntArray counts, int height, int nongappedCount)
+  public Profile(SparseIntArray counts, int ht, int nongappedCount)
   {
     this.profile = counts;
-    this.ht = height;
+    this.height = ht;
     this.nonGapped = nongappedCount;
   }