Jalview Imported Sources
[jalview.git] / src / jalview / schemes / ResidueColourScheme.java
1 package jalview.schemes;\r
2 \r
3 import jalview.datamodel.*;\r
4 import jalview.jbgui.*;\r
5 \r
6 import java.util.*;\r
7 import java.awt.*;\r
8 \r
9 public class ResidueColourScheme implements ColourSchemeI {\r
10     Color    [] colors;\r
11     int         threshold = 90;\r
12 \r
13     public ResidueColourScheme(Color[] colors, int threshold) {\r
14         this.colors    = colors;\r
15         this.threshold = threshold;\r
16     }\r
17 \r
18     public ResidueColourScheme() {\r
19     }\r
20 \r
21     public Color findColour(String aa)\r
22     {\r
23       return colors[((Integer)(ResidueProperties.aaHash.get(aa))).intValue()];\r
24     }\r
25 \r
26     public Color findColour(SequenceI seq,String s, int j, Vector aa) {\r
27         try {\r
28             return colors[((Integer)(ResidueProperties.aaHash.get(s))).intValue()];\r
29         } catch (Exception e) {\r
30             return Color.white;\r
31         }\r
32     }\r
33 \r
34     // aa should maybe be a class\r
35     public Color getColour(SequenceI seq, int j,Vector aa) {\r
36 \r
37         Color  c       = Color.white;\r
38         String s       = seq.getSequence(j,j+1);\r
39 \r
40         if (threshold > 0 && aa != null)\r
41         {\r
42             if (aboveThreshold(aa,seq,j,threshold))\r
43                 c = findColour(seq,s,j,aa);\r
44         }\r
45         else\r
46             c = findColour(seq,s,j,aa);\r
47 \r
48 \r
49       return c;\r
50     }\r
51     public int getThreshold() {\r
52         return threshold;\r
53     }\r
54 \r
55     public void setThreshold(int ct) {\r
56         threshold = ct;\r
57     }\r
58 \r
59     public Vector  getColours(SequenceI s, Vector aa) {\r
60         Vector colours = new Vector();\r
61 \r
62         for (int j = 0; j < s.getLength(); j++)\r
63             colours.addElement(getColour(s,j,aa));\r
64 \r
65         return colours;\r
66     }\r
67 \r
68     public Vector getColours(SequenceGroup sg, Vector aa) {\r
69         Vector colours = new Vector();\r
70 \r
71         for (int j = 0; j < sg.getSize(); j++) {\r
72             SequenceI s = sg.getSequenceAt(j);\r
73 \r
74             for (int i = 0; i < s.getLength();i++) {\r
75                 colours.addElement(getColour(s,i,aa));\r
76             }\r
77         }\r
78         return colours;\r
79     }\r
80 \r
81     public boolean aboveThreshold(Vector aa,SequenceI seq, int j, int threshold) {\r
82         String    s    = seq.getSequence(j,j+1);\r
83         Hashtable hash = (Hashtable)aa.elementAt(j);\r
84 \r
85         if (j < aa.size()) {\r
86             String maxRes = (String)hash.get("maxResidue");\r
87 \r
88             double sc = 0;\r
89 \r
90             if (((Integer)hash.get("maxCount")).intValue() != -1  && hash.contains(s)) {\r
91                 int maxCount = ((Integer)hash.get("maxCount")).intValue();\r
92                 int resCount = ((Integer)hash.get(s)).intValue();\r
93 \r
94                 sc = resCount * 100.0 / resCount;\r
95 \r
96                 // This should be isGap somewhere\r
97                 if  ( !s.equals("-")  && !s.equals(".") && !s.equals(" ")) {\r
98                     if (sc >= (double)threshold) {\r
99                         return true;\r
100                     }\r
101                 }\r
102             }\r
103         }\r
104         return false;\r
105     }\r
106 \r
107     public boolean canThreshold() {\r
108         return true;\r
109     }\r
110     public boolean isUserDefinable() {\r
111         return false;\r
112     }\r
113 }\r