1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (["jalview.datamodel.ASequence", "$.SequenceI", "jalview.jsdev.RegExp"], "jalview.datamodel.Sequence", ["jalview.analysis.AlignSeq", "jalview.datamodel.AlignmentAnnotation", "$.DBRefEntry", "$.DBRefSource", "$.PDBEntry", "$.SequenceFeature", "jalview.schemes.ResidueProperties", "jalview.util.Comparison", "$.StringUtils", "java.lang.StringBuffer", "java.util.ArrayList", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.datasetSequence = null;
7 this.description = null;
14 this.annotation = null;
16 this.sequenceFeatures = null;
19 Clazz.instantialize (this, arguments);
20 }, jalview.datamodel, "Sequence", jalview.datamodel.ASequence, jalview.datamodel.SequenceI);
21 Clazz.prepareFields (c$, function () {
22 this.limitrx = jalview.jsdev.RegExp.newRegex (["[/][0-9]{1,}[-][0-9]{1,}$"]);
23 this.endrx = jalview.jsdev.RegExp.newRegex (["[0-9]{1,}$"]);
25 Clazz.makeConstructor (c$,
26 function (name, sequence, start, end) {
27 Clazz.superConstructor (this, jalview.datamodel.Sequence, []);
28 this.initSeqAndName (name, sequence.toCharArray (), start, end);
30 Clazz.makeConstructor (c$,
31 function (name, sequence, start, end) {
32 Clazz.superConstructor (this, jalview.datamodel.Sequence, []);
33 this.initSeqAndName (name, sequence, start, end);
35 Clazz.defineMethod (c$, "initSeqAndName",
36 function (name2, sequence2, start2, end2) {
38 this.sequence = sequence2;
42 this.checkValidRange ();
44 Clazz.defineMethod (c$, "parseId",
46 if (this.name == null) {
47 System.err.println ("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
49 }if (this.limitrx.search (this.name)) {
50 this.name = this.limitrx.left ();
51 this.endrx.search (this.limitrx.stringMatched ());
52 this.setStart (Integer.parseInt (this.limitrx.stringMatched ().substring (1, this.endrx.matchedFrom () - 1)));
53 this.setEnd (Integer.parseInt (this.endrx.stringMatched ()));
55 Clazz.defineMethod (c$, "checkValidRange",
59 for (var j = 0; j < this.sequence.length; j++) {
60 if (!jalview.util.Comparison.isGap (this.sequence[j])) {
64 endRes += this.start - 1;
65 }if (this.end < endRes) {
68 Clazz.makeConstructor (c$,
69 function (name, sequence) {
70 this.construct (name, sequence, 1, -1);
72 Clazz.makeConstructor (c$,
74 this.construct (seq, seq.getAnnotation ());
75 }, "jalview.datamodel.SequenceI");
76 Clazz.makeConstructor (c$,
77 function (seq, alAnnotation) {
78 Clazz.superConstructor (this, jalview.datamodel.Sequence, []);
79 this.initSeqFrom (seq, alAnnotation);
80 }, "jalview.datamodel.SequenceI,~A");
81 Clazz.defineMethod (c$, "initSeqFrom",
82 function (seq, alAnnotation) {
83 this.initSeqAndName (seq.getName (), seq.getSequence (), seq.getStart (), seq.getEnd ());
84 this.description = seq.getDescription ();
85 if (seq.getSequenceFeatures () != null) {
86 var sf = seq.getSequenceFeatures ();
87 for (var i = 0; i < sf.length; i++) {
88 this.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf[i]));
90 }this.setDatasetSequence (seq.getDatasetSequence ());
91 if (this.datasetSequence == null && seq.getDBRef () != null) {
92 var dbr = seq.getDBRef ();
93 for (var i = 0; i < dbr.length; i++) {
94 this.addDBRef ( new jalview.datamodel.DBRefEntry (dbr[i]));
96 }if (seq.getAnnotation () != null) {
97 var sqann = seq.getAnnotation ();
98 for (var i = 0; i < sqann.length; i++) {
99 if (sqann[i] == null) {
101 }var found = (alAnnotation == null);
103 for (var apos = 0; !found && apos < alAnnotation.length; apos++) {
104 found = (alAnnotation[apos] === sqann[i]);
107 var newann = new jalview.datamodel.AlignmentAnnotation (sqann[i]);
108 this.addAlignmentAnnotation (newann);
110 }if (seq.getPDBId () != null) {
111 var ids = seq.getPDBId ();
112 var e = ids.elements ();
113 while (e.hasMoreElements ()) {
114 this.addPDBId ( new jalview.datamodel.PDBEntry (e.nextElement ()));
116 }}, "jalview.datamodel.SequenceI,~A");
117 Clazz.defineMethod (c$, "setSequenceFeatures",
118 function (features) {
119 this.sequenceFeatures = features;
121 Clazz.overrideMethod (c$, "addSequenceFeature",
123 if (this.sequenceFeatures == null) {
124 this.sequenceFeatures = new Array (0);
125 }for (var i = 0; i < this.sequenceFeatures.length; i++) {
126 if (this.sequenceFeatures[i].equals (sf)) {
129 var temp = new Array (this.sequenceFeatures.length + 1);
130 System.arraycopy (this.sequenceFeatures, 0, temp, 0, this.sequenceFeatures.length);
131 temp[this.sequenceFeatures.length] = sf;
132 this.sequenceFeatures = temp;
133 }, "jalview.datamodel.SequenceFeature");
134 Clazz.overrideMethod (c$, "deleteFeature",
136 if (this.sequenceFeatures == null) {
139 for (index = 0; index < this.sequenceFeatures.length; index++) {
140 if (this.sequenceFeatures[index].equals (sf)) {
143 if (index == this.sequenceFeatures.length) {
145 }var sfLength = this.sequenceFeatures.length;
147 this.sequenceFeatures = null;
149 var temp = new Array (sfLength - 1);
150 System.arraycopy (this.sequenceFeatures, 0, temp, 0, index);
151 if (index < sfLength) {
152 System.arraycopy (this.sequenceFeatures, index + 1, temp, index, this.sequenceFeatures.length - index - 1);
153 }this.sequenceFeatures = temp;
154 }}, "jalview.datamodel.SequenceFeature");
155 Clazz.defineMethod (c$, "getSequenceFeatures",
157 var features = this.sequenceFeatures;
160 while (features == null && seq.getDatasetSequence () != null && count++ < 10) {
161 seq = seq.getDatasetSequence ();
162 features = (seq).sequenceFeatures;
166 Clazz.overrideMethod (c$, "addPDBId",
168 if (this.pdbIds == null) {
169 this.pdbIds = new java.util.Vector ();
170 }if (this.pdbIds.contains (entry)) {
171 jalview.datamodel.Sequence.updatePDBEntry (this.pdbIds.get (this.pdbIds.indexOf (entry)), entry);
173 this.pdbIds.addElement (entry);
174 }}, "jalview.datamodel.PDBEntry");
175 c$.updatePDBEntry = Clazz.defineMethod (c$, "updatePDBEntry",
176 function (oldEntry, newEntry) {
177 if (newEntry.getFile () != null) {
178 oldEntry.setFile (newEntry.getFile ());
179 }}, "jalview.datamodel.PDBEntry,jalview.datamodel.PDBEntry");
180 Clazz.defineMethod (c$, "setPDBId",
183 }, "java.util.Vector");
184 Clazz.defineMethod (c$, "getPDBId",
188 Clazz.overrideMethod (c$, "getDisplayId",
189 function (jvsuffix) {
190 var result = new StringBuffer (this.name);
192 result.append ("/" + this.start + "-" + this.end);
193 }return result.toString ();
195 Clazz.overrideMethod (c$, "setName",
200 Clazz.defineMethod (c$, "getName",
204 Clazz.overrideMethod (c$, "setStart",
208 Clazz.defineMethod (c$, "getStart",
212 Clazz.overrideMethod (c$, "setEnd",
216 Clazz.defineMethod (c$, "getEnd",
220 Clazz.overrideMethod (c$, "getLength",
222 return this.sequence.length;
224 Clazz.defineMethod (c$, "setSequence",
226 this.sequence = seq.toCharArray ();
227 this.checkValidRange ();
229 Clazz.defineMethod (c$, "getSequenceAsString",
231 return String.instantialize (this.sequence);
233 Clazz.defineMethod (c$, "getSequenceAsString",
234 function (start, end) {
235 return String.instantialize (this.getSequence (start, end));
237 Clazz.defineMethod (c$, "getSequence",
239 return this.sequence;
241 Clazz.defineMethod (c$, "getSequence",
242 function (start, end) {
245 }if (start >= this.sequence.length) {
246 return Clazz.newCharArray (0, '\0');
247 }if (end >= this.sequence.length) {
248 end = this.sequence.length;
249 }var reply = Clazz.newCharArray (end - start, '\0');
250 System.arraycopy (this.sequence, start, reply, 0, end - start);
253 Clazz.overrideMethod (c$, "getSubSequence",
254 function (start, end) {
257 }var seq = this.getSequence (start, end);
258 if (seq.length == 0) {
260 }var nstart = this.findPosition (start);
261 var nend = this.findPosition (end) - 1;
262 var nseq = new jalview.datamodel.Sequence (this.getName (), seq, nstart, nend);
263 nseq.setDescription (this.description);
264 if (this.datasetSequence != null) {
265 nseq.setDatasetSequence (this.datasetSequence);
267 nseq.setDatasetSequence (this);
270 Clazz.overrideMethod (c$, "getCharAt",
272 if (i < this.sequence.length) {
273 return this.sequence[i];
277 Clazz.defineMethod (c$, "setDescription",
279 this.description = desc;
281 Clazz.defineMethod (c$, "getDescription",
283 return this.description;
285 Clazz.overrideMethod (c$, "findIndex",
289 while ((i < this.sequence.length) && (j <= this.end) && (j <= pos)) {
290 if (!jalview.util.Comparison.isGap (this.sequence[i])) {
294 if ((j == this.end) && (j < pos)) {
299 Clazz.overrideMethod (c$, "findPosition",
302 var pos = this.start;
303 var seqlen = this.sequence.length;
304 while ((j < i) && (j < seqlen)) {
305 if (!jalview.util.Comparison.isGap (this.sequence[j])) {
311 Clazz.overrideMethod (c$, "gapMap",
313 var seq = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence));
314 var map = Clazz.newIntArray (seq.length, 0);
317 while (j < this.sequence.length) {
318 if (!jalview.util.Comparison.isGap (this.sequence[j])) {
324 Clazz.overrideMethod (c$, "findPositionMap",
326 var map = Clazz.newIntArray (this.sequence.length, 0);
328 var pos = this.start;
329 var seqlen = this.sequence.length;
330 while ((j < seqlen)) {
332 if (!jalview.util.Comparison.isGap (this.sequence[j])) {
338 Clazz.overrideMethod (c$, "getInsertions",
340 var map = new java.util.ArrayList ();
343 var pos = this.start;
344 var seqlen = this.sequence.length;
345 while ((j < seqlen)) {
346 if (jalview.util.Comparison.isGap (this.sequence[j])) {
351 map.add ( Clazz.newIntArray (-1, [lastj, j - 1]));
356 map.add ( Clazz.newIntArray (-1, [lastj, j - 1]));
360 Clazz.overrideMethod (c$, "deleteChars",
362 var newstart = this.start;
363 var newend = this.end;
364 if (i >= this.sequence.length || i < 0) {
366 }var tmp = jalview.util.StringUtils.deleteChars (this.sequence, i, j);
367 var createNewDs = false;
372 for (var s = i; s < j; s++) {
373 if (jalview.schemes.ResidueProperties.aaIndex[this.sequence[s].charCodeAt (0)] != 23) {
378 sindex = this.findIndex (this.start) - 1;
381 newstart = this.findPosition (j);
385 eindex = this.findIndex (this.end) - 1;
388 newend = this.findPosition (i - 1);
394 if (createNewDs && this.datasetSequence != null) {
395 var ds = new jalview.datamodel.Sequence (this.datasetSequence);
396 ds.deleteChars (i, j);
397 this.datasetSequence = ds;
398 }this.start = newstart;
402 Clazz.defineMethod (c$, "insertCharAt",
403 function (i, length, c) {
404 var tmp = Clazz.newCharArray (this.sequence.length + length, '\0');
405 if (i >= this.sequence.length) {
406 System.arraycopy (this.sequence, 0, tmp, 0, this.sequence.length);
407 i = this.sequence.length;
409 System.arraycopy (this.sequence, 0, tmp, 0, i);
415 if (i < this.sequence.length) {
416 System.arraycopy (this.sequence, i, tmp, index, this.sequence.length - i);
417 }this.sequence = tmp;
419 Clazz.defineMethod (c$, "insertCharAt",
421 this.insertCharAt (i, 1, c);
423 Clazz.overrideMethod (c$, "getVamsasId",
425 return this.vamsasId;
427 Clazz.overrideMethod (c$, "setVamsasId",
431 Clazz.defineMethod (c$, "setDBRef",
435 Clazz.defineMethod (c$, "getDBRef",
437 if (this.dbrefs == null && this.datasetSequence != null && this !== this.datasetSequence) {
438 return this.datasetSequence.getDBRef ();
441 Clazz.overrideMethod (c$, "addDBRef",
443 if (this.dbrefs == null) {
444 this.dbrefs = new Array (0);
446 var iSize = this.dbrefs.length;
447 for (i = 0; i < iSize; i++) {
448 if (this.dbrefs[i].equalRef (entry)) {
449 if (entry.getMap () != null) {
450 if (this.dbrefs[i].getMap () == null) {
451 this.dbrefs[i] = entry;
454 var temp = new Array (iSize + 1);
455 System.arraycopy (this.dbrefs, 0, temp, 0, iSize);
456 temp[temp.length - 1] = entry;
458 }, "jalview.datamodel.DBRefEntry");
459 Clazz.defineMethod (c$, "setDatasetSequence",
461 this.datasetSequence = seq;
462 }, "jalview.datamodel.SequenceI");
463 Clazz.defineMethod (c$, "getDatasetSequence",
465 return this.datasetSequence;
467 Clazz.defineMethod (c$, "getAnnotation",
469 return this.annotation == null ? null : this.annotation.toArray ( new Array (this.annotation.size ()));
471 Clazz.overrideMethod (c$, "hasAnnotation",
473 return this.annotation == null ? false : this.annotation.contains (ann);
474 }, "jalview.datamodel.AlignmentAnnotation");
475 Clazz.defineMethod (c$, "addAlignmentAnnotation",
476 function (annotation) {
477 if (this.annotation == null) {
478 this.annotation = new java.util.Vector ();
479 }if (!this.annotation.contains (annotation)) {
480 this.annotation.addElement (annotation);
481 }annotation.setSequenceRef (this);
482 }, "jalview.datamodel.AlignmentAnnotation");
483 Clazz.overrideMethod (c$, "removeAlignmentAnnotation",
484 function (annotation) {
485 if (this.annotation != null) {
486 this.annotation.removeElement (annotation);
487 if (this.annotation.size () == 0) {
488 this.annotation = null;
489 }}}, "jalview.datamodel.AlignmentAnnotation");
490 Clazz.defineMethod (c$, "isValidDatasetSequence",
492 if (this.datasetSequence != null) {
494 }for (var i = 0; i < this.sequence.length; i++) {
495 if (jalview.util.Comparison.isGap (this.sequence[i])) {
500 Clazz.overrideMethod (c$, "deriveSequence",
502 var seq = new jalview.datamodel.Sequence (this);
503 if (this.datasetSequence != null) {
504 seq.setDatasetSequence (this.datasetSequence);
506 if (this.isValidDatasetSequence ()) {
507 seq.setDatasetSequence (this);
510 ds.setSequence (jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence)));
511 this.setDatasetSequence (ds);
512 ds.setSequenceFeatures (this.getSequenceFeatures ());
516 Clazz.overrideMethod (c$, "createDatasetSequence",
518 if (this.datasetSequence == null) {
519 this.datasetSequence = new jalview.datamodel.Sequence (this.getName (), jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, this.getSequenceAsString ()), this.getStart (), this.getEnd ());
520 this.datasetSequence.setSequenceFeatures (this.getSequenceFeatures ());
521 this.datasetSequence.setDescription (this.getDescription ());
522 this.setSequenceFeatures (null);
523 this.datasetSequence.setDBRef (this.getDBRef ());
524 this.setDBRef (null);
525 this.datasetSequence.setPDBId (this.getPDBId ());
526 this.setPDBId (null);
527 this.datasetSequence.updatePDBIds ();
528 if (this.annotation != null) {
529 for (var aa, $aa = this.annotation.iterator (); $aa.hasNext () && ((aa = $aa.next ()) || true);) {
530 var _aa = new jalview.datamodel.AlignmentAnnotation (aa);
531 _aa.sequenceRef = this.datasetSequence;
532 _aa.adjustForAlignment ();
533 this.datasetSequence.addAlignmentAnnotation (_aa);
535 }}return this.datasetSequence;
537 Clazz.overrideMethod (c$, "setAlignmentAnnotation",
538 function (annotations) {
539 if (this.annotation != null) {
540 this.annotation.removeAllElements ();
541 }if (annotations != null) {
542 for (var i = 0; i < annotations.length; i++) {
543 if (annotations[i] != null) {
544 this.addAlignmentAnnotation (annotations[i]);
547 Clazz.defineMethod (c$, "getAnnotation",
549 if (this.annotation == null || this.annotation.size () == 0) {
551 }var subset = new java.util.Vector ();
552 var e = this.annotation.elements ();
553 while (e.hasMoreElements ()) {
554 var ann = e.nextElement ();
555 if (ann.label != null && ann.label.equals (label)) {
556 subset.addElement (ann);
558 if (subset.size () == 0) {
560 }var anns = new Array (subset.size ());
562 e = subset.elements ();
563 while (e.hasMoreElements ()) {
564 anns[i++] = e.nextElement ();
566 subset.removeAllElements ();
569 Clazz.defineMethod (c$, "updatePDBIds",
571 if (this.datasetSequence != null) {
572 return this.datasetSequence.updatePDBIds ();
573 }if (this.dbrefs == null || this.dbrefs.length == 0) {
575 }var newpdb = new java.util.Vector ();
576 for (var i = 0; i < this.dbrefs.length; i++) {
577 if (jalview.datamodel.DBRefSource.PDB.equals (this.dbrefs[i].getSource ())) {
578 var pdbe = new jalview.datamodel.PDBEntry ();
579 pdbe.setId (this.dbrefs[i].getAccessionId ());
580 if (this.pdbIds == null || this.pdbIds.size () == 0) {
581 newpdb.addElement (pdbe);
583 var en = this.pdbIds.elements ();
585 while (!matched && en.hasMoreElements ()) {
586 var anentry = en.nextElement ();
587 if (anentry.getId ().equals (pdbe.getId ())) {
591 newpdb.addElement (pdbe);
593 if (newpdb.size () > 0) {
594 var en = newpdb.elements ();
595 while (en.hasMoreElements ()) {
596 this.addPDBId (en.nextElement ());
601 Clazz.defineMethod (c$, "transferAnnotation",
602 function (entry, mp) {
603 if (this.datasetSequence != null) {
604 this.datasetSequence.transferAnnotation (entry, mp);
606 }if (entry.getDatasetSequence () != null) {
607 this.transferAnnotation (entry.getDatasetSequence (), mp);
609 }if (entry.getSequenceFeatures () != null) {
610 var sfs = entry.getSequenceFeatures ();
611 for (var si = 0; si < sfs.length; si++) {
612 var sf = (mp != null) ? mp.locateFeature (sfs[si]) : Clazz.newArray (-1, [ new jalview.datamodel.SequenceFeature (sfs[si])]);
613 if (sf != null && sf.length > 0) {
614 for (var sfi = 0; sfi < sf.length; sfi++) {
615 this.addSequenceFeature (sf[sfi]);
618 }if (entry.getPDBId () != null) {
619 var e = entry.getPDBId ().elements ();
620 while (e.hasMoreElements ()) {
621 var pdb = e.nextElement ();
624 }var entryRefs = entry.getDBRef ();
625 if (entryRefs != null) {
626 for (var r = 0; r < entryRefs.length; r++) {
627 var newref = new jalview.datamodel.DBRefEntry (entryRefs[r]);
628 if (newref.getMap () != null && mp != null) {
629 }this.addDBRef (newref);
631 }}, "jalview.datamodel.SequenceI,jalview.datamodel.Mapping");
632 Clazz.overrideMethod (c$, "getIndex",
636 Clazz.overrideMethod (c$, "setIndex",
640 Clazz.overrideMethod (c$, "setRNA",
643 }, "jalview.jsdev.api.VarnaRNA");
644 Clazz.overrideMethod (c$, "getRNA",
648 Clazz.overrideMethod (c$, "getAlignmentAnnotations",
649 function (calcId, label) {
650 var result = new java.util.ArrayList ();
651 if (this.annotation != null) {
652 for (var ann, $ann = this.annotation.iterator (); $ann.hasNext () && ((ann = $ann.next ()) || true);) {
653 if (ann.calcId != null && ann.calcId.equals (calcId) && ann.label != null && ann.label.equals (label)) {