JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / schemes / Consensus.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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   public boolean isConserved(int[][] cons2, int col, int size)
57   {
58     return isConserved(cons2, col, size, true);
59   }
60
61   public boolean isConserved(int[][] cons2, int col, int size,
62           boolean includeGaps)
63   {
64     int tot = 0;
65     if (!includeGaps)
66     {
67       size -= cons2[col][cons2[col].length - 1];
68     }
69     for (int i = 0; i < mask.length; i++)
70     {
71       tot += cons2[col][mask[i]];
72     }
73
74     if ((double) tot > ((threshold * size) / 100))
75     {
76       // System.out.println("True conserved "+tot+" from "+threshold+" out of
77       // "+size+" : "+maskstr);
78       return true;
79     }
80
81     return false;
82   }
83
84   int[] setNums(String s)
85   {
86     int[] out = new int[s.length()];
87     int i = 0;
88
89     while (i < s.length())
90     {
91       out[i] = ResidueProperties.aaIndex[s.charAt(i)];
92       i++;
93     }
94
95     return out;
96   }
97 }