JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / schemes / ResidueColourScheme.js
1 Clazz.declarePackage ("jalview.schemes");\r
2 Clazz.load (["jalview.schemes.ColourSchemeI"], "jalview.schemes.ResidueColourScheme", ["jalview.util.Comparison", "$.MessageManager", "java.awt.Color", "java.lang.Error"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.symbolIndex = null;\r
5 this.conservationColouring = false;\r
6 this.colors = null;\r
7 this.threshold = 0;\r
8 this.ignoreGaps = "G";\r
9 this.consensus = null;\r
10 this.conservation = null;\r
11 this.conservationLength = 0;\r
12 this.inc = 30;\r
13 Clazz.instantialize (this, arguments);\r
14 }, jalview.schemes, "ResidueColourScheme", null, jalview.schemes.ColourSchemeI);\r
15 Clazz.makeConstructor (c$, \r
16 function (aaOrnaIndex, colours, threshold) {\r
17 this.symbolIndex = aaOrnaIndex;\r
18 this.colors = colours;\r
19 this.threshold = threshold;\r
20 }, "~A,~A,~N");\r
21 Clazz.makeConstructor (c$, \r
22 function (aaOrNaIndex) {\r
23 this.symbolIndex = aaOrNaIndex;\r
24 }, "~A");\r
25 Clazz.makeConstructor (c$, \r
26 function () {\r
27 this.symbolIndex = null;\r
28 });\r
29 Clazz.defineMethod (c$, "findColour", \r
30 function (c) {\r
31 return this.colors == null ? java.awt.Color.white : this.colors[this.symbolIndex[c.charCodeAt (0)]];\r
32 }, "~S");\r
33 Clazz.defineMethod (c$, "findColour", \r
34 function (c, j, seq) {\r
35 var currentColour;\r
36 if (this.colors != null && this.symbolIndex != null && (this.threshold == 0) || this.aboveThreshold (c, j)) {\r
37 currentColour = this.colors[this.symbolIndex[c.charCodeAt (0)]];\r
38 } else {\r
39 currentColour = java.awt.Color.white;\r
40 }if (this.conservationColouring) {\r
41 currentColour = this.applyConservation (currentColour, j);\r
42 }return currentColour;\r
43 }, "~S,~N,jalview.datamodel.SequenceI");\r
44 Clazz.overrideMethod (c$, "getThreshold", \r
45 function () {\r
46 return this.threshold;\r
47 });\r
48 Clazz.overrideMethod (c$, "setThreshold", \r
49 function (ct, ignoreGaps) {\r
50 this.threshold = ct;\r
51 if (ignoreGaps) {\r
52 this.ignoreGaps = "N";\r
53 } else {\r
54 this.ignoreGaps = "G";\r
55 }}, "~N,~B");\r
56 Clazz.defineMethod (c$, "aboveThreshold", \r
57 function (c, j) {\r
58 if ('a' <= c && c <= 'z') {\r
59 c = String.fromCharCode (c.charCodeAt (0) - (32));\r
60 }if (this.consensus == null || this.consensus.length < j || this.consensus[j] == null) {\r
61 return false;\r
62 }if (((this.consensus[j].get ("C")).intValue () != -1) && this.consensus[j].contains (String.valueOf (c))) {\r
63 if ((this.consensus[j].get (this.ignoreGaps)).floatValue () >= this.threshold) {\r
64 return true;\r
65 }}return false;\r
66 }, "~S,~N");\r
67 Clazz.overrideMethod (c$, "conservationApplied", \r
68 function () {\r
69 return this.conservationColouring;\r
70 });\r
71 Clazz.overrideMethod (c$, "setConservationApplied", \r
72 function (conservationApplied) {\r
73 this.conservationColouring = conservationApplied;\r
74 }, "~B");\r
75 Clazz.overrideMethod (c$, "setConservationInc", \r
76 function (i) {\r
77 this.inc = i;\r
78 }, "~N");\r
79 Clazz.overrideMethod (c$, "getConservationInc", \r
80 function () {\r
81 return this.inc;\r
82 });\r
83 Clazz.overrideMethod (c$, "setConsensus", \r
84 function (consensus) {\r
85 if (consensus == null) {\r
86 return;\r
87 }this.consensus = consensus;\r
88 }, "~A");\r
89 Clazz.overrideMethod (c$, "setConservation", \r
90 function (cons) {\r
91 if (cons == null) {\r
92 this.conservationColouring = false;\r
93 this.conservation = null;\r
94 } else {\r
95 this.conservationColouring = true;\r
96 var i;\r
97 var iSize = cons.getConsSequence ().getLength ();\r
98 this.conservation =  Clazz.newCharArray (iSize, '\0');\r
99 for (i = 0; i < iSize; i++) {\r
100 this.conservation[i] = cons.getConsSequence ().getCharAt (i);\r
101 }\r
102 this.conservationLength = this.conservation.length;\r
103 }}, "jalview.analysis.Conservation");\r
104 Clazz.defineMethod (c$, "applyConservation", \r
105 function (currentColour, i) {\r
106 if ((this.conservationLength > i) && (this.conservation[i] != '*') && (this.conservation[i] != '+')) {\r
107 if (jalview.util.Comparison.isGap (this.conservation[i])) {\r
108 currentColour = java.awt.Color.white;\r
109 } else {\r
110 var t = 11 - ((this.conservation[i]).charCodeAt (0) - 48);\r
111 if (t == 0) {\r
112 return java.awt.Color.white;\r
113 }var red = currentColour.getRed ();\r
114 var green = currentColour.getGreen ();\r
115 var blue = currentColour.getBlue ();\r
116 var dr = 255 - red;\r
117 var dg = 255 - green;\r
118 var db = 255 - blue;\r
119 dr *= t / 10;\r
120 dg *= t / 10;\r
121 db *= t / 10;\r
122 red += (this.inc / 20) * dr;\r
123 green += (this.inc / 20) * dg;\r
124 blue += (this.inc / 20) * db;\r
125 if (red > 255 || green > 255 || blue > 255) {\r
126 currentColour = java.awt.Color.white;\r
127 } else {\r
128 currentColour =  new java.awt.Color (red, green, blue);\r
129 }}}return currentColour;\r
130 }, "java.awt.Color,~N");\r
131 Clazz.overrideMethod (c$, "alignmentChanged", \r
132 function (alignment, hiddenReps) {\r
133 }, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");\r
134 Clazz.overrideMethod (c$, "applyTo", \r
135 function (sg, hiddenRepSequences) {\r
136 try {\r
137 return this.getClass ().newInstance ();\r
138 } catch (q) {\r
139 if (Clazz.exceptionOf (q, Exception)) {\r
140 throw  new Error (jalview.util.MessageManager.formatMessage ("error.implementation_error_cannot_duplicate_colour_scheme",  Clazz.newArray (-1, [this.getClass ().getName ()])), q);\r
141 } else {\r
142 throw q;\r
143 }\r
144 }\r
145 }, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");\r
146 });\r