Jalview 2.6 source licence
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index 58b379b..4079c9c 100644 (file)
-/*
- * 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;
-
-
-
-/**
- * <p>Title: </p>
- *
- * <p>Description: </p>
- *
- * <p>Copyright: Copyright (c) 2004</p>
- *
- * <p>Company: Dundee University</p>
- *
- * @author not attributable
- * @version 1.0
- */
-public class AlignmentView
-{
-    /**
-     * Transient object compactly representing a 'view' of an alignment - with discontinuities marked.
-     */
-    private SeqCigar[] sequences = null;
-  private int[] contigs = null;
-  private int width=0;
-  private int firstCol=0;
-  public AlignmentView(CigarArray seqcigararray)
-  {
-    if (!seqcigararray.isSeqCigarArray())
-      throw new Error("Implementation Error - can only make an alignment view from a CigarArray of sequences.");
-    //contigs = seqcigararray.applyDeletions();
-    contigs = seqcigararray.getDeletedRegions();
-    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)
-  {
-    this.sequences = sequences;
-  }
-
-  public void setContigs(int[] contigs)
-  {
-    this.contigs = contigs;
-  }
-
-  public SeqCigar[] getSequences()
-  {
-    return sequences;
-  }
-  /**
-   * @see CigarArray.getDeletedRegions
-   * @return int[] { vis_start, sym_start, length }
-   */
-  public int[] getContigs()
-  {
-    return contigs;
-  }
-  /**
-   * get the full alignment and a columnselection object marking the hidden regions
-   * @param gapCharacter char
-   * @return Object[] { SequenceI[], ColumnSelection}
-   */
-  public Object[] getAlignmentAndColumnSelection(char gapCharacter) {
-    ColumnSelection colsel = new ColumnSelection();
-
-    return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel};
-  }
-  /**
-   * getSequenceStrings
-   *
-   * @param c char
-   * @return String[]
-   */
-  public String[] getSequenceStrings(char c)
-  {
-    String[] seqs=new String[sequences.length];
-    for (int n=0; n<sequences.length; n++) {
-      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;
-  }
-  /**
-   *
-   * @return visible number of columns in alignment view
-   */
-  public int getWidth() {
-    return width;
-  }
-
-  protected void setWidth(int width) {
-    this.width = width;
-  }
-  /**
-   * get the contiguous subalignments in an alignment view.
-   * @param gapCharacter char
-   * @return SequenceI[][]
-   */
-  public SequenceI[][] getVisibleContigs(char gapCharacter) {
-    SequenceI[][] smsa;
-    int njobs = 1;
-    if (sequences==null || width<=0)
-      return null;
-    if (contigs != null && contigs.length > 0)
-    {
-      int start = 0;
-      njobs = 0;
-      int fwidth = width;
-      for (int contig = 0; contig < contigs.length; contig += 3)
-      {
-        if ( (contigs[contig + 1] - start) > 0)
-        {
-          njobs++;
-        }
-        fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions)
-        start = contigs[contig + 1] + contigs[contig + 2];
-      }
-      if (start < fwidth)
-      {
-        njobs++;
-      }
-      smsa = new SequenceI[njobs][];
-      start = 0;
-      int j = 0;
-      for (int contig = 0; contig < contigs.length; contig += 3)
-      {
-        if (contigs[contig + 1] - start > 0)
-        {
-          SequenceI mseq[] = new SequenceI[sequences.length];
-          for (int s = 0; s < mseq.length; s++)
-          {
-            mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-                contigs[contig + 1]);
-          }
-          smsa[j] = mseq;
-          j++;
-        }
-        start = contigs[contig + 1] + contigs[contig + 2];
-      }
-      if (start < fwidth)
-      {
-        SequenceI mseq[] = new SequenceI[sequences.length];
-        for (int s = 0; s < mseq.length; s++)
-        {
-          mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-              fwidth + 1);
-        }
-        smsa[j] = mseq;
-        j++;
-      }
-    }
-    else
-    {
-      smsa = new SequenceI[1][];
-      smsa[0] = new SequenceI[sequences.length];
-      for (int s = 0; s < sequences.length; s++)
-      {
-        smsa[0][s] = sequences[s].getSeq(gapCharacter);
-      }
-    }
-    return smsa;
-  }
-  /**
-   * return full msa and hidden regions with visible blocks replaced with new sub alignments
-   * @param nvismsa SequenceI[][]
-   * @param orders AlignmentOrder[] corresponding to each SequenceI[] block.
-   * @return Object[]
-   */
-  public Object[] getUpdatedView(SequenceI[][] nvismsa, AlignmentOrder[] orders, char gapCharacter) {
-    if (sequences == null || width <= 0)
-    {
-      throw new Error("empty view cannot be updated.");
-    }
-    if (nvismsa == null)
-      throw new Error(
-          "nvismsa==null. use getAlignmentAndColumnSelection() instead.");
-    if (contigs != null && contigs.length > 0)
-    {
-      SequenceI[] alignment = new SequenceI[sequences.length];
-      ColumnSelection columnselection = new ColumnSelection();
-      if (contigs != null && contigs.length > 0)
-      {
-        int start = 0;
-        int nwidth = 0;
-        int owidth = width;
-        int j = 0;
-        for (int contig = 0; contig < contigs.length; contig += 3)
-        {
-          owidth += contigs[contig + 2]; // recover final column width
-          if (contigs[contig + 1] - start > 0)
-          {
-            int swidth = 0; // subalignment width
-            if (nvismsa[j] != null)
-            {
-              SequenceI mseq[] = nvismsa[j];
-              AlignmentOrder order=(orders==null) ? null : orders[j];
-              j++;
-              if (mseq.length!=sequences.length)
-                throw new Error("Mismatch between number of sequences in block "+j+" ("+mseq.length+") and the original view ("+sequences.length+")");
-              swidth = mseq[0].getLength(); // JBPNote: could ensure padded here.
-              for (int s = 0; s < mseq.length; s++)
-              {
-                if (alignment[s] == null)
-                {
-                  alignment[s] = mseq[s];
-                }
-                else
-                {
-                  alignment[s].setSequence(alignment[s].getSequenceAsString() +
-                                           mseq[s].getSequence());
-                  if (mseq[s].getStart() <= mseq[s].getEnd())
-                  {
-                    alignment[s].setEnd(mseq[s].getEnd());
-                  }
-                  if (order!=null) {
-                    order.updateSequence(mseq[s], alignment[s]);
-                  }
-                }
-              }
-            }
-            else
-            {
-              // recover original alignment block or place gaps
-              if (true)
-              {
-                // recover input data
-                for (int s = 0; s < sequences.length; s++)
-                {
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-                      contigs[contig + 1]);
-                  if (swidth < oseq.getLength())
-                  {
-                    swidth = oseq.getLength();
-                  }
-                  if (alignment[s] == null)
-                  {
-                    alignment[s] = oseq;
-                  }
-                  else
-                  {
-                    alignment[s].setSequence(alignment[s].getSequenceAsString() +
-                                             oseq.getSequence());
-                    if (oseq.getEnd() >= oseq.getStart())
-                    {
-                      alignment[s].setEnd(oseq.getEnd());
-                    }
-                  }
-                }
-
-              }
-              j++;
-            }
-            nwidth += swidth;
-          }
-          // advance to begining of visible region
-          start = contigs[contig + 1] + contigs[contig + 2];
-          // add hidden segment to right of next region
-          for (int s = 0; s < sequences.length; s++)
-          {
-            SequenceI hseq = sequences[s].getSeq(gapCharacter).getSubSequence(contigs[contig +
-                1], start);
-            if (alignment[s] == null)
-            {
-              alignment[s] = hseq;
-            }
-            else
-            {
-              alignment[s].setSequence(alignment[s].getSequenceAsString() +
-                                       hseq.getSequence());
-              if (hseq.getEnd() >= hseq.getStart())
-              {
-                alignment[s].setEnd(hseq.getEnd());
-              }
-            }
-          }
-          // mark hidden segment as hidden in the new alignment
-          columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1);
-          nwidth += contigs[contig + 2];
-        }
-        // Do final segment - if it exists
-        if (j < nvismsa.length)
-        {
-          int swidth = 0;
-          if (nvismsa[j] != null)
-          {
-            SequenceI mseq[] = nvismsa[j];
-            AlignmentOrder order = (orders!=null) ? orders[j] : null;
-            swidth = mseq[0].getLength();
-            for (int s = 0; s < mseq.length; s++)
-            {
-              if (alignment[s] == null)
-              {
-                alignment[s] = mseq[s];
-              }
-              else
-              {
-                alignment[s].setSequence(alignment[s].getSequenceAsString() +
-                                         mseq[s].getSequence());
-                if (mseq[s].getEnd() >= mseq[s].getStart())
-                {
-                  alignment[s].setEnd(mseq[s].getEnd());
-                }
-                if (order!=null) {
-                  order.updateSequence(mseq[s], alignment[s]);
-                }
-              }
-            }
-          }
-          else
-          {
-            if (start < owidth)
-            {
-              // recover input data or place gaps
-              if (true)
-              {
-                // recover input data
-                for (int s = 0; s < sequences.length; s++)
-                {
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-                      owidth + 1);
-                  if (swidth < oseq.getLength())
-                  {
-                    swidth = oseq.getLength();
-                  }
-                  if (alignment[s] == null)
-                  {
-                    alignment[s] = oseq;
-                  }
-                  else
-                  {
-                    alignment[s].setSequence(alignment[s].getSequenceAsString() +
-                                             oseq.getSequence());
-                    if (oseq.getEnd() >= oseq.getStart())
-                    {
-                      alignment[s].setEnd(oseq.getEnd());
-                    }
-                  }
-                }
-                nwidth += swidth;
-              }
-              else
-              {
-                // place gaps.
-                throw new Error("Padding not yet implemented.");
-              }
-            }
-          }
-        }
-      }
-      return new Object[] { alignment, columnselection};
-    } else {
-      if (nvismsa.length!=1)
-        throw new Error("Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="+nvismsa.length);
-      if (nvismsa[0]!=null)
-        return new Object[] { nvismsa[0], new ColumnSelection()};
-      else
-        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;
-  }
-}
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)\r
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
+ * \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package jalview.datamodel;\r
+\r
+/**\r
+ * <p>\r
+ * Title:\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Description:\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Copyright: Copyright (c) 2004\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Company: Dundee University\r
+ * </p>\r
+ * \r
+ * @author not attributable\r
+ * @version 1.0\r
+ */\r
+public class AlignmentView\r
+{\r
+  /**\r
+   * Transient object compactly representing a 'view' of an alignment - with\r
+   * discontinuities marked.\r
+   */\r
+  private SeqCigar[] sequences = null;\r
+\r
+  private int[] contigs = null;\r
+\r
+  private int width = 0;\r
+\r
+  private int firstCol = 0;\r
+\r
+  public AlignmentView(CigarArray seqcigararray)\r
+  {\r
+    if (!seqcigararray.isSeqCigarArray())\r
+    {\r
+      throw new Error(\r
+              "Implementation Error - can only make an alignment view from a CigarArray of sequences.");\r
+    }\r
+    // contigs = seqcigararray.applyDeletions();\r
+    contigs = seqcigararray.getDeletedRegions();\r
+    sequences = seqcigararray.getSeqCigarArray();\r
+    width = seqcigararray.getWidth(); // visible width\r
+  }\r
+\r
+  /**\r
+   * Create an alignmentView where the first column corresponds with the\r
+   * 'firstcol' column of some reference alignment\r
+   * \r
+   * @param sdata\r
+   * @param firstcol\r
+   */\r
+  public AlignmentView(CigarArray sdata, int firstcol)\r
+  {\r
+    this(sdata);\r
+    firstCol = firstcol;\r
+  }\r
+\r
+  public void setSequences(SeqCigar[] sequences)\r
+  {\r
+    this.sequences = sequences;\r
+  }\r
+\r
+  public void setContigs(int[] contigs)\r
+  {\r
+    this.contigs = contigs;\r
+  }\r
+\r
+  public SeqCigar[] getSequences()\r
+  {\r
+    return sequences;\r
+  }\r
+\r
+  /**\r
+   * @see CigarArray.getDeletedRegions\r
+   * @return int[] { vis_start, sym_start, length }\r
+   */\r
+  public int[] getContigs()\r
+  {\r
+    return contigs;\r
+  }\r
+\r
+  /**\r
+   * get the full alignment and a columnselection object marking the hidden\r
+   * regions\r
+   * \r
+   * @param gapCharacter\r
+   *          char\r
+   * @return Object[] { SequenceI[], ColumnSelection}\r
+   */\r
+  public Object[] getAlignmentAndColumnSelection(char gapCharacter)\r
+  {\r
+    ColumnSelection colsel = new ColumnSelection();\r
+\r
+    return new Object[]\r
+    {\r
+        SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel,\r
+                contigs), colsel };\r
+  }\r
+\r
+  /**\r
+   * getSequenceStrings\r
+   * \r
+   * @param c\r
+   *          char\r
+   * @return String[]\r
+   */\r
+  public String[] getSequenceStrings(char c)\r
+  {\r
+    String[] seqs = new String[sequences.length];\r
+    for (int n = 0; n < sequences.length; n++)\r
+    {\r
+      String fullseq = sequences[n].getSequenceString(c);\r
+      if (contigs != null)\r
+      {\r
+        seqs[n] = "";\r
+        int p = 0;\r
+        for (int h = 0; h < contigs.length; h += 3)\r
+        {\r
+          seqs[n] += fullseq.substring(p, contigs[h + 1]);\r
+          p = contigs[h + 1] + contigs[h + 2];\r
+        }\r
+        seqs[n] += fullseq.substring(p);\r
+      }\r
+      else\r
+      {\r
+        seqs[n] = fullseq;\r
+      }\r
+    }\r
+    return seqs;\r
+  }\r
+\r
+  /**\r
+   * \r
+   * @return visible number of columns in alignment view\r
+   */\r
+  public int getWidth()\r
+  {\r
+    return width;\r
+  }\r
+\r
+  protected void setWidth(int width)\r
+  {\r
+    this.width = width;\r
+  }\r
+\r
+  /**\r
+   * get the contiguous subalignments in an alignment view.\r
+   * \r
+   * @param gapCharacter\r
+   *          char\r
+   * @return SequenceI[][]\r
+   */\r
+  public SequenceI[][] getVisibleContigs(char gapCharacter)\r
+  {\r
+    SequenceI[][] smsa;\r
+    int njobs = 1;\r
+    if (sequences == null || width <= 0)\r
+    {\r
+      return null;\r
+    }\r
+    if (contigs != null && contigs.length > 0)\r
+    {\r
+      int start = 0;\r
+      njobs = 0;\r
+      int fwidth = width;\r
+      for (int contig = 0; contig < contigs.length; contig += 3)\r
+      {\r
+        if ((contigs[contig + 1] - start) > 0)\r
+        {\r
+          njobs++;\r
+        }\r
+        fwidth += contigs[contig + 2]; // end up with full region width\r
+        // (including hidden regions)\r
+        start = contigs[contig + 1] + contigs[contig + 2];\r
+      }\r
+      if (start < fwidth)\r
+      {\r
+        njobs++;\r
+      }\r
+      smsa = new SequenceI[njobs][];\r
+      start = 0;\r
+      int j = 0;\r
+      for (int contig = 0; contig < contigs.length; contig += 3)\r
+      {\r
+        if (contigs[contig + 1] - start > 0)\r
+        {\r
+          SequenceI mseq[] = new SequenceI[sequences.length];\r
+          for (int s = 0; s < mseq.length; s++)\r
+          {\r
+            mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(\r
+                    start, contigs[contig + 1]);\r
+          }\r
+          smsa[j] = mseq;\r
+          j++;\r
+        }\r
+        start = contigs[contig + 1] + contigs[contig + 2];\r
+      }\r
+      if (start < fwidth)\r
+      {\r
+        SequenceI mseq[] = new SequenceI[sequences.length];\r
+        for (int s = 0; s < mseq.length; s++)\r
+        {\r
+          mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start,\r
+                  fwidth + 1);\r
+        }\r
+        smsa[j] = mseq;\r
+        j++;\r
+      }\r
+    }\r
+    else\r
+    {\r
+      smsa = new SequenceI[1][];\r
+      smsa[0] = new SequenceI[sequences.length];\r
+      for (int s = 0; s < sequences.length; s++)\r
+      {\r
+        smsa[0][s] = sequences[s].getSeq(gapCharacter);\r
+      }\r
+    }\r
+    return smsa;\r
+  }\r
+\r
+  /**\r
+   * return full msa and hidden regions with visible blocks replaced with new\r
+   * sub alignments\r
+   * \r
+   * @param nvismsa\r
+   *          SequenceI[][]\r
+   * @param orders\r
+   *          AlignmentOrder[] corresponding to each SequenceI[] block.\r
+   * @return Object[]\r
+   */\r
+  public Object[] getUpdatedView(SequenceI[][] nvismsa,\r
+          AlignmentOrder[] orders, char gapCharacter)\r
+  {\r
+    if (sequences == null || width <= 0)\r
+    {\r
+      throw new Error("empty view cannot be updated.");\r
+    }\r
+    if (nvismsa == null)\r
+    {\r
+      throw new Error(\r
+              "nvismsa==null. use getAlignmentAndColumnSelection() instead.");\r
+    }\r
+    if (contigs != null && contigs.length > 0)\r
+    {\r
+      SequenceI[] alignment = new SequenceI[sequences.length];\r
+      ColumnSelection columnselection = new ColumnSelection();\r
+      if (contigs != null && contigs.length > 0)\r
+      {\r
+        int start = 0;\r
+        int nwidth = 0;\r
+        int owidth = width;\r
+        int j = 0;\r
+        for (int contig = 0; contig < contigs.length; contig += 3)\r
+        {\r
+          owidth += contigs[contig + 2]; // recover final column width\r
+          if (contigs[contig + 1] - start > 0)\r
+          {\r
+            int swidth = 0; // subalignment width\r
+            if (nvismsa[j] != null)\r
+            {\r
+              SequenceI mseq[] = nvismsa[j];\r
+              AlignmentOrder order = (orders == null) ? null : orders[j];\r
+              j++;\r
+              if (mseq.length != sequences.length)\r
+              {\r
+                throw new Error(\r
+                        "Mismatch between number of sequences in block "\r
+                                + j + " (" + mseq.length\r
+                                + ") and the original view ("\r
+                                + sequences.length + ")");\r
+              }\r
+              swidth = mseq[0].getLength(); // JBPNote: could ensure padded\r
+              // here.\r
+              for (int s = 0; s < mseq.length; s++)\r
+              {\r
+                if (alignment[s] == null)\r
+                {\r
+                  alignment[s] = mseq[s];\r
+                }\r
+                else\r
+                {\r
+                  alignment[s].setSequence(alignment[s]\r
+                          .getSequenceAsString()\r
+                          + mseq[s].getSequenceAsString());\r
+                  if (mseq[s].getStart() <= mseq[s].getEnd())\r
+                  {\r
+                    alignment[s].setEnd(mseq[s].getEnd());\r
+                  }\r
+                  if (order != null)\r
+                  {\r
+                    order.updateSequence(mseq[s], alignment[s]);\r
+                  }\r
+                }\r
+              }\r
+            }\r
+            else\r
+            {\r
+              // recover original alignment block or place gaps\r
+              if (true)\r
+              {\r
+                // recover input data\r
+                for (int s = 0; s < sequences.length; s++)\r
+                {\r
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter)\r
+                          .getSubSequence(start, contigs[contig + 1]);\r
+                  if (swidth < oseq.getLength())\r
+                  {\r
+                    swidth = oseq.getLength();\r
+                  }\r
+                  if (alignment[s] == null)\r
+                  {\r
+                    alignment[s] = oseq;\r
+                  }\r
+                  else\r
+                  {\r
+                    alignment[s].setSequence(alignment[s]\r
+                            .getSequenceAsString()\r
+                            + oseq.getSequenceAsString());\r
+                    if (oseq.getEnd() >= oseq.getStart())\r
+                    {\r
+                      alignment[s].setEnd(oseq.getEnd());\r
+                    }\r
+                  }\r
+                }\r
+\r
+              }\r
+              j++;\r
+            }\r
+            nwidth += swidth;\r
+          }\r
+          // advance to begining of visible region\r
+          start = contigs[contig + 1] + contigs[contig + 2];\r
+          // add hidden segment to right of next region\r
+          for (int s = 0; s < sequences.length; s++)\r
+          {\r
+            SequenceI hseq = sequences[s].getSeq(gapCharacter)\r
+                    .getSubSequence(contigs[contig + 1], start);\r
+            if (alignment[s] == null)\r
+            {\r
+              alignment[s] = hseq;\r
+            }\r
+            else\r
+            {\r
+              alignment[s].setSequence(alignment[s].getSequenceAsString()\r
+                      + hseq.getSequenceAsString());\r
+              if (hseq.getEnd() >= hseq.getStart())\r
+              {\r
+                alignment[s].setEnd(hseq.getEnd());\r
+              }\r
+            }\r
+          }\r
+          // mark hidden segment as hidden in the new alignment\r
+          columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2]\r
+                  - 1);\r
+          nwidth += contigs[contig + 2];\r
+        }\r
+        // Do final segment - if it exists\r
+        if (j < nvismsa.length)\r
+        {\r
+          int swidth = 0;\r
+          if (nvismsa[j] != null)\r
+          {\r
+            SequenceI mseq[] = nvismsa[j];\r
+            AlignmentOrder order = (orders != null) ? orders[j] : null;\r
+            swidth = mseq[0].getLength();\r
+            for (int s = 0; s < mseq.length; s++)\r
+            {\r
+              if (alignment[s] == null)\r
+              {\r
+                alignment[s] = mseq[s];\r
+              }\r
+              else\r
+              {\r
+                alignment[s].setSequence(alignment[s].getSequenceAsString()\r
+                        + mseq[s].getSequenceAsString());\r
+                if (mseq[s].getEnd() >= mseq[s].getStart())\r
+                {\r
+                  alignment[s].setEnd(mseq[s].getEnd());\r
+                }\r
+                if (order != null)\r
+                {\r
+                  order.updateSequence(mseq[s], alignment[s]);\r
+                }\r
+              }\r
+            }\r
+          }\r
+          else\r
+          {\r
+            if (start < owidth)\r
+            {\r
+              // recover input data or place gaps\r
+              if (true)\r
+              {\r
+                // recover input data\r
+                for (int s = 0; s < sequences.length; s++)\r
+                {\r
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter)\r
+                          .getSubSequence(start, owidth + 1);\r
+                  if (swidth < oseq.getLength())\r
+                  {\r
+                    swidth = oseq.getLength();\r
+                  }\r
+                  if (alignment[s] == null)\r
+                  {\r
+                    alignment[s] = oseq;\r
+                  }\r
+                  else\r
+                  {\r
+                    alignment[s].setSequence(alignment[s]\r
+                            .getSequenceAsString()\r
+                            + oseq.getSequenceAsString());\r
+                    if (oseq.getEnd() >= oseq.getStart())\r
+                    {\r
+                      alignment[s].setEnd(oseq.getEnd());\r
+                    }\r
+                  }\r
+                }\r
+                nwidth += swidth;\r
+              }\r
+              else\r
+              {\r
+                // place gaps.\r
+                throw new Error("Padding not yet implemented.");\r
+              }\r
+            }\r
+          }\r
+        }\r
+      }\r
+      return new Object[]\r
+      { alignment, columnselection };\r
+    }\r
+    else\r
+    {\r
+      if (nvismsa.length != 1)\r
+      {\r
+        throw new Error(\r
+                "Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="\r
+                        + nvismsa.length);\r
+      }\r
+      if (nvismsa[0] != null)\r
+      {\r
+        return new Object[]\r
+        { nvismsa[0], new ColumnSelection() };\r
+      }\r
+      else\r
+      {\r
+        return getAlignmentAndColumnSelection(gapCharacter);\r
+      }\r
+    }\r
+  }\r
+\r
+  /**\r
+   * returns simple array of start end positions of visible range on alignment.\r
+   * vis_start and vis_end are inclusive - use\r
+   * SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence\r
+   * from underlying alignment.\r
+   * \r
+   * @return int[] { start_i, end_i } for 1<i<n visible regions.\r
+   */\r
+  public int[] getVisibleContigs()\r
+  {\r
+    if (contigs != null && contigs.length > 0)\r
+    {\r
+      int start = 0;\r
+      int nvis = 0;\r
+      int fwidth = width;\r
+      for (int contig = 0; contig < contigs.length; contig += 3)\r
+      {\r
+        if ((contigs[contig + 1] - start) > 0)\r
+        {\r
+          nvis++;\r
+        }\r
+        fwidth += contigs[contig + 2]; // end up with full region width\r
+        // (including hidden regions)\r
+        start = contigs[contig + 1] + contigs[contig + 2];\r
+      }\r
+      if (start < fwidth)\r
+      {\r
+        nvis++;\r
+      }\r
+      int viscontigs[] = new int[nvis * 2];\r
+      nvis = 0;\r
+      start = 0;\r
+      for (int contig = 0; contig < contigs.length; contig += 3)\r
+      {\r
+        if ((contigs[contig + 1] - start) > 0)\r
+        {\r
+          viscontigs[nvis] = start;\r
+          viscontigs[nvis + 1] = contigs[contig + 1] - 1; // end is inclusive\r
+          nvis += 2;\r
+        }\r
+        start = contigs[contig + 1] + contigs[contig + 2];\r
+      }\r
+      if (start < fwidth)\r
+      {\r
+        viscontigs[nvis] = start;\r
+        viscontigs[nvis + 1] = fwidth; // end is inclusive\r
+        nvis += 2;\r
+      }\r
+      return viscontigs;\r
+    }\r
+    else\r
+    {\r
+      return new int[]\r
+      { 0, width };\r
+    }\r
+  }\r
+\r
+  /**\r
+   * \r
+   * @return position of first visible column of AlignmentView within its\r
+   *         parent's alignment reference frame\r
+   */\r
+  public int getAlignmentOrigin()\r
+  {\r
+    // TODO Auto-generated method stub\r
+    return firstCol;\r
+  }\r
+}\r