2951e9e82bc6d9ea7b53aca7eb02d961462c0fea
[jalview.git] / src / jalview / datamodel / Profile.java
1 package jalview.datamodel;
2
3
4 /**
5  * A data bean to hold the result of computing a profile for a column of an
6  * alignment
7  * 
8  * @author gmcarstairs
9  *
10  */
11 public class Profile
12 {
13   /*
14    * counts of keys (chars)
15    */
16   private ResidueCount counts;
17
18   /*
19    * the number of sequences in the profile
20    */
21   private int height;
22
23   /*
24    * the number of non-gapped sequences in the profile
25    */
26   private int gapped;
27
28   /*
29    * the highest count for any residue in the profile
30    */
31   private int maxCount;
32
33   /*
34    * the residue (e.g. K) or residues (e.g. KQW) with the
35    * highest count in the profile
36    */
37   private String modalResidue;
38
39   /**
40    * Constructor which allows derived data to be stored without having to store
41    * the full profile
42    * 
43    * @param seqCount
44    *          the number of sequences in the profile
45    * @param gaps
46    *          the number of gapped sequences
47    * @param max
48    *          the highest count for any residue
49    * @param modalres
50    *          the residue (or concatenated residues) with the highest count
51    */
52   public Profile(int seqCount, int gaps, int max, String modalRes)
53   {
54     this.height = seqCount;
55     this.gapped = gaps;
56     this.maxCount = max;
57     this.modalResidue = modalRes;
58   }
59
60   /**
61    * Set the full profile of counts
62    * 
63    * @param residueCounts
64    */
65   public void setCounts(ResidueCount residueCounts)
66   {
67     this.counts = residueCounts;
68   }
69
70   /**
71    * Returns the percentage identity of the profile, i.e. the highest proportion
72    * of conserved (equal) symbols. The percentage is as a fraction of all
73    * sequences, or only ungapped sequences if flag ignoreGaps is set true.
74    * 
75    * @param ignoreGaps
76    * @return
77    */
78   public float getPercentageIdentity(boolean ignoreGaps)
79   {
80     if (height == 0)
81     {
82       return 0f;
83     }
84     float pid = 0f;
85     if (ignoreGaps && gapped < height)
86     {
87       pid = (maxCount * 100f) / (height - gapped);
88     }
89     else
90     {
91       pid = (maxCount * 100f) / height;
92     }
93     return pid;
94   }
95
96   /**
97    * Returns the full symbol counts for this profile
98    * 
99    * @return
100    */
101   public ResidueCount getCounts()
102   {
103     return counts;
104   }
105
106   /**
107    * Returns the number of sequences in the profile
108    * 
109    * @return
110    */
111   public int getHeight()
112   {
113     return height;
114   }
115
116   /**
117    * Returns the number of sequences in the profile which had a gap character
118    * (or were too short to be included in this column's profile)
119    * 
120    * @return
121    */
122   public int getGapped()
123   {
124     return gapped;
125   }
126
127   /**
128    * Returns the highest count for any symbol(s) in the profile
129    * 
130    * @return
131    */
132   public int getMaxCount()
133   {
134     return maxCount;
135   }
136
137   /**
138    * Returns the symbol (or concatenated symbols) which have the highest count
139    * in the profile, or an empty string if there were no symbols counted
140    * 
141    * @return
142    */
143   public String getModalResidue()
144   {
145     return modalResidue;
146   }
147
148   /**
149    * Answers the number of non-gapped sequences in the profile
150    * 
151    * @return
152    */
153   public int getNonGapped()
154   {
155     return height - gapped;
156   }
157 }