basic implementation of profile display and todos
[jalview.git] / src / jalview / analysis / AAFrequency.java
index 36534a3..6c21c74 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -156,4 +156,47 @@ public class AAFrequency
       result[i] = residueHash;
     }
   }
+
+  /**
+   * Compute all or part of the annotation row from the given consensus hashtable
+   * @param consensus - pre-allocated annotation row 
+   * @param hconsensus
+   * @param iStart
+   * @param width
+   * @param ignoreGapsInConsensusCalculation
+   */
+  public static void completeConsensus(AlignmentAnnotation consensus,
+          Hashtable[] hconsensus, int iStart, int width,
+          boolean ignoreGapsInConsensusCalculation)
+  {
+    for (int i = iStart; i < width; i++)
+    {
+      float value = 0;
+      if (ignoreGapsInConsensusCalculation)
+      {
+        value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
+                .floatValue();
+      }
+      else
+      {
+        value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
+                .floatValue();
+      }
+
+      String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
+              .toString();
+      String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
+              + " ";
+
+      if (maxRes.length() > 1)
+      {
+        mouseOver = "[" + maxRes + "] ";
+        maxRes = "+";
+      }
+
+      mouseOver += ((int) value + "%");
+      consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
+              value);
+    }
+  }
 }