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