JAL-2326 added setup method for JvOptionPane in all Jalveiw test classes to enable...
[jalview.git] / src / jalview / datamodel / Profile.java
1 package jalview.datamodel;
2
3
4 /**
5  * A profile for one column of an alignment
6  * 
7  * @author gmcarstairs
8  *
9  */
10 public class Profile implements ProfileI
11 {
12   /*
13    * an object holding counts of symbols in the profile
14    */
15   private ResidueCount counts;
16
17   /*
18    * the number of sequences (gapped or not) in the profile
19    */
20   private int height;
21
22   /*
23    * the number of non-gapped sequences in the profile
24    */
25   private int gapped;
26
27   /*
28    * the highest count for any residue in the profile
29    */
30   private int maxCount;
31
32   /*
33    * the residue (e.g. K) or residues (e.g. KQW) with the
34    * highest count in the profile
35    */
36   private String modalResidue;
37
38   /**
39    * Constructor which allows derived data to be stored without having to store
40    * the full profile
41    * 
42    * @param seqCount
43    *          the number of sequences in the profile
44    * @param gaps
45    *          the number of gapped sequences
46    * @param max
47    *          the highest count for any residue
48    * @param modalres
49    *          the residue (or concatenated residues) with the highest count
50    */
51   public Profile(int seqCount, int gaps, int max, String modalRes)
52   {
53     this.height = seqCount;
54     this.gapped = gaps;
55     this.maxCount = max;
56     this.modalResidue = modalRes;
57   }
58
59   /* (non-Javadoc)
60    * @see jalview.datamodel.ProfileI#setCounts(jalview.datamodel.ResidueCount)
61    */
62   @Override
63   public void setCounts(ResidueCount residueCounts)
64   {
65     this.counts = residueCounts;
66   }
67
68   /* (non-Javadoc)
69    * @see jalview.datamodel.ProfileI#getPercentageIdentity(boolean)
70    */
71   @Override
72   public float getPercentageIdentity(boolean ignoreGaps)
73   {
74     if (height == 0)
75     {
76       return 0f;
77     }
78     float pid = 0f;
79     if (ignoreGaps && gapped < height)
80     {
81       pid = (maxCount * 100f) / (height - gapped);
82     }
83     else
84     {
85       pid = (maxCount * 100f) / height;
86     }
87     return pid;
88   }
89
90   /* (non-Javadoc)
91    * @see jalview.datamodel.ProfileI#getCounts()
92    */
93   @Override
94   public ResidueCount getCounts()
95   {
96     return counts;
97   }
98
99   /* (non-Javadoc)
100    * @see jalview.datamodel.ProfileI#getHeight()
101    */
102   @Override
103   public int getHeight()
104   {
105     return height;
106   }
107
108   /* (non-Javadoc)
109    * @see jalview.datamodel.ProfileI#getGapped()
110    */
111   @Override
112   public int getGapped()
113   {
114     return gapped;
115   }
116
117   /* (non-Javadoc)
118    * @see jalview.datamodel.ProfileI#getMaxCount()
119    */
120   @Override
121   public int getMaxCount()
122   {
123     return maxCount;
124   }
125
126   /* (non-Javadoc)
127    * @see jalview.datamodel.ProfileI#getModalResidue()
128    */
129   @Override
130   public String getModalResidue()
131   {
132     return modalResidue;
133   }
134
135   /* (non-Javadoc)
136    * @see jalview.datamodel.ProfileI#getNonGapped()
137    */
138   @Override
139   public int getNonGapped()
140   {
141     return height - gapped;
142   }
143 }