1 package jalview.schemes;
3 import jalview.datamodel.AnnotatedCollectionI;
4 import jalview.datamodel.ResidueCount;
5 import jalview.datamodel.SequenceI;
7 import java.util.HashMap;
12 * An HMM colour scheme that uses local (alignment or sub-group) background
13 * frequencies for residues
17 public class HmmerLocalBackground extends HmmerColourScheme
22 * Constructor given a Hidden Markov Model
28 public HmmerLocalBackground(AnnotatedCollectionI ac)
30 super(ac.getHmmConsensus());
35 * Default constructor (required by ColourSchemes.loadColourSchemes)
37 public HmmerLocalBackground()
42 public String getSchemeName()
44 return JalviewColourScheme.HMMERA.toString();
48 * Counts and stores the relative frequency of every residue in the alignment
49 * (apart from any HMM consensus sequences)
53 public void countFrequencies(AnnotatedCollectionI sg)
55 // TODO or total counts in Consensus Profile (how do we get at it?)?
56 Map<Character, Float> freqs = new HashMap<>();
59 * count symbols, excluding any HMM consensus sequences
61 ResidueCount counts = new ResidueCount();
62 List<SequenceI> seqs = sg.getSequences();
63 for (SequenceI seq : seqs)
65 if (!seq.hasHMMProfile())
67 for (char c : seq.getSequence())
73 int total = counts.getTotalResidueCount(); // excludes gaps
75 for (char symbol : counts.getSymbolCounts().symbols)
77 double freq = counts.getCount(symbol) / (double) total;
78 freqs.put(symbol, (float) freq);
81 setFrequencies(freqs);
83 logTotalCount = (float) Math.log(total);
87 float getMaxInformationScore()
93 protected HmmerColourScheme newInstance(AnnotatedCollectionI ac)
95 return new HmmerLocalBackground(ac);