X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAAFrequency.java;h=ad1fe4e9b7911137ac7fd5e086d47b135b0c9a7b;hb=f24dacb1da56fccf05d684e2f4899facec2aecf7;hp=4ef250b2cf6b10d564fd938b9b85557144eae437;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 4ef250b..ad1fe4e 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -18,8 +18,6 @@ */ package jalview.analysis; -import jalview.analysis.*; - import jalview.datamodel.*; import java.util.*; @@ -43,39 +41,41 @@ public class AAFrequency * the values being the count of each residue in that column. * This class is used extensively in calculating alignment colourschemes * that depend on the amount of conservation in each alignment column. */ - public static Vector calculate(Vector sequences, int start, int end) + public static final Vector calculate(Vector sequences, int start, int end) { - Vector result = new Vector(); + Vector result = new Vector(); + Hashtable residueHash; + int count, maxCount, nongap, i, j, jSize = sequences.size(); + String maxResidue, sequence, res; + float percentage; - for (int i = start; i <= end; i++) + for (i = start; i <= end; i++) { - Hashtable residueHash = new Hashtable(); - int maxCount = 0; - String maxResidue = "-"; - int nongap = 0; + residueHash = new Hashtable(); + maxCount = 0; + maxResidue = "-"; + nongap = 0; - for (int j = 0; j < sequences.size(); j++) + for (j = 0; j < jSize; j++) { if (sequences.elementAt(j) instanceof Sequence) { - Sequence s = (Sequence) sequences.elementAt(j); + sequence = ((Sequence) sequences.elementAt(j)).getSequence(); - if (s.getSequence().length() > i) + if (sequence.length() > i) { - String res = s.getSequence().charAt(i) + ""; + res = String.valueOf(Character.toUpperCase(sequence.charAt(i))); - if (!jalview.util.Comparison.isGap(res.charAt(0))) - { - nongap++; - } - else + if (jalview.util.Comparison.isGap(res.charAt(0))) { res = "-"; // we always use this for gaps in the property vectors } + else + { nongap++; } if (residueHash.containsKey(res)) { - int count = ((Integer) residueHash.get(res)).intValue(); + count = ((Integer) residueHash.get(res)).intValue(); count++; if (!jalview.util.Comparison.isGap(res.charAt(0)) && @@ -104,7 +104,7 @@ public class AAFrequency { if (residueHash.containsKey("-")) { - int count = ((Integer) residueHash.get("-")).intValue(); + count = ((Integer) residueHash.get("-")).intValue(); count++; residueHash.put("-", new Integer(count)); } @@ -117,18 +117,23 @@ public class AAFrequency } residueHash.put("maxCount", new Integer(maxCount)); + residueHash.put("maxResidue", maxResidue); - if (maxCount < 0) - { - System.out.println("asasa " + maxCount); - } - residueHash.put("maxResidue", maxResidue); - residueHash.put("size", new Integer(sequences.size())); - residueHash.put("nongap", new Integer(nongap)); + //Size is redundant at present if we calculate percentage here + //residueHash.put("size", new Integer(jSize)); + //residueHash.put("nogaps", new Integer(nongap)); + + percentage = ((float)maxCount*100) / (float)jSize; + residueHash.put("pid_gaps", new Float(percentage) ); + + percentage = ((float)maxCount*100) / (float)nongap; + residueHash.put("pid_nogaps", new Float(percentage) ); result.addElement(residueHash); } + + return result; } }