merge from 2_4_Release branch
[jalview.git] / src / jalview / datamodel / CigarBase.java
index d44d599..b0efe6c 100644 (file)
@@ -1,17 +1,17 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\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
+ * \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
  * as published by the Free Software Foundation; either version 2\r
  * of the License, or (at your option) any later version.\r
- *\r
+ * \r
  * This program is distributed in the hope that it will be useful,\r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
  * GNU General Public License for more details.\r
- *\r
+ * \r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
@@ -23,9 +23,8 @@ import java.util.*;
 public abstract class CigarBase\r
 {\r
   /**\r
-   * Base class for compact idiosyncratic representation of gaps and aligned residues\r
-   * Regards to Tom Oldfield for his DynamicArray class.\r
-   * 17th July 2006\r
+   * Base class for compact idiosyncratic representation of gaps and aligned\r
+   * residues Regards to Tom Oldfield for his DynamicArray class. 17th July 2006\r
    * Not thread safe.\r
    */\r
   public CigarBase()\r
@@ -34,27 +33,44 @@ public abstract class CigarBase
   }\r
 \r
   protected int length = 0;\r
-  protected int _inc_length = 10; // extension range for addition of new operations\r
+\r
+  protected int _inc_length = 10; // extension range for addition of new\r
+                                  // operations\r
+\r
   protected char[] operation = null;\r
+\r
   protected int[] range = null;\r
+\r
   /**\r
    * Range of Hidden residues in seq (translated as deleted in seq)\r
    */\r
-  public static final char D = 'D'; /**\r
-  * Range of insertions to seq\r
-  */\r
- public static final char I = 'I'; /**\r
-  * Range of aligned residues\r
-  */\r
- public static final char M = 'M';\r
+  public static final char D = 'D';\r
+\r
+  /**\r
+   * Range of insertions to seq\r
+   */\r
+  public static final char I = 'I';\r
+\r
+  /**\r
+   * Range of aligned residues\r
+   */\r
+  public static final char M = 'M';\r
+\r
   static protected final char _case_shift = 'a' - 'A';\r
+\r
   /**\r
-   * Ugly function to get edited sequence string, start and end symbol positions and the deletion regions as an array of int pairs\r
-   * May return null for an empty cigar string.\r
-   * May return null for deletion ranges if there are none.\r
-   * @param reference - the symbol sequence to apply the cigar operations to (or null if no sequence)\r
-   * @param GapChar - the symbol to use for Insert operations\r
-   * @return Object[] { String, int[] {start, startcol, end, endcol}, int[][3] {start, end, col} or null} the gapped sequence, first and last residue index, and the deletion ranges on the reference sequence\r
+   * Ugly function to get edited sequence string, start and end symbol positions\r
+   * and the deletion regions as an array of int pairs May return null for an\r
+   * empty cigar string. May return null for deletion ranges if there are none.\r
+   * \r
+   * @param reference -\r
+   *                the symbol sequence to apply the cigar operations to (or\r
+   *                null if no sequence)\r
+   * @param GapChar -\r
+   *                the symbol to use for Insert operations\r
+   * @return Object[] { String, int[] {start, startcol, end, endcol}, int[][3]\r
+   *         {start, end, col} or null} the gapped sequence, first and last\r
+   *         residue index, and the deletion ranges on the reference sequence\r
    */\r
   public Object[] getSequenceAndDeletions(String reference, char GapChar)\r
   {\r
@@ -62,8 +78,7 @@ public abstract class CigarBase
     int[][] deletions = new int[length][];\r
     int[][] trunc_deletions = null;\r
     StringBuffer sq = new StringBuffer();\r
-    int cursor = 0, alcursor = 0, start = 0, startpos = 0, end = 0, endpos = 0,\r
-        delcount = -1;\r
+    int cursor = 0, alcursor = 0, start = 0, startpos = 0, end = 0, endpos = 0, delcount = -1;\r
     boolean consecutive_del = false;\r
     if (length == 0)\r
     {\r
@@ -78,56 +93,55 @@ public abstract class CigarBase
     {\r
       switch (operation[i])\r
       {\r
-        case D:\r
-          if (!consecutive_del)\r
-          {\r
-            deletions[++delcount] = new int[]\r
-                {\r
-                cursor, 0, alcursor};\r
-          }\r
-          cursor += range[i];\r
-          deletions[delcount][1] = cursor - 1;\r
-          consecutive_del = true;\r
-          break;\r
-        case I:\r
-          consecutive_del = false;\r
-          for (int r = 0; r < range[i]; r++)\r
-          {\r
-            sq.append(GapChar);\r
-            alcursor++;\r
-          }\r
-          break;\r
-        case M:\r
-          consecutive_del = false;\r
-          if (modstart)\r
-          {\r
-            start = cursor;\r
-            startpos = alcursor;\r
-            modstart = false;\r
-          }\r
-          if (reference != null)\r
+      case D:\r
+        if (!consecutive_del)\r
+        {\r
+          deletions[++delcount] = new int[]\r
+          { cursor, 0, alcursor };\r
+        }\r
+        cursor += range[i];\r
+        deletions[delcount][1] = cursor - 1;\r
+        consecutive_del = true;\r
+        break;\r
+      case I:\r
+        consecutive_del = false;\r
+        for (int r = 0; r < range[i]; r++)\r
+        {\r
+          sq.append(GapChar);\r
+          alcursor++;\r
+        }\r
+        break;\r
+      case M:\r
+        consecutive_del = false;\r
+        if (modstart)\r
+        {\r
+          start = cursor;\r
+          startpos = alcursor;\r
+          modstart = false;\r
+        }\r
+        if (reference != null)\r
+        {\r
+          int sbend = cursor + range[i];\r
+          if (sbend > rlength)\r
           {\r
-            int sbend = cursor + range[i];\r
-            if (sbend > rlength)\r
+            sq.append(reference.substring(cursor, rlength));\r
+            while (sbend-- >= rlength)\r
             {\r
-              sq.append(reference.substring(cursor, rlength));\r
-              while (sbend-- >= rlength)\r
-              {\r
-                sq.append(GapChar);\r
-              }\r
-            }\r
-            else\r
-            {\r
-              sq.append(reference.substring(cursor, sbend));\r
+              sq.append(GapChar);\r
             }\r
           }\r
-          alcursor += range[i];\r
-          cursor += range[i];\r
-          end = cursor - 1;\r
-          endpos = alcursor;\r
-          break;\r
-        default:\r
-          throw new Error("Unknown SeqCigar operation '" + operation[i] + "'");\r
+          else\r
+          {\r
+            sq.append(reference.substring(cursor, sbend));\r
+          }\r
+        }\r
+        alcursor += range[i];\r
+        cursor += range[i];\r
+        end = cursor - 1;\r
+        endpos = alcursor;\r
+        break;\r
+      default:\r
+        throw new Error("Unknown SeqCigar operation '" + operation[i] + "'");\r
       }\r
     }\r
     if (++delcount > 0)\r
@@ -137,11 +151,8 @@ public abstract class CigarBase
     }\r
     deletions = null;\r
     return new Object[]\r
-        {\r
-        ( (reference != null) ? sq.toString() : null),\r
-        new int[]\r
-        {\r
-        start, startpos, end, endpos}, trunc_deletions};\r
+    { ((reference != null) ? sq.toString() : null), new int[]\r
+    { start, startpos, end, endpos }, trunc_deletions };\r
   }\r
 \r
   protected void compact_operations()\r
@@ -174,19 +185,23 @@ public abstract class CigarBase
 \r
   /**\r
    * turn a cigar string into a series of operation range pairs\r
-   * @param cigarString String\r
+   * \r
+   * @param cigarString\r
+   *                String\r
    * @return object[] {char[] operation, int[] range}\r
-   * @throws java.lang.Exception for improperly formated cigar strings or ones with unknown operations\r
+   * @throws java.lang.Exception\r
+   *                 for improperly formated cigar strings or ones with unknown\r
+   *                 operations\r
    */\r
   public static Object[] parseCigarString(String cigarString)\r
-      throws Exception\r
+          throws Exception\r
   {\r
     int ops = 0;\r
     for (int i = 0, l = cigarString.length(); i < l; i++)\r
     {\r
       char c = cigarString.charAt(i);\r
-      if (c == M || c == (M - _case_shift) || c == I || c == (I - _case_shift) ||\r
-          c == D || c == (D - _case_shift))\r
+      if (c == M || c == (M - _case_shift) || c == I\r
+              || c == (I - _case_shift) || c == D || c == (D - _case_shift))\r
       {\r
         ops++;\r
       }\r
@@ -202,8 +217,7 @@ public abstract class CigarBase
       do\r
       {\r
         c = cigarString.charAt(j++);\r
-      }\r
-      while (c >= '0' && c <= '9' && j < l);\r
+      } while (c >= '0' && c <= '9' && j < l);\r
       if (j >= l && c >= '0' && c <= '9')\r
       {\r
         throw new Exception("Unterminated cigar string.");\r
@@ -213,8 +227,7 @@ public abstract class CigarBase
         String rangeint = cigarString.substring(i, j - 1);\r
         range[op] = Integer.parseInt(rangeint);\r
         i = j;\r
-      }\r
-      catch (Exception e)\r
+      } catch (Exception e)\r
       {\r
         throw new Error("Implementation bug in parseCigarString");\r
       }\r
@@ -222,26 +235,28 @@ public abstract class CigarBase
       {\r
         c -= _case_shift;\r
       }\r
-      if ( (c == M || c == I || c == D))\r
+      if ((c == M || c == I || c == D))\r
       {\r
         operation[op++] = c;\r
       }\r
       else\r
       {\r
-        throw new Exception("Unexpected operation '" + c +\r
-                            "' in cigar string (position " + i + " in '" +\r
-                            cigarString + "'");\r
+        throw new Exception("Unexpected operation '" + c\r
+                + "' in cigar string (position " + i + " in '"\r
+                + cigarString + "'");\r
       }\r
     }\r
     return new Object[]\r
-        {\r
-        operation, range};\r
+    { operation, range };\r
   }\r
 \r
   /**\r
    * add an operation to cigar string\r
-   * @param op char\r
-   * @param range int\r
+   * \r
+   * @param op\r
+   *                char\r
+   * @param range\r
+   *                int\r
    */\r
   public void addOperation(char op, int range)\r
   {\r
@@ -255,7 +270,8 @@ public abstract class CigarBase
     }\r
     if (range <= 0)\r
     {\r
-      throw new Error("Invalid range string (must be non-zero positive number)");\r
+      throw new Error(\r
+              "Invalid range string (must be non-zero positive number)");\r
     }\r
     int lngth = 0;\r
     if (operation == null)\r
@@ -274,7 +290,7 @@ public abstract class CigarBase
       System.arraycopy(rng, 0, this.range, 0, length);\r
       rng = null;\r
     }\r
-    if ( (length > 0) && (operation[length - 1] == op))\r
+    if ((length > 0) && (operation[length - 1] == op))\r
     {\r
       length--; // modify existing operation.\r
     }\r
@@ -287,130 +303,73 @@ public abstract class CigarBase
   }\r
 \r
   /**\r
-   * semi-efficient insert an operation on the current cigar string set at column pos (from 1)\r
-   * NOTE: Insertion operations simply extend width of cigar result - affecting registration of alignment\r
-   * Deletion ops will shorten length of result - and affect registration of alignment\r
-   * Match ops will also affect length of result - affecting registration of alignment\r
-   * (ie "10M".insert(4,I,3)->"4M3I3M") - (replace?)\r
-   * (ie "10M".insert(4,D,3)->"4M3D3M") - (shortens alignment)\r
-   * (ie "5I5M".insert(4,I,3)->"8I5M") - real insertion\r
-   * (ie "5I5M".insert(4,D,3)->"4I2D3M") - shortens aligment - I's are removed, Ms changed to Ds\r
-   * (ie "10M".insert(4,M,3)->"13M")  - lengthens - Is changed to M, Ds changed to M.\r
-   * (ie "5I5M".insert(4,M,3)->"4I8M") - effectively shifts sequence left by 1 residue and extends it by 3\r
-   * ( "10D5M".insert(-1,M,3)->"3M7D5M")\r
-   * ( "10D5M".insert(0,M,3)->"7D8M")\r
-   * ( "10D5M".insert(1,M,3)->"10D8M")\r
-   *\r
-   * ( "1M10D5M".insert(0,M,3)->"1M10D8M")\r
-   * ( "1M10D5M".insert(1,M,3)->"\r
-   *\r
+   * semi-efficient insert an operation on the current cigar string set at\r
+   * column pos (from 1) NOTE: Insertion operations simply extend width of cigar\r
+   * result - affecting registration of alignment Deletion ops will shorten\r
+   * length of result - and affect registration of alignment Match ops will also\r
+   * affect length of result - affecting registration of alignment (ie\r
+   * "10M".insert(4,I,3)->"4M3I3M") - (replace?) (ie\r
+   * "10M".insert(4,D,3)->"4M3D3M") - (shortens alignment) (ie\r
+   * "5I5M".insert(4,I,3)->"8I5M") - real insertion (ie\r
+   * "5I5M".insert(4,D,3)->"4I2D3M") - shortens aligment - I's are removed, Ms\r
+   * changed to Ds (ie "10M".insert(4,M,3)->"13M") - lengthens - Is changed to\r
+   * M, Ds changed to M. (ie "5I5M".insert(4,M,3)->"4I8M") - effectively shifts\r
+   * sequence left by 1 residue and extends it by 3 (\r
+   * "10D5M".insert(-1,M,3)->"3M7D5M") ( "10D5M".insert(0,M,3)->"7D8M") (\r
+   * "10D5M".insert(1,M,3)->"10D8M")\r
+   *  ( "1M10D5M".insert(0,M,3)->"1M10D8M") ( "1M10D5M".insert(1,M,3)->"\r
+   * \r
    * if pos is beyond width - I operations are added before the operation\r
-   * @param pos int -1, 0-length of visible region, or greater to append new ops (with insertions in between)\r
-   * @param op char\r
-   * @param range int\r
-     public void addOperationAt(int pos, char op, int range)\r
-     {\r
-   int cursor = -1; // mark the position for the current operation being edited.\r
-    int o = 0;\r
-    boolean last_d = false; // previous op was a deletion.\r
-    if (pos < -1)\r
-      throw new Error("pos<-1 is not supported.");\r
-    while (o<length) {\r
-      if (operation[o] != D)\r
-      {\r
-        if ( (cursor + this.range[o]) < pos)\r
-        {\r
-          cursor += this.range[o];\r
-          o++;\r
-          last_d=false;\r
-        }\r
-        else\r
-        {\r
-          break;\r
-        }\r
-      }\r
-      else {\r
-        last_d=true;\r
-        o++;\r
-      }\r
-    }\r
-    if (o==length) {\r
-      // must insert more operations before pos\r
-      if (pos-cursor>0)\r
-        addInsertion(pos-cursor);\r
-      // then just add the new operation. Regardless of what it is.\r
-      addOperation(op, range);\r
-    } else {\r
-      int diff = pos - cursor;\r
-\r
-      int e_length = length-o; // new edit operation array length.\r
-      // diff<0 - can only happen before first insertion or match. - affects op and all following\r
-      // dif==0 - only when at first position of existing op -\r
-      // diff>0 - must preserve some existing operations\r
-      int[] e_range = new int[e_length];\r
-      System.arraycopy(this.range, o, e_range, 0, e_length);\r
-      char[] e_op = new char[e_length];\r
-      System.arraycopy(this.operation, o, e_op, 0, e_length);\r
-      length = o; // can now use add_operation to extend list.\r
-      int e_o=0; // current operation being edited.\r
-      switch (op) {\r
-        case M:\r
-          switch (e_op[e_o])\r
-          {\r
-            case M:\r
-              if (last_d && diff <= 0)\r
-              {\r
-                // reduce D's, if possible\r
-                if (range<=this.range[o-1]) {\r
-                  this.range[o - 1] -= range;\r
-                } else {\r
-                  this.range[o-1]=0;\r
-                }\r
-                if (this.range[o-1]==0)\r
-                  o--; // lose this op.\r
-              }\r
-              e_range[e_o] += range; // just add more matched residues\r
-              break;\r
-            case I:\r
-              // change from insertion to match\r
-              if (last_d && diff<=0)\r
-              {\r
-                // reduce D's, if possible\r
-                if (range<=this.range[o-1]) {\r
-                  this.range[o - 1] -= range;\r
-                } else {\r
-                  this.range[o-1]=0;\r
-                }\r
-                if (this.range[o-1]==0)\r
-                  o--; // lose this op.\r
-              }\r
-              e_range[e_o]\r
-                    break;\r
-                default:\r
-                  throw new Inp\r
-                      }\r
-\r
-                      break;\r
-                case I:\r
-                  break;\r
-                case D:\r
-              }\r
-          break;\r
-        default:\r
-   throw new Error("Implementation Error: Unknown operation in addOperation!");\r
-      }\r
-      // finally, add remaining ops.\r
-      while (e_o<e_length) {\r
-        addOperation(e_op[e_o], e_range[e_o]);\r
-        e_o++;\r
-      }\r
-    }\r
-     }\r
-   **/\r
+   * \r
+   * @param pos\r
+   *                int -1, 0-length of visible region, or greater to append new\r
+   *                ops (with insertions in between)\r
+   * @param op\r
+   *                char\r
+   * @param range\r
+   *                int public void addOperationAt(int pos, char op, int range) {\r
+   *                int cursor = -1; // mark the position for the current\r
+   *                operation being edited. int o = 0; boolean last_d = false; //\r
+   *                previous op was a deletion. if (pos < -1) throw new\r
+   *                Error("pos<-1 is not supported."); while (o<length) { if\r
+   *                (operation[o] != D) { if ( (cursor + this.range[o]) < pos) {\r
+   *                cursor += this.range[o]; o++; last_d=false; } else { break; } }\r
+   *                else { last_d=true; o++; } } if (o==length) { // must insert\r
+   *                more operations before pos if (pos-cursor>0)\r
+   *                addInsertion(pos-cursor); // then just add the new\r
+   *                operation. Regardless of what it is. addOperation(op,\r
+   *                range); } else { int diff = pos - cursor;\r
+   * \r
+   * int e_length = length-o; // new edit operation array length. // diff<0 -\r
+   * can only happen before first insertion or match. - affects op and all\r
+   * following // dif==0 - only when at first position of existing op - //\r
+   * diff>0 - must preserve some existing operations int[] e_range = new\r
+   * int[e_length]; System.arraycopy(this.range, o, e_range, 0, e_length);\r
+   * char[] e_op = new char[e_length]; System.arraycopy(this.operation, o, e_op,\r
+   * 0, e_length); length = o; // can now use add_operation to extend list. int\r
+   * e_o=0; // current operation being edited. switch (op) { case M: switch\r
+   * (e_op[e_o]) { case M: if (last_d && diff <= 0) { // reduce D's, if possible\r
+   * if (range<=this.range[o-1]) { this.range[o - 1] -= range; } else {\r
+   * this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose this op. }\r
+   * e_range[e_o] += range; // just add more matched residues break; case I: //\r
+   * change from insertion to match if (last_d && diff<=0) { // reduce D's, if\r
+   * possible if (range<=this.range[o-1]) { this.range[o - 1] -= range; } else {\r
+   * this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose this op. }\r
+   * e_range[e_o] break; default: throw new Inp }\r
+   * \r
+   * break; case I: break; case D: } break; default: throw new\r
+   * Error("Implementation Error: Unknown operation in addOperation!"); } //\r
+   * finally, add remaining ops. while (e_o<e_length) { addOperation(e_op[e_o],\r
+   * e_range[e_o]); e_o++; } } }\r
+   */\r
   /**\r
-   * Mark residues from start to end (inclusive) as deleted from the alignment, and removes any insertions.\r
-   * @param start int\r
-   * @param end int\r
+   * Mark residues from start to end (inclusive) as deleted from the alignment,\r
+   * and removes any insertions.\r
+   * \r
+   * @param start\r
+   *                int\r
+   * @param end\r
+   *                int\r
    * @return deleted int - number of symbols marked as deleted\r
    */\r
   public int deleteRange(int start, int end)\r
@@ -423,7 +382,8 @@ public abstract class CigarBase
     }\r
     if (start < 0 || start > end)\r
     {\r
-      throw new Error("Implementation Error: deleteRange out of bounds: start must be non-negative and less than end.");\r
+      throw new Error(\r
+              "Implementation Error: deleteRange out of bounds: start must be non-negative and less than end.");\r
     }\r
     // find beginning\r
     int cursor = 0; // mark the position for the current operation being edited.\r
@@ -449,7 +409,7 @@ public abstract class CigarBase
       int remain = oldrange[o]; // number of op characters left to edit\r
       if (!editing)\r
       {\r
-        if ( (cursor + remain) <= start)\r
+        if ((cursor + remain) <= start)\r
         {\r
           addOperation(oldops[o], oldrange[o]);\r
           cursor += oldrange[o++];\r
@@ -468,37 +428,37 @@ public abstract class CigarBase
       {\r
         switch (oldops[o])\r
         {\r
-          case M:\r
-            if (rlength > remain)\r
-            {\r
-              addDeleted(remain);\r
-              deleted += remain;\r
-            }\r
-            else\r
-            {\r
-              deleted += rlength;\r
-              addDeleted(rlength);\r
-              if (remain - rlength > 0)\r
-              {\r
-                this.addOperation(M, remain - rlength); // add remaining back.\r
-              }\r
-              rlength = 0;\r
-              remain = 0;\r
-            }\r
-            break;\r
-          case I:\r
+        case M:\r
+          if (rlength > remain)\r
+          {\r
+            addDeleted(remain);\r
+            deleted += remain;\r
+          }\r
+          else\r
+          {\r
+            deleted += rlength;\r
+            addDeleted(rlength);\r
             if (remain - rlength > 0)\r
             {\r
-              // only remove some gaps\r
-              addInsertion(remain - rlength);\r
-              rlength = 0;\r
+              this.addOperation(M, remain - rlength); // add remaining back.\r
             }\r
-            break;\r
-          case D:\r
-            throw new Error("Implementation error."); // do nothing;\r
-          default:\r
-            throw new Error("Implementation Error! Unknown operation '" +\r
-                            oldops[o] + "'");\r
+            rlength = 0;\r
+            remain = 0;\r
+          }\r
+          break;\r
+        case I:\r
+          if (remain - rlength > 0)\r
+          {\r
+            // only remove some gaps\r
+            addInsertion(remain - rlength);\r
+            rlength = 0;\r
+          }\r
+          break;\r
+        case D:\r
+          throw new Error("Implementation error."); // do nothing;\r
+        default:\r
+          throw new Error("Implementation Error! Unknown operation '"\r
+                  + oldops[o] + "'");\r
         }\r
         rlength -= remain;\r
         remain = oldrange[++o]; // number of op characters left to edit\r
@@ -509,16 +469,17 @@ public abstract class CigarBase
     {\r
       addOperation(oldops[o], oldrange[o++]);\r
     }\r
-    //if (cursor<(start+1)) {\r
+    // if (cursor<(start+1)) {\r
     // ran out of ops - nothing to do here ?\r
     // addInsertion(start-cursor);\r
-    //}\r
+    // }\r
     return deleted;\r
   }\r
 \r
   /**\r
-   * Deleted regions mean that there will be discontinuous sequence numbering in the\r
-   * sequence returned by getSeq(char).\r
+   * Deleted regions mean that there will be discontinuous sequence numbering in\r
+   * the sequence returned by getSeq(char).\r
+   * \r
    * @return true if there deletions\r
    */\r
   public boolean hasDeletedRegions()\r
@@ -535,6 +496,7 @@ public abstract class CigarBase
 \r
   /**\r
    * enumerate the ranges on seq that are marked as deleted in this cigar\r
+   * \r
    * @return int[] { vis_start, sym_start, length }\r
    */\r
   public int[] getDeletedRegions()\r
@@ -549,15 +511,15 @@ public abstract class CigarBase
     {\r
       switch (operation[i])\r
       {\r
-        case M:\r
-          cursor += range[i];\r
-        case I:\r
-          vcursor += range[i];\r
-          break;\r
-        case D:\r
-          dr.addElement(new int[]\r
-                        {vcursor, cursor, range[i]});\r
-          cursor += range[i];\r
+      case M:\r
+        cursor += range[i];\r
+      case I:\r
+        vcursor += range[i];\r
+        break;\r
+      case D:\r
+        dr.addElement(new int[]\r
+        { vcursor, cursor, range[i] });\r
+        cursor += range[i];\r
       }\r
     }\r
     if (dr.size() == 0)\r
@@ -577,7 +539,9 @@ public abstract class CigarBase
 \r
   /**\r
    * sum of ranges in cigar string\r
-   * @return int number of residues hidden, matched, or gaps inserted into sequence\r
+   * \r
+   * @return int number of residues hidden, matched, or gaps inserted into\r
+   *         sequence\r
    */\r
   public int getFullWidth()\r
   {\r
@@ -594,6 +558,7 @@ public abstract class CigarBase
 \r
   /**\r
    * Visible length of aligned sequence\r
+   * \r
    * @return int length of including gaps and less hidden regions\r
    */\r
   public int getWidth()\r
@@ -614,7 +579,9 @@ public abstract class CigarBase
 \r
   /**\r
    * mark a range of inserted residues\r
-   * @param range int\r
+   * \r
+   * @param range\r
+   *                int\r
    */\r
   public void addInsertion(int range)\r
   {\r
@@ -623,7 +590,9 @@ public abstract class CigarBase
 \r
   /**\r
    * mark the next range residues as hidden (not aligned) or deleted\r
-   * @param range int\r
+   * \r
+   * @param range\r
+   *                int\r
    */\r
   public void addDeleted(int range)\r
   {\r
@@ -633,64 +602,30 @@ public abstract class CigarBase
   /**\r
    * Modifies operation list to delete columns from start to end (inclusive)\r
    * editing will remove insertion operations, and convert matches to deletions\r
-   * @param start alignment column\r
-   * @param end alignment column\r
-   * @return boolean true if residues were marked as deleted.\r
-     public boolean deleteRange(int start, int end)\r
-     {\r
-    boolean deleted = false;\r
-    int op = 0, prevop = -1, firstm = -1,\r
-        lastm = -1, postop = -1;\r
-    int width = 0; // zero'th column\r
-    if (length > 0)\r
-    {\r
-      // find operation bracketing start of the range\r
-      do\r
-      {\r
-        if (operation[op] != D)\r
-        {\r
-          width += range[prevop = op];\r
-        }\r
-        op++;\r
-      }\r
-      while (op < length && width < start);\r
-    }\r
-    if (width < start)\r
-    {\r
-      // run off end - add more operations up to deletion.\r
-      addInsertion(start - width);\r
-    }\r
-    else\r
-    {\r
-      // edit existing operations.\r
-      op = prevop;\r
-      width -= range[prevop];\r
-      int[] oldrange = range;\r
-      char[] oldops = operation;\r
-      range = new int[oldrange.length];\r
-      operation = new char[oldops.length];\r
-      if (op < length)\r
-      {\r
-        do\r
-        {\r
-          if (operation[op] != D)\r
-          {\r
-            width += range[postop = op];\r
-          }\r
-          op++;\r
-        }\r
-        while (op < length && width <= end);\r
-      }\r
-    }\r
-    if (deleted == true)\r
-    {\r
-      addDeleted(end - start + 1);\r
-    }\r
-    return deleted;\r
-     }\r
+   * \r
+   * @param start\r
+   *                alignment column\r
+   * @param end\r
+   *                alignment column\r
+   * @return boolean true if residues were marked as deleted. public boolean\r
+   *         deleteRange(int start, int end) { boolean deleted = false; int op =\r
+   *         0, prevop = -1, firstm = -1, lastm = -1, postop = -1; int width =\r
+   *         0; // zero'th column if (length > 0) { // find operation bracketing\r
+   *         start of the range do { if (operation[op] != D) { width +=\r
+   *         range[prevop = op]; } op++; } while (op < length && width < start); }\r
+   *         if (width < start) { // run off end - add more operations up to\r
+   *         deletion. addInsertion(start - width); } else { // edit existing\r
+   *         operations. op = prevop; width -= range[prevop]; int[] oldrange =\r
+   *         range; char[] oldops = operation; range = new int[oldrange.length];\r
+   *         operation = new char[oldops.length]; if (op < length) { do { if\r
+   *         (operation[op] != D) { width += range[postop = op]; } op++; } while\r
+   *         (op < length && width <= end); } } if (deleted == true) {\r
+   *         addDeleted(end - start + 1); } return deleted; }\r
    */\r
   /**\r
-   * Return an ENSEMBL style cigar string where D may indicates excluded parts of seq\r
+   * Return an ENSEMBL style cigar string where D may indicates excluded parts\r
+   * of seq\r
+   * \r
    * @return String of form ([0-9]+[IMD])+\r
    */\r
   public String getCigarstring()\r