return informationContent;
}
+ /**
+ * Returns the consensus sequence based on the most probable symbol at each
+ * position. The sequence is adjusted to match the length of the existing
+ * sequence alignment. Gap characters are used as padding.
+ *
+ * @param length
+ * The length of the longest sequence in the existing alignment.
+ * @return
+ */
+ public Sequence getConsensusSequence(int length)
+ {
+ int start;
+ int end;
+ int modelLength;
+ start = getNodeAlignmentColumn(1);
+ modelLength = getLength();
+ end = getNodeAlignmentColumn(modelLength);
+ char[] sequence = new char[length];
+ for (int index = 0; index < length; index++)
+ {
+ Character character;
+ if (consensusResidueIsActive())
+ {
+ character = getConsensusAtAlignColumn(index);
+ }
+ else
+ {
+ character = findConsensusCharacter(index);
+ }
+ if (character == null || character == '-')
+ {
+ sequence[index] = '-';
+ }
+ else
+ {
+ sequence[index] = Character.toUpperCase(character);
+ }
+ }
+
+
+ Sequence seq = new Sequence("HMM CONSENSUS", sequence, start, end);
+ return seq;
+ }
+
+ /**
+ * Finds the most probable character at a column in an alignment based on the
+ * HMM.
+ *
+ * @param nodeIndex
+ * The index of the node.
+ * @return
+ */
+ Character findConsensusCharacter(int column)
+ {
+ Character mostLikely = null;
+ double highestProb = 0;
+ for (char character : symbols)
+ {
+ Double prob = getMatchEmissionProbability(column, character);
+ if (prob > highestProb)
+ {
+ highestProb = prob;
+ mostLikely = character;
+ }
+ }
+ return mostLikely;
+ }
}
getViewport().getAlignment().getWidth());
getViewport().getAlignment().addAnnotation(annotation);
annotation.setHMM(hmm);
+ int length = getViewport().getAlignment().getWidth();
+ Sequence consensus = hmm.getConsensusSequence(length);
+ SequenceI[] consensusArr = new Sequence[] { consensus };
+ AlignmentI newAlignment = new Alignment(consensusArr);
+ newAlignment.append(getViewport().getAlignment());
+ getViewport().setAlignment(newAlignment);
isAnnotation = true;
}