JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / datamodel / Alignment.js
1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (["jalview.datamodel.AlignmentI", "$.HiddenSequences", "java.util.ArrayList", "$.Collections", "$.LinkedHashSet"], "jalview.datamodel.Alignment", ["jalview.analysis.AlignmentUtils", "jalview.datamodel.AlignmentAnnotation", "$.CigarArray", "$.SeqCigar", "$.Sequence", "jalview.util.Comparison", "$.MessageManager", "java.lang.Error", "java.util.HashSet", "$.Hashtable", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.dataset = null;
5 this.sequences = null;
6 this.groups = null;
7 this.gapCharacter = '-';
8 this.type = 1;
9 this.$hasRNAStructure = false;
10 this.annotations = null;
11 this.hiddenSequences = null;
12 this.alignmentProperties = null;
13 this.codonFrameList = null;
14 this.alignmentRefs = 0;
15 this.seqrep = null;
16 Clazz.instantialize (this, arguments);
17 }, jalview.datamodel, "Alignment", null, jalview.datamodel.AlignmentI);
18 Clazz.prepareFields (c$, function () {
19 this.groups = java.util.Collections.synchronizedList ( new java.util.ArrayList ());
20 this.hiddenSequences =  new jalview.datamodel.HiddenSequences (this);
21 this.codonFrameList =  new java.util.LinkedHashSet ();
22 });
23 Clazz.defineMethod (c$, "initAlignment", 
24 ($fz = function (seqs) {
25 var i = 0;
26 if (jalview.util.Comparison.isNucleotide (seqs)) {
27 this.type = 1;
28 } else {
29 this.type = 0;
30 }this.sequences = java.util.Collections.synchronizedList ( new java.util.ArrayList ());
31 for (i = 0; i < seqs.length; i++) {
32 this.sequences.add (seqs[i]);
33 }
34 }, $fz.isPrivate = true, $fz), "~A");
35 Clazz.makeConstructor (c$, 
36 function (al) {
37 var seqs = al.getSequencesArray ();
38 for (var i = 0; i < seqs.length; i++) {
39 seqs[i] =  new jalview.datamodel.Sequence (seqs[i]);
40 }
41 this.codonFrameList = (al).codonFrameList;
42 this.initAlignment (seqs);
43 }, "jalview.datamodel.AlignmentI");
44 Clazz.makeConstructor (c$, 
45 function (seqs) {
46 this.initAlignment (seqs);
47 }, "~A");
48 c$.createAlignment = Clazz.defineMethod (c$, "createAlignment", 
49 function (compactAlignment) {
50 throw  new Error (jalview.util.MessageManager.getString ("error.alignment_cigararray_not_implemented"));
51 }, "jalview.datamodel.CigarArray");
52 Clazz.defineMethod (c$, "getSequences", 
53 function () {
54 return this.sequences;
55 });
56 Clazz.defineMethod (c$, "getSequences", 
57 function (hiddenReps) {
58 return this.sequences;
59 }, "java.util.Map");
60 Clazz.defineMethod (c$, "getSequencesArray", 
61 function () {
62 if (this.sequences == null) {
63 return null;
64 }{
65 return this.sequences.toArray ( new Array (this.sequences.size ()));
66 }});
67 Clazz.overrideMethod (c$, "getSequencesByName", 
68 function () {
69 return jalview.analysis.AlignmentUtils.getSequencesByName (this);
70 });
71 Clazz.overrideMethod (c$, "getSequenceAt", 
72 function (i) {
73 {
74 if (i > -1 && i < this.sequences.size ()) {
75 return this.sequences.get (i);
76 }}return null;
77 }, "~N");
78 Clazz.overrideMethod (c$, "addSequence", 
79 function (snew) {
80 if (this.dataset != null) {
81 if (snew.getDatasetSequence () != null) {
82 this.getDataset ().addSequence (snew.getDatasetSequence ());
83 } else {
84 var adding = snew.deriveSequence ();
85 this.getDataset ().addSequence (adding.getDatasetSequence ());
86 snew = adding;
87 }}if (this.sequences == null) {
88 this.initAlignment ( Clazz.newArray (-1, [snew]));
89 } else {
90 {
91 this.sequences.add (snew);
92 }}if (this.hiddenSequences != null) {
93 this.hiddenSequences.adjustHeightSequenceAdded ();
94 }}, "jalview.datamodel.SequenceI");
95 Clazz.overrideMethod (c$, "setSequenceAt", 
96 function (i, snew) {
97 {
98 this.deleteSequence (i);
99 this.sequences.set (i, snew);
100 }}, "~N,jalview.datamodel.SequenceI");
101 Clazz.defineMethod (c$, "getGroups", 
102 function () {
103 return this.groups;
104 });
105 Clazz.overrideMethod (c$, "finalize", 
106 function () {
107 if (this.getDataset () != null) {
108 this.getDataset ().removeAlignmentRef ();
109 }this.dataset = null;
110 this.sequences = null;
111 this.groups = null;
112 this.annotations = null;
113 this.hiddenSequences = null;
114 });
115 Clazz.defineMethod (c$, "removeAlignmentRef", 
116 ($fz = function () {
117 if (--this.alignmentRefs == 0) {
118 this.finalize ();
119 }}, $fz.isPrivate = true, $fz));
120 Clazz.defineMethod (c$, "deleteSequence", 
121 function (s) {
122 this.deleteSequence (this.findIndex (s));
123 }, "jalview.datamodel.SequenceI");
124 Clazz.defineMethod (c$, "deleteSequence", 
125 function (i) {
126 if (i > -1 && i < this.getHeight ()) {
127 {
128 this.sequences.remove (i);
129 this.hiddenSequences.adjustHeightSequenceDeleted (i);
130 }}}, "~N");
131 Clazz.overrideMethod (c$, "findGroup", 
132 function (s) {
133 {
134 for (var i = 0; i < this.groups.size (); i++) {
135 var sg = this.groups.get (i);
136 if (sg.getSequences (null).contains (s)) {
137 return sg;
138 }}
139 }return null;
140 }, "jalview.datamodel.SequenceI");
141 Clazz.overrideMethod (c$, "findAllGroups", 
142 function (s) {
143 var temp =  new java.util.ArrayList ();
144 {
145 var gSize = this.groups.size ();
146 for (var i = 0; i < gSize; i++) {
147 var sg = this.groups.get (i);
148 if (sg == null || sg.getSequences () == null) {
149 this.deleteGroup (sg);
150 gSize--;
151 continue;
152 }if (sg.getSequences ().contains (s)) {
153 temp.add (sg);
154 }}
155 }var ret =  new Array (temp.size ());
156 return temp.toArray (ret);
157 }, "jalview.datamodel.SequenceI");
158 Clazz.overrideMethod (c$, "addGroup", 
159 function (sg) {
160 {
161 if (!this.groups.contains (sg)) {
162 if (this.hiddenSequences.getSize () > 0) {
163 var i;
164 var iSize = sg.getSize ();
165 for (i = 0; i < iSize; i++) {
166 if (!this.sequences.contains (sg.getSequenceAt (i))) {
167 sg.deleteSequence (sg.getSequenceAt (i), false);
168 iSize--;
169 i--;
170 }}
171 if (sg.getSize () < 1) {
172 return;
173 }}sg.setContext (this);
174 this.groups.add (sg);
175 }}}, "jalview.datamodel.SequenceGroup");
176 Clazz.defineMethod (c$, "removeAnnotationForGroup", 
177 ($fz = function (gp) {
178 if (this.annotations == null || this.annotations.length == 0) {
179 return;
180 }var t;
181 var todelete =  new Array (this.annotations.length);
182 var tokeep =  new Array (this.annotations.length);
183 var i;
184 var p;
185 var k;
186 if (gp == null) {
187 for (i = 0, p = 0, k = 0; i < this.annotations.length; i++) {
188 if (this.annotations[i].groupRef != null) {
189 todelete[p++] = this.annotations[i];
190 } else {
191 tokeep[k++] = this.annotations[i];
192 }}
193 } else {
194 for (i = 0, p = 0, k = 0; i < this.annotations.length; i++) {
195 if (this.annotations[i].groupRef === gp) {
196 todelete[p++] = this.annotations[i];
197 } else {
198 tokeep[k++] = this.annotations[i];
199 }}
200 }if (p > 0) {
201 for (i = 0; i < p; i++) {
202 this.unhookAnnotation (todelete[i]);
203 todelete[i] = null;
204 }
205 t =  new Array (k);
206 for (i = 0; i < k; i++) {
207 t[i] = tokeep[i];
208 }
209 this.annotations = t;
210 }}, $fz.isPrivate = true, $fz), "jalview.datamodel.SequenceGroup");
211 Clazz.overrideMethod (c$, "deleteAllGroups", 
212 function () {
213 {
214 if (this.annotations != null) {
215 this.removeAnnotationForGroup (null);
216 }for (var sg, $sg = this.groups.iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {
217 sg.setContext (null);
218 }
219 this.groups.clear ();
220 }});
221 Clazz.overrideMethod (c$, "deleteGroup", 
222 function (g) {
223 {
224 if (this.groups.contains (g)) {
225 this.removeAnnotationForGroup (g);
226 this.groups.remove (g);
227 g.setContext (null);
228 }}}, "jalview.datamodel.SequenceGroup");
229 Clazz.defineMethod (c$, "findName", 
230 function (name) {
231 return this.findName (name, false);
232 }, "~S");
233 Clazz.defineMethod (c$, "findName", 
234 function (token, b) {
235 return this.findName (null, token, b);
236 }, "~S,~B");
237 Clazz.defineMethod (c$, "findName", 
238 function (startAfter, token, b) {
239 var i = 0;
240 var sq = null;
241 var sqname = null;
242 if (startAfter != null) {
243 var matched = false;
244 while (i < this.sequences.size ()) {
245 if (this.getSequenceAt (i++) === startAfter) {
246 matched = true;
247 break;
248 }}
249 if (!matched) {
250 i = 0;
251 }}while (i < this.sequences.size ()) {
252 sq = this.getSequenceAt (i);
253 sqname = sq.getName ();
254 if (sqname.equals (token) || (b && (sqname.equalsIgnoreCase (token)))) {
255 return this.getSequenceAt (i);
256 }i++;
257 }
258 return null;
259 }, "jalview.datamodel.SequenceI,~S,~B");
260 Clazz.overrideMethod (c$, "findSequenceMatch", 
261 function (name) {
262 var matches =  new java.util.Vector ();
263 var i = 0;
264 while (i < this.sequences.size ()) {
265 if (this.getSequenceAt (i).getName ().equals (name)) {
266 matches.addElement (this.getSequenceAt (i));
267 }i++;
268 }
269 var result =  new Array (matches.size ());
270 for (i = 0; i < result.length; i++) {
271 result[i] = matches.elementAt (i);
272 }
273 return result;
274 }, "~S");
275 Clazz.defineMethod (c$, "findIndex", 
276 function (s) {
277 var i = 0;
278 while (i < this.sequences.size ()) {
279 if (s === this.getSequenceAt (i)) {
280 return i;
281 }i++;
282 }
283 return -1;
284 }, "jalview.datamodel.SequenceI");
285 Clazz.defineMethod (c$, "findIndex", 
286 function (results) {
287 var i = 0;
288 while (i < this.sequences.size ()) {
289 if (results.involvesSequence (this.getSequenceAt (i))) {
290 return i;
291 }i++;
292 }
293 return -1;
294 }, "jalview.datamodel.SearchResults");
295 Clazz.overrideMethod (c$, "getHeight", 
296 function () {
297 return this.sequences.size ();
298 });
299 Clazz.overrideMethod (c$, "getWidth", 
300 function () {
301 var maxLength = -1;
302 for (var i = 0; i < this.sequences.size (); i++) {
303 if (this.getSequenceAt (i).getLength () > maxLength) {
304 maxLength = this.getSequenceAt (i).getLength ();
305 }}
306 return maxLength;
307 });
308 Clazz.overrideMethod (c$, "setGapCharacter", 
309 function (gc) {
310 this.gapCharacter = gc;
311 {
312 for (var seq, $seq = this.sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
313 seq.setSequence (seq.getSequenceAsString ().$replace ('.', gc).$replace ('-', gc).$replace (' ', gc));
314 }
315 }}, "~S");
316 Clazz.defineMethod (c$, "getGapCharacter", 
317 function () {
318 return this.gapCharacter;
319 });
320 Clazz.defineMethod (c$, "isAligned", 
321 function () {
322 return this.isAligned (false);
323 });
324 Clazz.defineMethod (c$, "isAligned", 
325 function (includeHidden) {
326 var width = this.getWidth ();
327 if (this.hiddenSequences == null || this.hiddenSequences.getSize () == 0) {
328 includeHidden = true;
329 }for (var i = 0; i < this.sequences.size (); i++) {
330 if (includeHidden || !this.hiddenSequences.isHidden (this.getSequenceAt (i))) {
331 if (this.getSequenceAt (i).getLength () != width) {
332 return false;
333 }}}
334 return true;
335 }, "~B");
336 Clazz.overrideMethod (c$, "deleteAllAnnotations", 
337 function (includingAutoCalculated) {
338 var result = false;
339 for (var alan, $alan = 0, $$alan = this.getAlignmentAnnotation (); $alan < $$alan.length && ((alan = $$alan[$alan]) || true); $alan++) {
340 if (!alan.autoCalculated || includingAutoCalculated) {
341 this.deleteAnnotation (alan);
342 result = true;
343 }}
344 return result;
345 }, "~B");
346 Clazz.defineMethod (c$, "deleteAnnotation", 
347 function (aa) {
348 return this.deleteAnnotation (aa, true);
349 }, "jalview.datamodel.AlignmentAnnotation");
350 Clazz.defineMethod (c$, "deleteAnnotation", 
351 function (aa, unhook) {
352 var aSize = 1;
353 if (this.annotations != null) {
354 aSize = this.annotations.length;
355 }if (aSize < 1) {
356 return false;
357 }var temp =  new Array (aSize - 1);
358 var swap = false;
359 var tIndex = 0;
360 for (var i = 0; i < aSize; i++) {
361 if (this.annotations[i] === aa) {
362 swap = true;
363 continue;
364 }if (tIndex < temp.length) {
365 temp[tIndex++] = this.annotations[i];
366 }}
367 if (swap) {
368 this.annotations = temp;
369 if (unhook) {
370 this.unhookAnnotation (aa);
371 }}return swap;
372 }, "jalview.datamodel.AlignmentAnnotation,~B");
373 Clazz.defineMethod (c$, "unhookAnnotation", 
374 ($fz = function (aa) {
375 if (aa.sequenceRef != null) {
376 aa.sequenceRef.removeAlignmentAnnotation (aa);
377 }if (aa.groupRef != null) {
378 aa.groupRef = null;
379 }}, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentAnnotation");
380 Clazz.defineMethod (c$, "addAnnotation", 
381 function (aa) {
382 this.addAnnotation (aa, -1);
383 }, "jalview.datamodel.AlignmentAnnotation");
384 Clazz.defineMethod (c$, "addAnnotation", 
385 function (aa, pos) {
386 if (aa.getRNAStruc () != null) {
387 this.$hasRNAStructure = true;
388 }var aSize = 1;
389 if (this.annotations != null) {
390 aSize = this.annotations.length + 1;
391 }var temp =  new Array (aSize);
392 var i = 0;
393 if (pos == -1 || pos >= aSize) {
394 temp[aSize - 1] = aa;
395 } else {
396 temp[pos] = aa;
397 }if (aSize > 1) {
398 var p = 0;
399 for (i = 0; i < (aSize - 1); i++, p++) {
400 if (p == pos) {
401 p++;
402 }if (p < temp.length) {
403 temp[p] = this.annotations[i];
404 }}
405 }this.annotations = temp;
406 }, "jalview.datamodel.AlignmentAnnotation,~N");
407 Clazz.overrideMethod (c$, "setAnnotationIndex", 
408 function (aa, index) {
409 if (aa == null || this.annotations == null || this.annotations.length - 1 < index) {
410 return;
411 }var aSize = this.annotations.length;
412 var temp =  new Array (aSize);
413 temp[index] = aa;
414 for (var i = 0; i < aSize; i++) {
415 if (i == index) {
416 continue;
417 }if (i < index) {
418 temp[i] = this.annotations[i];
419 } else {
420 temp[i] = this.annotations[i - 1];
421 }}
422 this.annotations = temp;
423 }, "jalview.datamodel.AlignmentAnnotation,~N");
424 Clazz.defineMethod (c$, "getAlignmentAnnotation", 
425 function () {
426 return this.annotations;
427 });
428 Clazz.overrideMethod (c$, "setNucleotide", 
429 function (b) {
430 if (b) {
431 this.type = 1;
432 } else {
433 this.type = 0;
434 }}, "~B");
435 Clazz.defineMethod (c$, "isNucleotide", 
436 function () {
437 if (this.type == 1) {
438 return true;
439 } else {
440 return false;
441 }});
442 Clazz.overrideMethod (c$, "hasRNAStructure", 
443 function () {
444 return this.$hasRNAStructure;
445 });
446 Clazz.overrideMethod (c$, "setDataset", 
447 function (data) {
448 if (this.dataset == null && data == null) {
449 var seqs =  new Array (this.getHeight ());
450 var currentSeq;
451 for (var i = 0; i < this.getHeight (); i++) {
452 currentSeq = this.getSequenceAt (i);
453 if (currentSeq.getDatasetSequence () != null) {
454 seqs[i] = currentSeq.getDatasetSequence ();
455 } else {
456 seqs[i] = currentSeq.createDatasetSequence ();
457 }}
458 this.dataset =  new jalview.datamodel.Alignment (seqs);
459 } else if (this.dataset == null && data != null) {
460 this.dataset = data;
461 for (var i = 0; i < this.getHeight (); i++) {
462 var currentSeq = this.getSequenceAt (i);
463 var dsq = currentSeq.getDatasetSequence ();
464 if (dsq == null) {
465 dsq = currentSeq.createDatasetSequence ();
466 this.dataset.addSequence (dsq);
467 } else {
468 while (dsq.getDatasetSequence () != null) {
469 dsq = dsq.getDatasetSequence ();
470 }
471 if (this.dataset.findIndex (dsq) == -1) {
472 this.dataset.addSequence (dsq);
473 }}}
474 }this.dataset.addAlignmentRef ();
475 }, "jalview.datamodel.Alignment");
476 Clazz.defineMethod (c$, "addAlignmentRef", 
477 ($fz = function () {
478 this.alignmentRefs++;
479 }, $fz.isPrivate = true, $fz));
480 Clazz.overrideMethod (c$, "getDataset", 
481 function () {
482 return this.dataset;
483 });
484 Clazz.overrideMethod (c$, "padGaps", 
485 function () {
486 var modified = false;
487 var maxLength = -1;
488 var current;
489 for (var i = 0; i < this.sequences.size (); i++) {
490 current = this.getSequenceAt (i);
491 for (var j = current.getLength (); j > maxLength; j--) {
492 if (j > maxLength && !jalview.util.Comparison.isGap (current.getCharAt (j))) {
493 maxLength = j;
494 break;
495 }}
496 }
497 maxLength++;
498 var cLength;
499 for (var i = 0; i < this.sequences.size (); i++) {
500 current = this.getSequenceAt (i);
501 cLength = current.getLength ();
502 if (cLength < maxLength) {
503 current.insertCharAt (cLength, maxLength - cLength, this.gapCharacter);
504 modified = true;
505 } else if (current.getLength () > maxLength) {
506 current.deleteChars (maxLength, current.getLength ());
507 }}
508 return modified;
509 });
510 Clazz.overrideMethod (c$, "justify", 
511 function (right) {
512 var modified = false;
513 var maxLength = -1;
514 var ends =  Clazz.newIntArray (this.sequences.size () * 2, 0);
515 var current;
516 for (var i = 0; i < this.sequences.size (); i++) {
517 current = this.getSequenceAt (i);
518 ends[i * 2] = current.findIndex (current.getStart ());
519 ends[i * 2 + 1] = current.findIndex (current.getStart () + current.getLength ());
520 var hitres = false;
521 for (var j = 0, rs = 0, ssiz = current.getLength (); j < ssiz; j++) {
522 if (!jalview.util.Comparison.isGap (current.getCharAt (j))) {
523 if (!hitres) {
524 ends[i * 2] = j;
525 hitres = true;
526 } else {
527 ends[i * 2 + 1] = j;
528 if (j - ends[i * 2] > maxLength) {
529 maxLength = j - ends[i * 2];
530 }}}}
531 }
532 maxLength++;
533 var cLength;
534 var extent;
535 var diff;
536 for (var i = 0; i < this.sequences.size (); i++) {
537 current = this.getSequenceAt (i);
538 cLength = 1 + ends[i * 2 + 1] - ends[i * 2];
539 diff = maxLength - cLength;
540 extent = current.getLength ();
541 if (right) {
542 if (extent > ends[i * 2 + 1]) {
543 current.deleteChars (ends[i * 2 + 1] + 1, extent);
544 modified = true;
545 }if (ends[i * 2] > diff) {
546 current.deleteChars (0, ends[i * 2] - diff);
547 modified = true;
548 } else {
549 if (ends[i * 2] < diff) {
550 current.insertCharAt (0, diff - ends[i * 2], this.gapCharacter);
551 modified = true;
552 }}} else {
553 if (ends[i * 2] > 0) {
554 current.deleteChars (0, ends[i * 2]);
555 modified = true;
556 ends[i * 2 + 1] -= ends[i * 2];
557 extent -= ends[i * 2];
558 }if (extent > maxLength) {
559 current.deleteChars (maxLength + 1, extent);
560 modified = true;
561 } else {
562 if (extent < maxLength) {
563 current.insertCharAt (extent, maxLength - extent, this.gapCharacter);
564 modified = true;
565 }}}}
566 return modified;
567 }, "~B");
568 Clazz.defineMethod (c$, "getHiddenSequences", 
569 function () {
570 return this.hiddenSequences;
571 });
572 Clazz.overrideMethod (c$, "getCompactAlignment", 
573 function () {
574 {
575 var alseqs =  new Array (this.sequences.size ());
576 var i = 0;
577 for (var seq, $seq = this.sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
578 alseqs[i++] =  new jalview.datamodel.SeqCigar (seq);
579 }
580 var cal =  new jalview.datamodel.CigarArray (alseqs);
581 cal.addOperation ('M', this.getWidth ());
582 return cal;
583 }});
584 Clazz.overrideMethod (c$, "setProperty", 
585 function (key, value) {
586 if (this.alignmentProperties == null) {
587 this.alignmentProperties =  new java.util.Hashtable ();
588 }this.alignmentProperties.put (key, value);
589 }, "~O,~O");
590 Clazz.defineMethod (c$, "getProperty", 
591 function (key) {
592 if (this.alignmentProperties != null) {
593 return this.alignmentProperties.get (key);
594 } else {
595 return null;
596 }}, "~O");
597 Clazz.defineMethod (c$, "getProperties", 
598 function () {
599 return this.alignmentProperties;
600 });
601 Clazz.overrideMethod (c$, "addCodonFrame", 
602 function (codons) {
603 if (codons != null) {
604 this.codonFrameList.add (codons);
605 }}, "jalview.datamodel.AlignedCodonFrame");
606 Clazz.overrideMethod (c$, "getCodonFrame", 
607 function (seq) {
608 if (seq == null) {
609 return null;
610 }var cframes =  new java.util.ArrayList ();
611 for (var acf, $acf = this.codonFrameList.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
612 if (acf.involvesSequence (seq)) {
613 cframes.add (acf);
614 }}
615 return cframes;
616 }, "jalview.datamodel.SequenceI");
617 Clazz.overrideMethod (c$, "setCodonFrames", 
618 function (acfs) {
619 this.codonFrameList = acfs;
620 }, "java.util.Set");
621 Clazz.defineMethod (c$, "getCodonFrames", 
622 function () {
623 return this.codonFrameList;
624 });
625 Clazz.overrideMethod (c$, "removeCodonFrame", 
626 function (codons) {
627 if (codons == null || this.codonFrameList == null) {
628 return false;
629 }return this.codonFrameList.remove (codons);
630 }, "jalview.datamodel.AlignedCodonFrame");
631 Clazz.overrideMethod (c$, "append", 
632 function (toappend) {
633 if (toappend === this) {
634 System.err.println ("Self append may cause a deadlock.");
635 }var samegap = toappend.getGapCharacter () == this.getGapCharacter ();
636 var oldc = toappend.getGapCharacter ();
637 var hashidden = toappend.getHiddenSequences () != null && toappend.getHiddenSequences ().hiddenSequences != null;
638 var sqs = (hashidden) ? toappend.getHiddenSequences ().getFullAlignment ().getSequences () : toappend.getSequences ();
639 if (sqs != null) {
640 {
641 for (var addedsq, $addedsq = sqs.iterator (); $addedsq.hasNext () && ((addedsq = $addedsq.next ()) || true);) {
642 if (!samegap) {
643 var oldseq = addedsq.getSequence ();
644 for (var c = 0; c < oldseq.length; c++) {
645 if (oldseq[c] == oldc) {
646 oldseq[c] = this.gapCharacter;
647 }}
648 }this.addSequence (addedsq);
649 }
650 }}var alan = toappend.getAlignmentAnnotation ();
651 for (var a = 0; alan != null && a < alan.length; a++) {
652 this.addAnnotation (alan[a]);
653 }
654 this.codonFrameList.addAll (toappend.getCodonFrames ());
655 var sg = toappend.getGroups ();
656 if (sg != null) {
657 for (var _sg, $_sg = sg.iterator (); $_sg.hasNext () && ((_sg = $_sg.next ()) || true);) {
658 this.addGroup (_sg);
659 }
660 }if (toappend.getHiddenSequences () != null) {
661 var hs = toappend.getHiddenSequences ();
662 if (this.hiddenSequences == null) {
663 this.hiddenSequences =  new jalview.datamodel.HiddenSequences (this);
664 }if (hs.hiddenSequences != null) {
665 for (var s = 0; s < hs.hiddenSequences.length; s++) {
666 if (hs.hiddenSequences[s] != null) {
667 this.hiddenSequences.hideSequence (hs.hiddenSequences[s]);
668 }}
669 }}if (toappend.getProperties () != null) {
670 var key = toappend.getProperties ().keys ();
671 while (key.hasMoreElements ()) {
672 var k = key.nextElement ();
673 var ourval = this.getProperty (k);
674 var toapprop = toappend.getProperty (k);
675 if (ourval != null) {
676 if (ourval.getClass ().equals (toapprop.getClass ()) && !ourval.equals (toapprop)) {
677 if (Clazz.instanceOf (ourval, String)) {
678 this.setProperty (k, (ourval) + "; " + (toapprop));
679 } else {
680 if (Clazz.instanceOf (ourval, java.util.Vector)) {
681 var theirv = (toapprop).elements ();
682 while (theirv.hasMoreElements ()) {
683 (ourval).addElement (theirv);
684 }
685 }}}} else {
686 this.setProperty (k, toapprop);
687 }}
688 }}, "jalview.datamodel.AlignmentI");
689 Clazz.overrideMethod (c$, "findOrCreateAnnotation", 
690 function (name, calcId, autoCalc, seqRef, groupRef) {
691 if (this.annotations != null) {
692 for (var annot, $annot = 0, $$annot = this.getAlignmentAnnotation (); $annot < $$annot.length && ((annot = $$annot[$annot]) || true); $annot++) {
693 if (annot.autoCalculated == autoCalc && (name.equals (annot.label)) && (calcId == null || annot.getCalcId ().equals (calcId)) && annot.sequenceRef === seqRef && annot.groupRef === groupRef) {
694 return annot;
695 }}
696 }var annot =  new jalview.datamodel.AlignmentAnnotation (name, name,  new Array (1), 0, 0, 1);
697 annot.hasText = false;
698 annot.setCalcId ( String.instantialize (calcId));
699 annot.autoCalculated = autoCalc;
700 if (seqRef != null) {
701 annot.setSequenceRef (seqRef);
702 }annot.groupRef = groupRef;
703 this.addAnnotation (annot);
704 return annot;
705 }, "~S,~S,~B,jalview.datamodel.SequenceI,jalview.datamodel.SequenceGroup");
706 Clazz.overrideMethod (c$, "findAnnotation", 
707 function (calcId) {
708 var aa =  new java.util.ArrayList ();
709 for (var a, $a = 0, $$a = this.getAlignmentAnnotation (); $a < $$a.length && ((a = $$a[$a]) || true); $a++) {
710 if (a.getCalcId () === calcId || (a.getCalcId () != null && calcId != null && a.getCalcId ().equals (calcId))) {
711 aa.add (a);
712 }}
713 return aa;
714 }, "~S");
715 Clazz.overrideMethod (c$, "findAnnotations", 
716 function (seq, calcId, label) {
717 var aa =  new java.util.ArrayList ();
718 for (var ann, $ann = 0, $$ann = this.getAlignmentAnnotation (); $ann < $$ann.length && ((ann = $$ann[$ann]) || true); $ann++) {
719 if (ann.getCalcId () != null && ann.getCalcId ().equals (calcId) && ann.sequenceRef != null && ann.sequenceRef === seq && ann.label != null && ann.label.equals (label)) {
720 aa.add (ann);
721 }}
722 return aa;
723 }, "jalview.datamodel.SequenceI,~S,~S");
724 Clazz.overrideMethod (c$, "moveSelectedSequencesByOne", 
725 function (sg, map, up) {
726 {
727 if (up) {
728 for (var i = 1, iSize = this.sequences.size (); i < iSize; i++) {
729 var seq = this.sequences.get (i);
730 if (!sg.getSequences (map).contains (seq)) {
731 continue;
732 }var temp = this.sequences.get (i - 1);
733 if (sg.getSequences (null).contains (temp)) {
734 continue;
735 }this.sequences.set (i, temp);
736 this.sequences.set (i - 1, seq);
737 }
738 } else {
739 for (var i = this.sequences.size () - 2; i > -1; i--) {
740 var seq = this.sequences.get (i);
741 if (!sg.getSequences (map).contains (seq)) {
742 continue;
743 }var temp = this.sequences.get (i + 1);
744 if (sg.getSequences (map).contains (temp)) {
745 continue;
746 }this.sequences.set (i, temp);
747 this.sequences.set (i + 1, seq);
748 }
749 }}}, "jalview.datamodel.SequenceGroup,java.util.Map,~B");
750 Clazz.overrideMethod (c$, "validateAnnotation", 
751 function (alignmentAnnotation) {
752 alignmentAnnotation.validateRangeAndDisplay ();
753 if (this.isNucleotide () && alignmentAnnotation.isValidStruc ()) {
754 this.$hasRNAStructure = true;
755 }}, "jalview.datamodel.AlignmentAnnotation");
756 Clazz.overrideMethod (c$, "getSeqrep", 
757 function () {
758 return this.seqrep;
759 });
760 Clazz.overrideMethod (c$, "setSeqrep", 
761 function (seqrep) {
762 this.seqrep = seqrep;
763 }, "jalview.datamodel.SequenceI");
764 Clazz.overrideMethod (c$, "hasSeqrep", 
765 function () {
766 return this.seqrep != null;
767 });
768 Clazz.overrideMethod (c$, "getEndRes", 
769 function () {
770 return this.getWidth () - 1;
771 });
772 Clazz.overrideMethod (c$, "getStartRes", 
773 function () {
774 return 0;
775 });
776 Clazz.overrideMethod (c$, "getContext", 
777 function () {
778 return this.dataset;
779 });
780 Clazz.defineMethod (c$, "alignAs", 
781 function (al) {
782 return this.alignAs (al, false, true);
783 }, "jalview.datamodel.AlignmentI");
784 Clazz.defineMethod (c$, "alignAs", 
785 function (al, preserveMappedGaps, preserveUnmappedGaps) {
786 var count = 0;
787 var thisIsNucleotide = this.isNucleotide ();
788 var thatIsProtein = !al.isNucleotide ();
789 if (!thatIsProtein && !thisIsNucleotide) {
790 return jalview.analysis.AlignmentUtils.alignProteinAsDna (this, al);
791 }var thisGapChar = this.getGapCharacter ();
792 var gap = thisIsNucleotide && thatIsProtein ? String.valueOf ( Clazz.newCharArray (-1, [thisGapChar, thisGapChar, thisGapChar])) : String.valueOf (thisGapChar);
793 for (var alignTo, $alignTo = this.getSequences ().iterator (); $alignTo.hasNext () && ((alignTo = $alignTo.next ()) || true);) {
794 count += jalview.analysis.AlignmentUtils.alignSequenceAs (alignTo, al, gap, preserveMappedGaps, preserveUnmappedGaps) ? 1 : 0;
795 }
796 return count;
797 }, "jalview.datamodel.AlignmentI,~B,~B");
798 Clazz.overrideMethod (c$, "getSequenceNames", 
799 function () {
800 var names =  new java.util.HashSet ();
801 for (var seq, $seq = this.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
802 names.add (seq.getName ());
803 }
804 return names;
805 });
806 Clazz.overrideMethod (c$, "toString", 
807 function () {
808 var seq = this.getSequencesArray ();
809 {
810 return "" + JSON.stringify(seq);
811 }});
812 Clazz.defineStatics (c$,
813 "PROTEIN", 0,
814 "NUCLEOTIDE", 1);
815 });