package jalview.analysis;
-import jalview.ext.android.SparseIntArray;
+/**
+ * A data bean to hold the result of computing a profile for a column of an
+ * alignment
+ *
+ * @author gmcarstairs
+ *
+ */
public class Profile
{
/*
- * array of keys (chars) and values (counts)
+ * counts of keys (chars)
*/
- public final SparseIntArray profile;
+ private ResidueCount counts;
/*
* the number of sequences in the profile
*/
- public final int height;
+ private int height;
/*
* the number of non-gapped sequences in the profile
*/
- public final int nonGapped;
+ private int gapped;
- public Profile(SparseIntArray counts, int ht, int nongappedCount)
+ /*
+ * the highest count for any residue in the profile
+ */
+ private int maxCount;
+
+ /*
+ * the residue (e.g. K) or residues (e.g. KQW) with the
+ * highest count in the profile
+ */
+ private String modalResidue;
+
+ /**
+ * Constructor which allows derived data to be stored without having to store
+ * the full profile
+ *
+ * @param seqCount
+ * the number of sequences in the profile
+ * @param gaps
+ * the number of gapped sequences
+ * @param max
+ * the highest count for any residue
+ * @param modalres
+ * the residue (or concatenated residues) with the highest count
+ */
+ public Profile(int seqCount, int gaps, int max, String modalRes)
+ {
+ this.height = seqCount;
+ this.gapped = gaps;
+ this.maxCount = max;
+ this.modalResidue = modalRes;
+ }
+
+ /**
+ * Set the full profile of counts
+ *
+ * @param residueCounts
+ */
+ public void setCounts(ResidueCount residueCounts)
+ {
+ this.counts = residueCounts;
+ }
+
+ /**
+ * Returns the percentage identity of the profile, i.e. the highest proportion
+ * of conserved (equal) symbols. The percentage is as a fraction of all
+ * sequences, or only ungapped sequences if flag ignoreGaps is set true.
+ *
+ * @param ignoreGaps
+ * @return
+ */
+ public float getPercentageIdentity(boolean ignoreGaps)
{
- this.profile = counts;
- this.height = ht;
- this.nonGapped = nongappedCount;
+ if (height == 0)
+ {
+ return 0f;
+ }
+ float pid = 0f;
+ if (ignoreGaps && gapped < height)
+ {
+ pid = (maxCount * 100f) / (height - gapped);
+ }
+ else
+ {
+ pid = (maxCount * 100f) / height;
+ }
+ return pid;
}
- public SparseIntArray getProfile()
+ public ResidueCount getCounts()
+ {
+ return counts;
+ }
+
+ public int getHeight()
+ {
+ return height;
+ }
+
+ public int getGapped()
+ {
+ return gapped;
+ }
+
+ public int getMaxCount()
+ {
+ return maxCount;
+ }
+
+ public String getModalResidue()
+ {
+ return modalResidue;
+ }
+
+ /**
+ * Answers the number of non-gapped sequences in the profile
+ *
+ * @return
+ */
+ public int getNonGapped()
{
- return profile;
+ return height - gapped;
}
}