b27da9f47c1d2b530f5c73abd1632b0a5717f5b6
[jalview.git] / src / jalview / analysis / Profile.java
1 package jalview.analysis;
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   public ResidueCount getCounts()
97   {
98     return counts;
99   }
100
101   public int getHeight()
102   {
103     return height;
104   }
105
106   public int getGapped()
107   {
108     return gapped;
109   }
110
111   public int getMaxCount()
112   {
113     return maxCount;
114   }
115
116   public String getModalResidue()
117   {
118     return modalResidue;
119   }
120
121   /**
122    * Answers the number of non-gapped sequences in the profile
123    * 
124    * @return
125    */
126   public int getNonGapped()
127   {
128     return height - gapped;
129   }
130 }