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