package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.ResidueCount; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import java.util.HashMap; import java.util.List; import java.util.Map; /** * An HMM colour scheme that uses local (alignment or sub-group) background * frequencies for residues * * @author tzvanaalten */ public class HmmerLocalBackground extends HmmerColourScheme { float logTotalCount; /** * Constructor given a sequence collection * * @param ac */ public HmmerLocalBackground(AnnotatedCollectionI ac) { super(ac.getHmmSequences()); countFrequencies(ac); } /** * Default constructor (required by ColourSchemes.loadColourSchemes) */ public HmmerLocalBackground() { } @Override public String getSchemeName() { return JalviewColourScheme.HMMERA.toString(); } /** * Counts and stores the relative frequency of every residue in the alignment * (apart from any HMM consensus sequences) * * @param sc */ public void countFrequencies(SequenceCollectionI sc) { // TODO or total counts in Consensus Profile (how do we get at it?)? Map freqs = new HashMap<>(); /* * count symbols, excluding any HMM consensus sequences */ ResidueCount counts = new ResidueCount(); List seqs = sc.getSequences(); for (SequenceI seq : seqs) { if (!seq.hasHMMProfile()) { for (char c : seq.getSequence()) { counts.add(c); } } } int total = counts.getTotalResidueCount(); // excludes gaps for (char symbol : counts.getSymbolCounts().symbols) { double freq = counts.getCount(symbol) / (double) total; freqs.put(symbol, (float) freq); } setFrequencies(freqs); logTotalCount = (float) Math.log(total); } @Override float getMaxInformationScore() { return logTotalCount; } @Override protected HmmerColourScheme newInstance(AnnotatedCollectionI ac) { return new HmmerLocalBackground(ac); } }