2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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.analysis.*;
\r
23 import jalview.datamodel.*;
\r
29 * Takes in a vector of sequences and column start and column end
\r
30 * and returns a vector of size (end-start+1). Each element of the
\r
31 * vector contains a hashtable with the keys being residues and
\r
32 * the values being the count of each residue in that column.
\r
33 * This class is used extensively in calculating alignment colourschemes
\r
34 * that depend on the amount of conservation in each alignment column.
\r
36 * @version $Revision$
\r
38 public class AAFrequency
\r
40 /** Takes in a vector of sequences and column start and column end
\r
41 * and returns a vector of size (end-start+1). Each element of the
\r
42 * vector contains a hashtable with the keys being residues and
\r
43 * the values being the count of each residue in that column.
\r
44 * This class is used extensively in calculating alignment colourschemes
\r
45 * that depend on the amount of conservation in each alignment column. */
\r
46 public static Vector calculate(Vector sequences, int start, int end)
\r
48 Vector result = new Vector();
\r
50 for (int i = start; i <= end; i++)
\r
52 Hashtable residueHash = new Hashtable();
\r
54 String maxResidue = "-";
\r
57 for (int j = 0; j < sequences.size(); j++)
\r
59 if (sequences.elementAt(j) instanceof Sequence)
\r
61 Sequence s = (Sequence) sequences.elementAt(j);
\r
63 if (s.getSequence().length() > i)
\r
65 String res = s.getSequence().charAt(i) + "";
\r
67 if (!jalview.util.Comparison.isGap(res.charAt(0)))
\r
73 res = "-"; // we always use this for gaps in the property vectors
\r
76 if (residueHash.containsKey(res))
\r
78 int count = ((Integer) residueHash.get(res)).intValue();
\r
81 if (!jalview.util.Comparison.isGap(res.charAt(0)) &&
\r
82 (count >= maxCount))
\r
84 if (count > maxCount)
\r
88 else if (maxResidue.indexOf(res) == -1)
\r
96 residueHash.put(res, new Integer(count));
\r
100 residueHash.put(res, new Integer(1));
\r
105 if (residueHash.containsKey("-"))
\r
107 int count = ((Integer) residueHash.get("-")).intValue();
\r
109 residueHash.put("-", new Integer(count));
\r
113 residueHash.put("-", new Integer(1));
\r
119 residueHash.put("maxCount", new Integer(maxCount));
\r
123 System.out.println("asasa " + maxCount);
\r
126 residueHash.put("maxResidue", maxResidue);
\r
127 residueHash.put("size", new Integer(sequences.size()));
\r
128 residueHash.put("nongap", new Integer(nongap));
\r
129 result.addElement(residueHash);
\r