+
+ /**
+ * Returns the information content at a specified column.
+ *
+ * @param column
+ * Index of the column, starting from 0.
+ * @return
+ */
+ public static float getInformationContent(int column,
+ HiddenMarkovModel hmm)
+ {
+ float informationContent = 0f;
+
+ for (char symbol : hmm.getSymbols())
+ {
+ float freq = 0f;
+ if ("amino".equals(hmm.getAlphabetType()))
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ }
+ if ("DNA".equals(hmm.getAlphabetType()))
+ {
+ freq = ResidueProperties.dnaBackgroundFrequencies.get(symbol);
+ }
+ if ("RNA".equals(hmm.getAlphabetType()))
+ {
+ freq = ResidueProperties.rnaBackgroundFrequencies.get(symbol);
+ }
+ Double hmmProb = hmm.getMatchEmissionProbability(column, symbol);
+ float prob = hmmProb.floatValue();
+ informationContent += prob * (Math.log(prob / freq) / Math.log(2));
+
+ }
+
+ return informationContent;
+ }
+
+ /**
+ * Produces a HMM profile for a column in an alignment
+ *
+ * @param aa
+ * Alignment annotation for which the profile is being calculated.
+ * @param column
+ * Column in the alignment the profile is being made for.
+ * @param removeBelowBackground
+ * Boolean indicating whether to ignore residues with probabilities
+ * less than their background frequencies.
+ * @return
+ */
+ public static int[] extractHMMProfile(HiddenMarkovModel hmm, int column,
+ boolean removeBelowBackground)
+ {
+
+ if (hmm != null)
+ {
+ String alph = hmm.getAlphabetType();
+ int size = hmm.getNumberOfSymbols();
+ char symbols[] = new char[size];
+ int values[] = new int[size];
+ List<Character> charList = hmm.getSymbols();
+ Integer totalCount = 0;
+
+ for (int i = 0; i < size; i++)
+ {
+ char symbol = charList.get(i);
+ symbols[i] = symbol;
+ int value = getAnalogueCount(hmm, column, removeBelowBackground,
+ alph, symbol);
+ values[i] = value;
+ totalCount += value;
+ }
+
+ QuickSort.sort(values, symbols);
+
+ int[] profile = new int[3 + size * 2];
+
+ profile[0] = AlignmentAnnotation.SEQUENCE_PROFILE;
+ profile[1] = size;
+ profile[2] = 100;
+
+ if (totalCount != 0)
+ {
+ int arrayPos = 3;
+ for (int k = size - 1; k >= 0; k--)
+ {
+ Float percentage;
+ Integer value = values[k];
+ if (removeBelowBackground)
+ {
+ percentage = (value.floatValue() / totalCount.floatValue())
+ * 100;
+ }
+ else
+ {
+ percentage = value.floatValue() / 100f;
+ }
+ int intPercent = Math.round(percentage);
+ profile[arrayPos] = symbols[k];
+ profile[arrayPos + 1] = intPercent;
+ arrayPos += 2;
+ }
+ }
+ return profile;
+ }
+ return null;
+ }
+
+ private static int getAnalogueCount(HiddenMarkovModel hmm, int column,
+ boolean removeBelowBackground, String alph, char symbol)
+ {
+ Double value;
+
+ value = hmm.getMatchEmissionProbability(column, symbol);
+ double freq;
+
+ if (AMINO.equals(alph) && removeBelowBackground)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (DNA.equals(alph) && removeBelowBackground)
+ {
+ freq = ResidueProperties.dnaBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (RNA.equals(alph) && removeBelowBackground)
+ {
+ freq = ResidueProperties.rnaBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ value = value * 10000;
+ return Math.round(value.floatValue());
+ }