JAL-1807 test
[jalviewjs.git] / bin / jalview / datamodel / AlignedCodonFrame.js
1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (null, "jalview.datamodel.AlignedCodonFrame", ["jalview.datamodel.Mapping", "jalview.util.MappingUtils", "java.util.ArrayList"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.dnaSeqs = null;
5 this.dnaToProt = null;
6 Clazz.instantialize (this, arguments);
7 }, jalview.datamodel, "AlignedCodonFrame");
8 Clazz.makeConstructor (c$, 
9 function () {
10 });
11 Clazz.defineMethod (c$, "addMap", 
12 function (dnaseq, aaseq, map) {
13 var nlen = 1;
14 if (this.dnaSeqs != null) {
15 nlen = this.dnaSeqs.length + 1;
16 }var ndna =  new Array (nlen);
17 var ndtp =  new Array (nlen);
18 if (this.dnaSeqs != null) {
19 System.arraycopy (this.dnaSeqs, 0, ndna, 0, this.dnaSeqs.length);
20 System.arraycopy (this.dnaToProt, 0, ndtp, 0, this.dnaSeqs.length);
21 }this.dnaSeqs = ndna;
22 this.dnaToProt = ndtp;
23 nlen--;
24 this.dnaSeqs[nlen] = (dnaseq.getDatasetSequence () == null) ? dnaseq : dnaseq.getDatasetSequence ();
25 var mp =  new jalview.datamodel.Mapping (map);
26 mp.to = (aaseq.getDatasetSequence () == null) ? aaseq : aaseq.getDatasetSequence ();
27 this.dnaToProt[nlen] = mp;
28 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,jalview.util.MapList");
29 Clazz.defineMethod (c$, "getdnaSeqs", 
30 function () {
31 return this.dnaSeqs;
32 });
33 Clazz.defineMethod (c$, "getAaSeqs", 
34 function () {
35 if (this.dnaToProt == null) {
36 return null;
37 }var sqs =  new Array (this.dnaToProt.length);
38 for (var sz = 0; sz < this.dnaToProt.length; sz++) {
39 sqs[sz] = this.dnaToProt[sz].to;
40 }
41 return sqs;
42 });
43 Clazz.defineMethod (c$, "getdnaToProt", 
44 function () {
45 if (this.dnaToProt == null) {
46 return null;
47 }var sqs =  new Array (this.dnaToProt.length);
48 for (var sz = 0; sz < this.dnaToProt.length; sz++) {
49 sqs[sz] = this.dnaToProt[sz].map;
50 }
51 return sqs;
52 });
53 Clazz.defineMethod (c$, "getProtMappings", 
54 function () {
55 return this.dnaToProt;
56 });
57 Clazz.defineMethod (c$, "getMappingForSequence", 
58 function (seq) {
59 if (this.dnaSeqs == null) {
60 return null;
61 }var seqDs = seq.getDatasetSequence ();
62 seqDs = seqDs != null ? seqDs : seq;
63 for (var ds = 0; ds < this.dnaSeqs.length; ds++) {
64 if (this.dnaSeqs[ds] === seqDs || this.dnaToProt[ds].to === seqDs) {
65 return this.dnaToProt[ds];
66 }}
67 return null;
68 }, "jalview.datamodel.SequenceI");
69 Clazz.defineMethod (c$, "getAaForDnaSeq", 
70 function (dnaSeqRef) {
71 if (this.dnaSeqs == null) {
72 return null;
73 }var dnads = dnaSeqRef.getDatasetSequence ();
74 for (var ds = 0; ds < this.dnaSeqs.length; ds++) {
75 if (this.dnaSeqs[ds] === dnaSeqRef || this.dnaSeqs[ds] === dnads) {
76 return this.dnaToProt[ds].to;
77 }}
78 return null;
79 }, "jalview.datamodel.SequenceI");
80 Clazz.defineMethod (c$, "getDnaForAaSeq", 
81 function (aaSeqRef) {
82 if (this.dnaToProt == null) {
83 return null;
84 }var aads = aaSeqRef.getDatasetSequence ();
85 for (var as = 0; as < this.dnaToProt.length; as++) {
86 if (this.dnaToProt[as].to === aaSeqRef || this.dnaToProt[as].to === aads) {
87 return this.dnaSeqs[as];
88 }}
89 return null;
90 }, "jalview.datamodel.SequenceI");
91 Clazz.defineMethod (c$, "involvesSequence", 
92 function (seq) {
93 return this.getAaForDnaSeq (seq) != null || this.getDnaForAaSeq (seq) != null;
94 }, "jalview.datamodel.SequenceI");
95 Clazz.defineMethod (c$, "markMappedRegion", 
96 function (seq, index, results) {
97 if (this.dnaToProt == null) {
98 return;
99 }var codon;
100 var ds = seq.getDatasetSequence ();
101 for (var mi = 0; mi < this.dnaToProt.length; mi++) {
102 if (this.dnaSeqs[mi] === seq || this.dnaSeqs[mi] === ds) {
103 codon = this.dnaToProt[mi].map.locateInTo (index, index);
104 if (codon != null) {
105 for (var i = 0; i < codon.length; i += 2) {
106 results.addResult (this.dnaToProt[mi].to, codon[i], codon[i + 1]);
107 }
108 }} else if (this.dnaToProt[mi].to === seq || this.dnaToProt[mi].to === ds) {
109 {
110 codon = this.dnaToProt[mi].map.locateInFrom (index, index);
111 if (codon != null) {
112 for (var i = 0; i < codon.length; i += 2) {
113 results.addResult (this.dnaSeqs[mi], codon[i], codon[i + 1]);
114 }
115 }}}}
116 }, "jalview.datamodel.SequenceI,~N,jalview.datamodel.SearchResults");
117 Clazz.defineMethod (c$, "getDnaPosition", 
118 function (seq, aaPos) {
119 var ml = null;
120 for (var i = 0; i < this.dnaToProt.length; i++) {
121 if (this.dnaSeqs[i] === seq) {
122 ml = this.getdnaToProt ()[i];
123 break;
124 }}
125 return ml == null ? null : ml.locateInFrom (aaPos, aaPos);
126 }, "jalview.datamodel.SequenceI,~N");
127 Clazz.defineMethod (c$, "findAlignedSequence", 
128 function (seq, al) {
129 if (this.dnaToProt != null) {
130 for (var i = 0; i < this.dnaToProt.length; i++) {
131 if (this.dnaSeqs[i] === seq) {
132 for (var sourceAligned, $sourceAligned = al.getSequences ().iterator (); $sourceAligned.hasNext () && ((sourceAligned = $sourceAligned.next ()) || true);) {
133 if (this.dnaToProt[i].to === sourceAligned.getDatasetSequence ()) {
134 return sourceAligned;
135 }}
136 }}
137 }if (this.dnaToProt != null) {
138 for (var i = 0; i < this.dnaToProt.length; i++) {
139 if (this.dnaToProt[i].to === seq) {
140 for (var sourceAligned, $sourceAligned = al.getSequences ().iterator (); $sourceAligned.hasNext () && ((sourceAligned = $sourceAligned.next ()) || true);) {
141 if (this.dnaSeqs[i] === sourceAligned.getDatasetSequence ()) {
142 return sourceAligned;
143 }}
144 }}
145 }return null;
146 }, "jalview.datamodel.SequenceI,jalview.datamodel.AlignmentI");
147 Clazz.defineMethod (c$, "getMappedRegion", 
148 function (mappedFrom, mappedTo, pos) {
149 var targetDs = mappedFrom.getDatasetSequence () == null ? mappedFrom : mappedFrom.getDatasetSequence ();
150 var sourceDs = mappedTo.getDatasetSequence () == null ? mappedTo : mappedTo.getDatasetSequence ();
151 if (targetDs == null || sourceDs == null || this.dnaToProt == null) {
152 return null;
153 }for (var mi = 0; mi < this.dnaToProt.length; mi++) {
154 if (this.dnaSeqs[mi] === targetDs && this.dnaToProt[mi].to === sourceDs) {
155 var codon = this.dnaToProt[mi].map.locateInFrom (pos, pos);
156 if (codon != null) {
157 return codon;
158 }}}
159 return null;
160 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,~N");
161 Clazz.defineMethod (c$, "getMappedCodon", 
162 function (protein, aaPos) {
163 if (this.dnaToProt == null) {
164 return null;
165 }var ml = null;
166 var dnaSeq = null;
167 for (var i = 0; i < this.dnaToProt.length; i++) {
168 if (this.dnaToProt[i].to === protein) {
169 ml = this.getdnaToProt ()[i];
170 dnaSeq = this.dnaSeqs[i].getSequence ();
171 break;
172 }}
173 if (ml == null) {
174 return null;
175 }var codonPos = ml.locateInFrom (aaPos, aaPos);
176 if (codonPos == null) {
177 return null;
178 }codonPos = jalview.util.MappingUtils.flattenRanges (codonPos);
179 return  Clazz.newCharArray (-1, [dnaSeq[codonPos[0] - 1], dnaSeq[codonPos[1] - 1], dnaSeq[codonPos[2] - 1]]);
180 }, "jalview.datamodel.SequenceI,~N");
181 Clazz.defineMethod (c$, "getMappingsForSequence", 
182 function (seq) {
183 var result =  new java.util.ArrayList ();
184 if (this.dnaSeqs == null) {
185 return result;
186 }var related =  new java.util.ArrayList ();
187 var seqDs = seq.getDatasetSequence ();
188 seqDs = seqDs != null ? seqDs : seq;
189 for (var ds = 0; ds < this.dnaSeqs.length; ds++) {
190 var mapping = this.dnaToProt[ds];
191 if (this.dnaSeqs[ds] === seqDs || mapping.to === seqDs) {
192 if (!related.contains (mapping.to)) {
193 result.add (mapping);
194 related.add (mapping.to);
195 }}}
196 return result;
197 }, "jalview.datamodel.SequenceI");
198 });