package jalview.datamodel;
+import jalview.schemes.ResidueProperties;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
//contains the symbol index for each symbol
Map<Character, Integer> symbolIndexLookup = new HashMap<>();
+ Map<Character, Double> backgroundFrequencies = new HashMap();
+
final static String YES = "yes";
{
nodeIndex = nodeLookup.get(alignColumn + 1);
probability = getNode(nodeIndex).getMatchEmissions().get(symbolIndex);
- probability = Math.pow(Math.E, -probability);
return probability;
}
else
nodeIndex = nodeLookup.get(alignColumn + 1);
probability = getNode(nodeIndex).getInsertEmissions()
.get(symbolIndex);
- probability = Math.pow(Math.E, -probability);
return probability;
}
else
nodeIndex = nodeLookup.get(alignColumn + 1);
probability = getNode(nodeIndex).getStateTransitions()
.get(transitionIndex);
- probability = Math.pow(Math.E, -probability);
return probability;
}
else
return value;
}
+ public char getConsensus(int columnIndex)
+ {
+ char value;
+ Integer index = findNodeIndex(columnIndex + 1);
+ if (index == null)
+ {
+ return '-';
+ }
+ value = getNodes().get(index).getConsensusResidue();
+ return value;
+ }
+
public char getReferenceAnnotation(int nodeIndex)
{
char value = nodes.get(nodeIndex).getReferenceAnnotation();
return NO;
}
}
+
+ /**
+ * creates the HMM annotation
+ *
+ * @return
+ */
+ public AlignmentAnnotation createAnnotation(int length)
+ {
+ Annotation[] annotations = new Annotation[length];
+ float max = 0f;
+ for (int i = 0; i < length; i++)
+ {
+ Float content = getInformationContent(i);
+ if (content > max)
+ {
+ max = content;
+ }
+ String description = String.format("%.3f", content);
+ description += " bits";
+ annotations[i] = new Annotation(null, description, ' ', content);
+
+ }
+ AlignmentAnnotation annotation = new AlignmentAnnotation(
+ "Information Content",
+ "The information content of each column, measured in bits",
+ annotations,
+ 0f, max, AlignmentAnnotation.BAR_GRAPH);
+ return annotation;
+ }
+
+ public float getInformationContent(int column)
+ {
+ float informationContent = 0f;
+
+ for (char symbol : symbols)
+ {
+ float freq = 0f;
+ if (symbols.size() == 20)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ }
+ if (symbols.size() == 4)
+ {
+ freq = ResidueProperties.nucleotideBackgroundFrequencies
+ .get(symbol);
+ }
+ Double hmmProb = getMatchEmissionProbability(column, symbol);
+ float prob = hmmProb.floatValue();
+ informationContent += prob * (Math.log(prob / freq) / Math.log(2));
+
+ }
+
+ return informationContent;
+ }
}