a7fc8b85460df2d4e2617b93c634558e558346bd
[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     double freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
55     Double value = prob - freq;
56
57     Color colour = null;
58     if (value >= 0)
59     {
60
61       colour = ColorUtils.getGraduatedColour(value.floatValue(), 0,
62               Color.WHITE, 1f, Color.green);
63     }
64     else if (value < 0)
65     {
66       return Color.YELLOW;
67
68     }
69     return colour;
70
71   }
72     
73
74
75
76
77
78   @Override
79   public void alignmentChanged(AnnotatedCollectionI collection,
80           Map<SequenceI, SequenceCollectionI> hiddenReps)
81   {
82     AlignmentAnnotation[] annArr = collection.getAlignmentAnnotation();
83     for (AlignmentAnnotation ann : annArr)
84     {
85       if (ann.label.indexOf("Information Content") > -1)
86       {
87         hmm = ann.getHMM();
88       }
89     }
90
91   }
92
93   @Override
94   public ColourSchemeI getInstance(AnnotatedCollectionI sg,
95           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
96   {
97     HiddenMarkovModel markov = null;
98     AlignmentAnnotation[] annArr = sg.getAlignmentAnnotation();
99     for (AlignmentAnnotation ann : annArr)
100     {
101       if (ann.label.indexOf("Information Content") > -1)
102       {
103         markov = ann.getHMM();
104       }
105     }
106     
107     
108     
109     
110
111     HMMERColourScheme colour = new HMMERColourScheme(markov);
112     return colour;
113
114   }
115
116   @Override
117   public boolean isApplicableTo(AnnotatedCollectionI ac)
118   {
119       return true;
120
121   }
122
123   @Override
124   public String getSchemeName()
125   {
126
127     return JalviewColourScheme.HMMER.name();
128   }
129
130   @Override
131   public boolean isSimple()
132   {
133     // TODO Auto-generated method stub
134     return false;
135   }
136
137 }