1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (["jalview.analysis.CodonComparator"], "jalview.analysis.Dna", ["jalview.datamodel.AlignedCodon", "$.AlignedCodonFrame", "$.Alignment", "$.AlignmentAnnotation", "$.Annotation", "$.DBRefSource", "$.FeatureProperties", "$.GraphLine", "$.Sequence", "jalview.schemes.ResidueProperties", "jalview.util.Comparison", "$.DBRefUtils", "$.MapList", "$.ShiftList", "java.lang.IllegalStateException", "$.StringBuilder", "java.util.ArrayList", "$.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 this.annotations = null;
12 this.alignedCodons = null;
13 Clazz.instantialize (this, arguments);
14 }, jalview.analysis, "Dna");
15 Clazz.makeConstructor (c$,
16 function (viewport, visibleContigs) {
17 this.selection = java.util.Arrays.asList (viewport.getSequenceSelection ());
18 this.seqstring = viewport.getViewAsString (true);
19 this.contigs = visibleContigs;
20 this.gapChar = viewport.getGapCharacter ();
21 this.annotations = viewport.getAlignment ().getAlignmentAnnotation ();
22 this.dnaWidth = viewport.getAlignment ().getWidth ();
23 this.dataset = viewport.getAlignment ().getDataset ();
24 }, "jalview.api.AlignViewportI,~A");
25 c$.compareCodonPos = Clazz.defineMethod (c$, "compareCodonPos",
27 return jalview.analysis.Dna.comparator.compare (ac1, ac2);
28 }, "jalview.datamodel.AlignedCodon,jalview.datamodel.AlignedCodon");
29 Clazz.defineMethod (c$, "translateCdna",
31 var acf = new jalview.datamodel.AlignedCodonFrame ();
32 this.alignedCodons = new Array (this.dnaWidth);
34 var sSize = this.selection.size ();
35 var pepseqs = new java.util.ArrayList ();
36 for (s = 0; s < sSize; s++) {
37 var newseq = this.translateCodingRegion (this.selection.get (s), this.seqstring[s], acf, pepseqs);
41 if (this.dataset != null) {
42 while (ds.getDatasetSequence () != null) {
43 ds = ds.getDatasetSequence ();
45 this.dataset.addSequence (ds);
47 var newseqs = pepseqs.toArray ( new Array (pepseqs.size ()));
48 var al = new jalview.datamodel.Alignment (newseqs);
50 al.setDataset (this.dataset);
51 this.translateAlignedAnnotations (al, acf);
52 al.addCodonFrame (acf);
55 c$.canTranslate = Clazz.defineMethod (c$, "canTranslate",
56 function (selection, viscontigs) {
57 for (var gd = 0; gd < selection.length; gd++) {
58 var dna = selection[gd];
59 var dnarefs = jalview.util.DBRefUtils.selectRefs (dna.getDBRef (), jalview.datamodel.DBRefSource.DNACODINGDBS);
60 if (dnarefs != null) {
61 var mappedrefs = new java.util.ArrayList ();
62 var refs = dna.getDBRef ();
63 for (var d = 0; d < refs.length; d++) {
64 if (refs[d].getMap () != null && refs[d].getMap ().getMap () != null && refs[d].getMap ().getMap ().getFromRatio () == 3 && refs[d].getMap ().getMap ().getToRatio () == 1) {
65 mappedrefs.add (refs[d]);
67 dnarefs = mappedrefs.toArray ( new Array (mappedrefs.size ()));
68 for (var d = 0; d < dnarefs.length; d++) {
69 var mp = dnarefs[d].getMap ();
71 for (var vc = 0; vc < viscontigs.length; vc += 2) {
72 var mpr = mp.locateMappedRange (viscontigs[vc], viscontigs[vc + 1]);
80 Clazz.defineMethod (c$, "translateAlignedAnnotations",
82 if (this.annotations != null) {
83 for (var annotation, $annotation = 0, $$annotation = this.annotations; $annotation < $$annotation.length && ((annotation = $$annotation[$annotation]) || true); $annotation++) {
84 if (annotation.autoCalculated || !annotation.visible || annotation.isRNA ()) {
86 }var aSize = this.aaWidth;
87 var anots = (annotation.annotations == null) ? null : new Array (aSize);
89 for (var a = 0; a < aSize; a++) {
90 if (a < this.alignedCodons.length && this.alignedCodons[a] != null && this.alignedCodons[a].pos1 == (this.alignedCodons[a].pos3 - 2)) {
91 anots[a] = jalview.analysis.Dna.getCodonAnnotation (this.alignedCodons[a], annotation.annotations);
93 }var aa = new jalview.datamodel.AlignmentAnnotation (annotation.label, annotation.description, anots);
94 aa.graph = annotation.graph;
95 aa.graphGroup = annotation.graphGroup;
96 aa.graphHeight = annotation.graphHeight;
97 if (annotation.getThreshold () != null) {
98 aa.setThreshold ( new jalview.datamodel.GraphLine (annotation.getThreshold ()));
99 }if (annotation.$hasScore) {
100 aa.setScore (annotation.getScore ());
101 }var seqRef = annotation.sequenceRef;
102 if (seqRef != null) {
103 var aaSeq = acf.getAaForDnaSeq (seqRef);
105 aa.setSequenceRef (aaSeq);
106 aa.createSequenceMapping (aaSeq, aaSeq.getStart (), true);
107 aa.adjustForAlignment ();
108 aaSeq.addAlignmentAnnotation (aa);
109 }}al.addAnnotation (aa);
111 }}, "jalview.datamodel.AlignmentI,jalview.datamodel.AlignedCodonFrame");
112 c$.getCodonAnnotation = Clazz.defineMethod (c$, "getCodonAnnotation",
113 ($fz = function (is, annotations) {
116 for (var p = 1; p <= 3; p++) {
117 var dnaCol = is.getBaseColumn (p);
118 if (annotations[dnaCol] != null) {
120 annot = new jalview.datamodel.Annotation (annotations[dnaCol]);
123 var cpy = new jalview.datamodel.Annotation (annotations[dnaCol]);
124 if (annot.colour == null) {
125 annot.colour = cpy.colour;
126 }if (annot.description == null || annot.description.length == 0) {
127 annot.description = cpy.description;
128 }if (annot.displayCharacter == null) {
129 annot.displayCharacter = cpy.displayCharacter;
130 }if (annot.secondaryStructure.charCodeAt (0) == 0) {
131 annot.secondaryStructure = cpy.secondaryStructure;
132 }annot.value += cpy.value;
136 annot.value /= contrib;
138 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignedCodon,~A");
139 Clazz.defineMethod (c$, "translateCodingRegion",
140 function (selection, seqstring, acf, proteinSeqs) {
141 var skip = new java.util.ArrayList ();
143 var vismapping = new jalview.util.ShiftList ();
145 var scontigs = Clazz.newIntArray (this.contigs.length, 0);
147 for (vc = 0; vc < this.contigs.length; vc += 2) {
149 vismapping.addShift (npos, this.contigs[vc]);
151 vismapping.addShift (npos, this.contigs[vc] - this.contigs[vc - 1] + 1);
152 }scontigs[vc] = this.contigs[vc];
153 scontigs[vc + 1] = this.contigs[vc + 1];
155 var protein = new StringBuilder (Clazz.doubleToInt (seqstring.length / 2));
156 var seq = seqstring.$replace ('U', 'T').$replace ('u', 'T');
157 var codon = Clazz.newCharArray (3, '\0');
158 var cdp = Clazz.newIntArray (3, 0);
164 for (npos = 0, nend = seq.length; npos < nend; npos++) {
165 if (!jalview.util.Comparison.isGap (seq.charAt (npos))) {
167 codon[rf++] = seq.charAt (npos);
169 var alignedCodon = new jalview.datamodel.AlignedCodon (cdp[0], cdp[1], cdp[2]);
170 var aa = jalview.schemes.ResidueProperties.codonTranslate ( String.instantialize (codon));
172 var gapString = String.valueOf (this.gapChar);
175 if (skipint == null) {
176 skipint = Clazz.newIntArray (-1, [alignedCodon.pos1, alignedCodon.pos3]);
177 }skipint[1] = alignedCodon.pos3;
179 if (skipint != null) {
180 skipint[0] = vismapping.shift (skipint[0]);
181 skipint[1] = vismapping.shift (skipint[1]);
182 for (vc = 0; vc < scontigs.length; ) {
183 if (scontigs[vc + 1] < skipint[0]) {
186 }if (scontigs[vc] > skipint[1]) {
189 if (scontigs[vc] <= skipint[0]) {
190 if (skipint[0] == scontigs[vc]) {
191 if (scontigs[vc + 1] > skipint[1]) {
192 scontigs[vc] = skipint[1];
195 if (scontigs[vc + 1] == skipint[1]) {
196 t = Clazz.newIntArray (scontigs.length - 2, 0);
198 System.arraycopy (scontigs, 0, t, 0, vc - 1);
199 }if (vc + 2 < t.length) {
200 System.arraycopy (scontigs, vc + 2, t, vc, t.length - vc + 2);
203 scontigs[vc + 1] = skipint[0] - 1;
206 if (scontigs[vc + 1] < skipint[1]) {
207 scontigs[vc + 1] = skipint[0] - 1;
210 t = Clazz.newIntArray (scontigs.length + 2, 0);
211 System.arraycopy (scontigs, 0, t, 0, vc + 1);
212 t[vc + 1] = skipint[0];
213 t[vc + 2] = skipint[1];
214 System.arraycopy (scontigs, vc + 1, t, vc + 3, scontigs.length - (vc + 1));
220 }if (aa.equals ("STOP")) {
225 var compareCodonPos = jalview.analysis.Dna.compareCodonPos (alignedCodon, this.alignedCodons[aspos]);
226 switch (compareCodonPos) {
228 this.insertAAGap (aspos, proteinSeqs);
241 if (this.alignedCodons[aspos] == null) {
242 this.alignedCodons[aspos] = alignedCodon;
243 } else if (!this.alignedCodons[aspos].equals (alignedCodon)) {
244 throw new IllegalStateException ("Tried to coalign " + this.alignedCodons[aspos].toString () + " with " + alignedCodon.toString ());
245 }if (aspos >= this.aaWidth) {
246 this.aaWidth = aspos;
250 var newseq = new jalview.datamodel.Sequence (selection.getName (), protein.toString ());
252 var errMsg = "trimming contigs for incomplete terminal codon.";
253 System.err.println ("trimming contigs for incomplete terminal codon.");
254 vc = scontigs.length - 1;
255 lastnpos = vismapping.shift (lastnpos);
256 while (vc >= 0 && scontigs[vc] > lastnpos) {
257 if (vc > 0 && scontigs[vc - 1] > lastnpos) {
260 scontigs[vc] = lastnpos;
262 if (vc > 0 && (vc + 1) < scontigs.length) {
263 var t = Clazz.newIntArray (vc + 1, 0);
264 System.arraycopy (scontigs, 0, t, 0, vc + 1);
268 }}if (scontigs != null) {
270 for (vc = 0; vc < scontigs.length; vc += 2) {
271 scontigs[vc] = selection.findPosition (scontigs[vc]);
272 scontigs[vc + 1] = selection.findPosition (scontigs[vc + 1]);
273 if (scontigs[vc + 1] == selection.getEnd ()) {
276 if ((vc + 2) < scontigs.length) {
277 var t = Clazz.newIntArray (vc + 2, 0);
278 System.arraycopy (scontigs, 0, t, 0, vc + 2);
280 }var map = new jalview.util.MapList (scontigs, Clazz.newIntArray (-1, [1, resSize]), 3, 1);
281 jalview.analysis.Dna.transferCodedFeatures (selection, newseq, map, null, null);
282 var rseq = newseq.deriveSequence ();
283 acf.addMap (selection, rseq, map);
286 }, "jalview.datamodel.SequenceI,~S,jalview.datamodel.AlignedCodonFrame,java.util.List");
287 Clazz.defineMethod (c$, "insertAAGap",
288 function (pos, proteinSeqs) {
290 for (var seq, $seq = proteinSeqs.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
291 seq.insertCharAt (pos, this.gapChar);
293 this.checkCodonFrameWidth ();
294 if (pos < this.aaWidth) {
296 System.arraycopy (this.alignedCodons, pos, this.alignedCodons, pos + 1, this.alignedCodons.length - pos - 1);
297 this.alignedCodons[pos] = null;
298 }}, "~N,java.util.List");
299 Clazz.defineMethod (c$, "checkCodonFrameWidth",
301 if (this.alignedCodons[this.alignedCodons.length - 1] != null) {
302 var c = new Array (this.alignedCodons.length + 10);
303 System.arraycopy (this.alignedCodons, 0, c, 0, this.alignedCodons.length);
304 this.alignedCodons = c;
306 c$.transferCodedFeatures = Clazz.defineMethod (c$, "transferCodedFeatures",
307 ($fz = function (dna, pep, map, featureTypes, featureGroups) {
308 var sfs = dna.getSequenceFeatures ();
310 var dnarefs = jalview.util.DBRefUtils.selectRefs (dna.getDBRef (), jalview.datamodel.DBRefSource.DNACODINGDBS);
311 if (dnarefs != null) {
312 for (var d = 0; d < dnarefs.length; d++) {
313 var mp = dnarefs[d].getMap ();
317 for (var sf, $sf = 0, $$sf = sfs; $sf < $$sf.length && ((sf = $$sf[$sf]) || true); $sf++) {
318 fgstate = (featureGroups == null) ? null : featureGroups.get (sf.featureGroup);
319 if ((featureTypes == null || featureTypes.containsKey (sf.getType ())) && (fgstate == null || fgstate.booleanValue ())) {
320 if (jalview.datamodel.FeatureProperties.isCodingFeature (null, sf.getType ())) {
323 }}, $fz.isPrivate = true, $fz), "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,jalview.util.MapList,java.util.Map,java.util.Map");
324 Clazz.defineStatics (c$,
326 c$.comparator = c$.prototype.comparator = new jalview.analysis.CodonComparator ();