JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / datamodel / Mapping.js
1 Clazz.declarePackage ("jalview.datamodel");\r
2 Clazz.load (["java.util.Iterator"], "jalview.datamodel.Mapping", ["jalview.datamodel.AlignedCodon", "$.IncompleteCodonException", "$.SequenceFeature", "jalview.util.MapList", "java.util.NoSuchElementException", "$.Vector"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 if (!Clazz.isClassDefined ("jalview.datamodel.Mapping.AlignedCodonIterator")) {\r
5 jalview.datamodel.Mapping.$Mapping$AlignedCodonIterator$ ();\r
6 }\r
7 this.map = null;\r
8 this.to = null;\r
9 Clazz.instantialize (this, arguments);\r
10 }, jalview.datamodel, "Mapping");\r
11 Clazz.makeConstructor (c$, \r
12 function (map) {\r
13 this.map = map;\r
14 }, "jalview.util.MapList");\r
15 Clazz.makeConstructor (c$, \r
16 function (to, map) {\r
17 this.construct (map);\r
18 this.to = to;\r
19 }, "jalview.datamodel.SequenceI,jalview.util.MapList");\r
20 Clazz.makeConstructor (c$, \r
21 function (to, exon, is, i, j) {\r
22 this.construct (to,  new jalview.util.MapList (exon, is, i, j));\r
23 }, "jalview.datamodel.SequenceI,~A,~A,~N,~N");\r
24 Clazz.makeConstructor (c$, \r
25 function (map2) {\r
26 if (map2 !== this && map2 != null) {\r
27 if (map2.map != null) {\r
28 this.map =  new jalview.util.MapList (map2.map);\r
29 }this.to = map2.to;\r
30 }}, "jalview.datamodel.Mapping");\r
31 Clazz.defineMethod (c$, "getMap", \r
32 function () {\r
33 return this.map;\r
34 });\r
35 Clazz.defineMethod (c$, "setMap", \r
36 function (map) {\r
37 this.map = map;\r
38 }, "jalview.util.MapList");\r
39 Clazz.overrideMethod (c$, "equals", \r
40 function (o) {\r
41 if (o == null || !(Clazz.instanceOf (o, jalview.datamodel.Mapping))) {\r
42 return false;\r
43 }var other = o;\r
44 if (other === this) {\r
45 return true;\r
46 }if (other.to !== this.to) {\r
47 return false;\r
48 }if ((this.map != null && other.map == null) || (this.map == null && other.map != null)) {\r
49 return false;\r
50 }if ((this.map == null && other.map == null) || this.map.equals (other.map)) {\r
51 return true;\r
52 }return false;\r
53 }, "~O");\r
54 Clazz.defineMethod (c$, "getPosition", \r
55 function (mpos) {\r
56 if (this.map != null) {\r
57 var mp = this.map.shiftTo (mpos);\r
58 if (mp != null) {\r
59 return mp[0];\r
60 }}return mpos;\r
61 }, "~N");\r
62 Clazz.defineMethod (c$, "getWord", \r
63 function (mpos) {\r
64 if (this.map != null) {\r
65 return this.map.getToWord (mpos);\r
66 }return null;\r
67 }, "~N");\r
68 Clazz.defineMethod (c$, "getWidth", \r
69 function () {\r
70 if (this.map != null) {\r
71 return this.map.getFromRatio ();\r
72 }return 1;\r
73 });\r
74 Clazz.defineMethod (c$, "getMappedWidth", \r
75 function () {\r
76 if (this.map != null) {\r
77 return this.map.getToRatio ();\r
78 }return 1;\r
79 });\r
80 Clazz.defineMethod (c$, "getMappedPosition", \r
81 function (pos) {\r
82 if (this.map != null) {\r
83 var mp = this.map.shiftFrom (pos);\r
84 if (mp != null) {\r
85 return mp[0];\r
86 }}return pos;\r
87 }, "~N");\r
88 Clazz.defineMethod (c$, "getMappedWord", \r
89 function (pos) {\r
90 if (this.map != null) {\r
91 var mp = this.map.shiftFrom (pos);\r
92 if (mp != null) {\r
93 return  Clazz.newIntArray (-1, [mp[0], mp[0] + mp[2] * (this.map.getToRatio () - 1)]);\r
94 }}return null;\r
95 }, "~N");\r
96 Clazz.defineMethod (c$, "locateFeature", \r
97 function (f) {\r
98 if (true) {\r
99 if (this.map != null) {\r
100 var frange = this.map.locateInFrom (f.getBegin (), f.getEnd ());\r
101 if (frange == null) {\r
102 return null;\r
103 }var vf =  new Array (Clazz.doubleToInt (frange.length / 2));\r
104 for (var i = 0, v = 0; i < frange.length; i += 2, v++) {\r
105 vf[v] =  new jalview.datamodel.SequenceFeature (f);\r
106 vf[v].setBegin (frange[i]);\r
107 vf[v].setEnd (frange[i + 1]);\r
108 if (frange.length > 2) {\r
109 vf[v].setDescription (f.getDescription () + "\nPart " + (v + 1));\r
110 }}\r
111 return vf;\r
112 }}if (false) {\r
113 var word = this.getWord (f.getBegin ());\r
114 if (word[0] < word[1]) {\r
115 f.setBegin (word[0]);\r
116 } else {\r
117 f.setBegin (word[1]);\r
118 }word = this.getWord (f.getEnd ());\r
119 if (word[0] > word[1]) {\r
120 f.setEnd (word[0]);\r
121 } else {\r
122 f.setEnd (word[1]);\r
123 }}return  Clazz.newArray (-1, [f]);\r
124 }, "jalview.datamodel.SequenceFeature");\r
125 Clazz.defineMethod (c$, "locateRange", \r
126 function (from, to) {\r
127 if (this.map != null) {\r
128 if (from <= to) {\r
129 from = (this.map.getToLowest () < from) ? from : this.map.getToLowest ();\r
130 to = (this.map.getToHighest () > to) ? to : this.map.getToHighest ();\r
131 if (from > to) {\r
132 return null;\r
133 }} else {\r
134 from = (this.map.getToHighest () > from) ? from : this.map.getToHighest ();\r
135 to = (this.map.getToLowest () < to) ? to : this.map.getToLowest ();\r
136 if (from < to) {\r
137 return null;\r
138 }}return this.map.locateInFrom (from, to);\r
139 }return  Clazz.newIntArray (-1, [from, to]);\r
140 }, "~N,~N");\r
141 Clazz.defineMethod (c$, "locateMappedRange", \r
142 function (from, to) {\r
143 if (this.map != null) {\r
144 if (from <= to) {\r
145 from = (this.map.getFromLowest () < from) ? from : this.map.getFromLowest ();\r
146 to = (this.map.getFromHighest () > to) ? to : this.map.getFromHighest ();\r
147 if (from > to) {\r
148 return null;\r
149 }} else {\r
150 from = (this.map.getFromHighest () > from) ? from : this.map.getFromHighest ();\r
151 to = (this.map.getFromLowest () < to) ? to : this.map.getFromLowest ();\r
152 if (from < to) {\r
153 return null;\r
154 }}return this.map.locateInTo (from, to);\r
155 }return  Clazz.newIntArray (-1, [from, to]);\r
156 }, "~N,~N");\r
157 Clazz.defineMethod (c$, "intersectVisContigs", \r
158 function (viscontigs) {\r
159 var copy =  new jalview.datamodel.Mapping (this);\r
160 if (this.map != null) {\r
161 var vpos = 0;\r
162 var apos = 0;\r
163 var toRange =  new java.util.Vector ();\r
164 var fromRange =  new java.util.Vector ();\r
165 for (var vc = 0; vc < viscontigs.length; vc += 2) {\r
166 var mpr = this.locateMappedRange (1 + viscontigs[vc], viscontigs[vc + 1] - 1);\r
167 if (mpr != null) {\r
168 for (var m = 0; m < mpr.length; m += 2) {\r
169 toRange.addElement ( Clazz.newIntArray (-1, [mpr[m], mpr[m + 1]]));\r
170 var xpos = this.locateRange (mpr[m], mpr[m + 1]);\r
171 for (var x = 0; x < xpos.length; x += 2) {\r
172 fromRange.addElement ( Clazz.newIntArray (-1, [xpos[x], xpos[x + 1]]));\r
173 }\r
174 }\r
175 }}\r
176 var from =  Clazz.newIntArray (fromRange.size () * 2, 0);\r
177 var to =  Clazz.newIntArray (toRange.size () * 2, 0);\r
178 var r;\r
179 for (var f = 0, fSize = fromRange.size (); f < fSize; f++) {\r
180 r = fromRange.elementAt (f);\r
181 from[f * 2] = r[0];\r
182 from[f * 2 + 1] = r[1];\r
183 }\r
184 for (var f = 0, fSize = toRange.size (); f < fSize; f++) {\r
185 r = toRange.elementAt (f);\r
186 to[f * 2] = r[0];\r
187 to[f * 2 + 1] = r[1];\r
188 }\r
189 copy.setMap ( new jalview.util.MapList (from, to, this.map.getFromRatio (), this.map.getToRatio ()));\r
190 }return copy;\r
191 }, "~A");\r
192 Clazz.defineMethod (c$, "getTo", \r
193 function () {\r
194 return this.to;\r
195 });\r
196 Clazz.defineMethod (c$, "setTo", \r
197 function (tto) {\r
198 this.to = tto;\r
199 }, "jalview.datamodel.SequenceI");\r
200 Clazz.defineMethod (c$, "finalize", \r
201 function () {\r
202 this.map = null;\r
203 this.to = null;\r
204 Clazz.superCall (this, jalview.datamodel.Mapping, "finalize", []);\r
205 });\r
206 Clazz.defineMethod (c$, "getCodonIterator", \r
207 function (seq, gapChar) {\r
208 return Clazz.innerTypeInstance (jalview.datamodel.Mapping.AlignedCodonIterator, this, null, seq.getSequence (), gapChar);\r
209 }, "jalview.datamodel.SequenceI,~S");\r
210 c$.$Mapping$AlignedCodonIterator$ = function () {\r
211 Clazz.pu$h ();\r
212 c$ = Clazz.decorateAsClass (function () {\r
213 Clazz.prepareCallback (this, arguments);\r
214 this.gap = '\0';\r
215 this.alignedSeq = null;\r
216 this.alignedColumn = 0;\r
217 this.alignedBases = 0;\r
218 this.fromRanges = null;\r
219 this.toRanges = null;\r
220 this.currentFromRange = null;\r
221 this.currentToRange = null;\r
222 this.fromPosition = 0;\r
223 this.toPosition = 0;\r
224 Clazz.instantialize (this, arguments);\r
225 }, jalview.datamodel.Mapping, "AlignedCodonIterator", null, java.util.Iterator);\r
226 Clazz.makeConstructor (c$, \r
227 function (a, b) {\r
228 this.alignedSeq = a;\r
229 this.gap = b;\r
230 this.fromRanges = this.b$["jalview.datamodel.Mapping"].map.getFromRanges ().iterator ();\r
231 this.toRanges = this.b$["jalview.datamodel.Mapping"].map.getToRanges ().iterator ();\r
232 if (this.fromRanges.hasNext ()) {\r
233 this.currentFromRange = this.fromRanges.next ();\r
234 this.fromPosition = this.currentFromRange[0];\r
235 }if (this.toRanges.hasNext ()) {\r
236 this.currentToRange = this.toRanges.next ();\r
237 this.toPosition = this.currentToRange[0];\r
238 }}, "~A,~S");\r
239 Clazz.defineMethod (c$, "hasNext", \r
240 function () {\r
241 if (this.fromRanges.hasNext ()) {\r
242 return true;\r
243 }if (this.currentFromRange == null || this.fromPosition >= this.currentFromRange[1]) {\r
244 return false;\r
245 }return true;\r
246 });\r
247 Clazz.overrideMethod (c$, "next", \r
248 function () {\r
249 if (!this.hasNext ()) {\r
250 throw  new java.util.NoSuchElementException ();\r
251 }var a = this.getNextCodon ();\r
252 var b = this.getAlignedCodon (a);\r
253 var c = this.getPeptide ();\r
254 return  new jalview.datamodel.AlignedCodon (b[0], b[1], b[2], c);\r
255 });\r
256 Clazz.defineMethod (c$, "getPeptide", \r
257 ($fz = function () {\r
258 if (this.toPosition <= this.currentToRange[1]) {\r
259 var a = this.b$["jalview.datamodel.Mapping"].to.getSequence ()[this.toPosition - 1];\r
260 this.toPosition++;\r
261 return String.valueOf (a);\r
262 }if (!this.toRanges.hasNext ()) {\r
263 throw  new java.util.NoSuchElementException ("Ran out of peptide at position " + this.toPosition);\r
264 }this.currentToRange = this.toRanges.next ();\r
265 this.toPosition = this.currentToRange[0];\r
266 return this.getPeptide ();\r
267 }, $fz.isPrivate = true, $fz));\r
268 Clazz.defineMethod (c$, "getNextCodon", \r
269 ($fz = function () {\r
270 var a =  Clazz.newIntArray (3, 0);\r
271 var b = 0;\r
272 while (b < 3) {\r
273 if (this.fromPosition <= this.currentFromRange[1]) {\r
274 a[b++] = this.fromPosition++;\r
275 } else {\r
276 if (!this.fromRanges.hasNext ()) {\r
277 throw  new jalview.datamodel.IncompleteCodonException ();\r
278 }this.currentFromRange = this.fromRanges.next ();\r
279 this.fromPosition = this.currentFromRange[0];\r
280 }}\r
281 return a;\r
282 }, $fz.isPrivate = true, $fz));\r
283 Clazz.defineMethod (c$, "getAlignedCodon", \r
284 ($fz = function (a) {\r
285 var b =  Clazz.newIntArray (a.length, 0);\r
286 for (var c = 0; c < a.length; c++) {\r
287 b[c] = this.getAlignedColumn (a[c]);\r
288 }\r
289 return b;\r
290 }, $fz.isPrivate = true, $fz), "~A");\r
291 Clazz.defineMethod (c$, "getAlignedColumn", \r
292 ($fz = function (a) {\r
293 while (this.alignedBases < a && this.alignedColumn < this.alignedSeq.length) {\r
294 if (this.alignedSeq[this.alignedColumn++] != this.gap) {\r
295 this.alignedBases++;\r
296 }}\r
297 return this.alignedColumn - 1;\r
298 }, $fz.isPrivate = true, $fz), "~N");\r
299 Clazz.overrideMethod (c$, "remove", \r
300 function () {\r
301 });\r
302 c$ = Clazz.p0p ();\r
303 };\r
304 });\r