JAL-1807 - Bob's last(?) before leaving Dundee -- adds fast file loading
[jalviewjs.git] / site / j2s / jalview / schemes / AnnotationColourGradient.js
1 Clazz.declarePackage ("jalview.schemes");
2 Clazz.load (["jalview.schemes.FollowerColourScheme"], "jalview.schemes.AnnotationColourGradient", ["jalview.datamodel.AlignmentI", "$.GraphLine", "jalview.renderer.AnnotationRenderer", "jalview.schemes.ColourSchemeProperty", "jalview.util.Comparison", "java.awt.Color", "java.util.IdentityHashMap"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.annotation = null;
5 this.aboveAnnotationThreshold = -1;
6 this.thresholdIsMinMax = false;
7 this.annotationThreshold = null;
8 this.r1 = 0;
9 this.g1 = 0;
10 this.b1 = 0;
11 this.rr = 0;
12 this.gg = 0;
13 this.bb = 0;
14 this.predefinedColours = false;
15 this.seqAssociated = false;
16 this.noGradient = false;
17 this.seqannot = null;
18 this.aamin = 0;
19 this.aamax = 0;
20 Clazz.instantialize (this, arguments);
21 }, jalview.schemes, "AnnotationColourGradient", jalview.schemes.FollowerColourScheme);
22 Clazz.overrideMethod (c$, "applyTo", 
23 function (sg, hiddenRepSequences) {
24 var acg =  new jalview.schemes.AnnotationColourGradient (this.annotation, this.colourScheme, this.aboveAnnotationThreshold);
25 acg.thresholdIsMinMax = this.thresholdIsMinMax;
26 acg.annotationThreshold = (this.annotationThreshold == null) ? null :  new jalview.datamodel.GraphLine (this.annotationThreshold);
27 acg.r1 = this.r1;
28 acg.g1 = this.g1;
29 acg.b1 = this.b1;
30 acg.rr = this.rr;
31 acg.gg = this.gg;
32 acg.bb = this.bb;
33 acg.predefinedColours = this.predefinedColours;
34 acg.seqAssociated = this.seqAssociated;
35 acg.noGradient = this.noGradient;
36 return acg;
37 }, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");
38 Clazz.makeConstructor (c$, 
39 function (annotation, originalColour, aboveThreshold) {
40 Clazz.superConstructor (this, jalview.schemes.AnnotationColourGradient, []);
41 if (Clazz.instanceOf (originalColour, jalview.schemes.AnnotationColourGradient)) {
42 this.colourScheme = (originalColour).colourScheme;
43 } else {
44 this.colourScheme = originalColour;
45 }this.annotation = annotation;
46 this.aboveAnnotationThreshold = aboveThreshold;
47 if (aboveThreshold != -1 && annotation.threshold != null) {
48 this.annotationThreshold = annotation.threshold;
49 }this.r1 = 254;
50 this.g1 = 254;
51 this.b1 = 254;
52 this.rr = 0;
53 this.gg = 0;
54 this.bb = 0;
55 this.noGradient = true;
56 }, "jalview.datamodel.AlignmentAnnotation,jalview.schemes.ColourSchemeI,~N");
57 Clazz.makeConstructor (c$, 
58 function (annotation, minColour, maxColour, aboveThreshold) {
59 Clazz.superConstructor (this, jalview.schemes.AnnotationColourGradient, []);
60 this.annotation = annotation;
61 this.aboveAnnotationThreshold = aboveThreshold;
62 if (aboveThreshold != -1 && annotation.threshold != null) {
63 this.annotationThreshold = annotation.threshold;
64 }this.r1 = minColour.getRed ();
65 this.g1 = minColour.getGreen ();
66 this.b1 = minColour.getBlue ();
67 this.rr = maxColour.getRed () - this.r1;
68 this.gg = maxColour.getGreen () - this.g1;
69 this.bb = maxColour.getBlue () - this.b1;
70 this.noGradient = false;
71 this.aamax = annotation.graphMax;
72 this.aamin = annotation.graphMin;
73 if (annotation.isRNA ()) {
74 jalview.schemes.ColourSchemeProperty.initRnaHelicesShading (1 + Clazz.floatToInt (this.aamax));
75 }}, "jalview.datamodel.AlignmentAnnotation,java.awt.Color,java.awt.Color,~N");
76 Clazz.defineMethod (c$, "alignmentChanged", 
77 function (alignment, hiddenReps) {
78 Clazz.superCall (this, jalview.schemes.AnnotationColourGradient, "alignmentChanged", [alignment, hiddenReps]);
79 if (this.seqAssociated && this.annotation.getCalcId () != null) {
80 if (this.seqannot != null) {
81 this.seqannot.clear ();
82 } else {
83 this.seqannot =  new java.util.IdentityHashMap ();
84 }var alcontext = Clazz.instanceOf (alignment, jalview.datamodel.AlignmentI) ? alignment : alignment.getContext ();
85 var f = true;
86 var rna = false;
87 for (var alan, $alan = alcontext.findAnnotation (this.annotation.getCalcId ()).iterator (); $alan.hasNext () && ((alan = $alan.next ()) || true);) {
88 if (alan.sequenceRef != null && (alan.label != null && this.annotation != null && alan.label.equals (this.annotation.label))) {
89 if (!rna && alan.isRNA ()) {
90 rna = true;
91 }this.seqannot.put (alan.sequenceRef, alan);
92 if (f || alan.graphMax > this.aamax) {
93 this.aamax = alan.graphMax;
94 }if (f || alan.graphMin < this.aamin) {
95 this.aamin = alan.graphMin;
96 }f = false;
97 }}
98 if (rna) {
99 jalview.schemes.ColourSchemeProperty.initRnaHelicesShading (1 + Clazz.floatToInt (this.aamax));
100 }}}, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");
101 Clazz.defineMethod (c$, "getAnnotation", 
102 function () {
103 return this.annotation.label;
104 });
105 Clazz.defineMethod (c$, "getAboveThreshold", 
106 function () {
107 return this.aboveAnnotationThreshold;
108 });
109 Clazz.defineMethod (c$, "getAnnotationThreshold", 
110 function () {
111 if (this.annotationThreshold == null) {
112 return 0;
113 } else {
114 return this.annotationThreshold.value;
115 }});
116 Clazz.defineMethod (c$, "getMinColour", 
117 function () {
118 return  new java.awt.Color (Clazz.floatToInt (this.r1), Clazz.floatToInt (this.g1), Clazz.floatToInt (this.b1));
119 });
120 Clazz.defineMethod (c$, "getMaxColour", 
121 function () {
122 return  new java.awt.Color (Clazz.floatToInt (this.r1 + this.rr), Clazz.floatToInt (this.g1 + this.gg), Clazz.floatToInt (this.b1 + this.bb));
123 });
124 Clazz.overrideMethod (c$, "findColour", 
125 function (c) {
126 return java.awt.Color.red;
127 }, "~S");
128 Clazz.overrideMethod (c$, "findColourSeq", 
129 function (c, j, seq) {
130 var currentColour = java.awt.Color.white;
131 var annotation = (this.seqAssociated && this.seqannot != null ? this.seqannot.get (seq) : this.annotation);
132 if (annotation == null) {
133 return currentColour;
134 }if ((this.threshold == 0) || this.aboveThreshold (c, j)) {
135 if (annotation.annotations != null && j < annotation.annotations.length && annotation.annotations[j] != null && !jalview.util.Comparison.isGap (c)) {
136 var aj = annotation.annotations[j];
137 if (this.aboveAnnotationThreshold == -1 || (this.annotationThreshold != null && (this.aboveAnnotationThreshold == 1 ? aj.value >= this.annotationThreshold.value : aj.value <= this.annotationThreshold.value))) {
138 if (this.predefinedColours && aj.colour != null && !aj.colour.equals (java.awt.Color.black)) {
139 currentColour = aj.colour;
140 } else if (annotation.hasIcons && annotation.graph == 0) {
141 if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.' && aj.secondaryStructure != '-') {
142 if (this.colourScheme != null) {
143 currentColour = this.colourScheme.findColourSeq (c, j, seq);
144 } else {
145 if (annotation.isRNA ()) {
146 currentColour = jalview.schemes.ColourSchemeProperty.rnaHelices[Clazz.floatToInt (aj.value)];
147 } else {
148 currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR : jalview.renderer.AnnotationRenderer.STEM_COLOUR;
149 }}} else {
150 return java.awt.Color.white;
151 }} else if (this.noGradient) {
152 if (this.colourScheme != null) {
153 currentColour = this.colourScheme.findColourSeq (c, j, seq);
154 } else {
155 if (aj.colour != null) {
156 currentColour = aj.colour;
157 }}} else {
158 currentColour = this.shadeCalculation (annotation, j);
159 }}if (this.conservationColouring) {
160 currentColour = this.applyConservation (currentColour, j);
161 }}}return currentColour;
162 }, "~S,~N,jalview.datamodel.SequenceI");
163 Clazz.defineMethod (c$, "shadeCalculation", 
164  function (annotation, j) {
165 var range = 1;
166 if (this.thresholdIsMinMax && annotation.threshold != null && this.aboveAnnotationThreshold == 1 && annotation.annotations[j].value >= annotation.threshold.value) {
167 range = (annotation.annotations[j].value - annotation.threshold.value) / (annotation.graphMax - annotation.threshold.value);
168 } else if (this.thresholdIsMinMax && annotation.threshold != null && this.aboveAnnotationThreshold == 0 && annotation.annotations[j].value >= annotation.graphMin) {
169 range = (annotation.annotations[j].value - annotation.graphMin) / (annotation.threshold.value - annotation.graphMin);
170 } else {
171 if (annotation.graphMax != annotation.graphMin) {
172 range = (annotation.annotations[j].value - annotation.graphMin) / (annotation.graphMax - annotation.graphMin);
173 } else {
174 range = 0;
175 }}var dr = Clazz.floatToInt (this.rr * range + this.r1);
176 var dg = Clazz.floatToInt (this.gg * range + this.g1);
177 var db = Clazz.floatToInt (this.bb * range + this.b1);
178 return  new java.awt.Color (dr, dg, db);
179 }, "jalview.datamodel.AlignmentAnnotation,~N");
180 Clazz.defineMethod (c$, "isPredefinedColours", 
181 function () {
182 return this.predefinedColours;
183 });
184 Clazz.defineMethod (c$, "setPredefinedColours", 
185 function (predefinedColours) {
186 this.predefinedColours = predefinedColours;
187 }, "~B");
188 Clazz.defineMethod (c$, "isSeqAssociated", 
189 function () {
190 return this.seqAssociated;
191 });
192 Clazz.defineMethod (c$, "setSeqAssociated", 
193 function (sassoc) {
194 this.seqAssociated = sassoc;
195 }, "~B");
196 Clazz.defineStatics (c$,
197 "NO_THRESHOLD", -1,
198 "BELOW_THRESHOLD", 0,
199 "ABOVE_THRESHOLD", 1);
200 });