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