Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / analysis / AlignmentUtils.js
1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (null, "jalview.analysis.AlignmentUtils", ["jalview.analysis.CodonComparator", "jalview.datamodel.AlignedCodonFrame", "$.Alignment", "$.AlignmentAnnotation", "$.DBRefEntry", "$.DBRefSource", "$.FeatureProperties", "$.SearchResults", "$.Sequence", "jalview.schemes.ResidueProperties", "jalview.util.DBRefUtils", "$.MapList", "$.MappingUtils", "java.lang.StringBuilder", "java.util.ArrayList", "$.Arrays", "$.HashMap", "$.HashSet", "$.LinkedHashMap", "$.LinkedHashSet", "$.TreeMap"], function () {
3 c$ = Clazz.declareType (jalview.analysis, "AlignmentUtils");
4 c$.expandContext = Clazz.defineMethod (c$, "expandContext", 
5 function (core, flankSize) {
6 var sq =  new java.util.ArrayList ();
7 var maxoffset = 0;
8 for (var s, $s = core.getSequences ().iterator (); $s.hasNext () && ((s = $s.next ()) || true);) {
9 var newSeq = s.deriveSequence ();
10 var newSeqStart = newSeq.getStart () - 1;
11 if (newSeqStart > maxoffset && newSeq.getDatasetSequence ().getStart () < s.getStart ()) {
12 maxoffset = newSeqStart;
13 }sq.add (newSeq);
14 }
15 if (flankSize > -1) {
16 maxoffset = Math.min (maxoffset, flankSize);
17 }for (var s, $s = sq.iterator (); $s.hasNext () && ((s = $s.next ()) || true);) {
18 var ds = s;
19 while (ds.getDatasetSequence () != null) {
20 ds = ds.getDatasetSequence ();
21 }
22 var s_end = s.findPosition (s.getStart () + s.getLength ());
23 var ustream_ds = s.getStart () - ds.getStart ();
24 var dstream_ds = ds.getEnd () - s_end;
25 var offset = maxoffset - ustream_ds;
26 if (flankSize >= 0) {
27 if (flankSize < ustream_ds) {
28 offset = maxoffset - flankSize;
29 ustream_ds = flankSize;
30 }if (flankSize <= dstream_ds) {
31 dstream_ds = flankSize - 1;
32 }}var upstream =  String.instantialize (ds.getSequence (s.getStart () - 1 - ustream_ds, s.getStart () - 1)).toLowerCase ().toCharArray ();
33 var downstream =  String.instantialize (ds.getSequence (s_end - 1, s_end + dstream_ds)).toLowerCase ().toCharArray ();
34 var coreseq = s.getSequence ();
35 var nseq =  Clazz.newCharArray (offset + upstream.length + downstream.length + coreseq.length, '\0');
36 var c = core.getGapCharacter ();
37 var p = 0;
38 for (; p < offset; p++) {
39 nseq[p] = c;
40 }
41 System.arraycopy (upstream, 0, nseq, p, upstream.length);
42 System.arraycopy (coreseq, 0, nseq, p + upstream.length, coreseq.length);
43 System.arraycopy (downstream, 0, nseq, p + coreseq.length + upstream.length, downstream.length);
44 s.setSequence ( String.instantialize (nseq));
45 s.setStart (s.getStart () - ustream_ds);
46 s.setEnd (s_end + downstream.length);
47 }
48 var newAl =  new jalview.datamodel.Alignment (sq.toArray ( new Array (0)));
49 for (var s, $s = sq.iterator (); $s.hasNext () && ((s = $s.next ()) || true);) {
50 if (s.getAnnotation () != null) {
51 for (var aa, $aa = 0, $$aa = s.getAnnotation (); $aa < $$aa.length && ((aa = $$aa[$aa]) || true); $aa++) {
52 aa.adjustForAlignment ();
53 newAl.addAnnotation (aa);
54 }
55 }}
56 newAl.setDataset (core.getDataset ());
57 return newAl;
58 }, "jalview.datamodel.AlignmentI,~N");
59 c$.getSequenceIndex = Clazz.defineMethod (c$, "getSequenceIndex", 
60 function (al, seq) {
61 var result = -1;
62 var pos = 0;
63 for (var alSeq, $alSeq = al.getSequences ().iterator (); $alSeq.hasNext () && ((alSeq = $alSeq.next ()) || true);) {
64 if (alSeq === seq) {
65 result = pos;
66 break;
67 }pos++;
68 }
69 return result;
70 }, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceI");
71 c$.getSequencesByName = Clazz.defineMethod (c$, "getSequencesByName", 
72 function (al) {
73 var theMap =  new java.util.LinkedHashMap ();
74 for (var seq, $seq = al.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
75 var name = seq.getName ();
76 if (name != null) {
77 var seqs = theMap.get (name);
78 if (seqs == null) {
79 seqs =  new java.util.ArrayList ();
80 theMap.put (name, seqs);
81 }seqs.add (seq);
82 }}
83 return theMap;
84 }, "jalview.datamodel.AlignmentI");
85 c$.mapProteinToCdna = Clazz.defineMethod (c$, "mapProteinToCdna", 
86 function (proteinAlignment, cdnaAlignment) {
87 if (proteinAlignment == null || cdnaAlignment == null) {
88 return false;
89 }var mappedDna =  new java.util.HashSet ();
90 var mappedProtein =  new java.util.HashSet ();
91 var mappingPerformed = jalview.analysis.AlignmentUtils.mapProteinToCdna (proteinAlignment, cdnaAlignment, mappedDna, mappedProtein, true);
92 mappingPerformed = new Boolean (mappingPerformed | jalview.analysis.AlignmentUtils.mapProteinToCdna (proteinAlignment, cdnaAlignment, mappedDna, mappedProtein, false)).valueOf ();
93 return mappingPerformed;
94 }, "jalview.datamodel.AlignmentI,jalview.datamodel.AlignmentI");
95 c$.mapProteinToCdna = Clazz.defineMethod (c$, "mapProteinToCdna", 
96 function (proteinAlignment, cdnaAlignment, mappedDna, mappedProtein, xrefsOnly) {
97 var mappingPerformed = false;
98 var thisSeqs = proteinAlignment.getSequences ();
99 for (var aaSeq, $aaSeq = thisSeqs.iterator (); $aaSeq.hasNext () && ((aaSeq = $aaSeq.next ()) || true);) {
100 var proteinMapped = false;
101 var acf =  new jalview.datamodel.AlignedCodonFrame ();
102 for (var cdnaSeq, $cdnaSeq = cdnaAlignment.getSequences ().iterator (); $cdnaSeq.hasNext () && ((cdnaSeq = $cdnaSeq.next ()) || true);) {
103 if (xrefsOnly && !jalview.analysis.AlignmentUtils.haveCrossRef (aaSeq, cdnaSeq)) {
104 continue;
105 }if (!xrefsOnly && (mappedProtein.contains (aaSeq) || mappedDna.contains (cdnaSeq))) {
106 continue;
107 }if (!jalview.analysis.AlignmentUtils.mappingExists (proteinAlignment.getCodonFrames (), aaSeq.getDatasetSequence (), cdnaSeq.getDatasetSequence ())) {
108 var map = jalview.analysis.AlignmentUtils.mapProteinToCdna (aaSeq, cdnaSeq);
109 if (map != null) {
110 acf.addMap (cdnaSeq, aaSeq, map);
111 mappingPerformed = true;
112 proteinMapped = true;
113 mappedDna.add (cdnaSeq);
114 mappedProtein.add (aaSeq);
115 }}}
116 if (proteinMapped) {
117 proteinAlignment.addCodonFrame (acf);
118 }}
119 return mappingPerformed;
120 }, "jalview.datamodel.AlignmentI,jalview.datamodel.AlignmentI,java.util.Set,java.util.Set,~B");
121 c$.mappingExists = Clazz.defineMethod (c$, "mappingExists", 
122 function (set, aaSeq, cdnaSeq) {
123 if (set != null) {
124 for (var acf, $acf = set.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
125 if (cdnaSeq === acf.getDnaForAaSeq (aaSeq)) {
126 return true;
127 }}
128 }return false;
129 }, "java.util.Set,jalview.datamodel.SequenceI,jalview.datamodel.SequenceI");
130 c$.mapProteinToCdna = Clazz.defineMethod (c$, "mapProteinToCdna", 
131 function (proteinSeq, cdnaSeq) {
132 var proteinDataset = proteinSeq.getDatasetSequence ();
133 var aaSeqChars = proteinDataset != null ? proteinDataset.getSequence () : proteinSeq.getSequence ();
134 var cdnaDataset = cdnaSeq.getDatasetSequence ();
135 var cdnaSeqChars = cdnaDataset != null ? cdnaDataset.getSequence () : cdnaSeq.getSequence ();
136 if (aaSeqChars == null || cdnaSeqChars == null) {
137 return null;
138 }var mappedLength = 3 * aaSeqChars.length;
139 var cdnaLength = cdnaSeqChars.length;
140 var cdnaStart = 1;
141 var cdnaEnd = cdnaLength;
142 var proteinStart = 1;
143 var proteinEnd = aaSeqChars.length;
144 if (cdnaLength != mappedLength && cdnaLength > 2) {
145 var lastCodon = String.valueOf (cdnaSeqChars, cdnaLength - 3, 3).toUpperCase ();
146 for (var stop, $stop = jalview.schemes.ResidueProperties.STOP.iterator (); $stop.hasNext () && ((stop = $stop.next ()) || true);) {
147 if (lastCodon.equals (stop)) {
148 cdnaEnd -= 3;
149 cdnaLength -= 3;
150 break;
151 }}
152 }if (cdnaLength != mappedLength && cdnaLength > 2 && String.valueOf (cdnaSeqChars, 0, 3).toUpperCase ().equals (jalview.schemes.ResidueProperties.START)) {
153 cdnaStart += 3;
154 cdnaLength -= 3;
155 }if (cdnaLength != mappedLength) {
156 return null;
157 }if (!jalview.analysis.AlignmentUtils.translatesAs (cdnaSeqChars, cdnaStart - 1, aaSeqChars)) {
158 return null;
159 }var map =  new jalview.util.MapList ( Clazz.newIntArray (-1, [cdnaStart, cdnaEnd]),  Clazz.newIntArray (-1, [1, proteinEnd]), 3, 1);
160 return map;
161 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI");
162 c$.translatesAs = Clazz.defineMethod (c$, "translatesAs", 
163 function (cdnaSeqChars, cdnaStart, aaSeqChars) {
164 var aaResidue = 0;
165 for (var i = cdnaStart; i < cdnaSeqChars.length - 2 && aaResidue < aaSeqChars.length; i += 3, aaResidue++) {
166 var codon = String.valueOf (cdnaSeqChars, i, 3);
167 var translated = jalview.schemes.ResidueProperties.codonTranslate (codon);
168 var aaRes = aaSeqChars[aaResidue];
169 if ((translated == null || "STOP".equals (translated)) && aaRes == 'X') {
170 continue;
171 }if (translated == null || !(aaRes == translated.charAt (0))) {
172 return false;
173 }}
174 return (aaResidue == aaSeqChars.length);
175 }, "~A,~N,~A");
176 c$.alignSequenceAs = Clazz.defineMethod (c$, "alignSequenceAs", 
177 function (seq, al, gap, preserveMappedGaps, preserveUnmappedGaps) {
178 var mappings = al.getCodonFrame (seq);
179 if (mappings == null || mappings.isEmpty ()) {
180 return false;
181 }var alignFrom = null;
182 var mapping = null;
183 for (var mp, $mp = mappings.iterator (); $mp.hasNext () && ((mp = $mp.next ()) || true);) {
184 alignFrom = mp.findAlignedSequence (seq.getDatasetSequence (), al);
185 if (alignFrom != null) {
186 mapping = mp;
187 break;
188 }}
189 if (alignFrom == null) {
190 return false;
191 }jalview.analysis.AlignmentUtils.alignSequenceAs (seq, alignFrom, mapping, gap, al.getGapCharacter (), preserveMappedGaps, preserveUnmappedGaps);
192 return true;
193 }, "jalview.datamodel.SequenceI,jalview.datamodel.AlignmentI,~S,~B,~B");
194 c$.alignSequenceAs = Clazz.defineMethod (c$, "alignSequenceAs", 
195 function (alignTo, alignFrom, mapping, myGap, sourceGap, preserveMappedGaps, preserveUnmappedGaps) {
196 var thisSeq = alignTo.getSequence ();
197 var thatAligned = alignFrom.getSequence ();
198 var thisAligned =  new StringBuilder (2 * thisSeq.length);
199 var thisSeqPos = 0;
200 var sourceDsPos = 0;
201 var basesWritten = 0;
202 var myGapChar = myGap.charAt (0);
203 var ratio = myGap.length;
204 var sourceGapMappedLength = 0;
205 var inExon = false;
206 for (var sourceChar, $sourceChar = 0, $$sourceChar = thatAligned; $sourceChar < $$sourceChar.length && ((sourceChar = $$sourceChar[$sourceChar]) || true); $sourceChar++) {
207 if (sourceChar == sourceGap) {
208 sourceGapMappedLength += ratio;
209 continue;
210 }sourceDsPos++;
211 var mappedPos = mapping.getMappedRegion (alignTo, alignFrom, sourceDsPos);
212 if (mappedPos == null) {
213 System.err.println ("Can't align: no codon mapping to residue " + sourceDsPos + "(" + sourceChar + ")");
214 return;
215 }var mappedCodonStart = mappedPos[0];
216 var mappedCodonEnd = mappedPos[mappedPos.length - 1];
217 var trailingCopiedGap =  new StringBuilder ();
218 var intronLength = 0;
219 while (basesWritten < mappedCodonEnd && thisSeqPos < thisSeq.length) {
220 var c = thisSeq[thisSeqPos++];
221 if (c != myGapChar) {
222 basesWritten++;
223 if (basesWritten < mappedCodonStart) {
224 if (preserveUnmappedGaps && trailingCopiedGap.length () > 0) {
225 thisAligned.append (trailingCopiedGap.toString ());
226 intronLength += trailingCopiedGap.length ();
227 trailingCopiedGap =  new StringBuilder ();
228 }intronLength++;
229 inExon = false;
230 } else {
231 var startOfCodon = basesWritten == mappedCodonStart;
232 var gapsToAdd = jalview.analysis.AlignmentUtils.calculateGapsToInsert (preserveMappedGaps, preserveUnmappedGaps, sourceGapMappedLength, inExon, trailingCopiedGap.length (), intronLength, startOfCodon);
233 for (var i = 0; i < gapsToAdd; i++) {
234 thisAligned.append (myGapChar);
235 }
236 sourceGapMappedLength = 0;
237 inExon = true;
238 }thisAligned.append (c);
239 trailingCopiedGap =  new StringBuilder ();
240 } else {
241 if (inExon && preserveMappedGaps) {
242 trailingCopiedGap.append (myGapChar);
243 } else if (!inExon && preserveUnmappedGaps) {
244 trailingCopiedGap.append (myGapChar);
245 }}}
246 }
247 while (thisSeqPos < thisSeq.length) {
248 var c = thisSeq[thisSeqPos++];
249 if (c != myGapChar || preserveUnmappedGaps) {
250 thisAligned.append (c);
251 }}
252 alignTo.setSequence ( String.instantialize (thisAligned));
253 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,jalview.datamodel.AlignedCodonFrame,~S,~S,~B,~B");
254 c$.calculateGapsToInsert = Clazz.defineMethod (c$, "calculateGapsToInsert", 
255 function (preserveMappedGaps, preserveUnmappedGaps, sourceGapMappedLength, inExon, trailingGapLength, intronLength, startOfCodon) {
256 var gapsToAdd = 0;
257 if (startOfCodon) {
258 if (inExon && !preserveMappedGaps) {
259 trailingGapLength = 0;
260 }if (!inExon && !(preserveMappedGaps && preserveUnmappedGaps)) {
261 trailingGapLength = 0;
262 }if (inExon) {
263 gapsToAdd = Math.max (sourceGapMappedLength, trailingGapLength);
264 } else {
265 if (intronLength + trailingGapLength <= sourceGapMappedLength) {
266 gapsToAdd = sourceGapMappedLength - intronLength;
267 } else {
268 gapsToAdd = Math.min (intronLength + trailingGapLength - sourceGapMappedLength, trailingGapLength);
269 }}} else {
270 if (!preserveMappedGaps) {
271 trailingGapLength = 0;
272 }gapsToAdd = Math.max (sourceGapMappedLength, trailingGapLength);
273 }return gapsToAdd;
274 }, "~B,~B,~N,~B,~N,~N,~B");
275 c$.getAlignedTranslation = Clazz.defineMethod (c$, "getAlignedTranslation", 
276 function (sequences, gapCharacter, mappings) {
277 var alignedSeqs =  new java.util.ArrayList ();
278 for (var seq, $seq = sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
279 var mapped = jalview.analysis.AlignmentUtils.getAlignedTranslation (seq, gapCharacter, mappings);
280 alignedSeqs.addAll (mapped);
281 }
282 return alignedSeqs;
283 }, "java.util.List,~S,java.util.Set");
284 c$.getAlignedTranslation = Clazz.defineMethod (c$, "getAlignedTranslation", 
285 function (seq, gapCharacter, mappings) {
286 var result =  new java.util.ArrayList ();
287 for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) {
288 if (mapping.involvesSequence (seq)) {
289 var mapped = jalview.analysis.AlignmentUtils.getAlignedTranslation (seq, gapCharacter, mapping);
290 if (mapped != null) {
291 result.add (mapped);
292 }}}
293 return result;
294 }, "jalview.datamodel.SequenceI,~S,java.util.Set");
295 c$.getAlignedTranslation = Clazz.defineMethod (c$, "getAlignedTranslation", 
296 function (seq, gapCharacter, mapping) {
297 var gap = String.valueOf (gapCharacter);
298 var toDna = false;
299 var fromRatio = 1;
300 var mapTo = mapping.getDnaForAaSeq (seq);
301 if (mapTo != null) {
302 toDna = true;
303 gap = String.valueOf ( Clazz.newCharArray (-1, [gapCharacter, gapCharacter, gapCharacter]));
304 } else {
305 mapTo = mapping.getAaForDnaSeq (seq);
306 fromRatio = 3;
307 }var newseq =  new StringBuilder (seq.getLength () * (toDna ? 3 : 1));
308 var residueNo = 0;
309 var phrase =  Clazz.newIntArray (fromRatio, 0);
310 var phraseOffset = 0;
311 var gapWidth = 0;
312 var first = true;
313 var alignedSeq =  new jalview.datamodel.Sequence ("", "");
314 for (var c, $c = 0, $$c = seq.getSequence (); $c < $$c.length && ((c = $$c[$c]) || true); $c++) {
315 if (c == gapCharacter) {
316 gapWidth++;
317 if (gapWidth >= fromRatio) {
318 newseq.append (gap);
319 gapWidth = 0;
320 }} else {
321 phrase[phraseOffset++] = residueNo + 1;
322 if (phraseOffset == fromRatio) {
323 var sr =  new jalview.datamodel.SearchResults ();
324 for (var pos, $pos = 0, $$pos = phrase; $pos < $$pos.length && ((pos = $$pos[$pos]) || true); $pos++) {
325 mapping.markMappedRegion (seq, pos, sr);
326 }
327 newseq.append (sr.toString ());
328 if (first) {
329 first = false;
330 var mappedTo = sr.getResultSequence (0);
331 alignedSeq.setName (mappedTo.getName ());
332 alignedSeq.setDescription (mappedTo.getDescription ());
333 alignedSeq.setDatasetSequence (mappedTo);
334 }phraseOffset = 0;
335 }residueNo++;
336 }}
337 alignedSeq.setSequence (newseq.toString ());
338 return alignedSeq;
339 }, "jalview.datamodel.SequenceI,~S,jalview.datamodel.AlignedCodonFrame");
340 c$.alignProteinAsDna = Clazz.defineMethod (c$, "alignProteinAsDna", 
341 function (protein, dna) {
342 var mappings = protein.getCodonFrames ();
343 var alignedCodons =  new java.util.TreeMap ( new jalview.analysis.CodonComparator ());
344 for (var dnaSeq, $dnaSeq = dna.getSequences ().iterator (); $dnaSeq.hasNext () && ((dnaSeq = $dnaSeq.next ()) || true);) {
345 for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) {
346 var seqMap = mapping.getMappingForSequence (dnaSeq);
347 var prot = mapping.findAlignedSequence (dnaSeq.getDatasetSequence (), protein);
348 if (prot != null) {
349 jalview.analysis.AlignmentUtils.addCodonPositions (dnaSeq, prot, protein.getGapCharacter (), seqMap, alignedCodons);
350 }}
351 }
352 return jalview.analysis.AlignmentUtils.alignProteinAs (protein, alignedCodons);
353 }, "jalview.datamodel.AlignmentI,jalview.datamodel.AlignmentI");
354 c$.alignProteinAs = Clazz.defineMethod (c$, "alignProteinAs", 
355 function (protein, alignedCodons) {
356 var alignedWidth = alignedCodons.size ();
357 var gaps =  Clazz.newCharArray (alignedWidth, '\0');
358 java.util.Arrays.fill (gaps, protein.getGapCharacter ());
359 var allGaps = String.valueOf (gaps);
360 for (var seq, $seq = protein.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
361 seq.setSequence (allGaps);
362 }
363 var column = 0;
364 for (var codon, $codon = alignedCodons.keySet ().iterator (); $codon.hasNext () && ((codon = $codon.next ()) || true);) {
365 var columnResidues = alignedCodons.get (codon);
366 for (var entry, $entry = columnResidues.entrySet ().iterator (); $entry.hasNext () && ((entry = $entry.next ()) || true);) {
367 entry.getKey ().getSequence ()[column] = entry.getValue ().charAt (0);
368 }
369 column++;
370 }
371 return 0;
372 }, "jalview.datamodel.AlignmentI,java.util.Map");
373 c$.addCodonPositions = Clazz.defineMethod (c$, "addCodonPositions", 
374 function (dna, protein, gapChar, seqMap, alignedCodons) {
375 var codons = seqMap.getCodonIterator (dna, gapChar);
376 while (codons.hasNext ()) {
377 var codon = codons.next ();
378 var seqProduct = alignedCodons.get (codon);
379 if (seqProduct == null) {
380 seqProduct =  new java.util.HashMap ();
381 alignedCodons.put (codon, seqProduct);
382 }seqProduct.put (protein, codon.product);
383 }
384 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,~S,jalview.datamodel.Mapping,java.util.Map");
385 c$.isMappable = Clazz.defineMethod (c$, "isMappable", 
386 function (al1, al2) {
387 if (al1.isNucleotide () == al2.isNucleotide ()) {
388 return false;
389 }var dna = al1.isNucleotide () ? al1 : al2;
390 var protein = dna === al1 ? al2 : al1;
391 var mappings = protein.getCodonFrames ();
392 for (var dnaSeq, $dnaSeq = dna.getSequences ().iterator (); $dnaSeq.hasNext () && ((dnaSeq = $dnaSeq.next ()) || true);) {
393 for (var proteinSeq, $proteinSeq = protein.getSequences ().iterator (); $proteinSeq.hasNext () && ((proteinSeq = $proteinSeq.next ()) || true);) {
394 if (jalview.analysis.AlignmentUtils.isMappable (dnaSeq, proteinSeq, mappings)) {
395 return true;
396 }}
397 }
398 return false;
399 }, "jalview.datamodel.AlignmentI,jalview.datamodel.AlignmentI");
400 c$.isMappable = Clazz.defineMethod (c$, "isMappable", 
401 function (dnaSeq, proteinSeq, mappings) {
402 var dnaDs = dnaSeq.getDatasetSequence () == null ? dnaSeq : dnaSeq.getDatasetSequence ();
403 var proteinDs = proteinSeq.getDatasetSequence () == null ? proteinSeq : proteinSeq.getDatasetSequence ();
404 for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) {
405 if (proteinDs === mapping.getAaForDnaSeq (dnaDs)) {
406 return true;
407 }}
408 return jalview.analysis.AlignmentUtils.mapProteinToCdna (proteinDs, dnaDs) != null;
409 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,java.util.Set");
410 c$.findAddableReferenceAnnotations = Clazz.defineMethod (c$, "findAddableReferenceAnnotations", 
411 function (sequenceScope, labelForCalcId, candidates, al) {
412 if (sequenceScope == null) {
413 return;
414 }for (var seq, $seq = sequenceScope.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
415 var dataset = seq.getDatasetSequence ();
416 if (dataset == null) {
417 continue;
418 }var datasetAnnotations = dataset.getAnnotation ();
419 if (datasetAnnotations == null) {
420 continue;
421 }var result =  new java.util.ArrayList ();
422 for (var dsann, $dsann = 0, $$dsann = datasetAnnotations; $dsann < $$dsann.length && ((dsann = $$dsann[$dsann]) || true); $dsann++) {
423 var matchedAlignmentAnnotations = al.findAnnotations (seq, dsann.getCalcId (), dsann.label);
424 if (!matchedAlignmentAnnotations.iterator ().hasNext ()) {
425 result.add (dsann);
426 if (labelForCalcId != null) {
427 labelForCalcId.put (dsann.getCalcId (), dsann.label);
428 }}}
429 if (!result.isEmpty ()) {
430 candidates.put (seq, result);
431 }}
432 }, "java.util.List,java.util.Map,java.util.Map,jalview.datamodel.AlignmentI");
433 c$.addReferenceAnnotations = Clazz.defineMethod (c$, "addReferenceAnnotations", 
434 function (annotations, alignment, selectionGroup) {
435 for (var seq, $seq = annotations.keySet ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
436 for (var ann, $ann = annotations.get (seq).iterator (); $ann.hasNext () && ((ann = $ann.next ()) || true);) {
437 var copyAnn =  new jalview.datamodel.AlignmentAnnotation (ann);
438 var startRes = 0;
439 var endRes = ann.annotations.length;
440 if (selectionGroup != null) {
441 startRes = selectionGroup.getStartRes ();
442 endRes = selectionGroup.getEndRes ();
443 }copyAnn.restrict (startRes, endRes);
444 if (!seq.hasAnnotation (ann)) {
445 seq.addAlignmentAnnotation (copyAnn);
446 }copyAnn.adjustForAlignment ();
447 alignment.addAnnotation (copyAnn);
448 copyAnn.visible = true;
449 }
450 }
451 }, "java.util.Map,jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup");
452 c$.showOrHideSequenceAnnotations = Clazz.defineMethod (c$, "showOrHideSequenceAnnotations", 
453 function (al, types, forSequences, anyType, doShow) {
454 for (var aa, $aa = 0, $$aa = al.getAlignmentAnnotation (); $aa < $$aa.length && ((aa = $$aa[$aa]) || true); $aa++) {
455 if (anyType || types.contains (aa.label)) {
456 if ((aa.sequenceRef != null) && (forSequences == null || forSequences.contains (aa.sequenceRef))) {
457 aa.visible = doShow;
458 }}}
459 }, "jalview.datamodel.AlignmentI,java.util.Collection,java.util.List,~B,~B");
460 c$.haveCrossRef = Clazz.defineMethod (c$, "haveCrossRef", 
461 function (seq1, seq2) {
462 return jalview.analysis.AlignmentUtils.hasCrossRef (seq1, seq2) || jalview.analysis.AlignmentUtils.hasCrossRef (seq2, seq1);
463 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI");
464 c$.hasCrossRef = Clazz.defineMethod (c$, "hasCrossRef", 
465 function (seq1, seq2) {
466 if (seq1 == null || seq2 == null) {
467 return false;
468 }var name = seq2.getName ();
469 var xrefs = seq1.getDBRef ();
470 if (xrefs != null) {
471 for (var xref, $xref = 0, $$xref = xrefs; $xref < $$xref.length && ((xref = $$xref[$xref]) || true); $xref++) {
472 var xrefName = xref.getSource () + "|" + xref.getAccessionId ();
473 if (xrefName.equalsIgnoreCase (name)) {
474 return true;
475 }}
476 }return false;
477 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI");
478 c$.makeExonAlignment = Clazz.defineMethod (c$, "makeExonAlignment", 
479 function (dna, mappings) {
480 var newMappings =  new java.util.LinkedHashSet ();
481 var exonSequences =  new java.util.ArrayList ();
482 for (var dnaSeq, $dnaSeq = 0, $$dnaSeq = dna; $dnaSeq < $$dnaSeq.length && ((dnaSeq = $$dnaSeq[$dnaSeq]) || true); $dnaSeq++) {
483 var ds = dnaSeq.getDatasetSequence ();
484 var seqMappings = jalview.util.MappingUtils.findMappingsForSequence (ds, mappings);
485 for (var acf, $acf = seqMappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
486 var newMapping =  new jalview.datamodel.AlignedCodonFrame ();
487 var mappedExons = jalview.analysis.AlignmentUtils.makeExonSequences (ds, acf, newMapping);
488 if (!mappedExons.isEmpty ()) {
489 exonSequences.addAll (mappedExons);
490 newMappings.add (newMapping);
491 }}
492 }
493 var al =  new jalview.datamodel.Alignment (exonSequences.toArray ( new Array (exonSequences.size ())));
494 al.setDataset (null);
495 mappings.clear ();
496 mappings.addAll (newMappings);
497 return al;
498 }, "~A,java.util.Set");
499 c$.makeExonSequences = Clazz.defineMethod (c$, "makeExonSequences", 
500 function (dnaSeq, mapping, newMapping) {
501 var exonSequences =  new java.util.ArrayList ();
502 var seqMappings = mapping.getMappingsForSequence (dnaSeq);
503 var dna = dnaSeq.getSequence ();
504 for (var seqMapping, $seqMapping = seqMappings.iterator (); $seqMapping.hasNext () && ((seqMapping = $seqMapping.next ()) || true);) {
505 var newSequence =  new StringBuilder (dnaSeq.getLength ());
506 var dnaExonRanges = seqMapping.getMap ().getFromRanges ();
507 for (var range, $range = dnaExonRanges.iterator (); $range.hasNext () && ((range = $range.next ()) || true);) {
508 for (var pos = range[0]; pos <= range[1]; pos++) {
509 newSequence.append (dna[pos - 1]);
510 }
511 }
512 var exon =  new jalview.datamodel.Sequence (dnaSeq.getName (), newSequence.toString ());
513 var cdsAccId = jalview.datamodel.FeatureProperties.getCodingFeature (jalview.datamodel.DBRefSource.EMBL);
514 var cdsRefs = jalview.util.DBRefUtils.selectRefs (seqMapping.getTo ().getDBRef (), jalview.datamodel.DBRefSource.CODINGDBS);
515 if (cdsRefs != null) {
516 for (var cdsRef, $cdsRef = 0, $$cdsRef = cdsRefs; $cdsRef < $$cdsRef.length && ((cdsRef = $$cdsRef[$cdsRef]) || true); $cdsRef++) {
517 exon.addDBRef ( new jalview.datamodel.DBRefEntry (cdsRef));
518 cdsAccId = cdsRef.getAccessionId ();
519 }
520 }exon.setName (exon.getName () + "|" + cdsAccId);
521 exon.createDatasetSequence ();
522 var exonRange =  new java.util.ArrayList ();
523 exonRange.add ( Clazz.newIntArray (-1, [1, newSequence.length ()]));
524 var map =  new jalview.util.MapList (exonRange, seqMapping.getMap ().getToRanges (), 3, 1);
525 newMapping.addMap (exon.getDatasetSequence (), seqMapping.getTo (), map);
526 var cdsToDnaMap =  new jalview.util.MapList (dnaExonRanges, exonRange, 1, 1);
527 newMapping.addMap (dnaSeq, exon.getDatasetSequence (), cdsToDnaMap);
528 exonSequences.add (exon);
529 }
530 return exonSequences;
531 }, "jalview.datamodel.SequenceI,jalview.datamodel.AlignedCodonFrame,jalview.datamodel.AlignedCodonFrame");
532 });