1 package jalview.schemes;
3 import jalview.datamodel.AnnotatedCollectionI;
4 import jalview.datamodel.HiddenMarkovModel;
5 import jalview.datamodel.ResidueCount;
6 import jalview.datamodel.SequenceCollectionI;
7 import jalview.datamodel.SequenceI;
8 import jalview.util.ColorUtils;
9 import jalview.util.Comparison;
11 import java.awt.Color;
12 import java.util.HashMap;
13 import java.util.List;
16 public class HMMERAlignmentColourScheme extends ResidueColourScheme
18 Map<Character, Double> backgroundFrequencies = new HashMap<>();
22 HiddenMarkovModel hmm;
24 boolean peptideSpecific;
26 boolean nucleotideSpecific;
28 public HMMERAlignmentColourScheme(HiddenMarkovModel markov)
33 public HMMERAlignmentColourScheme()
39 public Color findColour(char symbol, int position, SequenceI seq,
40 String consensusResidue, float pid)
46 return findColour(symbol, position);
50 * Returns the colour at a particular symbol at a column in the alignment.
54 * @return Red for an insertion, white for a gap, orange for a negative
55 * information content, white to blue for increasing information
58 private Color findColour(char symbol, int position)
61 if (Comparison.isGap(symbol))
65 if (Character.isLowerCase(symbol))
67 symbol = Character.toUpperCase(symbol);
70 prob = hmm.getMatchEmissionProbability(position, symbol);
71 Double freq = backgroundFrequencies.get(symbol);
78 return new Color(230, 0, 0);
80 Double value = Math.log(prob / freq);
85 colour = ColorUtils.getGraduatedColour(value.floatValue(), 0,
86 Color.WHITE, maxLLR.floatValue(), Color.blue);
97 public void alignmentChanged(AnnotatedCollectionI collection,
98 Map<SequenceI, SequenceCollectionI> hiddenReps)
100 List<SequenceI> seqs = collection.getSequences();
101 for (SequenceI seq : seqs)
103 if (seq.isHMMConsensusSequence())
115 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
116 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
118 HiddenMarkovModel markov = null;
119 List<SequenceI> seqs = sg.getSequences();
120 for (SequenceI seq : seqs)
122 if (seq.getHMM() != null)
124 markov = seq.getHMM();
131 HMMERAlignmentColourScheme colour = new HMMERAlignmentColourScheme(
138 public boolean isApplicableTo(AnnotatedCollectionI ac)
145 public String getSchemeName()
148 return JalviewColourScheme.HMMERA.name();
152 public boolean isSimple()
157 public void count(AnnotatedCollectionI sg)
159 ResidueCount counts = new ResidueCount();
160 for (SequenceI seq : sg.getSequences())
162 for (int i = 0; i < seq.getLength(); i++)
164 if (!Comparison.isGap(seq.getCharAt(i)))
166 counts.add(seq.getCharAt(i));
171 int total = counts.getTotalCount();
173 for (char symbol : counts.getSymbolCounts().symbols)
175 double count = Double.valueOf(counts.getCount(symbol))
176 / Double.valueOf(total);
177 backgroundFrequencies.put(symbol, count);
179 maxLLR = Math.log(total);