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;
11 import java.util.List;
15 * A colour scheme based on a selected Hidden Markov Model. The colour is
17 * <li>white for a gap</li>
18 * <li>red for an insertion</li>
19 * <li>orange for negative information content</li>
20 * <li>white to blue for increasing information content</li>
22 * where information content is the log ratio
25 * log(profile match emission probability / residue background probability>
28 * using global ('Uniprot') background frequencies for residues.
33 public class HMMERColourScheme extends ResidueColourScheme
36 * The highest possible log ratio is when match emission probability in
37 * the HMM model is 1, and background (for W) is 0.0109 giving
38 * log(1/0.0109) = log(91.743) = 4.519
40 private static final float MAX_LOG_RATIO = 4.519f;
42 private static final Color REDDISH = new Color(230, 0, 0);
44 HiddenMarkovModel hmm;
47 * Constructor given a Hidden Markov Model
51 public HMMERColourScheme(HiddenMarkovModel markov)
57 * Default constructor (required by ColourSchemes.loadColourSchemes)
59 public HMMERColourScheme()
64 public Color findColour(char symbol, int position, SequenceI seq,
65 String consensusResidue, float pid)
67 return findColour(symbol, position);
71 * Returns the colour at a particular symbol at a column in the alignment:
73 * <li>white for a gap</li>
74 * <li>red for an insertion</li>
75 * <li>orange for negative information content</li>
76 * <li>white to blue for increasing information content</li>
83 private Color findColour(char symbol, int column)
85 if (hmm == null || Comparison.isGap(symbol))
89 if (Character.isLowerCase(symbol))
91 symbol = Character.toUpperCase(symbol);
94 double prob = hmm.getMatchEmissionProbability(column, symbol);
96 String alpha = hmm.getAlphabetType();
97 if (!ResidueProperties.backgroundFrequencies.get(alpha)
104 freq = ResidueProperties.backgroundFrequencies.get(alpha).get(symbol);
110 double value = Math.log(prob / freq.floatValue());
114 colour = ColorUtils.getGraduatedColour((float) value, 0,
115 Color.WHITE, MAX_LOG_RATIO, Color.blue);
125 public void alignmentChanged(AnnotatedCollectionI collection,
126 Map<SequenceI, SequenceCollectionI> hiddenReps)
129 * ? no need to do anything if alignment is adjusted
130 * since findColour() handles everything
135 * Answers a new colour scheme instance based on the HMM of the first sequence
136 * in sg that has an HMM
139 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
140 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
142 HiddenMarkovModel model = null;
143 List<SequenceI> seqs = sg.getHMMConsensusSequences();
146 model = seqs.get(0).getHMM();
148 HMMERColourScheme colour = new HMMERColourScheme(model);
153 public String getSchemeName()
155 return JalviewColourScheme.HMMERU.toString();
159 public boolean isSimple()
165 public boolean isApplicableTo(AnnotatedCollectionI ac)
167 return !ac.getHMMConsensusSequences().isEmpty();