+ public int[] getHMMProfileFor(AlignmentAnnotation aa, int column,
+ boolean removeBelowBackground)
+ {
+
+ HiddenMarkovModel hmm;
+ hmm = aa.getHMM();
+ int size = 0;
+ int alphabet = 0;
+ String alph = hmm.getAlphabetType();
+ if (alph.equals("amino"))
+ {
+ size = 20;
+ alphabet = AMINO;
+ }
+ else if (alph.equals("DNA"))
+ {
+ size = 4;
+ alphabet = DNA;
+ }
+
+ char symbols[] = new char[size];
+ int values[] = new int[size];
+
+ List<Character> charList = hmm.getSymbols();
+
+ int i = 0;
+ for (char character : charList)
+ {
+ symbols[i] = character;
+ i++;
+ }
+
+ Integer totalCount = 0;
+ for (int j = 0; j < size; j++)
+ {
+ Double value;
+ char symbol = symbols[j];
+ value = hmm.getMatchEmissionProbability(column, symbol);
+ double freq;
+
+ if (alphabet == AMINO && removeBelowBackground)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (alphabet == DNA && removeBelowBackground)
+ {
+ freq = ResidueProperties.nucleotideBackgroundFrequencies
+ .get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ value = value * 10000;
+ values[j] = 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;
+
+ 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;
+
+ }
+