/*
* the aligned HMM consensus sequence to use as reference for colouring
*/
- private SequenceI hmmSeq;
-
- private HiddenMarkovModel hmm;
+ private List<SequenceI> hmmSeqs=null;
+
private Map<Character, Float> frequencies;
/**
*/
public HmmerColourScheme(List<SequenceI> hmmSeqs)
{
- hmmSeq = hmmSeqs.isEmpty() ? null : hmmSeqs.get(0);
- hmm = hmmSeq == null ? null : hmmSeq.getHMM();
+ this.hmmSeqs = hmmSeqs.isEmpty() ? null : hmmSeqs;
+ }
+
+ protected String getAlphabetType()
+ {
+ if (hmmSeqs!=null) {
+ for (SequenceI hmmSeq : hmmSeqs)
+ {
+ if (hmmSeq != null)
+ {
+ HiddenMarkovModel hmm = hmmSeq.getHMM();
+ if (hmm != null)
+ {
+ return hmm.getAlphabetType();
+ }
+ }
+ }}
+ return ResidueProperties.ALPHABET_AMINO;
}
/**
*/
private Color findColour(char symbol, int column)
{
- if (getHmm() == null || Comparison.isGap(symbol))
+ if (hmmSeqs==null || Comparison.isGap(symbol))
{
+ // todo: could return probability of seeing a gap ?
return Color.white;
}
- if (Comparison.isGap(hmmSeq.getCharAt(column)))
- {
- return INSERTION_COLOUR;
- }
- if (Character.isLowerCase(symbol))
- {
- symbol = Character.toUpperCase(symbol);
- }
-
- final double prob = getHmm().getMatchEmissionProbability(column,
- symbol);
-
- Float freq = 0f;
-
- if (!frequencies.containsKey(symbol))
- {
- return Color.WHITE;
- }
- else
- {
- freq = frequencies.get(symbol);
- }
-
- /*
- * Orange if match emission probability is less than background probability
- */
- double infoRatio = prob / freq.floatValue();
- Color colour = Color.ORANGE;
- if (infoRatio >= 1)
+ // locate first hmm with a non-gap at this position
+ for (SequenceI hmmSeq:hmmSeqs)
{
- /*
- * log-scale graduated shade of blue if prob is greater than background
- */
- float infoLog = (float) Math.log(infoRatio);
- colour = ColorUtils.getGraduatedColour(infoLog, 0, Color.WHITE,
- getMaxInformationScore(), Color.blue);
+ if (hmmSeq==null)
+ {
+ continue;
+ }
+ if (!Comparison.isGap(hmmSeq.getCharAt(column)))
+ {
+ if (symbol >= 'a')
+ {
+ symbol += 'A' - 'a';
+ }
+
+ final double prob = hmmSeq.getHMM()
+ .getMatchEmissionProbability(column, symbol);
+
+ Float freq = 0f;
+
+ if (!frequencies.containsKey(symbol))
+ {
+ return Color.WHITE;
+ }
+ else
+ {
+ freq = frequencies.get(symbol);
+ }
+
+ /*
+ * Orange if match emission probability is less than background probability
+ */
+ double infoRatio = prob / freq.floatValue();
+ Color colour = Color.ORANGE;
+ if (infoRatio >= 1)
+ {
+ /*
+ * log-scale graduated shade of blue if prob is greater than background
+ */
+ float infoLog = (float) Math.log(infoRatio);
+ colour = ColorUtils.getGraduatedColour(infoLog, 0, Color.WHITE,
+ getMaxInformationScore(), Color.blue);
+ }
+
+ return colour;
+ }
}
-
- return colour;
+ // no more seqs. so
+ return INSERTION_COLOUR;
}
/**
{
this.frequencies = frequencies;
}
-
- protected HiddenMarkovModel getHmm()
- {
- return hmm;
- }
-
- protected SequenceI getHmmSequence()
- {
- return hmmSeq;
- }
}
import jalview.api.AlignViewportI;
import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.hmmer.HMMSearch;
/**
* An HMM colour scheme that uses global ('Uniprot') background frequencies for
public HmmerGlobalBackground(SequenceCollectionI ac)
{
super(ac.getHmmSequences());
- String alphabetType = getHmm() == null
- ? ResidueProperties.ALPHABET_AMINO
- : getHmm().getAlphabetType();
+ String alphabetType = getAlphabetType();
setFrequencies(
ResidueProperties.backgroundFrequencies.get(alphabetType));
}