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$ ();
9 Clazz.instantialize (this, arguments);
10 }, jalview.datamodel, "Mapping");
11 Clazz.makeConstructor (c$,
14 }, "jalview.util.MapList");
15 Clazz.makeConstructor (c$,
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$,
26 if (map2 !== this && map2 != null) {
27 if (map2.map != null) {
28 this.map = new jalview.util.MapList (map2.map);
30 }}, "jalview.datamodel.Mapping");
31 Clazz.defineMethod (c$, "getMap",
35 Clazz.defineMethod (c$, "setMap",
38 }, "jalview.util.MapList");
39 Clazz.overrideMethod (c$, "equals",
41 if (o == null || !(Clazz.instanceOf (o, jalview.datamodel.Mapping))) {
46 }if (other.to !== this.to) {
48 }if ((this.map != null && other.map == null) || (this.map == null && other.map != null)) {
50 }if ((this.map == null && other.map == null) || this.map.equals (other.map)) {
54 Clazz.defineMethod (c$, "getPosition",
56 if (this.map != null) {
57 var mp = this.map.shiftTo (mpos);
62 Clazz.defineMethod (c$, "getWord",
64 if (this.map != null) {
65 return this.map.getToWord (mpos);
68 Clazz.defineMethod (c$, "getWidth",
70 if (this.map != null) {
71 return this.map.getFromRatio ();
74 Clazz.defineMethod (c$, "getMappedWidth",
76 if (this.map != null) {
77 return this.map.getToRatio ();
80 Clazz.defineMethod (c$, "getMappedPosition",
82 if (this.map != null) {
83 var mp = this.map.shiftFrom (pos);
88 Clazz.defineMethod (c$, "getMappedWord",
90 if (this.map != null) {
91 var mp = this.map.shiftFrom (pos);
93 return Clazz.newIntArray (-1, [mp[0], mp[0] + mp[2] * (this.map.getToRatio () - 1)]);
96 Clazz.defineMethod (c$, "locateFeature",
99 if (this.map != null) {
100 var frange = this.map.locateInFrom (f.getBegin (), f.getEnd ());
101 if (frange == 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));
113 var word = this.getWord (f.getBegin ());
114 if (word[0] < word[1]) {
115 f.setBegin (word[0]);
117 f.setBegin (word[1]);
118 }word = this.getWord (f.getEnd ());
119 if (word[0] > 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) {
129 from = (this.map.getToLowest () < from) ? from : this.map.getToLowest ();
130 to = (this.map.getToHighest () > to) ? to : this.map.getToHighest ();
134 from = (this.map.getToHighest () > from) ? from : this.map.getToHighest ();
135 to = (this.map.getToLowest () < to) ? to : this.map.getToLowest ();
138 }}return this.map.locateInFrom (from, to);
139 }return Clazz.newIntArray (-1, [from, to]);
141 Clazz.defineMethod (c$, "locateMappedRange",
142 function (from, to) {
143 if (this.map != null) {
145 from = (this.map.getFromLowest () < from) ? from : this.map.getFromLowest ();
146 to = (this.map.getFromHighest () > to) ? to : this.map.getFromHighest ();
150 from = (this.map.getFromHighest () > from) ? from : this.map.getFromHighest ();
151 to = (this.map.getFromLowest () < to) ? to : this.map.getFromLowest ();
154 }}return this.map.locateInTo (from, to);
155 }return Clazz.newIntArray (-1, [from, to]);
157 Clazz.defineMethod (c$, "intersectVisContigs",
158 function (viscontigs) {
159 var copy = new jalview.datamodel.Mapping (this);
160 if (this.map != null) {
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);
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]]));
176 var from = Clazz.newIntArray (fromRange.size () * 2, 0);
177 var to = Clazz.newIntArray (toRange.size () * 2, 0);
179 for (var f = 0, fSize = fromRange.size (); f < fSize; f++) {
180 r = fromRange.elementAt (f);
182 from[f * 2 + 1] = r[1];
184 for (var f = 0, fSize = toRange.size (); f < fSize; f++) {
185 r = toRange.elementAt (f);
187 to[f * 2 + 1] = r[1];
189 copy.setMap ( new jalview.util.MapList (from, to, this.map.getFromRatio (), this.map.getToRatio ()));
192 Clazz.defineMethod (c$, "getTo",
196 Clazz.defineMethod (c$, "setTo",
199 }, "jalview.datamodel.SequenceI");
200 Clazz.defineMethod (c$, "finalize",
204 Clazz.superCall (this, jalview.datamodel.Mapping, "finalize", []);
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 () {
212 c$ = Clazz.decorateAsClass (function () {
213 Clazz.prepareCallback (this, arguments);
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;
224 Clazz.instantialize (this, arguments);
225 }, jalview.datamodel.Mapping, "AlignedCodonIterator", null, java.util.Iterator);
226 Clazz.makeConstructor (c$,
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];
239 Clazz.defineMethod (c$, "hasNext",
241 if (this.fromRanges.hasNext ()) {
243 }if (this.currentFromRange == null || this.fromPosition >= this.currentFromRange[1]) {
247 Clazz.overrideMethod (c$, "next",
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);
256 Clazz.defineMethod (c$, "getPeptide",
258 if (this.toPosition <= this.currentToRange[1]) {
259 var a = this.b$["jalview.datamodel.Mapping"].to.getSequence ()[this.toPosition - 1];
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",
270 var a = Clazz.newIntArray (3, 0);
273 if (this.fromPosition <= this.currentFromRange[1]) {
274 a[b++] = this.fromPosition++;
276 if (!this.fromRanges.hasNext ()) {
277 throw new jalview.datamodel.IncompleteCodonException ();
278 }this.currentFromRange = this.fromRanges.next ();
279 this.fromPosition = this.currentFromRange[0];
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]);
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) {
297 return this.alignedColumn - 1;
298 }, $fz.isPrivate = true, $fz), "~N");
299 Clazz.overrideMethod (c$, "remove",