2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
23 import jalview.datamodel.*;
\r
26 * Takes in a vector or array of sequences and column start and column end
\r
27 * and returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied.
\r
28 * This class is used extensively in calculating alignment colourschemes
\r
29 * that depend on the amount of conservation in each alignment column.
\r
31 * @version $Revision$
\r
33 public class AAFrequency
\r
35 //No need to store 1000s of strings which are not
\r
36 //visible to the user.
\r
37 public static final String MAXCOUNT = "C";
\r
38 public static final String MAXRESIDUE = "R";
\r
39 public static final String PID_GAPS = "G";
\r
40 public static final String PID_NOGAPS = "N";
\r
42 public static final Hashtable[] calculate(Vector sequences, int start,
\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
52 width = seqs[i].getLength();
\r
56 Hashtable[] reply = new Hashtable[width];
\r
63 calculate(seqs, start, end, reply);
\r
68 public static final void calculate(SequenceI[] sequences,
\r
72 Hashtable residueHash;
\r
73 int maxCount, nongap, i, j, v, jSize = sequences.length;
\r
78 int[] values = new int[255];
\r
82 for (i = start; i < end; i++)
\r
84 residueHash = new Hashtable();
\r
88 values = new int[255];
\r
90 for (j = 0; j < jSize; j++)
\r
92 seq = sequences[j].getSequence();
\r
97 if (c == '.' || c == ' ')
\r
107 else if ('a' <= c && c <= 'z')
\r
109 c -= 32; //('a' - 'A');
\r
122 for (v = 'A'; v < 'Z'; v++)
\r
124 if (values[v] < 2 || values[v] < maxCount)
\r
129 if (values[v] > maxCount)
\r
131 maxResidue = String.valueOf( (char) v);
\r
133 else if (values[v] == maxCount)
\r
135 maxResidue += String.valueOf( (char) v);
\r
137 maxCount = values[v];
\r
140 if (maxResidue.length() == 0)
\r
145 residueHash.put(MAXCOUNT, new Integer(maxCount));
\r
146 residueHash.put(MAXRESIDUE, maxResidue);
\r
148 percentage = ( (float) maxCount * 100) / (float) jSize;
\r
149 residueHash.put(PID_GAPS, new Float(percentage));
\r
151 percentage = ( (float) maxCount * 100) / (float) nongap;
\r
152 residueHash.put(PID_NOGAPS, new Float(percentage));
\r
153 result[i] = residueHash;
\r