2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
\r
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.datamodel;
\r
20 import jalview.util.ShiftList;
\r
22 import java.io.PrintStream;
\r
23 import java.util.Enumeration;
\r
24 import java.util.Vector;
\r
27 * Transient object compactly representing a 'view' of an alignment - with
\r
28 * discontinuities marked. Extended in Jalview 2.7 to optionally record sequence
\r
29 * groups and specific selected regions on the alignment.
\r
31 public class AlignmentView
\r
33 private SeqCigar[] sequences = null;
\r
35 private int[] contigs = null;
\r
37 private int width = 0;
\r
39 private int firstCol = 0;
\r
42 * one or more ScGroup objects, which are referenced by each seqCigar's group
\r
45 private Vector scGroups;
\r
48 * Group defined over SeqCigars. Unlike AlignmentI associated groups, each
\r
49 * SequenceGroup hold just the essential properties for the group, but no
\r
50 * references to the sequences involved. SeqCigars hold references to the
\r
51 * seuqenceGroup entities themselves.
\r
53 private class ScGroup
\r
57 public SequenceGroup sg;
\r
61 seqs = new Vector();
\r
66 * vector of selected seqCigars. This vector is also referenced by each
\r
67 * seqCigar contained in it.
\r
69 private Vector selected;
\r
72 * Construct an alignmentView from a live jalview alignment view. Note -
\r
73 * hidden rows will be excluded from alignmentView
\r
76 * - alignment as referenced by an AlignViewport
\r
77 * @param columnSelection
\r
80 * @param hasHiddenColumns
\r
81 * - mark the hidden columns in columnSelection as hidden in the view
\r
82 * @param selectedRegionOnly
\r
83 * - when set, only include the selected region in the view,
\r
84 * otherwise just mark the selected region on the constructed view.
\r
85 * @param recordGroups
\r
86 * - when set, any groups on the given alignment will be marked on
\r
89 public AlignmentView(AlignmentI alignment,
\r
90 ColumnSelection columnSelection, SequenceGroup selection,
\r
91 boolean hasHiddenColumns, boolean selectedRegionOnly,
\r
92 boolean recordGroups)
\r
94 // refactored from AlignViewport.getAlignmentView(selectedOnly);
\r
95 this(new jalview.datamodel.CigarArray(alignment,
\r
96 (hasHiddenColumns ? columnSelection : null),
\r
97 (selectedRegionOnly ? selection : null)),
\r
98 (selectedRegionOnly && selection != null) ? selection
\r
99 .getStartRes() : 0);
\r
100 // walk down SeqCigar array and Alignment Array - optionally restricted by
\r
101 // selected region.
\r
102 // test group membership for each sequence in each group, store membership
\r
103 // and record non-empty groups in group list.
\r
104 // record / sub-select selected region on the alignment view
\r
105 SequenceI[] selseqs;
\r
106 if (selection != null)
\r
108 Vector sel = selection.getSequences(null);
\r
109 this.selected = new Vector();
\r
110 selseqs = selection.getSequencesInOrder(alignment, selectedRegionOnly);
\r
114 selseqs = alignment.getSequencesArray();
\r
117 // get the alignment's group list and make a copy
\r
118 Vector grps = new Vector();
\r
119 Vector gg = alignment.getGroups();
\r
120 Enumeration gge = gg.elements();
\r
121 while (gge.hasMoreElements())
\r
123 grps.addElement(gge.nextElement());
\r
125 ScGroup[] sgrps = null;
\r
126 boolean addedgps[] = null;
\r
130 if (selection != null && selectedRegionOnly)
\r
132 // trim annotation to the region being stored.
\r
133 // strip out any groups that do not actually intersect with the
\r
134 // visible and selected region
\r
135 int ssel = selection.getStartRes(), esel = selection.getEndRes();
\r
136 Vector isg = new Vector();
\r
137 Enumeration en = grps.elements();
\r
138 while (en.hasMoreElements())
\r
140 sg = (SequenceGroup) en.nextElement();
\r
142 if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel))
\r
144 // adjust bounds of new group, if necessary.
\r
145 if (sg.getStartRes() < ssel)
\r
147 sg.setStartRes(ssel);
\r
149 if (sg.getEndRes() > esel)
\r
151 sg.setEndRes(esel);
\r
153 sg.setStartRes(sg.getStartRes()-ssel+1);
\r
154 sg.setEndRes(sg.getEndRes()-ssel+1);
\r
156 isg.addElement(sg);
\r
162 sgrps = new ScGroup[grps.size()];
\r
163 addedgps = new boolean[grps.size()];
\r
164 for (int g = 0; g < sgrps.length; g++)
\r
166 sg = (SequenceGroup) grps.elementAt(g);
\r
167 sgrps[g] = new ScGroup();
\r
168 sgrps[g].sg = new SequenceGroup(sg);
\r
169 addedgps[g] = false;
\r
170 grps.setElementAt(sg.getSequences(null), g);
\r
172 // grps now contains vectors (should be sets) for each group, so we can
\r
173 // track when we've done with the group
\r
176 for (int i = 0; i < selseqs.length; i++)
\r
178 if (selseqs[i] != null)
\r
180 if (selection != null && !selectedRegionOnly)
\r
182 sequences[csi].setGroupMembership(selected);
\r
183 selected.addElement(sequences[csi]);
\r
187 for (int sg = 0; sg < sgrps.length; sg++)
\r
189 if (((Vector) grps.elementAt(sg)).contains(selseqs[i]))
\r
191 sequences[csi].setGroupMembership(sgrps[sg]);
\r
192 sgrps[sg].sg.deleteSequence(selseqs[i], false);
\r
193 sgrps[sg].seqs.addElement(sequences[csi]);
\r
196 if (scGroups == null)
\r
198 scGroups = new Vector();
\r
200 addedgps[sg] = true;
\r
201 scGroups.addElement(sgrps[sg]);
\r
209 // finally, delete the remaining sequences (if any) not selected
\r
210 for (int sg = 0; sg < sgrps.length; sg++)
\r
212 SequenceI[] sqs = sgrps[sg].sg.getSequencesAsArray(null);
\r
213 for (int si = 0; si < sqs.length; si++)
\r
215 sgrps[sg].sg.deleteSequence(sqs[si], false);
\r
222 * construct an alignmentView from a SeqCigarArray. Errors are thrown if the
\r
223 * seqcigararray.isSeqCigarArray() flag is not set.
\r
225 public AlignmentView(CigarArray seqcigararray)
\r
227 if (!seqcigararray.isSeqCigarArray())
\r
230 "Implementation Error - can only make an alignment view from a CigarArray of sequences.");
\r
232 // contigs = seqcigararray.applyDeletions();
\r
233 contigs = seqcigararray.getDeletedRegions();
\r
234 sequences = seqcigararray.getSeqCigarArray();
\r
235 width = seqcigararray.getWidth(); // visible width
\r
239 * Create an alignmentView where the first column corresponds with the
\r
240 * 'firstcol' column of some reference alignment
\r
245 public AlignmentView(CigarArray sdata, int firstcol)
\r
248 firstCol = firstcol;
\r
251 public void setSequences(SeqCigar[] sequences)
\r
253 this.sequences = sequences;
\r
256 public void setContigs(int[] contigs)
\r
258 this.contigs = contigs;
\r
261 public SeqCigar[] getSequences()
\r
267 * @see CigarArray.getDeletedRegions
\r
268 * @return int[] { vis_start, sym_start, length }
\r
270 public int[] getContigs()
\r
276 * get the full alignment and a columnselection object marking the hidden
\r
279 * @param gapCharacter
\r
281 * @return Object[] { SequenceI[], ColumnSelection}
\r
283 public Object[] getAlignmentAndColumnSelection(char gapCharacter)
\r
285 ColumnSelection colsel = new ColumnSelection();
\r
287 return new Object[]
\r
289 SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel,
\r
290 contigs), colsel };
\r
294 * return the visible alignment corresponding to this view. Sequences in this
\r
295 * alignment are edited versions of the parent sequences - where hidden
\r
296 * regions have been removed. NOTE: the sequence data in this alignment is not
\r
302 public AlignmentI getVisibleAlignment(char c)
\r
304 SequenceI[] aln = getVisibleSeqs(c);
\r
306 AlignmentI vcal = new Alignment(aln);
\r
307 addPrunedGroupsInOrder(vcal, -1, -1, true);
\r
312 * add groups from view to the given alignment
\r
316 * -1 or 0 to width-1
\r
318 * -1 or gstart to width-1
\r
319 * @param viscontigs
\r
320 * - true if vcal is alignment of the visible regions of the view
\r
321 * (e.g. as returned from getVisibleAlignment)
\r
323 private void addPrunedGroupsInOrder(AlignmentI vcal, int gstart,
\r
324 int gend, boolean viscontigs)
\r
327 if (gstart > -1 && gstart <= gend)
\r
332 SequenceI[] aln = vcal.getSequencesArray();
\r
335 * prune any groups to the visible coordinates of the alignment.
\r
338 int nvg = (scGroups != null) ? scGroups.size() : 0;
\r
341 SequenceGroup[] nsg = new SequenceGroup[nvg];
\r
342 for (int g = 0; g < nvg; g++)
\r
344 SequenceGroup sg = ((ScGroup) scGroups.elementAt(g)).sg;
\r
347 if (sg.getStartRes() > gend || sg.getEndRes() < gstart)
\r
355 // clone group properties
\r
356 nsg[g] = new SequenceGroup(sg);
\r
358 // may need to shift/trim start and end ?
\r
359 if (r && !viscontigs)
\r
361 // Not fully tested code - routine not yet called with viscontigs==false
\r
362 if (nsg[g].getStartRes() < gstart)
\r
364 nsg[g].setStartRes(0);
\r
368 nsg[g].setStartRes(nsg[g].getStartRes() - gstart);
\r
369 nsg[g].setEndRes(nsg[g].getEndRes() - gstart);
\r
371 if (nsg[g].getEndRes() > (gend-gstart))
\r
373 nsg[g].setEndRes(gend-gstart);
\r
379 // prune groups to cover just the visible positions between
\r
381 if (contigs != null)
\r
384 ShiftList prune = new ShiftList();
\r
387 // adjust for start of alignment within visible window.
\r
388 prune.addShift(gstart, -gstart); //
\r
390 for (int h = 0; h < contigs.length; h += 3)
\r
393 prune.addShift(p + contigs[h + 1], contigs[h + 2]
\r
396 p = contigs[h + 1] + contigs[h + 2];
\r
398 for (int g = 0; g < nsg.length; g++)
\r
400 if (nsg[g] != null)
\r
402 int s = nsg[g].getStartRes(), t = nsg[g].getEndRes();
\r
415 s = prune.shift(s);
\r
416 t = prune.shift(t);
\r
417 nsg[g].setStartRes(s);
\r
418 nsg[g].setEndRes(t);
\r
424 for (int nsq = 0; nsq < aln.length; nsq++)
\r
426 for (int g = 0; g < nvg; g++)
\r
429 && sequences[nsq].isMemberOf(scGroups.elementAt(g)))
\r
431 nsg[g].addSequence(aln[nsq], false);
\r
435 for (int g = 0; g < nvg; g++)
\r
437 if (nsg[g] != null && nsg[g].getSize() > 0)
\r
439 vcal.addGroup(nsg[g]);
\r
449 * generate sequence array corresponding to the visible parts of the
\r
455 private SequenceI[] getVisibleSeqs(char c)
\r
457 SequenceI[] aln = new SequenceI[sequences.length];
\r
458 for (int i = 0, j = sequences.length; i < j; i++)
\r
460 aln[i] = sequences[i].getSeq('-');
\r
462 // Remove hidden regions from sequence objects.
\r
463 String seqs[] = getSequenceStrings('-');
\r
464 for (int i = 0, j = aln.length; i < j; i++)
\r
466 aln[i].setSequence(seqs[i]);
\r
472 * creates new alignment objects for all contiguous visible segments
\r
477 * @param regionOfInterest
\r
478 * specify which sequences to include (or null to include all
\r
480 * @return AlignmentI[] - all alignments where each sequence is a subsequence
\r
481 * constructed from visible contig regions of view
\r
483 public AlignmentI[] getVisibleContigAlignments(char c)
\r
486 int[] vcontigs = getVisibleContigs();
\r
487 SequenceI[][] contigviews = getVisibleContigs(c);
\r
488 AlignmentI[] vcals = new AlignmentI[contigviews.length];
\r
489 for (nvc = 0; nvc < contigviews.length; nvc++)
\r
491 vcals[nvc] = new Alignment(contigviews[nvc]);
\r
492 if (scGroups!=null && scGroups.size()>0)
\r
494 addPrunedGroupsInOrder(vcals[nvc], vcontigs[nvc*2],vcontigs[nvc*2+1], true);
\r
502 * get an array of visible sequence strings for a view on an alignment using
\r
503 * the given gap character
\r
509 public String[] getSequenceStrings(char c)
\r
511 String[] seqs = new String[sequences.length];
\r
512 for (int n = 0; n < sequences.length; n++)
\r
514 String fullseq = sequences[n].getSequenceString(c);
\r
515 if (contigs != null)
\r
519 for (int h = 0; h < contigs.length; h += 3)
\r
521 seqs[n] += fullseq.substring(p, contigs[h + 1]);
\r
522 p = contigs[h + 1] + contigs[h + 2];
\r
524 seqs[n] += fullseq.substring(p);
\r
536 * @return visible number of columns in alignment view
\r
538 public int getWidth()
\r
543 protected void setWidth(int width)
\r
545 this.width = width;
\r
549 * get the contiguous subalignments in an alignment view.
\r
551 * @param gapCharacter
\r
553 * @return SequenceI[][]
\r
555 public SequenceI[][] getVisibleContigs(char gapCharacter)
\r
557 SequenceI[][] smsa;
\r
559 if (sequences == null || width <= 0)
\r
563 if (contigs != null && contigs.length > 0)
\r
567 int fwidth = width;
\r
568 for (int contig = 0; contig < contigs.length; contig += 3)
\r
570 if ((contigs[contig + 1] - start) > 0)
\r
574 fwidth += contigs[contig + 2]; // end up with full region width
\r
575 // (including hidden regions)
\r
576 start = contigs[contig + 1] + contigs[contig + 2];
\r
578 if (start < fwidth)
\r
582 smsa = new SequenceI[njobs][];
\r
585 for (int contig = 0; contig < contigs.length; contig += 3)
\r
587 if (contigs[contig + 1] - start > 0)
\r
589 SequenceI mseq[] = new SequenceI[sequences.length];
\r
590 for (int s = 0; s < mseq.length; s++)
\r
592 mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(
\r
593 start, contigs[contig + 1]);
\r
598 start = contigs[contig + 1] + contigs[contig + 2];
\r
600 if (start < fwidth)
\r
602 SequenceI mseq[] = new SequenceI[sequences.length];
\r
603 for (int s = 0; s < mseq.length; s++)
\r
605 mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start,
\r
614 smsa = new SequenceI[1][];
\r
615 smsa[0] = new SequenceI[sequences.length];
\r
616 for (int s = 0; s < sequences.length; s++)
\r
618 smsa[0][s] = sequences[s].getSeq(gapCharacter);
\r
625 * return full msa and hidden regions with visible blocks replaced with new
\r
631 * AlignmentOrder[] corresponding to each SequenceI[] block.
\r
634 public Object[] getUpdatedView(SequenceI[][] nvismsa,
\r
635 AlignmentOrder[] orders, char gapCharacter)
\r
637 if (sequences == null || width <= 0)
\r
639 throw new Error("empty view cannot be updated.");
\r
641 if (nvismsa == null)
\r
644 "nvismsa==null. use getAlignmentAndColumnSelection() instead.");
\r
646 if (contigs != null && contigs.length > 0)
\r
648 SequenceI[] alignment = new SequenceI[sequences.length];
\r
649 ColumnSelection columnselection = new ColumnSelection();
\r
650 if (contigs != null && contigs.length > 0)
\r
654 int owidth = width;
\r
656 for (int contig = 0; contig < contigs.length; contig += 3)
\r
658 owidth += contigs[contig + 2]; // recover final column width
\r
659 if (contigs[contig + 1] - start > 0)
\r
661 int swidth = 0; // subalignment width
\r
662 if (nvismsa[j] != null)
\r
664 SequenceI mseq[] = nvismsa[j];
\r
665 AlignmentOrder order = (orders == null) ? null : orders[j];
\r
667 if (mseq.length != sequences.length)
\r
670 "Mismatch between number of sequences in block "
\r
671 + j + " (" + mseq.length
\r
672 + ") and the original view ("
\r
673 + sequences.length + ")");
\r
675 swidth = mseq[0].getLength(); // JBPNote: could ensure padded
\r
677 for (int s = 0; s < mseq.length; s++)
\r
679 if (alignment[s] == null)
\r
681 alignment[s] = mseq[s];
\r
685 alignment[s].setSequence(alignment[s]
\r
686 .getSequenceAsString()
\r
687 + mseq[s].getSequenceAsString());
\r
688 if (mseq[s].getStart() <= mseq[s].getEnd())
\r
690 alignment[s].setEnd(mseq[s].getEnd());
\r
694 order.updateSequence(mseq[s], alignment[s]);
\r
701 // recover original alignment block or place gaps
\r
704 // recover input data
\r
705 for (int s = 0; s < sequences.length; s++)
\r
707 SequenceI oseq = sequences[s].getSeq(gapCharacter)
\r
708 .getSubSequence(start, contigs[contig + 1]);
\r
709 if (swidth < oseq.getLength())
\r
711 swidth = oseq.getLength();
\r
713 if (alignment[s] == null)
\r
715 alignment[s] = oseq;
\r
719 alignment[s].setSequence(alignment[s]
\r
720 .getSequenceAsString()
\r
721 + oseq.getSequenceAsString());
\r
722 if (oseq.getEnd() >= oseq.getStart())
\r
724 alignment[s].setEnd(oseq.getEnd());
\r
734 // advance to begining of visible region
\r
735 start = contigs[contig + 1] + contigs[contig + 2];
\r
736 // add hidden segment to right of next region
\r
737 for (int s = 0; s < sequences.length; s++)
\r
739 SequenceI hseq = sequences[s].getSeq(gapCharacter)
\r
740 .getSubSequence(contigs[contig + 1], start);
\r
741 if (alignment[s] == null)
\r
743 alignment[s] = hseq;
\r
747 alignment[s].setSequence(alignment[s].getSequenceAsString()
\r
748 + hseq.getSequenceAsString());
\r
749 if (hseq.getEnd() >= hseq.getStart())
\r
751 alignment[s].setEnd(hseq.getEnd());
\r
755 // mark hidden segment as hidden in the new alignment
\r
756 columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2]
\r
758 nwidth += contigs[contig + 2];
\r
760 // Do final segment - if it exists
\r
761 if (j < nvismsa.length)
\r
764 if (nvismsa[j] != null)
\r
766 SequenceI mseq[] = nvismsa[j];
\r
767 AlignmentOrder order = (orders != null) ? orders[j] : null;
\r
768 swidth = mseq[0].getLength();
\r
769 for (int s = 0; s < mseq.length; s++)
\r
771 if (alignment[s] == null)
\r
773 alignment[s] = mseq[s];
\r
777 alignment[s].setSequence(alignment[s].getSequenceAsString()
\r
778 + mseq[s].getSequenceAsString());
\r
779 if (mseq[s].getEnd() >= mseq[s].getStart())
\r
781 alignment[s].setEnd(mseq[s].getEnd());
\r
785 order.updateSequence(mseq[s], alignment[s]);
\r
792 if (start < owidth)
\r
794 // recover input data or place gaps
\r
797 // recover input data
\r
798 for (int s = 0; s < sequences.length; s++)
\r
800 SequenceI oseq = sequences[s].getSeq(gapCharacter)
\r
801 .getSubSequence(start, owidth + 1);
\r
802 if (swidth < oseq.getLength())
\r
804 swidth = oseq.getLength();
\r
806 if (alignment[s] == null)
\r
808 alignment[s] = oseq;
\r
812 alignment[s].setSequence(alignment[s]
\r
813 .getSequenceAsString()
\r
814 + oseq.getSequenceAsString());
\r
815 if (oseq.getEnd() >= oseq.getStart())
\r
817 alignment[s].setEnd(oseq.getEnd());
\r
826 throw new Error("Padding not yet implemented.");
\r
832 return new Object[]
\r
833 { alignment, columnselection };
\r
837 if (nvismsa.length != 1)
\r
840 "Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="
\r
843 if (nvismsa[0] != null)
\r
845 return new Object[]
\r
846 { nvismsa[0], new ColumnSelection() };
\r
850 return getAlignmentAndColumnSelection(gapCharacter);
\r
856 * returns simple array of start end positions of visible range on alignment.
\r
857 * vis_start and vis_end are inclusive - use
\r
858 * SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence
\r
859 * from underlying alignment.
\r
861 * @return int[] { start_i, end_i } for 1<i<n visible regions.
\r
863 public int[] getVisibleContigs()
\r
865 if (contigs != null && contigs.length > 0)
\r
869 int fwidth = width;
\r
870 for (int contig = 0; contig < contigs.length; contig += 3)
\r
872 if ((contigs[contig + 1] - start) > 0)
\r
876 fwidth += contigs[contig + 2]; // end up with full region width
\r
877 // (including hidden regions)
\r
878 start = contigs[contig + 1] + contigs[contig + 2];
\r
880 if (start < fwidth)
\r
884 int viscontigs[] = new int[nvis * 2];
\r
887 for (int contig = 0; contig < contigs.length; contig += 3)
\r
889 if ((contigs[contig + 1] - start) > 0)
\r
891 viscontigs[nvis] = start;
\r
892 viscontigs[nvis + 1] = contigs[contig + 1] - 1; // end is inclusive
\r
895 start = contigs[contig + 1] + contigs[contig + 2];
\r
897 if (start < fwidth)
\r
899 viscontigs[nvis] = start;
\r
900 viscontigs[nvis + 1] = fwidth; // end is inclusive
\r
914 * @return position of first visible column of AlignmentView within its
\r
915 * parent's alignment reference frame
\r
917 public int getAlignmentOrigin()
\r
923 * compute a deletion map for the current view according to the given
\r
927 * (as returned from SequenceI.gapMap())
\r
928 * @return int[] {intersection of visible regions with gapMap)
\r
930 public int[] getVisibleContigMapFor(int[] gapMap)
\r
932 int[] delMap = null;
\r
933 int[] viscontigs = getVisibleContigs();
\r
936 if (viscontigs != null)
\r
938 // viscontigs maps from a subset of the gapMap to the gapMap, so it will
\r
939 // always be equal to or shorter than gapMap
\r
940 delMap = new int[gapMap.length];
\r
941 for (int contig = 0; contig < viscontigs.length; contig += 2)
\r
944 while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
\r
948 while (spos < gapMap.length
\r
949 && gapMap[spos] <= viscontigs[contig + 1])
\r
951 delMap[i++] = spos++;
\r
954 int tmap[] = new int[i];
\r
955 System.arraycopy(delMap, 0, tmap, 0, i);
\r
962 * apply the getSeq(gc) method to each sequence cigar, and return the array of
\r
963 * edited sequences, optionally with hidden regions removed.
\r
966 * gap character to use for insertions
\r
968 * remove hidden regions from sequences. Note: currently implemented
\r
969 * in a memory inefficient way - space needed is 2*result set for
\r
972 * @return SequenceI[]
\r
974 public SequenceI[] getEditedSequences(char gc, boolean delete)
\r
976 SeqCigar[] msf = getSequences();
\r
977 SequenceI[] aln = new SequenceI[msf.length];
\r
978 for (int i = 0, j = msf.length; i < j; i++)
\r
980 aln[i] = msf[i].getSeq(gc);
\r
984 String[] sqs = getSequenceStrings(gc);
\r
985 for (int i = 0; i < sqs.length; i++)
\r
987 aln[i].setSequence(sqs[i]);
\r
994 public static void summariseAlignmentView(AlignmentView view,
\r
997 os.print("View has " + view.sequences.length + " of which ");
\r
998 if (view.selected == null) {
\r
1001 os.print(" "+view.selected.size());
\r
1003 os.println(" are selected.");
\r
1004 os.print("View is " + view.getWidth() + " columns wide");
\r
1006 int[] contigs = view.getContigs();
\r
1007 if (contigs != null)
\r
1009 viswid = view.width;
\r
1010 for (int i = 0; i < contigs.length; i += 3)
\r
1012 viswid += contigs[i + 2];
\r
1014 os.println("with " + viswid + " visible columns spread over "
\r
1015 + contigs.length / 3 + " regions.");
\r
1019 viswid = view.width;
\r
1022 if (view.scGroups != null)
\r
1024 os.println("There are " + view.scGroups.size()
\r
1025 + " groups defined on the view.");
\r
1026 for (int g = 0; g < view.scGroups.size(); g++)
\r
1028 ScGroup sgr = (ScGroup) view.scGroups.elementAt(g);
\r
1029 os.println("Group " + g + ": Name = " + sgr.sg.getName()
\r
1030 + " Contains " + sgr.seqs.size() + " Seqs.");
\r
1031 os.println("This group runs from " + sgr.sg.getStartRes() + " to "
\r
1032 + sgr.sg.getEndRes());
\r
1033 for (int s = 0; s < sgr.seqs.size(); s++)
\r
1035 if (!((SeqCigar) sgr.seqs.elementAt(s)).isMemberOf(sgr))
\r
1037 os.println("** WARNING: sequence "
\r
1038 + ((SeqCigar) sgr.seqs.elementAt(s)).toString()
\r
1039 + " is not marked as member of group.");
\r
1043 AlignmentI visal = view.getVisibleAlignment('-');
\r
1044 if (visal != null)
\r
1046 os.println("Vis. alignment is " + visal.getWidth()
\r
1047 + " wide and has " + visal.getHeight() + " seqs.");
\r
1048 if (visal.getGroups() != null && visal.getGroups().size() > 0)
\r
1051 Enumeration en = visal.getGroups().elements();
\r
1053 while (en.hasMoreElements())
\r
1055 sg = (SequenceGroup) en.nextElement();
\r
1056 os.println("Group " + (i++) + " begins at column "
\r
1057 + sg.getStartRes() + " and ends at " + sg.getEndRes());
\r
1064 public static void testSelectionViews(AlignmentI alignment,
\r
1065 ColumnSelection csel, SequenceGroup selection)
\r
1067 System.out.println("Testing standard view creation:\n");
\r
1068 AlignmentView view = null;
\r
1072 .println("View with no hidden columns, no limit to selection, no groups to be collected:");
\r
1073 view = new AlignmentView(alignment, csel, selection, false, false,
\r
1075 summariseAlignmentView(view, System.out);
\r
1077 } catch (Exception e)
\r
1079 e.printStackTrace();
\r
1081 .println("Failed to generate alignment with selection but no groups marked.");
\r
1086 .println("View with no hidden columns, no limit to selection, and all groups to be collected:");
\r
1087 view = new AlignmentView(alignment, csel, selection, false, false,
\r
1089 summariseAlignmentView(view, System.out);
\r
1090 } catch (Exception e)
\r
1092 e.printStackTrace();
\r
1094 .println("Failed to generate alignment with selection marked but no groups marked.");
\r
1099 .println("View with no hidden columns, limited to selection and no groups to be collected:");
\r
1100 view = new AlignmentView(alignment, csel, selection, false, true,
\r
1102 summariseAlignmentView(view, System.out);
\r
1103 } catch (Exception e)
\r
1105 e.printStackTrace();
\r
1107 .println("Failed to generate alignment with selection restricted but no groups marked.");
\r
1112 .println("View with no hidden columns, limited to selection, and all groups to be collected:");
\r
1113 view = new AlignmentView(alignment, csel, selection, false, true,
\r
1115 summariseAlignmentView(view, System.out);
\r
1116 } catch (Exception e)
\r
1118 e.printStackTrace();
\r
1120 .println("Failed to generate alignment with selection restricted and groups marked.");
\r
1125 .println("View *with* hidden columns, no limit to selection, no groups to be collected:");
\r
1126 view = new AlignmentView(alignment, csel, selection, true, false,
\r
1128 summariseAlignmentView(view, System.out);
\r
1129 } catch (Exception e)
\r
1131 e.printStackTrace();
\r
1133 .println("Failed to generate alignment with selection but no groups marked.");
\r
1138 .println("View *with* hidden columns, no limit to selection, and all groups to be collected:");
\r
1139 view = new AlignmentView(alignment, csel, selection, true, false,
\r
1141 summariseAlignmentView(view, System.out);
\r
1142 } catch (Exception e)
\r
1144 e.printStackTrace();
\r
1146 .println("Failed to generate alignment with selection marked but no groups marked.");
\r
1151 .println("View *with* hidden columns, limited to selection and no groups to be collected:");
\r
1152 view = new AlignmentView(alignment, csel, selection, true, true,
\r
1154 summariseAlignmentView(view, System.out);
\r
1155 } catch (Exception e)
\r
1157 e.printStackTrace();
\r
1159 .println("Failed to generate alignment with selection restricted but no groups marked.");
\r
1164 .println("View *with* hidden columns, limited to selection, and all groups to be collected:");
\r
1165 view = new AlignmentView(alignment, csel, selection, true, true, true);
\r
1166 summariseAlignmentView(view, System.out);
\r
1167 } catch (Exception e)
\r
1169 e.printStackTrace();
\r
1171 .println("Failed to generate alignment with selection restricted and groups marked.");
\r