+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
package jalview.datamodel;
private SeqCigar[] sequences = null;
private int[] contigs = null;
private int width=0;
+ private int firstCol=0;
public AlignmentView(CigarArray seqcigararray)
{
if (!seqcigararray.isSeqCigarArray())
sequences = seqcigararray.getSeqCigarArray();
width = seqcigararray.getWidth(); // visible width
}
+ /**
+ * Create an alignmentView where the first column corresponds with the 'firstcol' column of some reference alignment
+ * @param sdata
+ * @param firstcol
+ */
+ public AlignmentView(CigarArray sdata, int firstcol) {
+ this(sdata);
+ firstCol=firstcol;
+ }
public void setSequences(SeqCigar[] sequences)
{
{
return sequences;
}
-
+ /**
+ * @see CigarArray.getDeletedRegions
+ * @return int[] { vis_start, sym_start, length }
+ */
public int[] getContigs()
{
return contigs;
{
String[] seqs=new String[sequences.length];
for (int n=0; n<sequences.length; n++) {
- seqs[n] = sequences[n].getSequenceString(c);
+ String fullseq = sequences[n].getSequenceString(c);
+ if (contigs != null)
+ {
+ seqs[n] = "";
+ int p = 0;
+ for (int h = 0; h < contigs.length; h += 3)
+ {
+ seqs[n] += fullseq.substring(p, contigs[h + 1]);
+ p = contigs[h + 1] + contigs[h + 2];
+ }
+ seqs[n] += fullseq.substring(p);
+ } else
+ seqs[n] = fullseq;
}
return seqs;
}
}
else
{
- alignment[s].setSequence(alignment[s].getSequence() +
+ alignment[s].setSequence(alignment[s].getSequenceAsString() +
mseq[s].getSequence());
if (mseq[s].getStart() <= mseq[s].getEnd())
{
}
else
{
- alignment[s].setSequence(alignment[s].getSequence() +
+ alignment[s].setSequence(alignment[s].getSequenceAsString() +
oseq.getSequence());
if (oseq.getEnd() >= oseq.getStart())
{
}
else
{
- alignment[s].setSequence(alignment[s].getSequence() +
+ alignment[s].setSequence(alignment[s].getSequenceAsString() +
hseq.getSequence());
if (hseq.getEnd() >= hseq.getStart())
{
}
else
{
- alignment[s].setSequence(alignment[s].getSequence() +
+ alignment[s].setSequence(alignment[s].getSequenceAsString() +
mseq[s].getSequence());
if (mseq[s].getEnd() >= mseq[s].getStart())
{
}
else
{
- alignment[s].setSequence(alignment[s].getSequence() +
+ alignment[s].setSequence(alignment[s].getSequenceAsString() +
oseq.getSequence());
if (oseq.getEnd() >= oseq.getStart())
{
return getAlignmentAndColumnSelection(gapCharacter);
}
}
-
+ /**
+ * returns simple array of start end positions of visible range on alignment.
+ * vis_start and vis_end are inclusive - use SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence from underlying alignment.
+ * @return int[] { start_i, end_i } for 1<i<n visible regions.
+ */
+ public int[] getVisibleContigs() {
+ if (contigs != null && contigs.length > 0)
+ {
+ int start = 0;
+ int nvis = 0;
+ int fwidth = width;
+ for (int contig = 0; contig < contigs.length; contig += 3)
+ {
+ if ( (contigs[contig + 1] - start) > 0)
+ {
+ nvis++;
+ }
+ fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions)
+ start = contigs[contig + 1] + contigs[contig + 2];
+ }
+ if (start < fwidth)
+ {
+ nvis++;
+ }
+ int viscontigs[] = new int[nvis*2];
+ nvis=0;
+ start=0;
+ for (int contig=0; contig<contigs.length; contig+=3) {
+ if ( (contigs[contig + 1] - start) > 0)
+ {
+ viscontigs[nvis] = start;
+ viscontigs[nvis+1]=contigs[contig+1]-1; // end is inclusive
+ nvis+=2;
+ }
+ start = contigs[contig + 1] + contigs[contig + 2];
+ }
+ if (start<fwidth) {
+ viscontigs[nvis] = start;
+ viscontigs[nvis+1]=fwidth; // end is inclusive
+ nvis+=2;
+ }
+ return viscontigs;
+ } else {
+ return new int[] { 0, width};
+ }
+ }
+ /**
+ *
+ * @return position of first visible column of AlignmentView within its parent's alignment reference frame
+ */
+ public int getAlignmentOrigin() {
+ // TODO Auto-generated method stub
+ return firstCol;
+ }
}