applied 2009 GPL license
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index ad4e895..bd8c18f 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)\r
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  * \r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
 package jalview.datamodel;\r
 \r
 /**\r
- * <p>Title: </p>\r
- *\r
- * <p>Description: </p>\r
- *\r
- * <p>Copyright: Copyright (c) 2004</p>\r
- *\r
- * <p>Company: Dundee University</p>\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 discontinuities marked.\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("Implementation Error - can only make an alignment view from a CigarArray of sequences.");\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.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 'firstcol' column of some reference alignment\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
@@ -87,8 +103,11 @@ public class AlignmentView
   }\r
 \r
   /**\r
-   * get the full alignment and a columnselection object marking the hidden regions\r
-   * @param gapCharacter char\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
@@ -96,15 +115,16 @@ public class AlignmentView
     ColumnSelection colsel = new ColumnSelection();\r
 \r
     return new Object[]\r
-        {\r
+    {\r
         SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel,\r
-                                          contigs), colsel};\r
+                contigs), colsel };\r
   }\r
 \r
   /**\r
    * getSequenceStrings\r
-   *\r
-   * @param c char\r
+   * \r
+   * @param c\r
+   *                char\r
    * @return String[]\r
    */\r
   public String[] getSequenceStrings(char c)\r
@@ -133,7 +153,7 @@ public class AlignmentView
   }\r
 \r
   /**\r
-   *\r
+   * \r
    * @return visible number of columns in alignment view\r
    */\r
   public int getWidth()\r
@@ -148,7 +168,9 @@ public class AlignmentView
 \r
   /**\r
    * get the contiguous subalignments in an alignment view.\r
-   * @param gapCharacter char\r
+   * \r
+   * @param gapCharacter\r
+   *                char\r
    * @return SequenceI[][]\r
    */\r
   public SequenceI[][] getVisibleContigs(char gapCharacter)\r
@@ -166,11 +188,12 @@ public class AlignmentView
       int fwidth = width;\r
       for (int contig = 0; contig < contigs.length; contig += 3)\r
       {\r
-        if ( (contigs[contig + 1] - start) > 0)\r
+        if ((contigs[contig + 1] - start) > 0)\r
         {\r
           njobs++;\r
         }\r
-        fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions)\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
@@ -187,8 +210,8 @@ public class AlignmentView
           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
-                contigs[contig + 1]);\r
+            mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(\r
+                    start, contigs[contig + 1]);\r
           }\r
           smsa[j] = mseq;\r
           j++;\r
@@ -201,7 +224,7 @@ public class AlignmentView
         for (int s = 0; s < mseq.length; s++)\r
         {\r
           mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(start,\r
-              fwidth + 1);\r
+                  fwidth + 1);\r
         }\r
         smsa[j] = mseq;\r
         j++;\r
@@ -220,13 +243,17 @@ public class AlignmentView
   }\r
 \r
   /**\r
-   * return full msa and hidden regions with visible blocks replaced with new sub alignments\r
-   * @param nvismsa SequenceI[][]\r
-   * @param orders AlignmentOrder[] corresponding to each SequenceI[] block.\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, AlignmentOrder[] orders,\r
-                                 char gapCharacter)\r
+  public Object[] getUpdatedView(SequenceI[][] nvismsa,\r
+          AlignmentOrder[] orders, char gapCharacter)\r
   {\r
     if (sequences == null || width <= 0)\r
     {\r
@@ -235,7 +262,7 @@ public class AlignmentView
     if (nvismsa == null)\r
     {\r
       throw new Error(\r
-          "nvismsa==null. use getAlignmentAndColumnSelection() instead.");\r
+              "nvismsa==null. use getAlignmentAndColumnSelection() instead.");\r
     }\r
     if (contigs != null && contigs.length > 0)\r
     {\r
@@ -261,11 +288,13 @@ public class AlignmentView
               if (mseq.length != sequences.length)\r
               {\r
                 throw new Error(\r
-                    "Mismatch between number of sequences in block " + j + " (" +\r
-                    mseq.length + ") and the original view (" +\r
-                    sequences.length + ")");\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 here.\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
@@ -274,8 +303,9 @@ public class AlignmentView
                 }\r
                 else\r
                 {\r
-                  alignment[s].setSequence(alignment[s].getSequenceAsString() +\r
-                                           mseq[s].getSequenceAsString());\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
@@ -295,9 +325,8 @@ public class AlignmentView
                 // recover input data\r
                 for (int s = 0; s < sequences.length; s++)\r
                 {\r
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).\r
-                      getSubSequence(start,\r
-                                     contigs[contig + 1]);\r
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter)\r
+                          .getSubSequence(start, contigs[contig + 1]);\r
                   if (swidth < oseq.getLength())\r
                   {\r
                     swidth = oseq.getLength();\r
@@ -308,8 +337,9 @@ public class AlignmentView
                   }\r
                   else\r
                   {\r
-                    alignment[s].setSequence(alignment[s].getSequenceAsString() +\r
-                                             oseq.getSequenceAsString());\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
@@ -327,17 +357,16 @@ public class AlignmentView
           // 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).getSubSequence(\r
-                contigs[contig +\r
-                1], start);\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
+              alignment[s].setSequence(alignment[s].getSequenceAsString()\r
+                      + hseq.getSequenceAsString());\r
               if (hseq.getEnd() >= hseq.getStart())\r
               {\r
                 alignment[s].setEnd(hseq.getEnd());\r
@@ -345,7 +374,8 @@ public class AlignmentView
             }\r
           }\r
           // mark hidden segment as hidden in the new alignment\r
-          columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1);\r
+          columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2]\r
+                  - 1);\r
           nwidth += contigs[contig + 2];\r
         }\r
         // Do final segment - if it exists\r
@@ -365,8 +395,8 @@ public class AlignmentView
               }\r
               else\r
               {\r
-                alignment[s].setSequence(alignment[s].getSequenceAsString() +\r
-                                         mseq[s].getSequenceAsString());\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
@@ -388,9 +418,8 @@ public class AlignmentView
                 // recover input data\r
                 for (int s = 0; s < sequences.length; s++)\r
                 {\r
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).\r
-                      getSubSequence(start,\r
-                                     owidth + 1);\r
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter)\r
+                          .getSubSequence(start, owidth + 1);\r
                   if (swidth < oseq.getLength())\r
                   {\r
                     swidth = oseq.getLength();\r
@@ -401,8 +430,9 @@ public class AlignmentView
                   }\r
                   else\r
                   {\r
-                    alignment[s].setSequence(alignment[s].getSequenceAsString() +\r
-                                             oseq.getSequenceAsString());\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
@@ -421,21 +451,20 @@ public class AlignmentView
         }\r
       }\r
       return new Object[]\r
-          {\r
-          alignment, columnselection};\r
+      { alignment, columnselection };\r
     }\r
     else\r
     {\r
       if (nvismsa.length != 1)\r
       {\r
-        throw new Error("Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks=" +\r
-                        nvismsa.length);\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
-            {\r
-            nvismsa[0], new ColumnSelection()};\r
+        { nvismsa[0], new ColumnSelection() };\r
       }\r
       else\r
       {\r
@@ -446,7 +475,10 @@ public class AlignmentView
 \r
   /**\r
    * returns simple array of start end positions of visible range on alignment.\r
-   * vis_start and vis_end are inclusive - use SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence from underlying 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
@@ -458,11 +490,12 @@ public class AlignmentView
       int fwidth = width;\r
       for (int contig = 0; contig < contigs.length; contig += 3)\r
       {\r
-        if ( (contigs[contig + 1] - start) > 0)\r
+        if ((contigs[contig + 1] - start) > 0)\r
         {\r
           nvis++;\r
         }\r
-        fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions)\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
@@ -474,7 +507,7 @@ public class AlignmentView
       start = 0;\r
       for (int contig = 0; contig < contigs.length; contig += 3)\r
       {\r
-        if ( (contigs[contig + 1] - start) > 0)\r
+        if ((contigs[contig + 1] - start) > 0)\r
         {\r
           viscontigs[nvis] = start;\r
           viscontigs[nvis + 1] = contigs[contig + 1] - 1; // end is inclusive\r
@@ -493,14 +526,14 @@ public class AlignmentView
     else\r
     {\r
       return new int[]\r
-          {\r
-          0, width};\r
+      { 0, width };\r
     }\r
   }\r
 \r
   /**\r
-   *\r
-   * @return position of first visible column of AlignmentView within its parent's alignment reference frame\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