add partial button fix to annotation and statistics output
[jalview.git] / src / jalview / schemes / HMMERColourScheme.java
1 package jalview.schemes;
2
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.AnnotatedCollectionI;
5 import jalview.datamodel.HiddenMarkovModel;
6 import jalview.datamodel.SequenceCollectionI;
7 import jalview.datamodel.SequenceI;
8 import jalview.util.ColorUtils;
9 import jalview.util.Comparison;
10
11 import java.awt.Color;
12 import java.util.Map;
13
14 public class HMMERColourScheme extends ResidueColourScheme
15 {
16
17   AnnotatedCollectionI alignment;
18
19   HiddenMarkovModel hmm;
20   
21   boolean peptideSpecific;
22
23   boolean nucleotideSpecific;
24
25   public HMMERColourScheme(HiddenMarkovModel markov)
26   {
27     hmm = markov;
28   }
29   public HMMERColourScheme()
30   {
31
32   }
33
34   @Override
35   public Color findColour(char symbol, int position, SequenceI seq,
36           String consensusResidue, float pid)
37   {
38     if (hmm ==null)
39     {
40       return Color.white;
41     }
42     return findColour(symbol, position);
43   }
44
45   public Color findColour(char symbol, int position)
46   {
47
48     if (Comparison.isGap(symbol))
49     {
50       return Color.white;
51     }
52     Double prob;
53     prob = hmm.getMatchEmissionProbability(position, symbol);
54     if (prob == 0)
55     {
56       return Color.red;
57     }
58     double freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
59     Double value = Math.log(prob / freq);
60     Color colour = null;
61     if (value > 0)
62     {
63
64       colour = ColorUtils.getGraduatedColour(value.floatValue(), 0,
65               Color.WHITE, 3f, Color.blue);
66     }
67     else if (value < 0)
68     {
69       return Color.ORANGE;
70
71     }
72     return colour;
73
74   }
75     
76
77
78
79
80
81   @Override
82   public void alignmentChanged(AnnotatedCollectionI collection,
83           Map<SequenceI, SequenceCollectionI> hiddenReps)
84   {
85     AlignmentAnnotation[] annArr = collection.getAlignmentAnnotation();
86     for (AlignmentAnnotation ann : annArr)
87     {
88       if (ann.label.indexOf("Information Content") > -1)
89       {
90         hmm = ann.getHMM();
91       }
92     }
93
94   }
95
96   @Override
97   public ColourSchemeI getInstance(AnnotatedCollectionI sg,
98           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
99   {
100     HiddenMarkovModel markov = null;
101     AlignmentAnnotation[] annArr = sg.getAlignmentAnnotation();
102     for (AlignmentAnnotation ann : annArr)
103     {
104       if (ann.label.indexOf("Information Content") > -1)
105       {
106         markov = ann.getHMM();
107       }
108     }
109     
110     
111     
112     
113
114     HMMERColourScheme colour = new HMMERColourScheme(markov);
115     return colour;
116
117   }
118
119   @Override
120   public boolean isApplicableTo(AnnotatedCollectionI ac)
121   {
122       return true;
123
124   }
125
126   @Override
127   public String getSchemeName()
128   {
129
130     return JalviewColourScheme.HMMER.name();
131   }
132
133   @Override
134   public boolean isSimple()
135   {
136     // TODO Auto-generated method stub
137     return false;
138   }
139
140 }