JAL-891; Sorting of Structure logo implemented; bug that caused
[jalview.git] / src / jalview / analysis / StructureFrequency.java
index 9bdaa10..c253dce 100644 (file)
@@ -96,8 +96,11 @@ public class StructureFrequency
       values = new int[255];
       pairs = new int[255][255];
       bpEnd = -1;
-
-      s = struc[i];
+      if(i<struc.length){
+        s = struc[i];
+      }else{
+        s = '-';
+      }
       if (s == '.' || s == ' ')
       {
         s = '-';
@@ -322,6 +325,7 @@ public class StructureFrequency
               .get(StructureFrequency.PROFILE);
       if (profile != null && includeAllConsSymbols) // Just responsible for the
       // tooltip
+      //TODO Update tooltips for Structure row
       {
         mouseOver = "";
         if (alphabet != null)
@@ -396,21 +400,32 @@ public class StructureFrequency
     if (profile == null)
       return null;
     
-    rtnval[0] = 1;
-    for (int j = 65; j <= 90; j++)
+    Object[] ca = new Object[625];
+    float[] vl = new float[625];
+    int x=0;
+    for (int c = 65; c < 90; c++)
     {
-      for (int k = 65; k <= 90; k++)
+      for(int d = 65; d< 90; d++)
       {
-        if (pairs[j][k] > 0)
-        {
-          rtnval[rtnval[0]++] = j;
-          rtnval[rtnval[0]++] = k;
-          rtnval[rtnval[0]++] = (int) ((float) pairs[j][k] * 100f / (float) profile[1][ignoreGapsInConsensusCalculation ? 1
-                  : 0]);
-        }
+      ca[x] = new int[]{ c, d};
+      vl[x] = (float) pairs[c][d];
+      x++;
       }
     }
-
+    jalview.util.QuickSort.sort(vl, ca);
+    
+    rtnval[0] = 1;
+    for (int c=624; c>0; c--)
+    {
+      if (vl[c]>0)
+      {
+        rtnval[rtnval[0]++] = ((int[]) ca[c])[0];
+        rtnval[rtnval[0]++] = ((int[]) ca[c])[1];
+        rtnval[rtnval[0]++] = (int) ((float) vl[c] * 100f / (float) profile[1][ignoreGapsInConsensusCalculation ? 1
+                : 0]);
+       }
+    }
+    
     return rtnval;
   }