+
+ /**
+ * 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[] getHMMProfileFor(AlignmentAnnotation aa, int column,
+ boolean removeBelowBackground)
+ {
+
+ HiddenMarkovModel hmm;
+ hmm = aa.getHMM();
+ 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;
+ Double value;
+
+ value = hmm.getMatchEmissionProbability(column, symbol);
+ double freq;
+
+ if (alph == AMINO && removeBelowBackground)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (alph == DNA && removeBelowBackground)
+ {
+ freq = ResidueProperties.nucleotideBackgroundFrequencies
+ .get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ value = value * 10000;
+ values[i] = value.intValue();
+ totalCount += value.intValue();
+ }
+
+ QuickSort.sort(values, symbols);
+
+ int[] profile = new int[3 + size * 2];
+
+ profile[0] = AlignmentAnnotation.SEQUENCE_PROFILE;
+ profile[1] = size;
+ profile[2] = totalCount / 100;
+
+ if (totalCount != 0)
+ {
+ int arrayPos = 3;
+ for (int k = size - 1; k >= 0; k--)
+ {
+ Double percentage;
+ Integer value = values[k];
+ percentage = (value.doubleValue() / totalCount.doubleValue())
+ * 100d;
+ profile[arrayPos] = symbols[k];
+ profile[arrayPos + 1] = percentage.intValue();
+ arrayPos += 2;
+ }
+ }
+ return profile;
+ }
+ return null;
+ }