JAL-2325 apply license to new source files
[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 /**
25  * A profile for one column of an alignment
26  * 
27  * @author gmcarstairs
28  *
29  */
30 public class Profile implements ProfileI
31 {
32   /*
33    * an object holding counts of symbols in the profile
34    */
35   private ResidueCount counts;
36
37   /*
38    * the number of sequences (gapped or not) in the profile
39    */
40   private int height;
41
42   /*
43    * the number of non-gapped sequences in the profile
44    */
45   private int gapped;
46
47   /*
48    * the highest count for any residue in the profile
49    */
50   private int maxCount;
51
52   /*
53    * the residue (e.g. K) or residues (e.g. KQW) with the
54    * highest count in the profile
55    */
56   private String modalResidue;
57
58   /**
59    * Constructor which allows derived data to be stored without having to store
60    * the full profile
61    * 
62    * @param seqCount
63    *          the number of sequences in the profile
64    * @param gaps
65    *          the number of gapped sequences
66    * @param max
67    *          the highest count for any residue
68    * @param modalres
69    *          the residue (or concatenated residues) with the highest count
70    */
71   public Profile(int seqCount, int gaps, int max, String modalRes)
72   {
73     this.height = seqCount;
74     this.gapped = gaps;
75     this.maxCount = max;
76     this.modalResidue = modalRes;
77   }
78
79   /* (non-Javadoc)
80    * @see jalview.datamodel.ProfileI#setCounts(jalview.datamodel.ResidueCount)
81    */
82   @Override
83   public void setCounts(ResidueCount residueCounts)
84   {
85     this.counts = residueCounts;
86   }
87
88   /* (non-Javadoc)
89    * @see jalview.datamodel.ProfileI#getPercentageIdentity(boolean)
90    */
91   @Override
92   public float getPercentageIdentity(boolean ignoreGaps)
93   {
94     if (height == 0)
95     {
96       return 0f;
97     }
98     float pid = 0f;
99     if (ignoreGaps && gapped < height)
100     {
101       pid = (maxCount * 100f) / (height - gapped);
102     }
103     else
104     {
105       pid = (maxCount * 100f) / height;
106     }
107     return pid;
108   }
109
110   /* (non-Javadoc)
111    * @see jalview.datamodel.ProfileI#getCounts()
112    */
113   @Override
114   public ResidueCount getCounts()
115   {
116     return counts;
117   }
118
119   /* (non-Javadoc)
120    * @see jalview.datamodel.ProfileI#getHeight()
121    */
122   @Override
123   public int getHeight()
124   {
125     return height;
126   }
127
128   /* (non-Javadoc)
129    * @see jalview.datamodel.ProfileI#getGapped()
130    */
131   @Override
132   public int getGapped()
133   {
134     return gapped;
135   }
136
137   /* (non-Javadoc)
138    * @see jalview.datamodel.ProfileI#getMaxCount()
139    */
140   @Override
141   public int getMaxCount()
142   {
143     return maxCount;
144   }
145
146   /* (non-Javadoc)
147    * @see jalview.datamodel.ProfileI#getModalResidue()
148    */
149   @Override
150   public String getModalResidue()
151   {
152     return modalResidue;
153   }
154
155   /* (non-Javadoc)
156    * @see jalview.datamodel.ProfileI#getNonGapped()
157    */
158   @Override
159   public int getNonGapped()
160   {
161     return height - gapped;
162   }
163 }