JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / analysis / AlignSeq.js
1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (["jalview.schemes.ResidueProperties", "java.lang.StringBuffer"], "jalview.analysis.AlignSeq", ["jalview.datamodel.Mapping", "$.Sequence", "jalview.util.Comparison", "$.Format", "$.MapList", "$.MessageManager", "java.awt.Color", "java.lang.Error", "$.StringBuilder", "java.util.ArrayList", "$.Arrays", "$.StringTokenizer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.score = null;
5 this.E = null;
6 this.F = null;
7 this.traceback = null;
8 this.seq1 = null;
9 this.seq2 = null;
10 this.s1 = null;
11 this.s2 = null;
12 this.s1str = null;
13 this.s2str = null;
14 this.maxi = 0;
15 this.maxj = 0;
16 this.aseq1 = null;
17 this.aseq2 = null;
18 this.astr1 = "";
19 this.astr2 = "";
20 this.seq1start = 0;
21 this.seq1end = 0;
22 this.seq2start = 0;
23 this.seq2end = 0;
24 this.count = 0;
25 this.maxscore = 0;
26 this.pid = 0;
27 this.prev = 0;
28 this.gapOpen = 120;
29 this.gapExtend = 20;
30 this.lookup = null;
31 this.intToStr = null;
32 this.defInt = 23;
33 this.output = null;
34 this.type = null;
35 this.charToInt = null;
36 Clazz.instantialize (this, arguments);
37 }, jalview.analysis, "AlignSeq");
38 Clazz.prepareFields (c$, function () {
39 this.lookup = jalview.schemes.ResidueProperties.getBLOSUM62 ();
40 this.intToStr = jalview.analysis.AlignSeq.pep;
41 this.output =  new StringBuffer ();
42 });
43 Clazz.makeConstructor (c$, 
44 function (s1, s2, type) {
45 this.SeqInit (s1, s1.getSequenceAsString (), s2, s2.getSequenceAsString (), type);
46 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,~S");
47 Clazz.makeConstructor (c$, 
48 function (s1, string1, s2, string2, type) {
49 this.SeqInit (s1, string1.toUpperCase (), s2, string2.toUpperCase (), type);
50 }, "jalview.datamodel.SequenceI,~S,jalview.datamodel.SequenceI,~S,~S");
51 Clazz.defineMethod (c$, "getMaxScore", 
52 function () {
53 return this.maxscore;
54 });
55 Clazz.defineMethod (c$, "getSeq2Start", 
56 function () {
57 return this.seq2start;
58 });
59 Clazz.defineMethod (c$, "getSeq2End", 
60 function () {
61 return this.seq2end;
62 });
63 Clazz.defineMethod (c$, "getSeq1Start", 
64 function () {
65 return this.seq1start;
66 });
67 Clazz.defineMethod (c$, "getSeq1End", 
68 function () {
69 return this.seq1end;
70 });
71 Clazz.defineMethod (c$, "getOutput", 
72 function () {
73 return this.output.toString ();
74 });
75 Clazz.defineMethod (c$, "getAStr1", 
76 function () {
77 return this.astr1;
78 });
79 Clazz.defineMethod (c$, "getAStr2", 
80 function () {
81 return this.astr2;
82 });
83 Clazz.defineMethod (c$, "getASeq1", 
84 function () {
85 return this.aseq1;
86 });
87 Clazz.defineMethod (c$, "getASeq2", 
88 function () {
89 return this.aseq2;
90 });
91 Clazz.defineMethod (c$, "getS1", 
92 function () {
93 return this.s1;
94 });
95 Clazz.defineMethod (c$, "getS2", 
96 function () {
97 return this.s2;
98 });
99 Clazz.defineMethod (c$, "getAlignedSeq1", 
100 function () {
101 var alSeq1 =  new jalview.datamodel.Sequence (this.s1.getName (), this.getAStr1 ());
102 alSeq1.setStart (this.s1.getStart () + this.getSeq1Start () - 1);
103 alSeq1.setEnd (this.s1.getStart () + this.getSeq1End () - 1);
104 alSeq1.setDatasetSequence (this.s1.getDatasetSequence () == null ? this.s1 : this.s1.getDatasetSequence ());
105 return alSeq1;
106 });
107 Clazz.defineMethod (c$, "getAlignedSeq2", 
108 function () {
109 var alSeq2 =  new jalview.datamodel.Sequence (this.s2.getName (), this.getAStr2 ());
110 alSeq2.setStart (this.s2.getStart () + this.getSeq2Start () - 1);
111 alSeq2.setEnd (this.s2.getStart () + this.getSeq2End () - 1);
112 alSeq2.setDatasetSequence (this.s2.getDatasetSequence () == null ? this.s2 : this.s2.getDatasetSequence ());
113 return alSeq2;
114 });
115 Clazz.defineMethod (c$, "SeqInit", 
116 function (s1, string1, s2, string2, type) {
117 this.s1 = s1;
118 this.s2 = s2;
119 this.setDefaultParams (type);
120 this.SeqInit (string1, string2);
121 }, "jalview.datamodel.SequenceI,~S,jalview.datamodel.SequenceI,~S,~S");
122 Clazz.defineMethod (c$, "SeqInit", 
123 function (s1, string1, s2, string2, scoreMatrix) {
124 this.s1 = s1;
125 this.s2 = s2;
126 this.setType (scoreMatrix.isDNA () ? "dna" : "pep");
127 this.lookup = scoreMatrix.getMatrix ();
128 }, "jalview.datamodel.SequenceI,~S,jalview.datamodel.SequenceI,~S,jalview.schemes.ScoreMatrix");
129 Clazz.defineMethod (c$, "SeqInit", 
130 ($fz = function (string1, string2) {
131 this.s1str = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, string1);
132 this.s2str = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, string2);
133 if (this.s1str.length == 0 || this.s2str.length == 0) {
134 this.output.append ("ALL GAPS: " + (this.s1str.length == 0 ? this.s1.getName () : " ") + (this.s2str.length == 0 ? this.s2.getName () : ""));
135 return;
136 }this.seq1 =  Clazz.newIntArray (this.s1str.length, 0);
137 this.seq2 =  Clazz.newIntArray (this.s2str.length, 0);
138 this.score =  Clazz.newIntArray (this.s1str.length, this.s2str.length, 0);
139 this.E =  Clazz.newIntArray (this.s1str.length, this.s2str.length, 0);
140 this.F =  Clazz.newIntArray (this.s1str.length, this.s2str.length, 0);
141 this.traceback =  Clazz.newIntArray (this.s1str.length, this.s2str.length, 0);
142 this.seq1 = this.stringToInt (this.s1str, this.type);
143 this.seq2 = this.stringToInt (this.s2str, this.type);
144 }, $fz.isPrivate = true, $fz), "~S,~S");
145 Clazz.defineMethod (c$, "setDefaultParams", 
146 ($fz = function (type) {
147 this.setType (type);
148 if (type.equals ("pep")) {
149 this.lookup = jalview.schemes.ResidueProperties.getDefaultPeptideMatrix ();
150 } else if (type.equals ("dna")) {
151 this.lookup = jalview.schemes.ResidueProperties.getDefaultDnaMatrix ();
152 }}, $fz.isPrivate = true, $fz), "~S");
153 Clazz.defineMethod (c$, "setType", 
154 ($fz = function (type2) {
155 this.type = type2;
156 if (this.type.equals ("pep")) {
157 this.intToStr = jalview.analysis.AlignSeq.pep;
158 this.charToInt = jalview.schemes.ResidueProperties.aaIndex;
159 this.defInt = 23;
160 } else if (this.type.equals ("dna")) {
161 this.intToStr = jalview.analysis.AlignSeq.dna;
162 this.charToInt = jalview.schemes.ResidueProperties.nucleotideIndex;
163 this.defInt = 10;
164 } else {
165 this.output.append ("Wrong type = dna or pep only");
166 throw  new Error (jalview.util.MessageManager.formatMessage ("error.unknown_type_dna_or_pep",  Clazz.newArray (-1, [type2])));
167 }}, $fz.isPrivate = true, $fz), "~S");
168 Clazz.defineMethod (c$, "traceAlignment", 
169 function () {
170 var max = -9999;
171 for (var i = 0; i < this.seq1.length; i++) {
172 if (this.score[i][this.seq2.length - 1] > max) {
173 max = this.score[i][this.seq2.length - 1];
174 this.maxi = i;
175 this.maxj = this.seq2.length - 1;
176 }}
177 for (var j = 0; j < this.seq2.length; j++) {
178 if (this.score[this.seq1.length - 1][j] > max) {
179 max = this.score[this.seq1.length - 1][j];
180 this.maxi = this.seq1.length - 1;
181 this.maxj = j;
182 }}
183 var i = this.maxi;
184 var j = this.maxj;
185 var trace;
186 this.maxscore = Clazz.doubleToInt (this.score[i][j] / 10);
187 this.seq1end = this.maxi + 1;
188 this.seq2end = this.maxj + 1;
189 this.aseq1 =  Clazz.newIntArray (this.seq1.length + this.seq2.length, 0);
190 this.aseq2 =  Clazz.newIntArray (this.seq1.length + this.seq2.length, 0);
191 this.count = (this.seq1.length + this.seq2.length) - 1;
192 while ((i > 0) && (j > 0)) {
193 if ((this.aseq1[this.count] != this.defInt) && (i >= 0)) {
194 this.aseq1[this.count] = this.seq1[i];
195 this.astr1 = this.s1str.charAt (i) + this.astr1;
196 }if ((this.aseq2[this.count] != this.defInt) && (j > 0)) {
197 this.aseq2[this.count] = this.seq2[j];
198 this.astr2 = this.s2str.charAt (j) + this.astr2;
199 }trace = this.findTrace (i, j);
200 if (trace == 0) {
201 i--;
202 j--;
203 } else if (trace == 1) {
204 j--;
205 this.aseq1[this.count] = this.defInt;
206 this.astr1 = "-" + this.astr1.substring (1);
207 } else if (trace == -1) {
208 i--;
209 this.aseq2[this.count] = this.defInt;
210 this.astr2 = "-" + this.astr2.substring (1);
211 }this.count--;
212 }
213 this.seq1start = i + 1;
214 this.seq2start = j + 1;
215 if (this.aseq1[this.count] != this.defInt) {
216 this.aseq1[this.count] = this.seq1[i];
217 this.astr1 = this.s1str.charAt (i) + this.astr1;
218 }if (this.aseq2[this.count] != this.defInt) {
219 this.aseq2[this.count] = this.seq2[j];
220 this.astr2 = this.s2str.charAt (j) + this.astr2;
221 }});
222 Clazz.defineMethod (c$, "printAlignment", 
223 function (os) {
224 var s1id = this.s1.getName ();
225 var s2id = this.s2.getName ();
226 var maxid = this.s1.getName ().length;
227 if (this.s2.getName ().length > maxid) {
228 maxid = this.s2.getName ().length;
229 }if (maxid > 30) {
230 maxid = 30;
231 if (this.s1.getName ().length > maxid) {
232 s1id = this.s1.getName ().substring (0, 30);
233 }if (this.s2.getName ().length > maxid) {
234 s2id = this.s2.getName ().substring (0, 30);
235 }}var len = 72 - maxid - 1;
236 var nochunks = (Clazz.doubleToInt ((this.aseq1.length - this.count) / len)) + 1;
237 this.pid = 0;
238 this.output.append ("Score = ").append ("" + this.score[this.maxi][this.maxj]).append (jalview.analysis.AlignSeq.NEWLINE);
239 this.output.append ("Length of alignment = ").append (String.valueOf (this.aseq1.length - this.count)).append (jalview.analysis.AlignSeq.NEWLINE);
240 this.output.append ("Sequence ");
241 this.output.append ( new jalview.util.Format ("%" + maxid + "s").form (this.s1.getName ()));
242 this.output.append (" :  ").append (String.valueOf (this.s1.getStart ())).append (" - ").append (String.valueOf (this.s1.getEnd ()));
243 this.output.append (" (Sequence length = ").append (String.valueOf (this.s1str.length)).append (")").append (jalview.analysis.AlignSeq.NEWLINE);
244 this.output.append ("Sequence ");
245 this.output.append ( new jalview.util.Format ("%" + maxid + "s").form (this.s2.getName ()));
246 this.output.append (" :  ").append (String.valueOf (this.s2.getStart ())).append (" - ").append (String.valueOf (this.s2.getEnd ()));
247 this.output.append (" (Sequence length = ").append (String.valueOf (this.s2str.length)).append (")").append (jalview.analysis.AlignSeq.NEWLINE).append (jalview.analysis.AlignSeq.NEWLINE);
248 for (var j = 0; j < nochunks; j++) {
249 this.output.append ( new jalview.util.Format ("%" + (maxid) + "s").form (s1id)).append (" ");
250 for (var i = 0; i < len; i++) {
251 if ((i + (j * len)) < this.astr1.length) {
252 this.output.append (this.astr1.charAt (i + (j * len)));
253 }}
254 this.output.append (jalview.analysis.AlignSeq.NEWLINE);
255 this.output.append ( new jalview.util.Format ("%" + (maxid) + "s").form (" ")).append (" ");
256 for (var i = 0; i < len; i++) {
257 if ((i + (j * len)) < this.astr1.length) {
258 if (this.astr1.charAt (i + (j * len)) == this.astr2.charAt (i + (j * len)) && !jalview.util.Comparison.isGap (this.astr1.charAt (i + (j * len)))) {
259 this.pid++;
260 this.output.append ("|");
261 } else if (this.type.equals ("pep")) {
262 if (jalview.schemes.ResidueProperties.getPAM250 (this.astr1.charAt (i + (j * len)), this.astr2.charAt (i + (j * len))) > 0) {
263 this.output.append (".");
264 } else {
265 this.output.append (" ");
266 }} else {
267 this.output.append (" ");
268 }}}
269 this.output = this.output.append (jalview.analysis.AlignSeq.NEWLINE);
270 this.output = this.output.append ( new jalview.util.Format ("%" + (maxid) + "s").form (s2id)).append (" ");
271 for (var i = 0; i < len; i++) {
272 if ((i + (j * len)) < this.astr2.length) {
273 this.output.append (this.astr2.charAt (i + (j * len)));
274 }}
275 this.output.append (jalview.analysis.AlignSeq.NEWLINE).append (jalview.analysis.AlignSeq.NEWLINE);
276 }
277 this.pid = this.pid / (this.aseq1.length - this.count) * 100;
278 this.output = this.output.append ( new jalview.util.Format ("Percentage ID = %2.2f\n\n").formDouble (this.pid));
279 try {
280 os.print (this.output.toString ());
281 } catch (ex) {
282 if (Clazz.exceptionOf (ex, Exception)) {
283 } else {
284 throw ex;
285 }
286 }
287 }, "java.io.PrintStream");
288 Clazz.defineMethod (c$, "printScoreMatrix", 
289 function (mat) {
290 var n = this.seq1.length;
291 var m = this.seq2.length;
292 for (var i = 0; i < n; i++) {
293 if (i == 0) {
294 jalview.util.Format.print (System.out, "%8s", this.s2str.substring (0, 1));
295 for (var jj = 1; jj < m; jj++) {
296 jalview.util.Format.print (System.out, "%5s", this.s2str.substring (jj, jj + 1));
297 }
298 System.out.println ();
299 }for (var j = 0; j < m; j++) {
300 if (j == 0) {
301 jalview.util.Format.print (System.out, "%3s", this.s1str.substring (i, i + 1));
302 }jalview.util.Format.printLong (System.out, "%3d ", Clazz.doubleToInt (mat[i][j] / 10));
303 }
304 System.out.println ();
305 }
306 }, "~A");
307 Clazz.defineMethod (c$, "findTrace", 
308 function (i, j) {
309 var t = 0;
310 var max = this.score[i - 1][j - 1] + (this.lookup[this.seq1[i]][this.seq2[j]] * 10);
311 if (this.F[i][j] > max) {
312 max = this.F[i][j];
313 t = -1;
314 } else if (this.F[i][j] == max) {
315 if (this.prev == -1) {
316 max = this.F[i][j];
317 t = -1;
318 }}if (this.E[i][j] >= max) {
319 max = this.E[i][j];
320 t = 1;
321 } else if (this.E[i][j] == max) {
322 if (this.prev == 1) {
323 max = this.E[i][j];
324 t = 1;
325 }}this.prev = t;
326 return t;
327 }, "~N,~N");
328 Clazz.defineMethod (c$, "calcScoreMatrix", 
329 function () {
330 var n = this.seq1.length;
331 var m = this.seq2.length;
332 this.score[0][0] = this.lookup[this.seq1[0]][this.seq2[0]] * 10;
333 this.E[0][0] = -this.gapExtend;
334 this.F[0][0] = 0;
335 for (var j = 1; j < m; j++) {
336 this.E[0][j] = this.max (this.score[0][j - 1] - this.gapOpen, this.E[0][j - 1] - this.gapExtend);
337 this.F[0][j] = -this.gapExtend;
338 this.score[0][j] = this.max (this.lookup[this.seq1[0]][this.seq2[j]] * 10, -this.gapOpen, -this.gapExtend);
339 this.traceback[0][j] = 1;
340 }
341 for (var i = 1; i < n; i++) {
342 this.E[i][0] = -this.gapOpen;
343 this.F[i][0] = this.max (this.score[i - 1][0] - this.gapOpen, this.F[i - 1][0] - this.gapExtend);
344 this.score[i][0] = this.max (this.lookup[this.seq1[i]][this.seq2[0]] * 10, this.E[i][0], this.F[i][0]);
345 this.traceback[i][0] = -1;
346 }
347 for (var i = 1; i < n; i++) {
348 for (var j = 1; j < m; j++) {
349 this.E[i][j] = this.max (this.score[i][j - 1] - this.gapOpen, this.E[i][j - 1] - this.gapExtend);
350 this.F[i][j] = this.max (this.score[i - 1][j] - this.gapOpen, this.F[i - 1][j] - this.gapExtend);
351 this.score[i][j] = this.max (this.score[i - 1][j - 1] + (this.lookup[this.seq1[i]][this.seq2[j]] * 10), this.E[i][j], this.F[i][j]);
352 this.traceback[i][j] = this.findTrace (i, j);
353 }
354 }
355 });
356 c$.extractGaps = Clazz.defineMethod (c$, "extractGaps", 
357 function (gapChars, seq) {
358 if (gapChars == null || seq == null) {
359 return null;
360 }var str =  new java.util.StringTokenizer (seq, gapChars);
361 var newString =  new StringBuilder (seq.length);
362 while (str.hasMoreTokens ()) {
363 newString.append (str.nextToken ());
364 }
365 return newString.toString ();
366 }, "~S,~S");
367 Clazz.defineMethod (c$, "max", 
368 function (i1, i2, i3) {
369 var max = i1;
370 if (i2 > i1) {
371 max = i2;
372 }if (i3 > max) {
373 max = i3;
374 }return max;
375 }, "~N,~N,~N");
376 Clazz.defineMethod (c$, "max", 
377 function (i1, i2) {
378 var max = i1;
379 if (i2 > i1) {
380 max = i2;
381 }return max;
382 }, "~N,~N");
383 Clazz.defineMethod (c$, "stringToInt", 
384 function (s, type) {
385 var seq1 =  Clazz.newIntArray (s.length, 0);
386 for (var i = 0; i < s.length; i++) {
387 var c = s.charAt (i);
388 if ('a' <= c && c <= 'z') {
389 c = String.fromCharCode (c.charCodeAt (0) - (32));
390 }try {
391 seq1[i] = this.charToInt[c.charCodeAt (0)];
392 if (seq1[i] < 0 || seq1[i] > this.defInt) {
393 seq1[i] = this.defInt;
394 }} catch (e) {
395 if (Clazz.exceptionOf (e, Exception)) {
396 seq1[i] = this.defInt;
397 } else {
398 throw e;
399 }
400 }
401 }
402 return seq1;
403 }, "~S,~S");
404 c$.displayMatrix = Clazz.defineMethod (c$, "displayMatrix", 
405 function (g, mat, n, m, psize) {
406 var max = -1000;
407 var min = 1000;
408 for (var i = 0; i < n; i++) {
409 for (var j = 0; j < m; j++) {
410 if (mat[i][j] >= max) {
411 max = mat[i][j];
412 }if (mat[i][j] <= min) {
413 min = mat[i][j];
414 }}
415 }
416 System.out.println (max + " " + min);
417 for (var i = 0; i < n; i++) {
418 for (var j = 0; j < m; j++) {
419 var x = psize * i;
420 var y = psize * j;
421 var score = (mat[i][j] - min) / (max - min);
422 g.setColor ( new java.awt.Color (score, 0, 0));
423 g.fillRect (x, y, psize, psize);
424 }
425 }
426 }, "java.awt.Graphics,~A,~N,~N,~N");
427 c$.doGlobalNWAlignment = Clazz.defineMethod (c$, "doGlobalNWAlignment", 
428 function (s1, s2, type) {
429 var as =  new jalview.analysis.AlignSeq (s1, s2, type);
430 as.calcScoreMatrix ();
431 as.traceAlignment ();
432 return as;
433 }, "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI,~S");
434 Clazz.defineMethod (c$, "getMappingFromS1", 
435 function (allowmismatch) {
436 var as1 =  new java.util.ArrayList ();
437 var as2 =  new java.util.ArrayList ();
438 var pdbpos = this.s2.getStart () + this.getSeq2Start () - 2;
439 var alignpos = this.s1.getStart () + this.getSeq1Start () - 2;
440 var lp2 = pdbpos - 3;
441 var lp1 = alignpos - 3;
442 var lastmatch = false;
443 for (var i = 0; i < this.astr1.length; i++) {
444 var c1 = this.astr1.charAt (i);
445 var c2 = this.astr2.charAt (i);
446 if (c1 != '-') {
447 alignpos++;
448 }if (c2 != '-') {
449 pdbpos++;
450 }if (allowmismatch || c1 == c2) {
451 if (lp1 + 1 != alignpos || lp2 + 1 != pdbpos) {
452 as1.add (Integer.$valueOf (alignpos));
453 as2.add (Integer.$valueOf (pdbpos));
454 }lastmatch = true;
455 lp1 = alignpos;
456 lp2 = pdbpos;
457 } else {
458 if (lastmatch) {
459 as1.add (Integer.$valueOf (lp1));
460 as2.add (Integer.$valueOf (lp2));
461 }lastmatch = false;
462 }}
463 var mapseq1 =  Clazz.newIntArray (as1.size () + (lastmatch ? 1 : 0), 0);
464 var mapseq2 =  Clazz.newIntArray (as2.size () + (lastmatch ? 1 : 0), 0);
465 var i = 0;
466 for (var ip, $ip = as1.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
467 mapseq1[i++] = (ip).intValue ();
468 }
469 ;i = 0;
470 for (var ip, $ip = as2.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
471 mapseq2[i++] = (ip).intValue ();
472 }
473 ;if (lastmatch) {
474 mapseq1[mapseq1.length - 1] = alignpos;
475 mapseq2[mapseq2.length - 1] = pdbpos;
476 }var map =  new jalview.util.MapList (mapseq1, mapseq2, 1, 1);
477 var mapping =  new jalview.datamodel.Mapping (map);
478 mapping.setTo (this.s2);
479 return mapping;
480 }, "~B");
481 c$.replaceMatchingSeqsWith = Clazz.defineMethod (c$, "replaceMatchingSeqsWith", 
482 function (seqs, annotations, ochains, al, dnaOrProtein, removeOldAnnots) {
483 var orig =  new java.util.ArrayList ();
484 var repl =  new java.util.ArrayList ();
485 var aligs =  new java.util.ArrayList ();
486 if (al != null && al.getHeight () > 0) {
487 var matches =  new java.util.ArrayList ();
488 var aligns =  new java.util.ArrayList ();
489 for (var sq, $sq = ochains.iterator (); $sq.hasNext () && ((sq = $sq.next ()) || true);) {
490 var bestm = null;
491 var bestaseq = null;
492 var bestscore = 0;
493 for (var msq, $msq = al.getSequences ().iterator (); $msq.hasNext () && ((msq = $msq.next ()) || true);) {
494 var aseq = jalview.analysis.AlignSeq.doGlobalNWAlignment (msq, sq, dnaOrProtein);
495 if (bestm == null || aseq.getMaxScore () > bestscore) {
496 bestscore = aseq.getMaxScore ();
497 bestaseq = aseq;
498 bestm = msq;
499 }}
500 System.out.println ("Best Score for " + (matches.size () + 1) + " :" + bestscore);
501 matches.add (bestm);
502 aligns.add (bestaseq);
503 al.deleteSequence (bestm);
504 }
505 for (var p = 0, pSize = seqs.size (); p < pSize; p++) {
506 var sq;
507 var sp = seqs.get (p);
508 var q;
509 if ((q = ochains.indexOf (sp)) > -1) {
510 seqs.set (p, sq = matches.get (q));
511 orig.add (sp);
512 repl.add (sq);
513 sq.setName (sp.getName ());
514 sq.setDescription (sp.getDescription ());
515 var sp2sq;
516 sq.transferAnnotation (sp, sp2sq = aligns.get (q).getMappingFromS1 (false));
517 aligs.add (aligns.get (q));
518 var inspos = -1;
519 for (var ap = 0; ap < annotations.size (); ) {
520 if (annotations.get (ap).sequenceRef === sp) {
521 if (inspos == -1) {
522 inspos = ap;
523 }if (removeOldAnnots) {
524 annotations.remove (ap);
525 } else {
526 var alan = annotations.remove (ap);
527 alan.liftOver (sq, sp2sq);
528 alan.setSequenceRef (sq);
529 sq.addAlignmentAnnotation (alan);
530 }} else {
531 ap++;
532 }}
533 if (sq.getAnnotation () != null && sq.getAnnotation ().length > 0) {
534 annotations.addAll (inspos == -1 ? annotations.size () : inspos, java.util.Arrays.asList (sq.getAnnotation ()));
535 }}}
536 }return java.util.Arrays.asList ([orig, repl, aligs]);
537 }, "java.util.List,java.util.List,java.util.List,jalview.datamodel.AlignmentI,~S,~B");
538 c$.computeRedundancyMatrix = Clazz.defineMethod (c$, "computeRedundancyMatrix", 
539 function (originalSequences, omitHidden, start, end, ungapped) {
540 var height = originalSequences.length;
541 var redundancy =  Clazz.newFloatArray (height, 0);
542 var lngth =  Clazz.newIntArray (height, 0);
543 for (var i = 0; i < height; i++) {
544 redundancy[i] = 0;
545 lngth[i] = -1;
546 }
547 var pid;
548 var seqi;
549 var seqj;
550 for (var i = 0; i < height; i++) {
551 for (var j = 0; j < i; j++) {
552 if (i == j) {
553 continue;
554 }if (omitHidden == null) {
555 seqi = originalSequences[i].getSequenceAsString (start, end);
556 seqj = originalSequences[j].getSequenceAsString (start, end);
557 } else {
558 seqi = omitHidden[i];
559 seqj = omitHidden[j];
560 }if (lngth[i] == -1) {
561 var ug = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, seqi);
562 lngth[i] = ug.length;
563 if (ungapped) {
564 seqi = ug;
565 }}if (lngth[j] == -1) {
566 var ug = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, seqj);
567 lngth[j] = ug.length;
568 if (ungapped) {
569 seqj = ug;
570 }}pid = jalview.util.Comparison.PID (seqi, seqj);
571 if (lngth[j] < lngth[i]) {
572 redundancy[j] = Math.max (pid, redundancy[j]);
573 } else {
574 redundancy[i] = Math.max (pid, redundancy[i]);
575 }}
576 }
577 return redundancy;
578 }, "~A,~A,~N,~N,~B");
579 Clazz.defineStatics (c$,
580 "PEP", "pep",
581 "DNA", "dna");
582 c$.NEWLINE = c$.prototype.NEWLINE = System.lineSeparator ();
583 Clazz.defineStatics (c$,
584 "dna",  Clazz.newArray (-1, ["A", "C", "G", "T", "-"]),
585 "pep",  Clazz.newArray (-1, ["A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F", "P", "S", "T", "W", "Y", "V", "B", "Z", "X", "-"]));
586 });