2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.analysis;
\r
21 import jalview.datamodel.*;
\r
27 * Takes in a vector or array of sequences and column start and column end
\r
28 * and returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied.
\r
29 * This class is used extensively in calculating alignment colourschemes
\r
30 * that depend on the amount of conservation in each alignment column.
\r
32 * @version $Revision$
\r
34 public class AAFrequency
\r
36 //No need to store 1000s of strings which are not
\r
37 //visible to the user.
\r
38 public static final String MAXCOUNT = "C";
\r
39 public static final String MAXRESIDUE="R";
\r
40 public static final String PID_GAPS = "G";
\r
41 public static final String PID_NOGAPS="N";
\r
43 public static final Hashtable [] calculate(Vector sequences, int start, int end)
\r
45 SequenceI [] seqs = new SequenceI[sequences.size()];
\r
47 for(int i=0; i<sequences.size(); i++)
\r
49 seqs[i] = (SequenceI) sequences.elementAt(i);
\r
50 if(seqs[i].getLength()>width)
\r
51 width = seqs[i].getLength();
\r
54 Hashtable [] reply = new Hashtable[width];
\r
56 calculate(seqs, start, end, reply);
\r
61 public static final void calculate(SequenceI[] sequences,
\r
63 Hashtable [] result)
\r
65 Hashtable residueHash;
\r
66 int maxCount, nongap, i, j, v, jSize = sequences.length;
\r
71 int[] values = new int[132];
\r
75 for (i = start; i < end; i++)
\r
77 residueHash = new Hashtable();
\r
81 values = new int[132];
\r
83 for (j = 0; j < jSize; j++)
\r
85 seq = sequences[j].getSequence();
\r
86 if (seq.length() > i)
\r
90 if(c == '.' || c==' ')
\r
98 else if ('a' <= c && c <= 'z')
\r
100 c -= 32 ;//('a' - 'A');
\r
113 for (v = 'A'; v < 'Z'; v++)
\r
115 if (values[v] < 2 || values[v] < maxCount)
\r
118 if (values[v] > maxCount)
\r
120 maxResidue = String.valueOf( (char) v);
\r
122 else if (values[v] == maxCount)
\r
124 maxResidue += String.valueOf( (char) v);
\r
126 maxCount = values[v];
\r
129 if(maxResidue.length()==0)
\r
132 residueHash.put(MAXCOUNT, new Integer(maxCount));
\r
133 residueHash.put(MAXRESIDUE, maxResidue);
\r
135 percentage = ( (float) maxCount * 100) / (float) jSize;
\r
136 residueHash.put(PID_GAPS, new Float(percentage));
\r
138 percentage = ( (float) maxCount * 100) / (float) nongap;
\r
139 residueHash.put(PID_NOGAPS, new Float(percentage));
\r
140 result[i] = residueHash;
\r