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