1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (null, "jalview.datamodel.AlignmentView", ["jalview.datamodel.Alignment", "$.CigarArray", "$.ColumnSelection", "$.SeqCigar", "$.SequenceGroup", "jalview.util.MessageManager", "$.ShiftList", "java.lang.Error", "java.util.ArrayList", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
10 if (!Clazz.isClassDefined ("jalview.datamodel.AlignmentView.ScGroup")) {
11 jalview.datamodel.AlignmentView.$AlignmentView$ScGroup$ ();
14 Clazz.instantialize (this, arguments);
15 }, jalview.datamodel, "AlignmentView");
16 Clazz.defineMethod (c$, "isNa",
20 Clazz.makeConstructor (c$,
21 function (alignment, columnSelection, selection, hasHiddenColumns, selectedRegionOnly, recordGroups) {
22 this.construct ( new jalview.datamodel.CigarArray (alignment, (hasHiddenColumns ? columnSelection : null), (selectedRegionOnly ? selection : null)), (selectedRegionOnly && selection != null) ? selection.getStartRes () : 0);
23 this.$isNa = alignment.isNucleotide ();
25 if (selection != null && selection.getSize () > 0) {
26 var sel = selection.getSequences (null);
27 this.selected = new java.util.Vector ();
28 selseqs = selection.getSequencesInOrder (alignment, selectedRegionOnly);
30 selseqs = alignment.getSequencesArray ();
31 }var seqsets = new java.util.ArrayList ();
32 var grps = new java.util.ArrayList ();
33 var gg = alignment.getGroups ();
38 if (selection != null && selectedRegionOnly) {
39 var ssel = selection.getStartRes ();
40 var esel = selection.getEndRes ();
41 var isg = new java.util.ArrayList ();
42 for (var sg, $sg = grps.iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {
43 if (!(sg.getStartRes () > esel || sg.getEndRes () < ssel)) {
44 if (sg.getStartRes () < ssel) {
45 sg.setStartRes (ssel);
46 }if (sg.getEndRes () > esel) {
48 }sg.setStartRes (sg.getStartRes () - ssel + 1);
49 sg.setEndRes (sg.getEndRes () - ssel + 1);
53 }sgrps = new Array (grps.size ());
54 addedgps = Clazz.newBooleanArray (grps.size (), false);
55 for (var g = 0; g < sgrps.length; g++) {
56 var sg = grps.get (g);
57 sgrps[g] = Clazz.innerTypeInstance (jalview.datamodel.AlignmentView.ScGroup, this, null);
58 sgrps[g].sg = new jalview.datamodel.SequenceGroup (sg);
60 seqsets.add (sg.getSequences ());
63 for (var i = 0; i < selseqs.length; i++) {
64 if (selseqs[i] != null) {
65 if (selection != null && selection.getSize () > 0 && !selectedRegionOnly) {
66 this.sequences[csi].setGroupMembership (this.selected);
67 this.selected.addElement (this.sequences[csi]);
68 }if (seqsets != null) {
69 for (var sg = 0; sg < sgrps.length; sg++) {
70 if ((seqsets.get (sg)).contains (selseqs[i])) {
71 this.sequences[csi].setGroupMembership (sgrps[sg]);
72 sgrps[sg].sg.deleteSequence (selseqs[i], false);
73 sgrps[sg].seqs.addElement (this.sequences[csi]);
75 if (this.scGroups == null) {
76 this.scGroups = new java.util.ArrayList ();
78 this.scGroups.add (sgrps[sg]);
82 for (var sg = 0; sg < sgrps.length; sg++) {
83 var sqs = sgrps[sg].sg.getSequencesAsArray (null);
84 for (var si = 0; si < sqs.length; si++) {
85 sgrps[sg].sg.deleteSequence (sqs[si], false);
89 }, "jalview.datamodel.AlignmentI,jalview.datamodel.ColumnSelection,jalview.datamodel.SequenceGroup,~B,~B,~B");
90 Clazz.makeConstructor (c$,
91 function (seqcigararray) {
92 if (!seqcigararray.isSeqCigarArray ()) {
93 throw new Error (jalview.util.MessageManager.getString ("error.implementation_error_can_only_make_alignmnet_from_cigararray"));
94 }this.contigs = seqcigararray.getDeletedRegions ();
95 this.sequences = seqcigararray.getSeqCigarArray ();
96 this.width = seqcigararray.getWidth ();
97 }, "jalview.datamodel.CigarArray");
98 Clazz.makeConstructor (c$,
99 function (sdata, firstcol) {
100 this.construct (sdata);
101 this.firstCol = firstcol;
102 }, "jalview.datamodel.CigarArray,~N");
103 Clazz.defineMethod (c$, "setSequences",
104 function (sequences) {
105 this.sequences = sequences;
107 Clazz.defineMethod (c$, "setContigs",
109 this.contigs = contigs;
111 Clazz.defineMethod (c$, "getSequences",
113 return this.sequences;
115 Clazz.defineMethod (c$, "getContigs",
119 Clazz.defineMethod (c$, "getAlignmentAndColumnSelection",
120 function (gapCharacter) {
121 var colsel = new jalview.datamodel.ColumnSelection ();
122 return Clazz.newArray (-1, [jalview.datamodel.SeqCigar.createAlignmentSequences (this.sequences, gapCharacter, colsel, this.contigs), colsel]);
124 Clazz.defineMethod (c$, "getVisibleAlignment",
126 var aln = this.getVisibleSeqs (c);
127 var vcal = new jalview.datamodel.Alignment (aln);
128 this.addPrunedGroupsInOrder (vcal, -1, -1, true);
131 Clazz.defineMethod (c$, "addPrunedGroupsInOrder",
132 ($fz = function (vcal, gstart, gend, viscontigs) {
134 if (gstart > -1 && gstart <= gend) {
136 }var aln = vcal.getSequencesArray ();
139 var nvg = (this.scGroups != null) ? this.scGroups.size () : 0;
141 var nsg = new Array (nvg);
142 for (var g = 0; g < nvg; g++) {
143 var sg = this.scGroups.get (g).sg;
145 if (sg.getStartRes () > gend || sg.getEndRes () < gstart) {
148 }}nsg[g] = new jalview.datamodel.SequenceGroup (sg);
149 if (r && !viscontigs) {
150 if (nsg[g].getStartRes () < gstart) {
151 nsg[g].setStartRes (0);
153 nsg[g].setStartRes (nsg[g].getStartRes () - gstart);
154 nsg[g].setEndRes (nsg[g].getEndRes () - gstart);
155 }if (nsg[g].getEndRes () > (gend - gstart)) {
156 nsg[g].setEndRes (gend - gstart);
159 if (this.contigs != null) {
161 var prune = new jalview.util.ShiftList ();
163 prune.addShift (gstart, -gstart);
164 }for (var h = 0; h < this.contigs.length; h += 3) {
166 prune.addShift (p + this.contigs[h + 1], this.contigs[h + 2] - this.contigs[h + 1]);
167 }p = this.contigs[h + 1] + this.contigs[h + 2];
169 for (var g = 0; g < nsg.length; g++) {
170 if (nsg[g] != null) {
171 var s = nsg[g].getStartRes ();
172 var t = nsg[g].getEndRes ();
179 }}s = prune.shift (s);
181 nsg[g].setStartRes (s);
182 nsg[g].setEndRes (t);
184 }}for (var nsq = 0; nsq < aln.length; nsq++) {
185 for (var g = 0; g < nvg; g++) {
186 if (nsg[g] != null && this.sequences[nsq].isMemberOf (this.scGroups.get (g))) {
187 nsg[g].addSequence (aln[nsq], false);
190 for (var g = 0; g < nvg; g++) {
191 if (nsg[g] != null && nsg[g].getSize () > 0) {
192 vcal.addGroup (nsg[g]);
195 }}}}, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,~N,~N,~B");
196 Clazz.defineMethod (c$, "getVisibleSeqs",
197 ($fz = function (c) {
198 var aln = new Array (this.sequences.length);
199 for (var i = 0, j = this.sequences.length; i < j; i++) {
200 aln[i] = this.sequences[i].getSeq ('-');
202 var seqs = this.getSequenceStrings ('-');
203 for (var i = 0, j = aln.length; i < j; i++) {
204 aln[i].setSequence (seqs[i]);
207 }, $fz.isPrivate = true, $fz), "~S");
208 Clazz.defineMethod (c$, "getVisibleContigAlignments",
211 var vcontigs = this.getVisibleContigs ();
212 var contigviews = this.getVisibleContigs (c);
213 var vcals = new Array (contigviews.length);
214 for (nvc = 0; nvc < contigviews.length; nvc++) {
215 vcals[nvc] = new jalview.datamodel.Alignment (contigviews[nvc]);
216 if (this.scGroups != null && this.scGroups.size () > 0) {
217 this.addPrunedGroupsInOrder (vcals[nvc], vcontigs[nvc * 2], vcontigs[nvc * 2 + 1], true);
221 Clazz.defineMethod (c$, "getSequenceStrings",
223 var seqs = new Array (this.sequences.length);
224 for (var n = 0; n < this.sequences.length; n++) {
225 var fullseq = this.sequences[n].getSequenceString (c);
226 if (this.contigs != null) {
229 for (var h = 0; h < this.contigs.length; h += 3) {
230 seqs[n] += fullseq.substring (p, this.contigs[h + 1]);
231 p = this.contigs[h + 1] + this.contigs[h + 2];
233 seqs[n] += fullseq.substring (p);
239 Clazz.defineMethod (c$, "getWidth",
243 Clazz.defineMethod (c$, "setWidth",
247 Clazz.defineMethod (c$, "getVisibleContigs",
248 function (gapCharacter) {
251 if (this.sequences == null || this.width <= 0) {
253 }if (this.contigs != null && this.contigs.length > 0) {
256 var fwidth = this.width;
257 for (var contig = 0; contig < this.contigs.length; contig += 3) {
258 if ((this.contigs[contig + 1] - start) > 0) {
260 }fwidth += this.contigs[contig + 2];
261 start = this.contigs[contig + 1] + this.contigs[contig + 2];
263 if (start < fwidth) {
265 }smsa = new Array (njobs);
268 for (var contig = 0; contig < this.contigs.length; contig += 3) {
269 if (this.contigs[contig + 1] - start > 0) {
270 var mseq = new Array (this.sequences.length);
271 for (var s = 0; s < mseq.length; s++) {
272 mseq[s] = this.sequences[s].getSeq (gapCharacter).getSubSequence (start, this.contigs[contig + 1]);
276 }start = this.contigs[contig + 1] + this.contigs[contig + 2];
278 if (start < fwidth) {
279 var mseq = new Array (this.sequences.length);
280 for (var s = 0; s < mseq.length; s++) {
281 mseq[s] = this.sequences[s].getSeq (gapCharacter).getSubSequence (start, fwidth + 1);
286 smsa = new Array (1);
287 smsa[0] = new Array (this.sequences.length);
288 for (var s = 0; s < this.sequences.length; s++) {
289 smsa[0][s] = this.sequences[s].getSeq (gapCharacter);
293 Clazz.defineMethod (c$, "getUpdatedView",
294 function (nvismsa, orders, gapCharacter) {
295 if (this.sequences == null || this.width <= 0) {
296 throw new Error (jalview.util.MessageManager.getString ("error.empty_view_cannot_be_updated"));
297 }if (nvismsa == null) {
298 throw new Error ("nvismsa==null. use getAlignmentAndColumnSelection() instead.");
299 }if (this.contigs != null && this.contigs.length > 0) {
300 var alignment = new Array (this.sequences.length);
301 var columnselection = new jalview.datamodel.ColumnSelection ();
302 if (this.contigs != null && this.contigs.length > 0) {
305 var owidth = this.width;
307 for (var contig = 0; contig < this.contigs.length; contig += 3) {
308 owidth += this.contigs[contig + 2];
309 if (this.contigs[contig + 1] - start > 0) {
311 if (nvismsa[j] != null) {
312 var mseq = nvismsa[j];
313 var order = (orders == null) ? null : orders[j];
315 if (mseq.length != this.sequences.length) {
316 throw new Error (jalview.util.MessageManager.formatMessage ("error.mismatch_between_number_of_sequences_in_block", Clazz.newArray (-1, [Integer.$valueOf (j).toString (), Integer.$valueOf (mseq.length).toString (), Integer.$valueOf (this.sequences.length).toString ()])));
317 }swidth = mseq[0].getLength ();
318 for (var s = 0; s < mseq.length; s++) {
319 if (alignment[s] == null) {
320 alignment[s] = mseq[s];
322 alignment[s].setSequence (alignment[s].getSequenceAsString () + mseq[s].getSequenceAsString ());
323 if (mseq[s].getStart () <= mseq[s].getEnd ()) {
324 alignment[s].setEnd (mseq[s].getEnd ());
325 }if (order != null) {
326 order.updateSequence (mseq[s], alignment[s]);
330 for (var s = 0; s < this.sequences.length; s++) {
331 var oseq = this.sequences[s].getSeq (gapCharacter).getSubSequence (start, this.contigs[contig + 1]);
332 if (swidth < oseq.getLength ()) {
333 swidth = oseq.getLength ();
334 }if (alignment[s] == null) {
337 alignment[s].setSequence (alignment[s].getSequenceAsString () + oseq.getSequenceAsString ());
338 if (oseq.getEnd () >= oseq.getStart ()) {
339 alignment[s].setEnd (oseq.getEnd ());
343 }start = this.contigs[contig + 1] + this.contigs[contig + 2];
344 for (var s = 0; s < this.sequences.length; s++) {
345 var hseq = this.sequences[s].getSeq (gapCharacter).getSubSequence (this.contigs[contig + 1], start);
346 if (alignment[s] == null) {
349 alignment[s].setSequence (alignment[s].getSequenceAsString () + hseq.getSequenceAsString ());
350 if (hseq.getEnd () >= hseq.getStart ()) {
351 alignment[s].setEnd (hseq.getEnd ());
353 columnselection.hideColumns (nwidth, nwidth + this.contigs[contig + 2] - 1);
354 nwidth += this.contigs[contig + 2];
356 if (j < nvismsa.length) {
358 if (nvismsa[j] != null) {
359 var mseq = nvismsa[j];
360 var order = (orders != null) ? orders[j] : null;
361 swidth = mseq[0].getLength ();
362 for (var s = 0; s < mseq.length; s++) {
363 if (alignment[s] == null) {
364 alignment[s] = mseq[s];
366 alignment[s].setSequence (alignment[s].getSequenceAsString () + mseq[s].getSequenceAsString ());
367 if (mseq[s].getEnd () >= mseq[s].getStart ()) {
368 alignment[s].setEnd (mseq[s].getEnd ());
369 }if (order != null) {
370 order.updateSequence (mseq[s], alignment[s]);
373 if (start < owidth) {
375 for (var s = 0; s < this.sequences.length; s++) {
376 var oseq = this.sequences[s].getSeq (gapCharacter).getSubSequence (start, owidth + 1);
377 if (swidth < oseq.getLength ()) {
378 swidth = oseq.getLength ();
379 }if (alignment[s] == null) {
382 alignment[s].setSequence (alignment[s].getSequenceAsString () + oseq.getSequenceAsString ());
383 if (oseq.getEnd () >= oseq.getStart ()) {
384 alignment[s].setEnd (oseq.getEnd ());
388 throw new Error (jalview.util.MessageManager.getString ("error.padding_not_yet_implemented"));
389 }}}}}return Clazz.newArray (-1, [alignment, columnselection]);
391 if (nvismsa.length != 1) {
392 throw new Error (jalview.util.MessageManager.formatMessage ("error.mismatch_between_visible_blocks_to_update_and_number_of_contigs_in_view", Clazz.newArray (-1, [Integer.$valueOf (nvismsa.length).toString ()])));
393 }if (nvismsa[0] != null) {
394 return Clazz.newArray (-1, [nvismsa[0], new jalview.datamodel.ColumnSelection ()]);
396 return this.getAlignmentAndColumnSelection (gapCharacter);
398 Clazz.defineMethod (c$, "getVisibleContigs",
400 if (this.contigs != null && this.contigs.length > 0) {
403 var fwidth = this.width;
404 for (var contig = 0; contig < this.contigs.length; contig += 3) {
405 if ((this.contigs[contig + 1] - start) > 0) {
407 }fwidth += this.contigs[contig + 2];
408 start = this.contigs[contig + 1] + this.contigs[contig + 2];
410 if (start < fwidth) {
412 }var viscontigs = Clazz.newIntArray (nvis * 2, 0);
415 for (var contig = 0; contig < this.contigs.length; contig += 3) {
416 if ((this.contigs[contig + 1] - start) > 0) {
417 viscontigs[nvis] = start;
418 viscontigs[nvis + 1] = this.contigs[contig + 1] - 1;
420 }start = this.contigs[contig + 1] + this.contigs[contig + 2];
422 if (start < fwidth) {
423 viscontigs[nvis] = start;
424 viscontigs[nvis + 1] = fwidth;
428 return Clazz.newIntArray (-1, [0, this.width]);
430 Clazz.defineMethod (c$, "getAlignmentOrigin",
432 return this.firstCol;
434 Clazz.defineMethod (c$, "getVisibleContigMapFor",
437 var viscontigs = this.getVisibleContigs ();
440 if (viscontigs != null) {
441 delMap = Clazz.newIntArray (gapMap.length, 0);
442 for (var contig = 0; contig < viscontigs.length; contig += 2) {
443 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig]) {
446 while (spos < gapMap.length && gapMap[spos] <= viscontigs[contig + 1]) {
447 delMap[i++] = spos++;
450 var tmap = Clazz.newIntArray (i, 0);
451 System.arraycopy (delMap, 0, tmap, 0, i);
455 Clazz.defineMethod (c$, "getEditedSequences",
456 function (gc, $delete) {
457 var msf = this.getSequences ();
458 var aln = new Array (msf.length);
459 for (var i = 0, j = msf.length; i < j; i++) {
460 aln[i] = msf[i].getSeq (gc);
463 var sqs = this.getSequenceStrings (gc);
464 for (var i = 0; i < sqs.length; i++) {
465 aln[i].setSequence (sqs[i]);
470 c$.summariseAlignmentView = Clazz.defineMethod (c$, "summariseAlignmentView",
471 function (view, os) {
472 os.print ("View has " + view.sequences.length + " of which ");
473 if (view.selected == null) {
476 os.print (" " + view.selected.size ());
477 }os.println (" are selected.");
478 os.print ("View is " + view.getWidth () + " columns wide");
480 var contigs = view.getContigs ();
481 if (contigs != null) {
483 for (var i = 0; i < contigs.length; i += 3) {
484 viswid += contigs[i + 2];
486 os.println ("with " + viswid + " visible columns spread over " + Clazz.doubleToInt (contigs.length / 3) + " regions.");
490 }if (view.scGroups != null) {
491 os.println ("There are " + view.scGroups.size () + " groups defined on the view.");
492 for (var g = 0; g < view.scGroups.size (); g++) {
493 var sgr = view.scGroups.get (g);
494 os.println ("Group " + g + ": Name = " + sgr.sg.getName () + " Contains " + sgr.seqs.size () + " Seqs.");
495 os.println ("This group runs from " + sgr.sg.getStartRes () + " to " + sgr.sg.getEndRes ());
496 for (var s = 0; s < sgr.seqs.size (); s++) {
497 if (!(sgr.seqs.elementAt (s)).isMemberOf (sgr)) {
498 os.println ("** WARNING: sequence " + (sgr.seqs.elementAt (s)).toString () + " is not marked as member of group.");
501 var visal = view.getVisibleAlignment ('-');
503 os.println ("Vis. alignment is " + visal.getWidth () + " wide and has " + visal.getHeight () + " seqs.");
504 if (visal.getGroups () != null && visal.getGroups ().size () > 0) {
506 for (var sg, $sg = visal.getGroups ().iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {
507 os.println ("Group " + (i++) + " begins at column " + sg.getStartRes () + " and ends at " + sg.getEndRes ());
509 }}}}, "jalview.datamodel.AlignmentView,java.io.PrintStream");
510 c$.testSelectionViews = Clazz.defineMethod (c$, "testSelectionViews",
511 function (alignment, csel, selection) {
512 System.out.println ("Testing standard view creation:\n");
515 System.out.println ("View with no hidden columns, no limit to selection, no groups to be collected:");
516 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, false, false, false);
517 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
519 if (Clazz.exceptionOf (e, Exception)) {
520 e.printStackTrace ();
521 System.err.println ("Failed to generate alignment with selection but no groups marked.");
527 System.out.println ("View with no hidden columns, no limit to selection, and all groups to be collected:");
528 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, false, false, true);
529 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
531 if (Clazz.exceptionOf (e, Exception)) {
532 e.printStackTrace ();
533 System.err.println ("Failed to generate alignment with selection marked but no groups marked.");
539 System.out.println ("View with no hidden columns, limited to selection and no groups to be collected:");
540 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, false, true, false);
541 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
543 if (Clazz.exceptionOf (e, Exception)) {
544 e.printStackTrace ();
545 System.err.println ("Failed to generate alignment with selection restricted but no groups marked.");
551 System.out.println ("View with no hidden columns, limited to selection, and all groups to be collected:");
552 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, false, true, true);
553 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
555 if (Clazz.exceptionOf (e, Exception)) {
556 e.printStackTrace ();
557 System.err.println ("Failed to generate alignment with selection restricted and groups marked.");
563 System.out.println ("View *with* hidden columns, no limit to selection, no groups to be collected:");
564 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, true, false, false);
565 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
567 if (Clazz.exceptionOf (e, Exception)) {
568 e.printStackTrace ();
569 System.err.println ("Failed to generate alignment with selection but no groups marked.");
575 System.out.println ("View *with* hidden columns, no limit to selection, and all groups to be collected:");
576 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, true, false, true);
577 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
579 if (Clazz.exceptionOf (e, Exception)) {
580 e.printStackTrace ();
581 System.err.println ("Failed to generate alignment with selection marked but no groups marked.");
587 System.out.println ("View *with* hidden columns, limited to selection and no groups to be collected:");
588 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, true, true, false);
589 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
591 if (Clazz.exceptionOf (e, Exception)) {
592 e.printStackTrace ();
593 System.err.println ("Failed to generate alignment with selection restricted but no groups marked.");
599 System.out.println ("View *with* hidden columns, limited to selection, and all groups to be collected:");
600 view = new jalview.datamodel.AlignmentView (alignment, csel, selection, true, true, true);
601 jalview.datamodel.AlignmentView.summariseAlignmentView (view, System.out);
603 if (Clazz.exceptionOf (e, Exception)) {
604 e.printStackTrace ();
605 System.err.println ("Failed to generate alignment with selection restricted and groups marked.");
610 }, "jalview.datamodel.AlignmentI,jalview.datamodel.ColumnSelection,jalview.datamodel.SequenceGroup");
611 c$.$AlignmentView$ScGroup$ = function () {
613 c$ = Clazz.decorateAsClass (function () {
614 Clazz.prepareCallback (this, arguments);
617 Clazz.instantialize (this, arguments);
618 }, jalview.datamodel.AlignmentView, "ScGroup");
619 Clazz.makeConstructor (c$,
621 this.seqs = new java.util.Vector ();