From 9832a6ac361db1a51c020ef1ebdb7f495676c72d Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 10 Oct 2006 10:27:36 +0000 Subject: [PATCH] static final strings for consensus keys --- src/jalview/analysis/AAFrequency.java | 49 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 15618de..c1c4f71 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -24,10 +24,8 @@ import java.util.*; /** - * Takes in a vector of sequences and column start and column end - * and returns a vector of size (end-start+1). Each element of the - * vector contains a hashtable with the keys being residues and - * the values being the count of each residue in that column. + * Takes in a vector or array of sequences and column start and column end + * and returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied. * This class is used extensively in calculating alignment colourschemes * that depend on the amount of conservation in each alignment column. * @author $author$ @@ -35,12 +33,12 @@ import java.util.*; */ public class AAFrequency { - /** Takes in a !!ARRAY!! of sequences and column start and column end - * and fills given Vector of size (end-start+1). Each element of the - * vector contains a hashtable with the keys being residues and - * 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. */ + //No need to store 1000s of strings which are not + //visible to the user. + public static final String MAXCOUNT = "C"; + public static final String MAXRESIDUE="R"; + public static final String PID_GAPS = "G"; + public static final String PID_NOGAPS="N"; public static final Hashtable [] calculate(Vector sequences, int start, int end) { @@ -72,6 +70,8 @@ public static final void calculate(SequenceI[] sequences, int[] values = new int[132]; + String seq; + for (i = start; i < end; i++) { residueHash = new Hashtable(); @@ -82,24 +82,25 @@ public static final void calculate(SequenceI[] sequences, for (j = 0; j < jSize; j++) { - if (sequences[j].getLength() > i) + seq = sequences[j].getSequence(); + if (seq.length() > i) { - c = sequences[j].getCharAt(i); + c = seq.charAt(i); - if ('a' <= c && c <= 'z') - { - c -= ('a' - 'A'); - } + if(c == '.' || c==' ') + c = '-'; - if (jalview.util.Comparison.isGap(c)) + if(c=='-') { - c = '-'; // we always use this for gaps in the property vectors + values['-']++; + continue; } - else + else if ('a' <= c && c <= 'z') { - nongap++; + c -= 32 ;//('a' - 'A'); } + nongap++; values[c]++; } @@ -126,14 +127,14 @@ public static final void calculate(SequenceI[] sequences, } - residueHash.put("maxCount", new Integer(maxCount)); - residueHash.put("maxResidue", maxResidue); + residueHash.put(MAXCOUNT, new Integer(maxCount)); + residueHash.put(MAXRESIDUE, maxResidue); percentage = ( (float) maxCount * 100) / (float) jSize; - residueHash.put("pid_gaps", new Float(percentage)); + residueHash.put(PID_GAPS, new Float(percentage)); percentage = ( (float) maxCount * 100) / (float) nongap; - residueHash.put("pid_nogaps", new Float(percentage)); + residueHash.put(PID_NOGAPS, new Float(percentage)); result[i] = residueHash; } } -- 1.7.10.2