1 package jalview.schemes;
3 import jalview.datamodel.AnnotatedCollectionI;
4 import jalview.datamodel.HiddenMarkovModel;
5 import jalview.datamodel.SequenceCollectionI;
6 import jalview.datamodel.SequenceI;
7 import jalview.util.ColorUtils;
8 import jalview.util.Comparison;
10 import java.awt.Color;
14 * A colour scheme based on a selected Hidden Markov Model. The colour is
16 * <li>white for a gap</li>
17 * <li>red for an insertion</li>
18 * <li>orange for negative information content</li>
19 * <li>white to blue for increasing information content</li>
21 * where information content is the log ratio
24 * log(profile match emission probability / residue background probability>
27 * using global ('Uniprot') background frequencies for residues.
32 public class HMMERColourScheme extends ResidueColourScheme
35 * The highest possible log ratio is when match emission probability in
36 * the HMM model is 1, and background (for W) is 0.0109 giving
37 * log(1/0.0109) = log(91.743) = 4.519
39 private static final float MAX_LOG_RATIO = 4.519f;
41 private static final Color REDDISH = new Color(230, 0, 0);
43 HiddenMarkovModel hmm;
46 * Constructor given a Hidden Markov Model
50 public HMMERColourScheme(HiddenMarkovModel markov)
56 * Default constructor (required by ColourSchemes.loadColourSchemes)
58 public HMMERColourScheme()
63 public Color findColour(char symbol, int position, SequenceI seq,
64 String consensusResidue, float pid)
66 return findColour(symbol, position);
70 * Returns the colour at a particular symbol at a column in the alignment:
72 * <li>white for a gap</li>
73 * <li>red for an insertion</li>
74 * <li>orange for negative information content</li>
75 * <li>white to blue for increasing information content</li>
82 private Color findColour(char symbol, int column)
84 if (hmm == null || Comparison.isGap(symbol))
88 if (Character.isLowerCase(symbol))
90 symbol = Character.toUpperCase(symbol);
93 double prob = hmm.getMatchEmissionProbability(column, symbol);
95 String alpha = hmm.getAlphabetType();
96 if (!ResidueProperties.backgroundFrequencies.get(alpha)
103 freq = ResidueProperties.backgroundFrequencies.get(alpha).get(symbol);
109 double value = Math.log(prob / freq.floatValue());
113 colour = ColorUtils.getGraduatedColour((float) value, 0,
114 Color.WHITE, MAX_LOG_RATIO, Color.blue);
124 public void alignmentChanged(AnnotatedCollectionI collection,
125 Map<SequenceI, SequenceCollectionI> hiddenReps)
128 * ? no need to do anything if alignment is adjusted
129 * since findColour() handles everything
134 * Answers a new colour scheme instance based on the HMM of the first sequence
135 * in sg that has an HMM
138 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
139 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
141 SequenceI hmmSeq = sg.getHmmConsensus();
142 HiddenMarkovModel model = hmmSeq == null ? null : hmmSeq.getHMM();
144 HMMERColourScheme colour = new HMMERColourScheme(model);
149 public String getSchemeName()
151 return JalviewColourScheme.HMMERU.toString();
155 public boolean isSimple()
161 * Answers true if the sequence collection has an HMM consensus sequence, else
165 public boolean isApplicableTo(AnnotatedCollectionI ac)
167 return ac.getHmmConsensus() != null;