Remove redundancy in Eclipse
[jalview.git] / src / jalview / analysis / AAFrequency.java
index 4ef250b..ad1fe4e 100755 (executable)
@@ -18,8 +18,6 @@
 */\r
 package jalview.analysis;\r
 \r
-import jalview.analysis.*;\r
-\r
 import jalview.datamodel.*;\r
 \r
 import java.util.*;\r
@@ -43,39 +41,41 @@ public class AAFrequency
     * the values being the count of each residue in that column.\r
     * This class is used extensively in calculating alignment colourschemes\r
     * that depend on the amount of conservation in each alignment column. */\r
-    public static Vector calculate(Vector sequences, int start, int end)\r
+    public static final Vector calculate(Vector sequences, int start, int end)\r
     {\r
-        Vector result = new Vector();\r
+      Vector result = new Vector();\r
+      Hashtable residueHash;\r
+      int count, maxCount, nongap, i, j, jSize = sequences.size();\r
+      String maxResidue, sequence, res;\r
+      float percentage;\r
 \r
-        for (int i = start; i <= end; i++)\r
+        for (i = start; i <= end; i++)\r
         {\r
-            Hashtable residueHash = new Hashtable();\r
-            int maxCount = 0;\r
-            String maxResidue = "-";\r
-            int nongap = 0;\r
+            residueHash = new Hashtable();\r
+            maxCount = 0;\r
+            maxResidue = "-";\r
+            nongap = 0;\r
 \r
-            for (int j = 0; j < sequences.size(); j++)\r
+            for (j = 0; j < jSize; j++)\r
             {\r
                 if (sequences.elementAt(j) instanceof Sequence)\r
                 {\r
-                    Sequence s = (Sequence) sequences.elementAt(j);\r
+                    sequence = ((Sequence) sequences.elementAt(j)).getSequence();\r
 \r
-                    if (s.getSequence().length() > i)\r
+                    if (sequence.length() > i)\r
                     {\r
-                        String res = s.getSequence().charAt(i) + "";\r
+                        res = String.valueOf(Character.toUpperCase(sequence.charAt(i)));\r
 \r
-                        if (!jalview.util.Comparison.isGap(res.charAt(0)))\r
-                        {\r
-                            nongap++;\r
-                        }\r
-                        else\r
+                        if (jalview.util.Comparison.isGap(res.charAt(0)))\r
                         {\r
                             res = "-"; // we always use this for gaps in the property vectors\r
                         }\r
+                        else\r
+                        {   nongap++;    }\r
 \r
                         if (residueHash.containsKey(res))\r
                         {\r
-                            int count = ((Integer) residueHash.get(res)).intValue();\r
+                            count = ((Integer) residueHash.get(res)).intValue();\r
                             count++;\r
 \r
                             if (!jalview.util.Comparison.isGap(res.charAt(0)) &&\r
@@ -104,7 +104,7 @@ public class AAFrequency
                     {\r
                         if (residueHash.containsKey("-"))\r
                         {\r
-                            int count = ((Integer) residueHash.get("-")).intValue();\r
+                            count = ((Integer) residueHash.get("-")).intValue();\r
                             count++;\r
                             residueHash.put("-", new Integer(count));\r
                         }\r
@@ -117,18 +117,23 @@ public class AAFrequency
             }\r
 \r
             residueHash.put("maxCount", new Integer(maxCount));\r
+            residueHash.put("maxResidue", maxResidue);\r
 \r
-            if (maxCount < 0)\r
-            {\r
-                System.out.println("asasa " + maxCount);\r
-            }\r
 \r
-            residueHash.put("maxResidue", maxResidue);\r
-            residueHash.put("size", new Integer(sequences.size()));\r
-            residueHash.put("nongap", new Integer(nongap));\r
+            //Size is redundant at present if we calculate percentage here\r
+            //residueHash.put("size", new Integer(jSize));\r
+            //residueHash.put("nogaps", new Integer(nongap));\r
+\r
+            percentage = ((float)maxCount*100) / (float)jSize;\r
+            residueHash.put("pid_gaps", new Float(percentage) );\r
+\r
+            percentage = ((float)maxCount*100) / (float)nongap;\r
+            residueHash.put("pid_nogaps", new Float(percentage) );\r
             result.addElement(residueHash);\r
         }\r
 \r
+\r
+\r
         return result;\r
     }\r
 }\r