JAL-3285 code changes to HMMER colour schemes not included in merge
[jalview.git] / src / jalview / schemes / HmmerGlobalBackground.java
1 package jalview.schemes;
2
3 import jalview.api.AlignViewportI;
4 import jalview.datamodel.AnnotatedCollectionI;
5 import jalview.datamodel.SequenceCollectionI;
6
7 /**
8  * An HMM colour scheme that uses global ('Uniprot') background frequencies for
9  * residues
10  * 
11  * @author tzvanaalten
12  */
13 public class HmmerGlobalBackground extends HmmerColourScheme
14 {
15   /*
16    * The highest possible log ratio is when match emission probability in
17    * the HMM model is 1, and background (for W) is 0.0109 giving
18    * log(1/0.0109) = log(91.743) = 4.519
19    */
20   private static final float MAX_LOG_RATIO = 4.519f;
21
22   /**
23    * Constructor given a sequence collection
24    * 
25    * @param ac
26    */
27   public HmmerGlobalBackground(SequenceCollectionI ac)
28   {
29     super(ac.getHmmSequences());
30     String alphabetType = getHmm() == null
31             ? ResidueProperties.ALPHABET_AMINO
32             : getHmm().getAlphabetType();
33     setFrequencies(
34             ResidueProperties.backgroundFrequencies.get(alphabetType));
35   }
36
37   /**
38    * Default constructor (required by ColourSchemes.loadColourSchemes)
39    */
40   public HmmerGlobalBackground()
41   {
42   }
43
44   @Override
45   public String getSchemeName()
46   {
47     return JalviewColourScheme.HMMERU.toString();
48   }
49
50   @Override
51   protected HmmerColourScheme newInstance(AnnotatedCollectionI ac)
52   {
53     return new HmmerGlobalBackground(ac);
54   }
55
56   @Override
57   float getMaxInformationScore()
58   {
59     return MAX_LOG_RATIO;
60   }
61
62   /**
63    * Answers a new colour scheme instance based on the HMM of the first sequence
64    * in alignment that has an HMM
65    */
66   @Override
67   public ColourSchemeI getInstance(AlignViewportI viewport,
68           AnnotatedCollectionI ac)
69   {
70     return newInstance(ac);
71   }
72
73 }