AAFrequency optimized
[jalview.git] / src / jalview / gui / AlignViewport.java
index 6d0f766..07a7453 100755 (executable)
@@ -84,7 +84,7 @@ public class AlignViewport
 
 
     /** DOCUMENT ME!! */
-    public Vector vconsensus;
+    public Hashtable [] hconsensus;
     AlignmentAnnotation consensus;
     AlignmentAnnotation conservation;
     AlignmentAnnotation quality;
@@ -187,7 +187,7 @@ public class AlignViewport
 
         // We must set conservation and consensus before setting colour,
         // as Blosum and Clustal require this to be done
-        if(vconsensus==null && !isDataset)
+        if(hconsensus==null && !isDataset)
         {
           updateConservation();
           updateConsensus();
@@ -206,7 +206,7 @@ public class AlignViewport
 
             if (globalColourScheme != null)
             {
-                globalColourScheme.setConsensus(vconsensus);
+                globalColourScheme.setConsensus(hconsensus);
             }
         }
     }
@@ -236,6 +236,8 @@ public class AlignViewport
       if(alignment.isNucleotide())
           return;
 
+     // System.out.println("UPDATING CONSERVATION");
+
       try{
         Conservation cons = new jalview.analysis.Conservation("All",
             jalview.schemes.ResidueProperties.propHash, 3,
@@ -360,48 +362,33 @@ public class AlignViewport
       }
     }
 
+
     /**
      * DOCUMENT ME!
      */
     public void updateConsensus()
     {
       try{
-        Annotation[] annotations = new Annotation[alignment.getWidth()];
-
-        // this routine prevents vconsensus becoming a new object each time
-        // consenus is calculated. Important for speed of Blosum62
-        // and PID colouring of alignment
-        if (vconsensus == null)
-        {
-          vconsensus = alignment.getAAFrequency();
-        }
-        else
-        {
-          Vector temp = alignment.getAAFrequency();
-          vconsensus.clear();
-
-          Enumeration e = temp.elements();
+        int aWidth = alignment.getWidth();
 
-          while (e.hasMoreElements())
-          {
-            vconsensus.add(e.nextElement());
-          }
-        }
+        Annotation[] annotations = new Annotation[aWidth];
 
-        Hashtable hash = null;
+        hconsensus = new Hashtable[aWidth];
+        AAFrequency.calculate(alignment.getSequencesArray(),
+                              0,
+                              alignment.getWidth(),
+                              hconsensus);
 
-        for (int i = 0; i < alignment.getWidth(); i++)
+        for (int  i = 0; i < aWidth; i++)
         {
-          hash = (Hashtable) vconsensus.elementAt(i);
-
           float value = 0;
           if (ignoreGapsInConsensusCalculation)
-            value = ( (Float) hash.get("pid_nogaps")).floatValue();
+            value = ( (Float) hconsensus[i].get("pid_nogaps")).floatValue();
           else
-            value = ( (Float) hash.get("pid_gaps")).floatValue();
+            value = ( (Float) hconsensus[i].get("pid_gaps")).floatValue();
 
-          String maxRes = hash.get("maxResidue").toString();
-          String mouseOver = hash.get("maxResidue") + " ";
+          String maxRes = hconsensus[i].get("maxResidue").toString();
+          String mouseOver = hconsensus[i].get("maxResidue") + " ";
 
           if (maxRes.length() > 1)
           {
@@ -429,7 +416,7 @@ public class AlignViewport
         }
 
         if (globalColourScheme != null)
-          globalColourScheme.setConsensus(vconsensus);
+          globalColourScheme.setConsensus(hconsensus);
 
       }catch(OutOfMemoryError error)
       {