1 /* Jalview - a java multiple alignment editor
\r
2 * Copyright (C) 1998 Michele Clamp
\r
4 * This program is free software; you can redistribute it and/or
\r
5 * modify it under the terms of the GNU General Public License
\r
6 * as published by the Free Software Foundation; either version 2
\r
7 * of the License, or (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program; if not, write to the Free Software
\r
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
18 package jalview.analysis;
\r
22 import jalview.gui.*;
\r
23 import jalview.datamodel.*;
\r
26 public class Conservation {
\r
31 Vector total = new Vector();
\r
33 String consString = "";
\r
35 DrawableSequence consSequence;
\r
41 public Conservation(String name,Hashtable propHash, int threshold, Vector sequences, int start, int end) {
\r
43 this.propHash = propHash;
\r
44 this.threshold = threshold;
\r
45 this.sequences = sequences;
\r
51 public void calculate() {
\r
53 for (int i = start;i <= end; i++) {
\r
54 Hashtable resultHash = null;
\r
55 Hashtable residueHash = null;
\r
57 resultHash = new Hashtable();
\r
58 residueHash = new Hashtable();
\r
60 for (int j=0; j < sequences.size(); j++) {
\r
62 if (sequences.elementAt(j) instanceof Sequence) {
\r
63 Sequence s = (Sequence)sequences.elementAt(j);
\r
65 if (s.getLength() > i) {
\r
66 String res = s.getSequence().substring(i,i+1);
\r
68 if (residueHash.containsKey(res)) {
\r
69 int count = ((Integer)residueHash.get(res)).intValue() ;
\r
71 residueHash.put(res,new Integer(count));
\r
73 residueHash.put(res,new Integer(1));
\r
76 if (residueHash.containsKey("-")) {
\r
77 int count = ((Integer)residueHash.get("-")).intValue() ;
\r
79 residueHash.put("-",new Integer(count));
\r
81 residueHash.put("-",new Integer(1));
\r
87 //What is the count threshold to count the residues in residueHash()
\r
88 int thresh = threshold*(sequences.size())/100;
\r
90 //loop over all the found residues
\r
91 Enumeration e = residueHash.keys();
\r
93 while (e.hasMoreElements()) {
\r
95 String res = (String)e.nextElement();
\r
96 if (((Integer)residueHash.get(res)).intValue() > thresh) {
\r
98 //Now loop over the properties
\r
99 Enumeration e2 = propHash.keys();
\r
101 while (e2.hasMoreElements()) {
\r
102 String type = (String)e2.nextElement();
\r
103 Hashtable ht = (Hashtable)propHash.get(type);
\r
105 //Have we ticked this before?
\r
106 if (! resultHash.containsKey(type)) {
\r
107 if (ht.containsKey(res)) {
\r
108 resultHash.put(type,ht.get(res));
\r
110 resultHash.put(type,ht.get("-"));
\r
112 } else if ( ((Integer)resultHash.get(type)).equals((Integer)ht.get(res)) == false) {
\r
113 resultHash.put(type,new Integer(-1));
\r
118 total.addElement(resultHash);
\r
122 public int countGaps(int j)
\r
126 for (int i = 0; i < sequences.size();i++)
\r
128 if( j+1 > ((Sequence)sequences.elementAt(i)).getSequence().length())
\r
129 { count++; continue;}
\r
131 char c = ((Sequence)sequences.elementAt(i)).getSequence().charAt(j);
\r
132 if (jalview.util.Comparison.isGap((c)))
\r
139 public void verdict(boolean consflag, float percentageGaps) {
\r
140 String consString = "";
\r
142 for (int i=start; i <= end; i++) {
\r
143 int totGaps = countGaps(i);
\r
144 float pgaps = (float)totGaps*100/(float)sequences.size();
\r
146 if (percentageGaps > pgaps)
\r
148 Hashtable resultHash = (Hashtable)total.elementAt(i-start);
\r
150 //Now find the verdict
\r
152 Enumeration e3 = resultHash.keys();
\r
154 while (e3.hasMoreElements())
\r
156 String type = (String)e3.nextElement();
\r
157 Integer result = (Integer)resultHash.get(type);
\r
159 //Do we want to count +ve conservation or +ve and -ve cons.?
\r
163 if (result.intValue() == 1)
\r
168 if (result.intValue() != -1)
\r
174 consString = consString + String.valueOf(count);
\r
176 consString = consString + "*";
\r
181 consString = consString + "-";
\r
185 consSequence = new DrawableSequence(name,consString,start,end);
\r
188 public jalview.gui.DrawableSequence getConsSequence() {
\r
189 return consSequence;
\r