X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fdatamodel%2FSequence.js;h=06c83291e714136b4977598e2e7c54acb679b44d;hp=6a150910d123b375956bfbe4922dfb19c401ee5d;hb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/datamodel/Sequence.js b/bin/jalview/datamodel/Sequence.js index 6a15091..06c8329 100644 --- a/bin/jalview/datamodel/Sequence.js +++ b/bin/jalview/datamodel/Sequence.js @@ -1,658 +1,658 @@ -Clazz.declarePackage ("jalview.datamodel"); -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 () { -c$ = Clazz.decorateAsClass (function () { -this.datasetSequence = null; -this.name = null; -this.sequence = null; -this.description = null; -this.start = 0; -this.end = 0; -this.pdbIds = null; -this.vamsasId = null; -this.dbrefs = null; -this.rna = null; -this.annotation = null; -this.index = -1; -this.sequenceFeatures = null; -this.limitrx = null; -this.endrx = null; -Clazz.instantialize (this, arguments); -}, jalview.datamodel, "Sequence", jalview.datamodel.ASequence, jalview.datamodel.SequenceI); -Clazz.prepareFields (c$, function () { -this.limitrx = jalview.jsdev.RegExp.newRegex (["[/][0-9]{1,}[-][0-9]{1,}$"]); -this.endrx = jalview.jsdev.RegExp.newRegex (["[0-9]{1,}$"]); -}); -Clazz.makeConstructor (c$, -function (name, sequence, start, end) { -Clazz.superConstructor (this, jalview.datamodel.Sequence, []); -this.initSeqAndName (name, sequence.toCharArray (), start, end); -}, "~S,~S,~N,~N"); -Clazz.makeConstructor (c$, -function (name, sequence, start, end) { -Clazz.superConstructor (this, jalview.datamodel.Sequence, []); -this.initSeqAndName (name, sequence, start, end); -}, "~S,~A,~N,~N"); -Clazz.defineMethod (c$, "initSeqAndName", -function (name2, sequence2, start2, end2) { -this.name = name2; -this.sequence = sequence2; -this.start = start2; -this.end = end2; -this.parseId (); -this.checkValidRange (); -}, "~S,~A,~N,~N"); -Clazz.defineMethod (c$, "parseId", -function () { -if (this.name == null) { -System.err.println ("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor."); -this.name = ""; -}if (this.limitrx.search (this.name)) { -this.name = this.limitrx.left (); -this.endrx.search (this.limitrx.stringMatched ()); -this.setStart (Integer.parseInt (this.limitrx.stringMatched ().substring (1, this.endrx.matchedFrom () - 1))); -this.setEnd (Integer.parseInt (this.endrx.stringMatched ())); -}}); -Clazz.defineMethod (c$, "checkValidRange", -function () { -{ -var endRes = 0; -for (var j = 0; j < this.sequence.length; j++) { -if (!jalview.util.Comparison.isGap (this.sequence[j])) { -endRes++; -}} -if (endRes > 0) { -endRes += this.start - 1; -}if (this.end < endRes) { -this.end = endRes; -}}}); -Clazz.makeConstructor (c$, -function (name, sequence) { -this.construct (name, sequence, 1, -1); -}, "~S,~S"); -Clazz.makeConstructor (c$, -function (seq) { -this.construct (seq, seq.getAnnotation ()); -}, "jalview.datamodel.SequenceI"); -Clazz.makeConstructor (c$, -function (seq, alAnnotation) { -Clazz.superConstructor (this, jalview.datamodel.Sequence, []); -this.initSeqFrom (seq, alAnnotation); -}, "jalview.datamodel.SequenceI,~A"); -Clazz.defineMethod (c$, "initSeqFrom", -function (seq, alAnnotation) { -this.initSeqAndName (seq.getName (), seq.getSequence (), seq.getStart (), seq.getEnd ()); -this.description = seq.getDescription (); -if (seq.getSequenceFeatures () != null) { -var sf = seq.getSequenceFeatures (); -for (var i = 0; i < sf.length; i++) { -this.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf[i])); -} -}this.setDatasetSequence (seq.getDatasetSequence ()); -if (this.datasetSequence == null && seq.getDBRef () != null) { -var dbr = seq.getDBRef (); -for (var i = 0; i < dbr.length; i++) { -this.addDBRef ( new jalview.datamodel.DBRefEntry (dbr[i])); -} -}if (seq.getAnnotation () != null) { -var sqann = seq.getAnnotation (); -for (var i = 0; i < sqann.length; i++) { -if (sqann[i] == null) { -continue; -}var found = (alAnnotation == null); -if (!found) { -for (var apos = 0; !found && apos < alAnnotation.length; apos++) { -found = (alAnnotation[apos] === sqann[i]); -} -}if (found) { -var newann = new jalview.datamodel.AlignmentAnnotation (sqann[i]); -this.addAlignmentAnnotation (newann); -}} -}if (seq.getPDBId () != null) { -var ids = seq.getPDBId (); -var e = ids.elements (); -while (e.hasMoreElements ()) { -this.addPDBId ( new jalview.datamodel.PDBEntry (e.nextElement ())); -} -}}, "jalview.datamodel.SequenceI,~A"); -Clazz.defineMethod (c$, "setSequenceFeatures", -function (features) { -this.sequenceFeatures = features; -}, "~A"); -Clazz.overrideMethod (c$, "addSequenceFeature", -function (sf) { -if (this.sequenceFeatures == null) { -this.sequenceFeatures = new Array (0); -}for (var i = 0; i < this.sequenceFeatures.length; i++) { -if (this.sequenceFeatures[i].equals (sf)) { -return; -}} -var temp = new Array (this.sequenceFeatures.length + 1); -System.arraycopy (this.sequenceFeatures, 0, temp, 0, this.sequenceFeatures.length); -temp[this.sequenceFeatures.length] = sf; -this.sequenceFeatures = temp; -}, "jalview.datamodel.SequenceFeature"); -Clazz.overrideMethod (c$, "deleteFeature", -function (sf) { -if (this.sequenceFeatures == null) { -return; -}var index = 0; -for (index = 0; index < this.sequenceFeatures.length; index++) { -if (this.sequenceFeatures[index].equals (sf)) { -break; -}} -if (index == this.sequenceFeatures.length) { -return; -}var sfLength = this.sequenceFeatures.length; -if (sfLength < 2) { -this.sequenceFeatures = null; -} else { -var temp = new Array (sfLength - 1); -System.arraycopy (this.sequenceFeatures, 0, temp, 0, index); -if (index < sfLength) { -System.arraycopy (this.sequenceFeatures, index + 1, temp, index, this.sequenceFeatures.length - index - 1); -}this.sequenceFeatures = temp; -}}, "jalview.datamodel.SequenceFeature"); -Clazz.defineMethod (c$, "getSequenceFeatures", -function () { -var features = this.sequenceFeatures; -var seq = this; -var count = 0; -while (features == null && seq.getDatasetSequence () != null && count++ < 10) { -seq = seq.getDatasetSequence (); -features = (seq).sequenceFeatures; -} -return features; -}); -Clazz.overrideMethod (c$, "addPDBId", -function (entry) { -if (this.pdbIds == null) { -this.pdbIds = new java.util.Vector (); -}if (this.pdbIds.contains (entry)) { -jalview.datamodel.Sequence.updatePDBEntry (this.pdbIds.get (this.pdbIds.indexOf (entry)), entry); -} else { -this.pdbIds.addElement (entry); -}}, "jalview.datamodel.PDBEntry"); -c$.updatePDBEntry = Clazz.defineMethod (c$, "updatePDBEntry", -($fz = function (oldEntry, newEntry) { -if (newEntry.getFile () != null) { -oldEntry.setFile (newEntry.getFile ()); -}}, $fz.isPrivate = true, $fz), "jalview.datamodel.PDBEntry,jalview.datamodel.PDBEntry"); -Clazz.defineMethod (c$, "setPDBId", -function (id) { -this.pdbIds = id; -}, "java.util.Vector"); -Clazz.defineMethod (c$, "getPDBId", -function () { -return this.pdbIds; -}); -Clazz.overrideMethod (c$, "getDisplayId", -function (jvsuffix) { -var result = new StringBuffer (this.name); -if (jvsuffix) { -result.append ("/" + this.start + "-" + this.end); -}return result.toString (); -}, "~B"); -Clazz.overrideMethod (c$, "setName", -function (name) { -this.name = name; -this.parseId (); -}, "~S"); -Clazz.defineMethod (c$, "getName", -function () { -return this.name; -}); -Clazz.overrideMethod (c$, "setStart", -function (start) { -this.start = start; -}, "~N"); -Clazz.defineMethod (c$, "getStart", -function () { -return this.start; -}); -Clazz.overrideMethod (c$, "setEnd", -function (end) { -this.end = end; -}, "~N"); -Clazz.defineMethod (c$, "getEnd", -function () { -return this.end; -}); -Clazz.overrideMethod (c$, "getLength", -function () { -return this.sequence.length; -}); -Clazz.defineMethod (c$, "setSequence", -function (seq) { -this.sequence = seq.toCharArray (); -this.checkValidRange (); -}, "~S"); -Clazz.defineMethod (c$, "getSequenceAsString", -function () { -return String.instantialize (this.sequence); -}); -Clazz.defineMethod (c$, "getSequenceAsString", -function (start, end) { -return String.instantialize (this.getSequence (start, end)); -}, "~N,~N"); -Clazz.defineMethod (c$, "getSequence", -function () { -return this.sequence; -}); -Clazz.defineMethod (c$, "getSequence", -function (start, end) { -if (start < 0) { -start = 0; -}if (start >= this.sequence.length) { -return Clazz.newCharArray (0, '\0'); -}if (end >= this.sequence.length) { -end = this.sequence.length; -}var reply = Clazz.newCharArray (end - start, '\0'); -System.arraycopy (this.sequence, start, reply, 0, end - start); -return reply; -}, "~N,~N"); -Clazz.overrideMethod (c$, "getSubSequence", -function (start, end) { -if (start < 0) { -start = 0; -}var seq = this.getSequence (start, end); -if (seq.length == 0) { -return null; -}var nstart = this.findPosition (start); -var nend = this.findPosition (end) - 1; -var nseq = new jalview.datamodel.Sequence (this.getName (), seq, nstart, nend); -nseq.setDescription (this.description); -if (this.datasetSequence != null) { -nseq.setDatasetSequence (this.datasetSequence); -} else { -nseq.setDatasetSequence (this); -}return nseq; -}, "~N,~N"); -Clazz.overrideMethod (c$, "getCharAt", -function (i) { -if (i < this.sequence.length) { -return this.sequence[i]; -} else { -return ' '; -}}, "~N"); -Clazz.defineMethod (c$, "setDescription", -function (desc) { -this.description = desc; -}, "~S"); -Clazz.defineMethod (c$, "getDescription", -function () { -return this.description; -}); -Clazz.overrideMethod (c$, "findIndex", -function (pos) { -var j = this.start; -var i = 0; -while ((i < this.sequence.length) && (j <= this.end) && (j <= pos)) { -if (!jalview.util.Comparison.isGap (this.sequence[i])) { -j++; -}i++; -} -if ((j == this.end) && (j < pos)) { -return this.end + 1; -} else { -return i; -}}, "~N"); -Clazz.overrideMethod (c$, "findPosition", -function (i) { -var j = 0; -var pos = this.start; -var seqlen = this.sequence.length; -while ((j < i) && (j < seqlen)) { -if (!jalview.util.Comparison.isGap (this.sequence[j])) { -pos++; -}j++; -} -return pos; -}, "~N"); -Clazz.overrideMethod (c$, "gapMap", -function () { -var seq = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence)); -var map = Clazz.newIntArray (seq.length, 0); -var j = 0; -var p = 0; -while (j < this.sequence.length) { -if (!jalview.util.Comparison.isGap (this.sequence[j])) { -map[p++] = j; -}j++; -} -return map; -}); -Clazz.overrideMethod (c$, "findPositionMap", -function () { -var map = Clazz.newIntArray (this.sequence.length, 0); -var j = 0; -var pos = this.start; -var seqlen = this.sequence.length; -while ((j < seqlen)) { -map[j] = pos; -if (!jalview.util.Comparison.isGap (this.sequence[j])) { -pos++; -}j++; -} -return map; -}); -Clazz.overrideMethod (c$, "getInsertions", -function () { -var map = new java.util.ArrayList (); -var lastj = -1; -var j = 0; -var pos = this.start; -var seqlen = this.sequence.length; -while ((j < seqlen)) { -if (jalview.util.Comparison.isGap (this.sequence[j])) { -if (lastj == -1) { -lastj = j; -}} else { -if (lastj != -1) { -map.add ( Clazz.newIntArray (-1, [lastj, j - 1])); -lastj = -1; -}}j++; -} -if (lastj != -1) { -map.add ( Clazz.newIntArray (-1, [lastj, j - 1])); -lastj = -1; -}return map; -}); -Clazz.overrideMethod (c$, "deleteChars", -function (i, j) { -var newstart = this.start; -var newend = this.end; -if (i >= this.sequence.length || i < 0) { -return; -}var tmp = jalview.util.StringUtils.deleteChars (this.sequence, i, j); -var createNewDs = false; -var eindex = -1; -var sindex = -1; -var ecalc = false; -var scalc = false; -for (var s = i; s < j; s++) { -if (jalview.schemes.ResidueProperties.aaIndex[this.sequence[s].charCodeAt (0)] != 23) { -if (createNewDs) { -newend--; -} else { -if (!scalc) { -sindex = this.findIndex (this.start) - 1; -scalc = true; -}if (sindex == s) { -newstart = this.findPosition (j); -break; -} else { -if (!ecalc) { -eindex = this.findIndex (this.end) - 1; -ecalc = true; -}if (eindex < j) { -newend = this.findPosition (i - 1); -break; -} else { -createNewDs = true; -newend--; -}}}}} -if (createNewDs && this.datasetSequence != null) { -var ds = new jalview.datamodel.Sequence (this.datasetSequence); -ds.deleteChars (i, j); -this.datasetSequence = ds; -}this.start = newstart; -this.end = newend; -this.sequence = tmp; -}, "~N,~N"); -Clazz.defineMethod (c$, "insertCharAt", -function (i, length, c) { -var tmp = Clazz.newCharArray (this.sequence.length + length, '\0'); -if (i >= this.sequence.length) { -System.arraycopy (this.sequence, 0, tmp, 0, this.sequence.length); -i = this.sequence.length; -} else { -System.arraycopy (this.sequence, 0, tmp, 0, i); -}var index = i; -while (length > 0) { -tmp[index++] = c; -length--; -} -if (i < this.sequence.length) { -System.arraycopy (this.sequence, i, tmp, index, this.sequence.length - i); -}this.sequence = tmp; -}, "~N,~N,~S"); -Clazz.defineMethod (c$, "insertCharAt", -function (i, c) { -this.insertCharAt (i, 1, c); -}, "~N,~S"); -Clazz.overrideMethod (c$, "getVamsasId", -function () { -return this.vamsasId; -}); -Clazz.overrideMethod (c$, "setVamsasId", -function (id) { -this.vamsasId = id; -}, "~S"); -Clazz.defineMethod (c$, "setDBRef", -function (dbref) { -this.dbrefs = dbref; -}, "~A"); -Clazz.defineMethod (c$, "getDBRef", -function () { -if (this.dbrefs == null && this.datasetSequence != null && this !== this.datasetSequence) { -return this.datasetSequence.getDBRef (); -}return this.dbrefs; -}); -Clazz.overrideMethod (c$, "addDBRef", -function (entry) { -if (this.dbrefs == null) { -this.dbrefs = new Array (0); -}var i; -var iSize = this.dbrefs.length; -for (i = 0; i < iSize; i++) { -if (this.dbrefs[i].equalRef (entry)) { -if (entry.getMap () != null) { -if (this.dbrefs[i].getMap () == null) { -this.dbrefs[i] = entry; -}}return; -}} -var temp = new Array (iSize + 1); -System.arraycopy (this.dbrefs, 0, temp, 0, iSize); -temp[temp.length - 1] = entry; -this.dbrefs = temp; -}, "jalview.datamodel.DBRefEntry"); -Clazz.defineMethod (c$, "setDatasetSequence", -function (seq) { -this.datasetSequence = seq; -}, "jalview.datamodel.SequenceI"); -Clazz.defineMethod (c$, "getDatasetSequence", -function () { -return this.datasetSequence; -}); -Clazz.defineMethod (c$, "getAnnotation", -function () { -return this.annotation == null ? null : this.annotation.toArray ( new Array (this.annotation.size ())); -}); -Clazz.overrideMethod (c$, "hasAnnotation", -function (ann) { -return this.annotation == null ? false : this.annotation.contains (ann); -}, "jalview.datamodel.AlignmentAnnotation"); -Clazz.defineMethod (c$, "addAlignmentAnnotation", -function (annotation) { -if (this.annotation == null) { -this.annotation = new java.util.Vector (); -}if (!this.annotation.contains (annotation)) { -this.annotation.addElement (annotation); -}annotation.setSequenceRef (this); -}, "jalview.datamodel.AlignmentAnnotation"); -Clazz.overrideMethod (c$, "removeAlignmentAnnotation", -function (annotation) { -if (this.annotation != null) { -this.annotation.removeElement (annotation); -if (this.annotation.size () == 0) { -this.annotation = null; -}}}, "jalview.datamodel.AlignmentAnnotation"); -Clazz.defineMethod (c$, "isValidDatasetSequence", -($fz = function () { -if (this.datasetSequence != null) { -return false; -}for (var i = 0; i < this.sequence.length; i++) { -if (jalview.util.Comparison.isGap (this.sequence[i])) { -return false; -}} -return true; -}, $fz.isPrivate = true, $fz)); -Clazz.overrideMethod (c$, "deriveSequence", -function () { -var seq = new jalview.datamodel.Sequence (this); -if (this.datasetSequence != null) { -seq.setDatasetSequence (this.datasetSequence); -} else { -if (this.isValidDatasetSequence ()) { -seq.setDatasetSequence (this); -} else { -var ds = seq; -ds.setSequence (jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence))); -this.setDatasetSequence (ds); -ds.setSequenceFeatures (this.getSequenceFeatures ()); -seq = this; -}}return seq; -}); -Clazz.overrideMethod (c$, "createDatasetSequence", -function () { -if (this.datasetSequence == null) { -this.datasetSequence = new jalview.datamodel.Sequence (this.getName (), jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, this.getSequenceAsString ()), this.getStart (), this.getEnd ()); -this.datasetSequence.setSequenceFeatures (this.getSequenceFeatures ()); -this.datasetSequence.setDescription (this.getDescription ()); -this.setSequenceFeatures (null); -this.datasetSequence.setDBRef (this.getDBRef ()); -this.setDBRef (null); -this.datasetSequence.setPDBId (this.getPDBId ()); -this.setPDBId (null); -this.datasetSequence.updatePDBIds (); -if (this.annotation != null) { -for (var aa, $aa = this.annotation.iterator (); $aa.hasNext () && ((aa = $aa.next ()) || true);) { -var _aa = new jalview.datamodel.AlignmentAnnotation (aa); -_aa.sequenceRef = this.datasetSequence; -_aa.adjustForAlignment (); -this.datasetSequence.addAlignmentAnnotation (_aa); -} -}}return this.datasetSequence; -}); -Clazz.overrideMethod (c$, "setAlignmentAnnotation", -function (annotations) { -if (this.annotation != null) { -this.annotation.removeAllElements (); -}if (annotations != null) { -for (var i = 0; i < annotations.length; i++) { -if (annotations[i] != null) { -this.addAlignmentAnnotation (annotations[i]); -}} -}}, "~A"); -Clazz.defineMethod (c$, "getAnnotation", -function (label) { -if (this.annotation == null || this.annotation.size () == 0) { -return null; -}var subset = new java.util.Vector (); -var e = this.annotation.elements (); -while (e.hasMoreElements ()) { -var ann = e.nextElement (); -if (ann.label != null && ann.label.equals (label)) { -subset.addElement (ann); -}} -if (subset.size () == 0) { -return null; -}var anns = new Array (subset.size ()); -var i = 0; -e = subset.elements (); -while (e.hasMoreElements ()) { -anns[i++] = e.nextElement (); -} -subset.removeAllElements (); -return anns; -}, "~S"); -Clazz.defineMethod (c$, "updatePDBIds", -function () { -if (this.datasetSequence != null) { -return this.datasetSequence.updatePDBIds (); -}if (this.dbrefs == null || this.dbrefs.length == 0) { -return false; -}var newpdb = new java.util.Vector (); -for (var i = 0; i < this.dbrefs.length; i++) { -if (jalview.datamodel.DBRefSource.PDB.equals (this.dbrefs[i].getSource ())) { -var pdbe = new jalview.datamodel.PDBEntry (); -pdbe.setId (this.dbrefs[i].getAccessionId ()); -if (this.pdbIds == null || this.pdbIds.size () == 0) { -newpdb.addElement (pdbe); -} else { -var en = this.pdbIds.elements (); -var matched = false; -while (!matched && en.hasMoreElements ()) { -var anentry = en.nextElement (); -if (anentry.getId ().equals (pdbe.getId ())) { -matched = true; -}} -if (!matched) { -newpdb.addElement (pdbe); -}}}} -if (newpdb.size () > 0) { -var en = newpdb.elements (); -while (en.hasMoreElements ()) { -this.addPDBId (en.nextElement ()); -} -return true; -}return false; -}); -Clazz.defineMethod (c$, "transferAnnotation", -function (entry, mp) { -if (this.datasetSequence != null) { -this.datasetSequence.transferAnnotation (entry, mp); -return; -}if (entry.getDatasetSequence () != null) { -this.transferAnnotation (entry.getDatasetSequence (), mp); -return; -}if (entry.getSequenceFeatures () != null) { -var sfs = entry.getSequenceFeatures (); -for (var si = 0; si < sfs.length; si++) { -var sf = (mp != null) ? mp.locateFeature (sfs[si]) : Clazz.newArray (-1, [ new jalview.datamodel.SequenceFeature (sfs[si])]); -if (sf != null && sf.length > 0) { -for (var sfi = 0; sfi < sf.length; sfi++) { -this.addSequenceFeature (sf[sfi]); -} -}} -}if (entry.getPDBId () != null) { -var e = entry.getPDBId ().elements (); -while (e.hasMoreElements ()) { -var pdb = e.nextElement (); -this.addPDBId (pdb); -} -}var entryRefs = entry.getDBRef (); -if (entryRefs != null) { -for (var r = 0; r < entryRefs.length; r++) { -var newref = new jalview.datamodel.DBRefEntry (entryRefs[r]); -if (newref.getMap () != null && mp != null) { -}this.addDBRef (newref); -} -}}, "jalview.datamodel.SequenceI,jalview.datamodel.Mapping"); -Clazz.overrideMethod (c$, "getIndex", -function () { -return this.index; -}); -Clazz.overrideMethod (c$, "setIndex", -function (value) { -this.index = value; -}, "~N"); -Clazz.overrideMethod (c$, "setRNA", -function (r) { -this.rna = r; -}, "jalview.jsdev.api.VarnaRNA"); -Clazz.overrideMethod (c$, "getRNA", -function () { -return this.rna; -}); -Clazz.overrideMethod (c$, "getAlignmentAnnotations", -function (calcId, label) { -var result = new java.util.ArrayList (); -if (this.annotation != null) { -for (var ann, $ann = this.annotation.iterator (); $ann.hasNext () && ((ann = $ann.next ()) || true);) { -if (ann.calcId != null && ann.calcId.equals (calcId) && ann.label != null && ann.label.equals (label)) { -result.add (ann); -}} -}return result; -}, "~S,~S"); -}); +Clazz.declarePackage ("jalview.datamodel"); +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 () { +c$ = Clazz.decorateAsClass (function () { +this.datasetSequence = null; +this.name = null; +this.sequence = null; +this.description = null; +this.start = 0; +this.end = 0; +this.pdbIds = null; +this.vamsasId = null; +this.dbrefs = null; +this.rna = null; +this.annotation = null; +this.index = -1; +this.sequenceFeatures = null; +this.limitrx = null; +this.endrx = null; +Clazz.instantialize (this, arguments); +}, jalview.datamodel, "Sequence", jalview.datamodel.ASequence, jalview.datamodel.SequenceI); +Clazz.prepareFields (c$, function () { +this.limitrx = jalview.jsdev.RegExp.newRegex (["[/][0-9]{1,}[-][0-9]{1,}$"]); +this.endrx = jalview.jsdev.RegExp.newRegex (["[0-9]{1,}$"]); +}); +Clazz.makeConstructor (c$, +function (name, sequence, start, end) { +Clazz.superConstructor (this, jalview.datamodel.Sequence, []); +this.initSeqAndName (name, sequence.toCharArray (), start, end); +}, "~S,~S,~N,~N"); +Clazz.makeConstructor (c$, +function (name, sequence, start, end) { +Clazz.superConstructor (this, jalview.datamodel.Sequence, []); +this.initSeqAndName (name, sequence, start, end); +}, "~S,~A,~N,~N"); +Clazz.defineMethod (c$, "initSeqAndName", +function (name2, sequence2, start2, end2) { +this.name = name2; +this.sequence = sequence2; +this.start = start2; +this.end = end2; +this.parseId (); +this.checkValidRange (); +}, "~S,~A,~N,~N"); +Clazz.defineMethod (c$, "parseId", +function () { +if (this.name == null) { +System.err.println ("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor."); +this.name = ""; +}if (this.limitrx.search (this.name)) { +this.name = this.limitrx.left (); +this.endrx.search (this.limitrx.stringMatched ()); +this.setStart (Integer.parseInt (this.limitrx.stringMatched ().substring (1, this.endrx.matchedFrom () - 1))); +this.setEnd (Integer.parseInt (this.endrx.stringMatched ())); +}}); +Clazz.defineMethod (c$, "checkValidRange", +function () { +{ +var endRes = 0; +for (var j = 0; j < this.sequence.length; j++) { +if (!jalview.util.Comparison.isGap (this.sequence[j])) { +endRes++; +}} +if (endRes > 0) { +endRes += this.start - 1; +}if (this.end < endRes) { +this.end = endRes; +}}}); +Clazz.makeConstructor (c$, +function (name, sequence) { +this.construct (name, sequence, 1, -1); +}, "~S,~S"); +Clazz.makeConstructor (c$, +function (seq) { +this.construct (seq, seq.getAnnotation ()); +}, "jalview.datamodel.SequenceI"); +Clazz.makeConstructor (c$, +function (seq, alAnnotation) { +Clazz.superConstructor (this, jalview.datamodel.Sequence, []); +this.initSeqFrom (seq, alAnnotation); +}, "jalview.datamodel.SequenceI,~A"); +Clazz.defineMethod (c$, "initSeqFrom", +function (seq, alAnnotation) { +this.initSeqAndName (seq.getName (), seq.getSequence (), seq.getStart (), seq.getEnd ()); +this.description = seq.getDescription (); +if (seq.getSequenceFeatures () != null) { +var sf = seq.getSequenceFeatures (); +for (var i = 0; i < sf.length; i++) { +this.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf[i])); +} +}this.setDatasetSequence (seq.getDatasetSequence ()); +if (this.datasetSequence == null && seq.getDBRef () != null) { +var dbr = seq.getDBRef (); +for (var i = 0; i < dbr.length; i++) { +this.addDBRef ( new jalview.datamodel.DBRefEntry (dbr[i])); +} +}if (seq.getAnnotation () != null) { +var sqann = seq.getAnnotation (); +for (var i = 0; i < sqann.length; i++) { +if (sqann[i] == null) { +continue; +}var found = (alAnnotation == null); +if (!found) { +for (var apos = 0; !found && apos < alAnnotation.length; apos++) { +found = (alAnnotation[apos] === sqann[i]); +} +}if (found) { +var newann = new jalview.datamodel.AlignmentAnnotation (sqann[i]); +this.addAlignmentAnnotation (newann); +}} +}if (seq.getPDBId () != null) { +var ids = seq.getPDBId (); +var e = ids.elements (); +while (e.hasMoreElements ()) { +this.addPDBId ( new jalview.datamodel.PDBEntry (e.nextElement ())); +} +}}, "jalview.datamodel.SequenceI,~A"); +Clazz.defineMethod (c$, "setSequenceFeatures", +function (features) { +this.sequenceFeatures = features; +}, "~A"); +Clazz.overrideMethod (c$, "addSequenceFeature", +function (sf) { +if (this.sequenceFeatures == null) { +this.sequenceFeatures = new Array (0); +}for (var i = 0; i < this.sequenceFeatures.length; i++) { +if (this.sequenceFeatures[i].equals (sf)) { +return; +}} +var temp = new Array (this.sequenceFeatures.length + 1); +System.arraycopy (this.sequenceFeatures, 0, temp, 0, this.sequenceFeatures.length); +temp[this.sequenceFeatures.length] = sf; +this.sequenceFeatures = temp; +}, "jalview.datamodel.SequenceFeature"); +Clazz.overrideMethod (c$, "deleteFeature", +function (sf) { +if (this.sequenceFeatures == null) { +return; +}var index = 0; +for (index = 0; index < this.sequenceFeatures.length; index++) { +if (this.sequenceFeatures[index].equals (sf)) { +break; +}} +if (index == this.sequenceFeatures.length) { +return; +}var sfLength = this.sequenceFeatures.length; +if (sfLength < 2) { +this.sequenceFeatures = null; +} else { +var temp = new Array (sfLength - 1); +System.arraycopy (this.sequenceFeatures, 0, temp, 0, index); +if (index < sfLength) { +System.arraycopy (this.sequenceFeatures, index + 1, temp, index, this.sequenceFeatures.length - index - 1); +}this.sequenceFeatures = temp; +}}, "jalview.datamodel.SequenceFeature"); +Clazz.defineMethod (c$, "getSequenceFeatures", +function () { +var features = this.sequenceFeatures; +var seq = this; +var count = 0; +while (features == null && seq.getDatasetSequence () != null && count++ < 10) { +seq = seq.getDatasetSequence (); +features = (seq).sequenceFeatures; +} +return features; +}); +Clazz.overrideMethod (c$, "addPDBId", +function (entry) { +if (this.pdbIds == null) { +this.pdbIds = new java.util.Vector (); +}if (this.pdbIds.contains (entry)) { +jalview.datamodel.Sequence.updatePDBEntry (this.pdbIds.get (this.pdbIds.indexOf (entry)), entry); +} else { +this.pdbIds.addElement (entry); +}}, "jalview.datamodel.PDBEntry"); +c$.updatePDBEntry = Clazz.defineMethod (c$, "updatePDBEntry", +($fz = function (oldEntry, newEntry) { +if (newEntry.getFile () != null) { +oldEntry.setFile (newEntry.getFile ()); +}}, $fz.isPrivate = true, $fz), "jalview.datamodel.PDBEntry,jalview.datamodel.PDBEntry"); +Clazz.defineMethod (c$, "setPDBId", +function (id) { +this.pdbIds = id; +}, "java.util.Vector"); +Clazz.defineMethod (c$, "getPDBId", +function () { +return this.pdbIds; +}); +Clazz.overrideMethod (c$, "getDisplayId", +function (jvsuffix) { +var result = new StringBuffer (this.name); +if (jvsuffix) { +result.append ("/" + this.start + "-" + this.end); +}return result.toString (); +}, "~B"); +Clazz.overrideMethod (c$, "setName", +function (name) { +this.name = name; +this.parseId (); +}, "~S"); +Clazz.defineMethod (c$, "getName", +function () { +return this.name; +}); +Clazz.overrideMethod (c$, "setStart", +function (start) { +this.start = start; +}, "~N"); +Clazz.defineMethod (c$, "getStart", +function () { +return this.start; +}); +Clazz.overrideMethod (c$, "setEnd", +function (end) { +this.end = end; +}, "~N"); +Clazz.defineMethod (c$, "getEnd", +function () { +return this.end; +}); +Clazz.overrideMethod (c$, "getLength", +function () { +return this.sequence.length; +}); +Clazz.defineMethod (c$, "setSequence", +function (seq) { +this.sequence = seq.toCharArray (); +this.checkValidRange (); +}, "~S"); +Clazz.defineMethod (c$, "getSequenceAsString", +function () { +return String.instantialize (this.sequence); +}); +Clazz.defineMethod (c$, "getSequenceAsString", +function (start, end) { +return String.instantialize (this.getSequence (start, end)); +}, "~N,~N"); +Clazz.defineMethod (c$, "getSequence", +function () { +return this.sequence; +}); +Clazz.defineMethod (c$, "getSequence", +function (start, end) { +if (start < 0) { +start = 0; +}if (start >= this.sequence.length) { +return Clazz.newCharArray (0, '\0'); +}if (end >= this.sequence.length) { +end = this.sequence.length; +}var reply = Clazz.newCharArray (end - start, '\0'); +System.arraycopy (this.sequence, start, reply, 0, end - start); +return reply; +}, "~N,~N"); +Clazz.overrideMethod (c$, "getSubSequence", +function (start, end) { +if (start < 0) { +start = 0; +}var seq = this.getSequence (start, end); +if (seq.length == 0) { +return null; +}var nstart = this.findPosition (start); +var nend = this.findPosition (end) - 1; +var nseq = new jalview.datamodel.Sequence (this.getName (), seq, nstart, nend); +nseq.setDescription (this.description); +if (this.datasetSequence != null) { +nseq.setDatasetSequence (this.datasetSequence); +} else { +nseq.setDatasetSequence (this); +}return nseq; +}, "~N,~N"); +Clazz.overrideMethod (c$, "getCharAt", +function (i) { +if (i < this.sequence.length) { +return this.sequence[i]; +} else { +return ' '; +}}, "~N"); +Clazz.defineMethod (c$, "setDescription", +function (desc) { +this.description = desc; +}, "~S"); +Clazz.defineMethod (c$, "getDescription", +function () { +return this.description; +}); +Clazz.overrideMethod (c$, "findIndex", +function (pos) { +var j = this.start; +var i = 0; +while ((i < this.sequence.length) && (j <= this.end) && (j <= pos)) { +if (!jalview.util.Comparison.isGap (this.sequence[i])) { +j++; +}i++; +} +if ((j == this.end) && (j < pos)) { +return this.end + 1; +} else { +return i; +}}, "~N"); +Clazz.overrideMethod (c$, "findPosition", +function (i) { +var j = 0; +var pos = this.start; +var seqlen = this.sequence.length; +while ((j < i) && (j < seqlen)) { +if (!jalview.util.Comparison.isGap (this.sequence[j])) { +pos++; +}j++; +} +return pos; +}, "~N"); +Clazz.overrideMethod (c$, "gapMap", +function () { +var seq = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence)); +var map = Clazz.newIntArray (seq.length, 0); +var j = 0; +var p = 0; +while (j < this.sequence.length) { +if (!jalview.util.Comparison.isGap (this.sequence[j])) { +map[p++] = j; +}j++; +} +return map; +}); +Clazz.overrideMethod (c$, "findPositionMap", +function () { +var map = Clazz.newIntArray (this.sequence.length, 0); +var j = 0; +var pos = this.start; +var seqlen = this.sequence.length; +while ((j < seqlen)) { +map[j] = pos; +if (!jalview.util.Comparison.isGap (this.sequence[j])) { +pos++; +}j++; +} +return map; +}); +Clazz.overrideMethod (c$, "getInsertions", +function () { +var map = new java.util.ArrayList (); +var lastj = -1; +var j = 0; +var pos = this.start; +var seqlen = this.sequence.length; +while ((j < seqlen)) { +if (jalview.util.Comparison.isGap (this.sequence[j])) { +if (lastj == -1) { +lastj = j; +}} else { +if (lastj != -1) { +map.add ( Clazz.newIntArray (-1, [lastj, j - 1])); +lastj = -1; +}}j++; +} +if (lastj != -1) { +map.add ( Clazz.newIntArray (-1, [lastj, j - 1])); +lastj = -1; +}return map; +}); +Clazz.overrideMethod (c$, "deleteChars", +function (i, j) { +var newstart = this.start; +var newend = this.end; +if (i >= this.sequence.length || i < 0) { +return; +}var tmp = jalview.util.StringUtils.deleteChars (this.sequence, i, j); +var createNewDs = false; +var eindex = -1; +var sindex = -1; +var ecalc = false; +var scalc = false; +for (var s = i; s < j; s++) { +if (jalview.schemes.ResidueProperties.aaIndex[this.sequence[s].charCodeAt (0)] != 23) { +if (createNewDs) { +newend--; +} else { +if (!scalc) { +sindex = this.findIndex (this.start) - 1; +scalc = true; +}if (sindex == s) { +newstart = this.findPosition (j); +break; +} else { +if (!ecalc) { +eindex = this.findIndex (this.end) - 1; +ecalc = true; +}if (eindex < j) { +newend = this.findPosition (i - 1); +break; +} else { +createNewDs = true; +newend--; +}}}}} +if (createNewDs && this.datasetSequence != null) { +var ds = new jalview.datamodel.Sequence (this.datasetSequence); +ds.deleteChars (i, j); +this.datasetSequence = ds; +}this.start = newstart; +this.end = newend; +this.sequence = tmp; +}, "~N,~N"); +Clazz.defineMethod (c$, "insertCharAt", +function (i, length, c) { +var tmp = Clazz.newCharArray (this.sequence.length + length, '\0'); +if (i >= this.sequence.length) { +System.arraycopy (this.sequence, 0, tmp, 0, this.sequence.length); +i = this.sequence.length; +} else { +System.arraycopy (this.sequence, 0, tmp, 0, i); +}var index = i; +while (length > 0) { +tmp[index++] = c; +length--; +} +if (i < this.sequence.length) { +System.arraycopy (this.sequence, i, tmp, index, this.sequence.length - i); +}this.sequence = tmp; +}, "~N,~N,~S"); +Clazz.defineMethod (c$, "insertCharAt", +function (i, c) { +this.insertCharAt (i, 1, c); +}, "~N,~S"); +Clazz.overrideMethod (c$, "getVamsasId", +function () { +return this.vamsasId; +}); +Clazz.overrideMethod (c$, "setVamsasId", +function (id) { +this.vamsasId = id; +}, "~S"); +Clazz.defineMethod (c$, "setDBRef", +function (dbref) { +this.dbrefs = dbref; +}, "~A"); +Clazz.defineMethod (c$, "getDBRef", +function () { +if (this.dbrefs == null && this.datasetSequence != null && this !== this.datasetSequence) { +return this.datasetSequence.getDBRef (); +}return this.dbrefs; +}); +Clazz.overrideMethod (c$, "addDBRef", +function (entry) { +if (this.dbrefs == null) { +this.dbrefs = new Array (0); +}var i; +var iSize = this.dbrefs.length; +for (i = 0; i < iSize; i++) { +if (this.dbrefs[i].equalRef (entry)) { +if (entry.getMap () != null) { +if (this.dbrefs[i].getMap () == null) { +this.dbrefs[i] = entry; +}}return; +}} +var temp = new Array (iSize + 1); +System.arraycopy (this.dbrefs, 0, temp, 0, iSize); +temp[temp.length - 1] = entry; +this.dbrefs = temp; +}, "jalview.datamodel.DBRefEntry"); +Clazz.defineMethod (c$, "setDatasetSequence", +function (seq) { +this.datasetSequence = seq; +}, "jalview.datamodel.SequenceI"); +Clazz.defineMethod (c$, "getDatasetSequence", +function () { +return this.datasetSequence; +}); +Clazz.defineMethod (c$, "getAnnotation", +function () { +return this.annotation == null ? null : this.annotation.toArray ( new Array (this.annotation.size ())); +}); +Clazz.overrideMethod (c$, "hasAnnotation", +function (ann) { +return this.annotation == null ? false : this.annotation.contains (ann); +}, "jalview.datamodel.AlignmentAnnotation"); +Clazz.defineMethod (c$, "addAlignmentAnnotation", +function (annotation) { +if (this.annotation == null) { +this.annotation = new java.util.Vector (); +}if (!this.annotation.contains (annotation)) { +this.annotation.addElement (annotation); +}annotation.setSequenceRef (this); +}, "jalview.datamodel.AlignmentAnnotation"); +Clazz.overrideMethod (c$, "removeAlignmentAnnotation", +function (annotation) { +if (this.annotation != null) { +this.annotation.removeElement (annotation); +if (this.annotation.size () == 0) { +this.annotation = null; +}}}, "jalview.datamodel.AlignmentAnnotation"); +Clazz.defineMethod (c$, "isValidDatasetSequence", +($fz = function () { +if (this.datasetSequence != null) { +return false; +}for (var i = 0; i < this.sequence.length; i++) { +if (jalview.util.Comparison.isGap (this.sequence[i])) { +return false; +}} +return true; +}, $fz.isPrivate = true, $fz)); +Clazz.overrideMethod (c$, "deriveSequence", +function () { +var seq = new jalview.datamodel.Sequence (this); +if (this.datasetSequence != null) { +seq.setDatasetSequence (this.datasetSequence); +} else { +if (this.isValidDatasetSequence ()) { +seq.setDatasetSequence (this); +} else { +var ds = seq; +ds.setSequence (jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, String.instantialize (this.sequence))); +this.setDatasetSequence (ds); +ds.setSequenceFeatures (this.getSequenceFeatures ()); +seq = this; +}}return seq; +}); +Clazz.overrideMethod (c$, "createDatasetSequence", +function () { +if (this.datasetSequence == null) { +this.datasetSequence = new jalview.datamodel.Sequence (this.getName (), jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, this.getSequenceAsString ()), this.getStart (), this.getEnd ()); +this.datasetSequence.setSequenceFeatures (this.getSequenceFeatures ()); +this.datasetSequence.setDescription (this.getDescription ()); +this.setSequenceFeatures (null); +this.datasetSequence.setDBRef (this.getDBRef ()); +this.setDBRef (null); +this.datasetSequence.setPDBId (this.getPDBId ()); +this.setPDBId (null); +this.datasetSequence.updatePDBIds (); +if (this.annotation != null) { +for (var aa, $aa = this.annotation.iterator (); $aa.hasNext () && ((aa = $aa.next ()) || true);) { +var _aa = new jalview.datamodel.AlignmentAnnotation (aa); +_aa.sequenceRef = this.datasetSequence; +_aa.adjustForAlignment (); +this.datasetSequence.addAlignmentAnnotation (_aa); +} +}}return this.datasetSequence; +}); +Clazz.overrideMethod (c$, "setAlignmentAnnotation", +function (annotations) { +if (this.annotation != null) { +this.annotation.removeAllElements (); +}if (annotations != null) { +for (var i = 0; i < annotations.length; i++) { +if (annotations[i] != null) { +this.addAlignmentAnnotation (annotations[i]); +}} +}}, "~A"); +Clazz.defineMethod (c$, "getAnnotation", +function (label) { +if (this.annotation == null || this.annotation.size () == 0) { +return null; +}var subset = new java.util.Vector (); +var e = this.annotation.elements (); +while (e.hasMoreElements ()) { +var ann = e.nextElement (); +if (ann.label != null && ann.label.equals (label)) { +subset.addElement (ann); +}} +if (subset.size () == 0) { +return null; +}var anns = new Array (subset.size ()); +var i = 0; +e = subset.elements (); +while (e.hasMoreElements ()) { +anns[i++] = e.nextElement (); +} +subset.removeAllElements (); +return anns; +}, "~S"); +Clazz.defineMethod (c$, "updatePDBIds", +function () { +if (this.datasetSequence != null) { +return this.datasetSequence.updatePDBIds (); +}if (this.dbrefs == null || this.dbrefs.length == 0) { +return false; +}var newpdb = new java.util.Vector (); +for (var i = 0; i < this.dbrefs.length; i++) { +if (jalview.datamodel.DBRefSource.PDB.equals (this.dbrefs[i].getSource ())) { +var pdbe = new jalview.datamodel.PDBEntry (); +pdbe.setId (this.dbrefs[i].getAccessionId ()); +if (this.pdbIds == null || this.pdbIds.size () == 0) { +newpdb.addElement (pdbe); +} else { +var en = this.pdbIds.elements (); +var matched = false; +while (!matched && en.hasMoreElements ()) { +var anentry = en.nextElement (); +if (anentry.getId ().equals (pdbe.getId ())) { +matched = true; +}} +if (!matched) { +newpdb.addElement (pdbe); +}}}} +if (newpdb.size () > 0) { +var en = newpdb.elements (); +while (en.hasMoreElements ()) { +this.addPDBId (en.nextElement ()); +} +return true; +}return false; +}); +Clazz.defineMethod (c$, "transferAnnotation", +function (entry, mp) { +if (this.datasetSequence != null) { +this.datasetSequence.transferAnnotation (entry, mp); +return; +}if (entry.getDatasetSequence () != null) { +this.transferAnnotation (entry.getDatasetSequence (), mp); +return; +}if (entry.getSequenceFeatures () != null) { +var sfs = entry.getSequenceFeatures (); +for (var si = 0; si < sfs.length; si++) { +var sf = (mp != null) ? mp.locateFeature (sfs[si]) : Clazz.newArray (-1, [ new jalview.datamodel.SequenceFeature (sfs[si])]); +if (sf != null && sf.length > 0) { +for (var sfi = 0; sfi < sf.length; sfi++) { +this.addSequenceFeature (sf[sfi]); +} +}} +}if (entry.getPDBId () != null) { +var e = entry.getPDBId ().elements (); +while (e.hasMoreElements ()) { +var pdb = e.nextElement (); +this.addPDBId (pdb); +} +}var entryRefs = entry.getDBRef (); +if (entryRefs != null) { +for (var r = 0; r < entryRefs.length; r++) { +var newref = new jalview.datamodel.DBRefEntry (entryRefs[r]); +if (newref.getMap () != null && mp != null) { +}this.addDBRef (newref); +} +}}, "jalview.datamodel.SequenceI,jalview.datamodel.Mapping"); +Clazz.overrideMethod (c$, "getIndex", +function () { +return this.index; +}); +Clazz.overrideMethod (c$, "setIndex", +function (value) { +this.index = value; +}, "~N"); +Clazz.overrideMethod (c$, "setRNA", +function (r) { +this.rna = r; +}, "jalview.jsdev.api.VarnaRNA"); +Clazz.overrideMethod (c$, "getRNA", +function () { +return this.rna; +}); +Clazz.overrideMethod (c$, "getAlignmentAnnotations", +function (calcId, label) { +var result = new java.util.ArrayList (); +if (this.annotation != null) { +for (var ann, $ann = this.annotation.iterator (); $ann.hasNext () && ((ann = $ann.next ()) || true);) { +if (ann.calcId != null && ann.calcId.equals (calcId) && ann.label != null && ann.label.equals (label)) { +result.add (ann); +}} +}return result; +}, "~S,~S"); +});