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