JAL-891; Labeling of structure conservation is improved a bit.
[jalview.git] / src / jalview / analysis / StructureFrequency.java
index 9bdaa10..7b97a8d 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 = '-';
@@ -141,11 +144,11 @@ public class StructureFrequency
             cEnd = seq[bpEnd];
             if (checkBpType(c, cEnd))
             {
-              values['H']++; // H means it's a helix (structured)
+              values['(']++; // H means it's a helix (structured)
             }
             pairs[c][cEnd]++;
 
-            maxResidue = "H";
+            maxResidue = "(";
           }
         }
         // nonGap++;
@@ -160,7 +163,7 @@ public class StructureFrequency
         residueHash.put(PAIRPROFILE, pairs);
       }
 
-      count = values['H'];
+      count = values['('];
 
       residueHash.put(MAXCOUNT, new Integer(count));
       residueHash.put(MAXRESIDUE, maxResidue);
@@ -175,7 +178,29 @@ public class StructureFrequency
         result[i] = residueHash;
       }
       if (bpEnd > 0)
-      {
+      {     
+        values[')']=values['('];
+        values['(']=0;
+        
+        residueHash = new Hashtable();
+        maxResidue = ")";
+        
+        if (profile)
+        {
+          residueHash.put(PROFILE, new int[][]
+          { values, new int[]
+          { jSize, (jSize - values['-']) } });
+
+          residueHash.put(PAIRPROFILE, pairs);
+        }
+        
+        residueHash.put(MAXCOUNT, new Integer(count));
+        residueHash.put(MAXRESIDUE, maxResidue);
+
+        percentage = ((float) count * 100) / (float) jSize;
+        residueHash.put(PID_GAPS, new Float(percentage));
+
+        
         result[bpEnd] = residueHash;
       }
     }
@@ -322,6 +347,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 +422,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;
   }