- /**
- * Creates the HMM Logo alignment annotation, and populates it with
- * information content data.
- *
- * @return The alignment annotation.
- */
- public AlignmentAnnotation createAnnotation(int length)
- {
- Annotation[] annotations = new Annotation[length];
- float max = 0f;
- for (int alignPos = 0; alignPos < length; alignPos++)
- {
- Float content = getInformationContent(alignPos);
- if (content > max)
- {
- max = content;
- }
-
- Character cons;
-
- cons = getConsensusAtAlignColumn(alignPos);
-
- cons = Character.toUpperCase(cons);
-
- String description = String.format("%.3f", content);
- description += " bits";
- annotations[alignPos] = new Annotation(cons.toString(), description,
- ' ',
- content);
-
- }
- AlignmentAnnotation annotation = new AlignmentAnnotation(
- "Information",
- "The information content of each column, measured in bits",
- annotations,
- 0f, max, AlignmentAnnotation.BAR_GRAPH);
- annotation.setHMM(this);
- return annotation;
- }
-
- /**
- * Returns the information content at a specified column.
- *
- * @param column
- * Index of the column, starting from 0.
- * @return
- */
- public float getInformationContent(int column)
- {
- float informationContent = 0f;
-
- for (char symbol : symbols)
- {
- float freq = 0f;
- if ("amino".equals(getAlphabetType()))
- {
- freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
- }
- if ("DNA".equals(getAlphabetType()))
- {
- freq = ResidueProperties.dnaBackgroundFrequencies.get(symbol);
- }
- if ("RNA".equals(getAlphabetType()))
- {
- freq = ResidueProperties.rnaBackgroundFrequencies
- .get(symbol);
- }
- Double hmmProb = getMatchEmissionProbability(column, symbol);
- float prob = hmmProb.floatValue();
- informationContent += prob * (Math.log(prob / freq) / Math.log(2));