update author list in license for (JAL-826)
[jalview.git] / src / jalview / schemes / Consensus.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.schemes;
19
20 // //////////////////////////////////////////
21 // This does nothing at all at the moment!!!!!!!!!!
22 // AW 15th Dec 2004
23 // ///////////////////////////////////////
24 public class Consensus
25 {
26   int[] mask;
27
28   double threshold;
29
30   String maskstr;
31
32   public Consensus(String mask, double threshold)
33   {
34     // this.id = id;
35     // this.mask = mask;
36     this.maskstr = mask;
37     setMask(mask);
38     this.threshold = threshold;
39   }
40
41   public void setMask(String s)
42   {
43     this.mask = setNums(s);
44
45     // for (int i=0; i < mask.length; i++) {
46     // System.out.println(mask[i] + " " + ResidueProperties.aa[mask[i]]);
47     // }
48   }
49
50   /**
51    * @deprecated Use {@link #isConserved(int[][],int,int,boolean)} instead
52    */
53   public boolean isConserved(int[][] cons2, int col, int size)
54   {
55     return isConserved(cons2, col, size, true);
56   }
57
58   public boolean isConserved(int[][] cons2, int col, int size,
59           boolean includeGaps)
60   {
61     int tot = 0;
62     if (!includeGaps)
63     {
64       size -= cons2[col][cons2[col].length - 1];
65     }
66     for (int i = 0; i < mask.length; i++)
67     {
68       tot += cons2[col][mask[i]];
69     }
70
71     if ((double) tot > ((threshold * size) / 100))
72     {
73       // System.out.println("True conserved "+tot+" from "+threshold+" out of
74       // "+size+" : "+maskstr);
75       return true;
76     }
77
78     return false;
79   }
80
81   int[] setNums(String s)
82   {
83     int[] out = new int[s.length()];
84     int i = 0;
85
86     while (i < s.length())
87     {
88       out[i] = ResidueProperties.aaIndex[s.charAt(i)];
89       i++;
90     }
91
92     return out;
93   }
94 }