Merge branch 'develop' into releases/Release_2_11_2_Branch
[jalview.git] / src / jalview / schemes / Consensus.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.schemes;
22
23 // //////////////////////////////////////////
24 // This does nothing at all at the moment!!!!!!!!!!
25 // AW 15th Dec 2004
26 // ///////////////////////////////////////
27 public class Consensus
28 {
29   int[] mask;
30
31   double threshold;
32
33   String maskstr;
34
35   public Consensus(String mask, double threshold)
36   {
37     // this.id = id;
38     // this.mask = mask;
39     this.maskstr = mask;
40     setMask(mask);
41     this.threshold = threshold;
42   }
43
44   public void setMask(String s)
45   {
46     this.mask = setNums(s);
47
48     // for (int i=0; i < mask.length; i++) {
49     // System.out.println(mask[i] + " " + ResidueProperties.aa[mask[i]]);
50     // }
51   }
52
53   /**
54    * @deprecated Use {@link #isConserved(int[][],int,int,boolean)} instead
55    */
56   @Deprecated
57   public boolean isConserved(int[][] cons2, int col, int size)
58   {
59     System.out.println("DEPRECATED!!!!");
60     return isConserved(cons2, col, size, true);
61   }
62
63   public boolean isConserved(int[][] cons2, int col, int size,
64           boolean includeGaps)
65   {
66     int tot = 0;
67     if (!includeGaps)
68     {
69       size -= cons2[col][cons2[col].length - 1];
70     }
71     for (int i = 0; i < mask.length; i++)
72     {
73       tot += cons2[col][mask[i]];
74     }
75
76     if (tot > ((threshold * size) / 100))
77     {
78       // System.out.println("True conserved "+tot+" from "+threshold+" out of
79       // "+size+" : "+maskstr);
80       return true;
81     }
82
83     return false;
84   }
85
86   int[] setNums(String s)
87   {
88     int[] out = new int[s.length()];
89     int i = 0;
90
91     while (i < s.length())
92     {
93       out[i] = ResidueProperties.aaIndex[s.charAt(i)];
94       i++;
95     }
96
97     return out;
98   }
99 }