JAL-4392 Consensus secondary structure: Display Secondary structure consensus for...
[jalview.git] / src / jalview / datamodel / Profile.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.datamodel;
22
23 /**
24  * A profile for one column of an alignment
25  * 
26  * @author gmcarstairs
27  *
28  */
29 public class Profile implements ProfileI
30 {
31   /*
32    * an object holding counts of symbols in the profile
33    */
34   private ResidueCount counts;
35   
36   private SecondaryStructureCount ssCounts;
37
38   /*
39    * the number of sequences (gapped or not) in the profile
40    */
41   private int height;
42
43   /*
44    * the number of non-gapped sequences in the profile
45    */
46   private int gapped;
47
48   /*
49    * the highest count for any residue in the profile
50    */
51   private int maxCount;
52   private int maxSSCount;
53   
54
55   /*
56    * the residue (e.g. K) or residues (e.g. KQW) with the
57    * highest count in the profile
58    */
59   private String modalResidue;
60   
61   private String modalSS;
62
63   /**
64    * Constructor which allows derived data to be stored without having to store
65    * the full profile
66    * 
67    * @param seqCount
68    *          the number of sequences in the profile
69    * @param gaps
70    *          the number of gapped sequences
71    * @param max
72    *          the highest count for any residue
73    * @param modalres
74    *          the residue (or concatenated residues) with the highest count
75    */
76   public Profile(int seqCount, int gaps, int max, String modalRes)
77   {
78     this.height = seqCount;
79     this.gapped = gaps;
80     this.maxCount = max;
81     this.modalResidue = modalRes;
82   }
83   
84   public Profile(String modalSS, int ssCount, int gaps, int maxSSCount)
85   {
86     this.height = ssCount;
87     this.gapped = gaps;
88     this.maxSSCount = maxSSCount;
89     this.modalSS = modalSS;
90   }
91
92   /* (non-Javadoc)
93    * @see jalview.datamodel.ProfileI#setCounts(jalview.datamodel.ResidueCount)
94    */
95   @Override
96   public void setCounts(ResidueCount residueCounts)
97   {
98     this.counts = residueCounts;
99   }
100   
101   @Override
102   public void setSSCounts(SecondaryStructureCount secondaryStructureCount)
103   {
104     this.ssCounts = secondaryStructureCount;
105   }
106
107   /* (non-Javadoc)
108    * @see jalview.datamodel.ProfileI#getPercentageIdentity(boolean)
109    */
110   @Override
111   public float getPercentageIdentity(boolean ignoreGaps)
112   {
113     if (height == 0)
114     {
115       return 0f;
116     }
117     float pid = 0f;
118     if (ignoreGaps && gapped < height)
119     {
120       pid = (maxCount * 100f) / (height - gapped);
121     }
122     else
123     {
124       pid = (maxCount * 100f) / height;
125     }
126     return pid;
127   }
128   
129   @Override
130   public float getSSPercentageIdentity(boolean ignoreGaps)
131   {
132     if (height == 0)
133     {
134       return 0f;
135     }
136     float ssPid = 0f;
137     if (ignoreGaps && gapped < height)
138     {
139       ssPid = (maxSSCount * 100f) / (height - gapped);
140     }
141     else
142     {
143       ssPid = (maxSSCount * 100f) / height;
144     }
145     return ssPid;
146   }
147
148   /* (non-Javadoc)
149    * @see jalview.datamodel.ProfileI#getCounts()
150    */
151   @Override
152   public ResidueCount getCounts()
153   {
154     return counts;
155   }
156   
157   @Override
158   public SecondaryStructureCount getSSCounts()
159   {
160     return ssCounts;
161   }
162
163   /* (non-Javadoc)
164    * @see jalview.datamodel.ProfileI#getHeight()
165    */
166   @Override
167   public int getHeight()
168   {
169     return height;
170   }
171
172   /* (non-Javadoc)
173    * @see jalview.datamodel.ProfileI#getGapped()
174    */
175   @Override
176   public int getGapped()
177   {
178     return gapped;
179   }
180
181   /* (non-Javadoc)
182    * @see jalview.datamodel.ProfileI#getMaxCount()
183    */
184   @Override
185   public int getMaxCount()
186   {
187     return maxCount;
188   }
189   
190   @Override
191   public int getMaxSSCount()
192   {
193     return maxSSCount;
194   }
195
196   /* (non-Javadoc)
197    * @see jalview.datamodel.ProfileI#getModalResidue()
198    */
199   @Override
200   public String getModalResidue()
201   {
202     return modalResidue;
203   }
204   
205   @Override
206   public String getModalSS()
207   {
208     return modalSS;
209   }
210
211   /* (non-Javadoc)
212    * @see jalview.datamodel.ProfileI#getNonGapped()
213    */
214   @Override
215   public int getNonGapped()
216   {
217     return height - gapped;
218   }
219 }