JAL-4090 JAL-1551 spotlessApply
[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     // jalview.bin.Console.outPrintln(mask[i] + " " +
50     // ResidueProperties.aa[mask[i]]);
51     // }
52   }
53
54   /**
55    * @deprecated Use {@link #isConserved(int[][],int,int,boolean)} instead
56    */
57   @Deprecated
58   public boolean isConserved(int[][] cons2, int col, int size)
59   {
60     jalview.bin.Console.outPrintln("DEPRECATED!!!!");
61     return isConserved(cons2, col, size, true);
62   }
63
64   public boolean isConserved(int[][] cons2, int col, int size,
65           boolean includeGaps)
66   {
67     int tot = 0;
68     if (!includeGaps)
69     {
70       size -= cons2[col][cons2[col].length - 1];
71     }
72     for (int i = 0; i < mask.length; i++)
73     {
74       tot += cons2[col][mask[i]];
75     }
76
77     if (tot > ((threshold * size) / 100))
78     {
79       // jalview.bin.Console.outPrintln("True conserved "+tot+" from
80       // "+threshold+" out of
81       // "+size+" : "+maskstr);
82       return true;
83     }
84
85     return false;
86   }
87
88   int[] setNums(String s)
89   {
90     int[] out = new int[s.length()];
91     int i = 0;
92
93     while (i < s.length())
94     {
95       out[i] = ResidueProperties.aaIndex[s.charAt(i)];
96       i++;
97     }
98
99     return out;
100   }
101 }