2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.analysis;
23 import jalview.datamodel.*;
26 * Takes in a vector or array of sequences and column start and column end
27 * and returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied.
28 * This class is used extensively in calculating alignment colourschemes
29 * that depend on the amount of conservation in each alignment column.
33 public class AAFrequency
35 //No need to store 1000s of strings which are not
36 //visible to the user.
37 public static final String MAXCOUNT = "C";
38 public static final String MAXRESIDUE = "R";
39 public static final String PID_GAPS = "G";
40 public static final String PID_NOGAPS = "N";
42 public static final Hashtable[] calculate(Vector sequences, int start,
45 SequenceI[] seqs = new SequenceI[sequences.size()];
47 for (int i = 0; i < sequences.size(); i++)
49 seqs[i] = (SequenceI) sequences.elementAt(i);
50 if (seqs[i].getLength() > width)
52 width = seqs[i].getLength();
56 Hashtable[] reply = new Hashtable[width];
63 calculate(seqs, start, end, reply);
68 public static final void calculate(SequenceI[] sequences,
72 Hashtable residueHash;
73 int maxCount, nongap, i, j, v, jSize = sequences.length;
78 int[] values = new int[255];
82 for (i = start; i < end; i++)
84 residueHash = new Hashtable();
88 values = new int[255];
90 for (j = 0; j < jSize; j++)
92 seq = sequences[j].getSequence();
97 if (c == '.' || c == ' ')
107 else if ('a' <= c && c <= 'z')
109 c -= 32; //('a' - 'A');
122 for (v = 'A'; v < 'Z'; v++)
124 if (values[v] < 2 || values[v] < maxCount)
129 if (values[v] > maxCount)
131 maxResidue = String.valueOf( (char) v);
133 else if (values[v] == maxCount)
135 maxResidue += String.valueOf( (char) v);
137 maxCount = values[v];
140 if (maxResidue.length() == 0)
145 residueHash.put(MAXCOUNT, new Integer(maxCount));
146 residueHash.put(MAXRESIDUE, maxResidue);
148 percentage = ( (float) maxCount * 100) / (float) jSize;
149 residueHash.put(PID_GAPS, new Float(percentage));
151 percentage = ( (float) maxCount * 100) / (float) nongap;
152 residueHash.put(PID_NOGAPS, new Float(percentage));
153 result[i] = residueHash;