7b0dbbb034ccf033b9848e9315cdbb75c9d04e5f
[jalview.git] / src / jalview / schemes / Consensus.java
1 /* Jalview - a java multiple alignment editor\r
2  * Copyright (C) 1998  Michele Clamp\r
3  *\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
8  *\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
13  *\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
17  */\r
18 \r
19 package jalview.schemes;\r
20 \r
21 import jalview.datamodel.*;\r
22 import java.util.*;\r
23 ////////////////////////////////////////////\r
24 // This does nothing at all at the moment!!!!!!!!!!\r
25 // AW 15th Dec 2004\r
26 /////////////////////////////////////////\r
27 public class Consensus {\r
28 \r
29   int[] mask;\r
30   double threshold;\r
31 \r
32   public Consensus(String m, double threshold)\r
33   {\r
34     mask = setNums(m);\r
35     this.threshold = threshold;\r
36   }\r
37 \r
38 \r
39   public boolean isConserved(int[][] cons2,int col, int res,int size)\r
40   {\r
41     int tot = 0;\r
42 \r
43 try{\r
44     for (int i=0; i < mask.length; i++)\r
45       tot += cons2[col][mask[i]];\r
46 }catch(Exception ex)\r
47 { return true; }\r
48 \r
49     if ((double)tot > threshold*size/100)\r
50       return true;\r
51 \r
52     return false;\r
53   }\r
54 \r
55   int[] setNums(String s)\r
56   {\r
57     int [] out = new int[s.length()];\r
58     int i = 0;\r
59     while (i < s.length())\r
60     {\r
61       out[i] = ( (Integer) ResidueProperties.aaHash.get(s.substring(i, i + 1))).intValue();\r
62       i++;\r
63     }\r
64     return out;\r
65   }\r
66 \r
67 \r
68 }\r
69 \r
70 \r
71 \r
72 \r