JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / schemes / RNAHelicesColour.js
1 Clazz.declarePackage ("jalview.schemes");\r
2 Clazz.load (["jalview.schemes.ResidueColourScheme", "java.util.Hashtable"], "jalview.schemes.RNAHelicesColour", ["jalview.schemes.ResidueProperties", "jalview.util.ColorUtils", "java.awt.Color"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.helixcolorhash = null;\r
5 this.positionsToHelix = null;\r
6 this.numHelix = 0;\r
7 this.annotation = null;\r
8 this.lastrefresh = -1;\r
9 Clazz.instantialize (this, arguments);\r
10 }, jalview.schemes, "RNAHelicesColour", jalview.schemes.ResidueColourScheme);\r
11 Clazz.prepareFields (c$, function () {\r
12 this.helixcolorhash =  new java.util.Hashtable ();\r
13 this.positionsToHelix =  new java.util.Hashtable ();\r
14 });\r
15 Clazz.makeConstructor (c$, \r
16 function (annotation) {\r
17 Clazz.superConstructor (this, jalview.schemes.RNAHelicesColour, [jalview.schemes.ResidueProperties.nucleotideIndex]);\r
18 this.annotation = annotation;\r
19 this.refresh ();\r
20 }, "jalview.datamodel.AlignmentAnnotation");\r
21 Clazz.makeConstructor (c$, \r
22 function (alignment) {\r
23 Clazz.superConstructor (this, jalview.schemes.RNAHelicesColour, [jalview.schemes.ResidueProperties.nucleotideIndex]);\r
24 this.alignmentChanged (alignment, null);\r
25 }, "jalview.datamodel.AnnotatedCollectionI");\r
26 Clazz.overrideMethod (c$, "alignmentChanged", \r
27 function (alignment, hiddenReps) {\r
28 var annotations = alignment.getAlignmentAnnotation ();\r
29 for (var i = 0; i < annotations.length; i++) {\r
30 if (annotations[i].getRNAStruc () != null) {\r
31 this.annotation = annotations[i];\r
32 break;\r
33 }}\r
34 this.refresh ();\r
35 }, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");\r
36 Clazz.defineMethod (c$, "refresh", \r
37 function () {\r
38 if (this.annotation != null && ((this.annotation._rnasecstr == null || this.lastrefresh != this.annotation._rnasecstr.hashCode ()) && this.annotation.isValidStruc ())) {\r
39 this.annotation.getRNAStruc ();\r
40 this.lastrefresh = this.annotation._rnasecstr.hashCode ();\r
41 this.numHelix = 0;\r
42 this.positionsToHelix =  new java.util.Hashtable ();\r
43 for (var x = 0; x < this.annotation._rnasecstr.length; x++) {\r
44 this.positionsToHelix.put (new Integer (this.annotation._rnasecstr[x].getBegin ()), this.annotation._rnasecstr[x].getFeatureGroup ());\r
45 this.positionsToHelix.put (new Integer (this.annotation._rnasecstr[x].getEnd ()), this.annotation._rnasecstr[x].getFeatureGroup ());\r
46 if (Integer.parseInt (this.annotation._rnasecstr[x].getFeatureGroup ()) > this.numHelix) {\r
47 this.numHelix = Integer.parseInt (this.annotation._rnasecstr[x].getFeatureGroup ());\r
48 }}\r
49 for (var j = 0; j <= this.numHelix; j++) {\r
50 if (!this.helixcolorhash.containsKey (Integer.toString (j))) {\r
51 this.helixcolorhash.put (Integer.toString (j), jalview.util.ColorUtils.generateRandomColor (java.awt.Color.white));\r
52 }}\r
53 }});\r
54 Clazz.defineMethod (c$, "findColour", \r
55 function (c) {\r
56 return jalview.schemes.ResidueProperties.purinepyrimidine[jalview.schemes.ResidueProperties.purinepyrimidineIndex[c.charCodeAt (0)]];\r
57 }, "~S");\r
58 Clazz.defineMethod (c$, "findColour", \r
59 function (c, j, seq) {\r
60 this.refresh ();\r
61 var currentColour = java.awt.Color.white;\r
62 var currentHelix = null;\r
63 currentHelix = this.positionsToHelix.get (new Integer (j));\r
64 if (currentHelix != null) {\r
65 currentColour = this.helixcolorhash.get (currentHelix);\r
66 }return currentColour;\r
67 }, "~S,~N,jalview.datamodel.SequenceI");\r
68 });\r